Created
April 29, 2017 14:38
-
-
Save dazsim/13d83d0afcdce668c8eeb1b0e171400d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.immersiveminds.beimcraft.block; | |
import com.immersiveminds.beimcraft.BeimCraft; | |
import com.immersiveminds.beimcraft.api.BlockConfig; | |
import com.immersiveminds.beimcraft.entity.ExtendedPlayer; | |
import com.immersiveminds.beimcraft.item.ItemBeimcraftArmor; | |
import com.immersiveminds.beimcraft.tile.TileBlock; | |
import net.minecraft.block.Block; | |
import net.minecraft.block.ITileEntityProvider; | |
import net.minecraft.block.material.Material; | |
import net.minecraft.client.renderer.texture.IIconRegister; | |
import net.minecraft.entity.EntityLivingBase; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.util.IIcon; | |
import net.minecraft.util.MathHelper; | |
import net.minecraft.world.World; | |
public class ConstructionBlock extends Block implements ITileEntityProvider { | |
public IIcon[] icon = new IIcon[9]; | |
protected ConstructionBlock(Material m) { | |
super(m); | |
} | |
protected ConstructionBlock(String unlocalizedName, Material material) { | |
super(material); | |
this.setBlockName(unlocalizedName); | |
this.setBlockTextureName(BeimCraft.MODID + ":" + unlocalizedName); | |
this.setCreativeTab(BeimCraft.tabBlocks); | |
this.setHardness(2.0F); | |
this.setResistance(2.0F); | |
this.setLightLevel(0.0F); | |
this.setHarvestLevel("pickaxe", 3); | |
this.setStepSound(soundTypeStone); | |
} | |
@Override | |
public void registerBlockIcons(IIconRegister reg) { | |
/*for (int i = 0; i < 6; i ++) { | |
this.icons[i] = reg.registerIcon(this.textureName + "_" + i); | |
}*/ | |
this.icon[0] = reg.registerIcon(this.textureName); | |
this.icon[8] = reg.registerIcon(this.textureName+"_brk"); | |
} | |
@Override | |
public IIcon getIcon(int side, int meta) { | |
//int i,j,k,l; | |
//World world = MinecraftServer.getServer().worldServerForDimension(0); | |
//i = this.x | |
//l=0; | |
/*TileBlock tile = (TileBlock) world.getTileEntity(i, j, k); | |
if (tile != null) | |
{ | |
l = tile.breakTimer; | |
}*/ | |
//System.out.println("meta = " + meta); | |
if (((meta >> 3) & 1)==0) | |
{ | |
return this.icon[0]; //this is a basic block | |
} else | |
{ | |
return this.icon[8]; //this block is being tested for stability/temp | |
} | |
} | |
/** | |
* Called when the block is placed in the world. | |
*/ | |
public void onBlockPlacedBy(World world, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase player, ItemStack p_149689_6_) | |
{ | |
byte b0 = 0; | |
int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; | |
if (l == 0) | |
{ | |
b0 = 2; | |
} | |
if (l == 1) | |
{ | |
b0 = 5; | |
} | |
if (l == 2) | |
{ | |
b0 = 3; | |
} | |
if (l == 3) | |
{ | |
b0 = 4; | |
} | |
world.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, b0, 3); | |
if (!world.isRemote) | |
{ | |
BlockConfig bc = BeimCraft.getBlockConfig(this.getUnlocalizedName().substring(5)); | |
ExtendedPlayer p = ExtendedPlayer.get((EntityPlayer) player); | |
//ExtendedPlayer p = ExtendedPlayer.get(Minecraft.getMinecraft().thePlayer); | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.BCOST_WATCHER,p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.BCOST_WATCHER) + bc.cost); | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.TCOST_WATCHER,p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.TCOST_WATCHER) + bc.cost); | |
//p.totalCost += bc.cost; | |
if (p.player.inventory.armorInventory[0]!=null) | |
{ | |
if (p.player.inventory.armorInventory[0].getItem() instanceof ItemBeimcraftArmor) | |
{ | |
//do not punish | |
} else | |
{ | |
//punish | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.FCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.FCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.TCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.TCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
} | |
}else | |
{ | |
//punish | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.FCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.FCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.TCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.TCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
} | |
if (p.player.inventory.armorInventory[1]!=null) | |
{ | |
if (p.player.inventory.armorInventory[1].getItem() instanceof ItemBeimcraftArmor) | |
{ | |
//do not punish | |
} else | |
{ | |
//punish | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.FCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.FCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.TCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.TCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
} | |
}else | |
{ | |
//punish | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.FCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.FCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.TCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.TCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
} | |
if (p.player.inventory.armorInventory[2]!=null) | |
{ | |
if (p.player.inventory.armorInventory[2].getItem() instanceof ItemBeimcraftArmor) | |
{ | |
//do not punish | |
} else | |
{ | |
//punish | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.FCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.FCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.TCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.TCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
} | |
}else | |
{ | |
//punish | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.FCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.FCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.TCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.TCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
} | |
if (p.player.inventory.armorInventory[3]!=null) | |
{ | |
if (p.player.inventory.armorInventory[3].getItem() instanceof ItemBeimcraftArmor) | |
{ | |
//do not punish | |
} else | |
{ | |
//punish | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.FCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.FCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.TCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.TCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
} | |
}else | |
{ | |
//punish | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.FCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.FCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
p.player.getDataWatcher().updateObject(ExtendedPlayer.TCOST_WATCHER, p.player.getDataWatcher().getWatchableObjectInt(ExtendedPlayer.TCOST_WATCHER)+BeimCraft.playerMissingArmorFine); | |
} | |
} | |
//ExtendedPlayer p = (ExtendedPlayer)player; | |
//p.blockCost += bc.cost; | |
} | |
@Override | |
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { | |
// TODO Auto-generated method stub | |
//return null; | |
BlockConfig bc = BeimCraft.getBlockConfig(this.getUnlocalizedName()); | |
if (bc!=null) | |
{ | |
return new TileBlock(bc.insulated,bc.sustainable,false,bc.insulation,bc.sustainability,0,bc.cost); | |
} else | |
return null; | |
} | |
@Override | |
public boolean hasTileEntity() { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment