diff options
| author | bspkrs <bspkrs@gmail.com> | 2013-12-16 10:15:10 -0500 |
|---|---|---|
| committer | bspkrs <bspkrs@gmail.com> | 2013-12-16 10:15:10 -0500 |
| commit | f420b194af2d3640d006d9a9ddfb0d9d35a8b0a7 (patch) | |
| tree | 7ac5b029d3b9ac83d3df8877b8a8f98a892cf3a0 /common | |
| parent | 24ff7e4f3c399a3b23c45dbdef8829d57084e443 (diff) | |
added world.isRemote checks in block methods
Diffstat (limited to 'common')
| -rw-r--r-- | common/darkknight/jewelrycraft/block/BlockMolder.java | 24 | ||||
| -rw-r--r-- | common/darkknight/jewelrycraft/block/BlockSmelter.java | 130 |
2 files changed, 99 insertions, 55 deletions
diff --git a/common/darkknight/jewelrycraft/block/BlockMolder.java b/common/darkknight/jewelrycraft/block/BlockMolder.java index f63388e..b5b8368 100644 --- a/common/darkknight/jewelrycraft/block/BlockMolder.java +++ b/common/darkknight/jewelrycraft/block/BlockMolder.java @@ -43,6 +43,9 @@ public class BlockMolder extends BlockContainer @Override public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) { + if (world.isRemote) + return true; + TileEntityMolder te = (TileEntityMolder) world.getBlockTileEntity(i, j, k); ItemStack item = entityPlayer.inventory.getCurrentItem(); if (te != null && item != null && !te.hasMold && item.itemID == ItemList.molds.itemID) @@ -61,9 +64,12 @@ public class BlockMolder extends BlockContainer } @Override - public void onBlockDestroyedByPlayer(World par1World, int i, int j, int k, int par5) + public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int par5) { - TileEntityMolder te = (TileEntityMolder) par1World.getBlockTileEntity(i, j, k); + if (world.isRemote) + return; + + TileEntityMolder te = (TileEntityMolder) world.getBlockTileEntity(i, j, k); if (te != null) { float f = this.rand.nextFloat() * 0.8F + 0.1F; @@ -71,7 +77,7 @@ public class BlockMolder extends BlockContainer float f2 = this.rand.nextFloat() * 0.8F + 0.1F; if (te.hasMold) { - EntityItem entityitem = new EntityItem(par1World, i + f, j + f1, k + f2, new ItemStack(te.mold.itemID, 1, te.mold.getItemDamage())); + EntityItem entityitem = new EntityItem(world, i + f, j + f1, k + f2, new ItemStack(te.mold.itemID, 1, te.mold.getItemDamage())); if (te.mold.hasTagCompound()) { @@ -82,11 +88,11 @@ public class BlockMolder extends BlockContainer entityitem.motionX = (float) this.rand.nextGaussian() * f3; entityitem.motionY = (float) this.rand.nextGaussian() * f3 + 0.2F; entityitem.motionZ = (float) this.rand.nextGaussian() * f3; - par1World.spawnEntityInWorld(entityitem); + world.spawnEntityInWorld(entityitem); } if (te.hasJewelBase) { - EntityItem entityitem = new EntityItem(par1World, i + f, j + f1, k + f2, new ItemStack(te.jewelBase.itemID, 1, te.jewelBase.getItemDamage())); + EntityItem entityitem = new EntityItem(world, i + f, j + f1, k + f2, new ItemStack(te.jewelBase.itemID, 1, te.jewelBase.getItemDamage())); if (te.jewelBase.hasTagCompound()) { @@ -97,7 +103,7 @@ public class BlockMolder extends BlockContainer entityitem.motionX = (float) this.rand.nextGaussian() * f3; entityitem.motionY = (float) this.rand.nextGaussian() * f3 + 0.2F; entityitem.motionZ = (float) this.rand.nextGaussian() * f3; - par1World.spawnEntityInWorld(entityitem); + world.spawnEntityInWorld(entityitem); } } } @@ -105,6 +111,9 @@ public class BlockMolder extends BlockContainer @Override public void onBlockDestroyedByExplosion(World world, int i, int j, int k, Explosion par5Explosion) { + if (world.isRemote) + return; + onBlockDestroyedByPlayer(world, i, j, k, 0); } @@ -124,6 +133,9 @@ public class BlockMolder extends BlockContainer @Override public void onBlockClicked(World world, int i, int j, int k, EntityPlayer player) { + if (world.isRemote) + return; + TileEntityMolder me = (TileEntityMolder) world.getBlockTileEntity(i, j, k); if (me != null && me.hasJewelBase) { diff --git a/common/darkknight/jewelrycraft/block/BlockSmelter.java b/common/darkknight/jewelrycraft/block/BlockSmelter.java index d4119e4..b066284 100644 --- a/common/darkknight/jewelrycraft/block/BlockSmelter.java +++ b/common/darkknight/jewelrycraft/block/BlockSmelter.java @@ -2,8 +2,6 @@ package darkknight.jewelrycraft.block; import java.util.Random; -import darkknight.jewelrycraft.tileentity.TileEntityMolder; -import darkknight.jewelrycraft.tileentity.TileEntitySmelter; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; @@ -17,61 +15,72 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.Explosion; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import darkknight.jewelrycraft.tileentity.TileEntityMolder; +import darkknight.jewelrycraft.tileentity.TileEntitySmelter; public class BlockSmelter extends BlockContainer { Random rand = new Random(); + protected BlockSmelter(int par1, Material par2Material) { super(par1, par2Material); } - + @Override public TileEntity createNewTileEntity(World world) { return new TileEntitySmelter(); } - + @Override public boolean renderAsNormalBlock() { return false; } - - public void onBlockDestroyedByPlayer(World par1World, int i, int j, int k, int par5) + + @Override + public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int par5) { - TileEntitySmelter te = (TileEntitySmelter) par1World.getBlockTileEntity(i, j, k); - if(te != null) - { + if (world.isRemote) + return; + + TileEntitySmelter te = (TileEntitySmelter) world.getBlockTileEntity(i, j, k); + if (te != null) + { float f = this.rand.nextFloat() * 0.8F + 0.1F; float f1 = this.rand.nextFloat() * 0.8F + 0.1F; float f2 = this.rand.nextFloat() * 0.8F + 0.1F; - if(te.hasMetal) + if (te.hasMetal) { - EntityItem entityitem = new EntityItem(par1World, (double)((float)i + f), (double)((float)j + f1), (double)((float)k + f2), new ItemStack(te.metal.itemID, 1, te.metal.getItemDamage())); - + EntityItem entityitem = new EntityItem(world, i + f, j + f1, k + f2, new ItemStack(te.metal.itemID, 1, te.metal.getItemDamage())); + if (te.metal.hasTagCompound()) { - entityitem.getEntityItem().setTagCompound((NBTTagCompound)te.metal.getTagCompound().copy()); + entityitem.getEntityItem().setTagCompound((NBTTagCompound) te.metal.getTagCompound().copy()); } - + float f3 = 0.05F; - entityitem.motionX = (double)((float)this.rand.nextGaussian() * f3); - entityitem.motionY = (double)((float)this.rand.nextGaussian() * f3 + 0.2F); - entityitem.motionZ = (double)((float)this.rand.nextGaussian() * f3); - par1World.spawnEntityInWorld(entityitem); + entityitem.motionX = (float) this.rand.nextGaussian() * f3; + entityitem.motionY = (float) this.rand.nextGaussian() * f3 + 0.2F; + entityitem.motionZ = (float) this.rand.nextGaussian() * f3; + world.spawnEntityInWorld(entityitem); } } } - public void onBlockDestroyedByExplosion(World world, int i, int j, int k, Explosion par5Explosion) + @Override + public void onBlockDestroyedByExplosion(World world, int i, int j, int k, Explosion par5Explosion) { onBlockDestroyedByPlayer(world, i, j, k, 0); } - + @Override public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) { + if (world.isRemote) + return true; + TileEntitySmelter te = (TileEntitySmelter) world.getBlockTileEntity(i, j, k); ItemStack item = entityPlayer.inventory.getCurrentItem(); if (te != null && !world.isRemote) @@ -89,7 +98,7 @@ public class BlockSmelter extends BlockContainer entityPlayer.addChatMessage("The Smelter contains molten " + te.moltenMetal.getDisplayName().toLowerCase().replace("ingot", "")); else if (item != null && !item.getDisplayName().contains("Ingot")) entityPlayer.addChatMessage("The item needs to be an ingot!"); - + if (te.hasMetal && entityPlayer.isSneaking()) { entityPlayer.dropPlayerItem(te.metal); @@ -99,19 +108,27 @@ public class BlockSmelter extends BlockContainer } return true; } - - public void onBlockClicked(World world, int i, int j, int k, EntityPlayer player) + + @Override + public void onBlockClicked(World world, int i, int j, int k, EntityPlayer player) { + if (world.isRemote) + return; + TileEntitySmelter te = (TileEntitySmelter) world.getBlockTileEntity(i, j, k); TileEntityMolder me = null; - if(world.getBlockMetadata(i, j, k) == 0) me = (TileEntityMolder) world.getBlockTileEntity(i, j, k - 1); - else if(world.getBlockMetadata(i, j, k) == 1) me = (TileEntityMolder) world.getBlockTileEntity(i + 1, j, k); - else if(world.getBlockMetadata(i, j, k) == 2) me = (TileEntityMolder) world.getBlockTileEntity(i, j, k + 1); - else if(world.getBlockMetadata(i, j, k) == 3) me = (TileEntityMolder) world.getBlockTileEntity(i - 1, j, k); - - if(te.hasMoltenMetal && me != null) + if (world.getBlockMetadata(i, j, k) == 0) + me = (TileEntityMolder) world.getBlockTileEntity(i, j, k - 1); + else if (world.getBlockMetadata(i, j, k) == 1) + me = (TileEntityMolder) world.getBlockTileEntity(i + 1, j, k); + else if (world.getBlockMetadata(i, j, k) == 2) + me = (TileEntityMolder) world.getBlockTileEntity(i, j, k + 1); + else if (world.getBlockMetadata(i, j, k) == 3) + me = (TileEntityMolder) world.getBlockTileEntity(i - 1, j, k); + + if (te.hasMoltenMetal && me != null) { - if(isConnectedToMolder(world, i, j, k) && me.hasMold && !me.hasMoltenMetal && !me.hasJewelBase) + if (isConnectedToMolder(world, i, j, k) && me.hasMold && !me.hasMoltenMetal && !me.hasJewelBase) { me.moltenMetal = te.moltenMetal; me.hasMoltenMetal = true; @@ -119,49 +136,64 @@ public class BlockSmelter extends BlockContainer te.moltenMetal = new ItemStack(0, 0, 0); te.hasMoltenMetal = false; } - else if(me.hasMoltenMetal) player.addChatMessage("The Molder already has molten metal in it!"); - else if(!me.hasMold) player.addChatMessage("The Molder doesn't have a mold in it! You might as well pour this stuff on the ground, won't you?"); - else if(me.hasJewelBase) player.addChatMessage("The Molder contains an item in it. Now you wouldn't want it to be destroyed, would you?"); - else player.addChatMessage("You need a Molder in front of this block in order to pour the molten metal!"); + else if (me.hasMoltenMetal) + player.addChatMessage("The Molder already has molten metal in it!"); + else if (!me.hasMold) + player.addChatMessage("The Molder doesn't have a mold in it! You might as well pour this stuff on the ground, won't you?"); + else if (me.hasJewelBase) + player.addChatMessage("The Molder contains an item in it. Now you wouldn't want it to be destroyed, would you?"); + else + player.addChatMessage("You need a Molder in front of this block in order to pour the molten metal!"); } - + } - + public boolean isConnectedToMolder(World world, int i, int j, int k) { int blockMeta = world.getBlockMetadata(i, j, k); - if(blockMeta == 0 && world.getBlockId(i, j, k - 1) == BlockList.molder.blockID) return true; - else if(blockMeta == 1 && world.getBlockId(i + 1, j, k) == BlockList.molder.blockID) return true; - else if(blockMeta == 2 && world.getBlockId(i, j, k + 1) == BlockList.molder.blockID) return true; - else if(blockMeta == 3 && world.getBlockId(i - 1, j, k) == BlockList.molder.blockID) return true; + if (blockMeta == 0 && world.getBlockId(i, j, k - 1) == BlockList.molder.blockID) + return true; + else if (blockMeta == 1 && world.getBlockId(i + 1, j, k) == BlockList.molder.blockID) + return true; + else if (blockMeta == 2 && world.getBlockId(i, j, k + 1) == BlockList.molder.blockID) + return true; + else if (blockMeta == 3 && world.getBlockId(i - 1, j, k) == BlockList.molder.blockID) + return true; return false; } - - public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityLiving, ItemStack par6ItemStack) + + @Override + public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityLiving, ItemStack par6ItemStack) { - int rotation = MathHelper.floor_double((double)(entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; + if (world.isRemote) + return; + + int rotation = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; world.setBlockMetadataWithNotify(i, j, k, rotation, 2); } - + + @Override public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l) { return false; } - + + @Override public boolean isOpaqueCube() { return false; } - + @Override public int getRenderType() { return -1; } - - public void registerIcons(IconRegister icon) + + @Override + public void registerIcons(IconRegister icon) { this.blockIcon = icon.registerIcon("jewelrycraft:smelter"); } - + } |
