From 99b87355bdcf27f7e3e4d2220c43a69e3ad27211 Mon Sep 17 00:00:00 2001 From: Kittychanley Date: Fri, 20 May 2016 14:45:52 -0500 Subject: [PATCH] Logic of checking for solid blocks around forge is now consistent across the block itself, and using a firestarter or flint and steel to create it. Flint and steel now plays the "click" sound played when creating a fire block when creating firepits and forges, as well as lighting pit kilns and re-lighting firepits and forges. Attempted to fix solid-side check for blocks chiseled using stair mode (no guarantees). Firepits can now be created on non-wood/cloth blocks with just a solid top face, instead of requiring an opaque cube. Fixed flint and steel not being able to be used on the top face of wood/cloth material blocks due to firepit creation logic. Fixed slab solid-side check being inaccurrate when using the TFC_Core method to check. Added comments to ChiselMode_Stair to explain which corners correspond to which bits. --- .../com/bioxx/tfc/Blocks/BlockStair.java | 26 +++-- .../tfc/Blocks/Devices/BlockFirepit.java | 58 ++++----- .../bioxx/tfc/Blocks/Devices/BlockForge.java | 110 ++++++------------ src/Common/com/bioxx/tfc/Core/TFC_Core.java | 51 +++----- .../tfc/Items/Tools/ItemFirestarter.java | 36 ++---- .../bioxx/tfc/Items/Tools/ItemFlintSteel.java | 96 +++++++-------- .../com/bioxx/tfc/Tools/ChiselMode_Stair.java | 29 +++-- 7 files changed, 169 insertions(+), 237 deletions(-) diff --git a/src/Common/com/bioxx/tfc/Blocks/BlockStair.java b/src/Common/com/bioxx/tfc/Blocks/BlockStair.java index e4d016a62..232b5076f 100644 --- a/src/Common/com/bioxx/tfc/Blocks/BlockStair.java +++ b/src/Common/com/bioxx/tfc/Blocks/BlockStair.java @@ -81,15 +81,25 @@ public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirecti { TEPartial te = (TEPartial) world.getTileEntity(x, y, z); long rvmeta = te.extraData; - switch(side) + + // Left byte bottom, Right byte top + // Bits are SE, NW, NE, SW - 1 means square is missing + switch (side) { - case DOWN:return (rvmeta & 15) == 15; - case UP:return (rvmeta & 240) == 240; - case NORTH:return (rvmeta & 102) == 102; - case SOUTH:return (rvmeta & 153) == 153; - case EAST:return (rvmeta & 170) == 170; - case WEST:return (rvmeta & 85) == 85; - default: return false; + case DOWN: + return (rvmeta & 0b1111_0000) == 0; + case UP: + return (rvmeta & 0b0000_1111) == 0; + case NORTH: + return (rvmeta & 0b0110_0110) == 0; + case SOUTH: + return (rvmeta & 0b1001_1001) == 0; + case EAST: + return (rvmeta & 0b1010_1010) == 0; + case WEST: + return (rvmeta & 0b0101_0101) == 0; + default: + return false; } } diff --git a/src/Common/com/bioxx/tfc/Blocks/Devices/BlockFirepit.java b/src/Common/com/bioxx/tfc/Blocks/Devices/BlockFirepit.java index c0bc0d019..2f1fb942c 100644 --- a/src/Common/com/bioxx/tfc/Blocks/Devices/BlockFirepit.java +++ b/src/Common/com/bioxx/tfc/Blocks/Devices/BlockFirepit.java @@ -9,6 +9,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; +import net.minecraft.item.ItemFlintAndSteel; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; @@ -24,9 +25,10 @@ import com.bioxx.tfc.Reference; import com.bioxx.tfc.TerraFirmaCraft; import com.bioxx.tfc.Blocks.BlockTerraContainer; +import com.bioxx.tfc.Core.TFC_Core; +import com.bioxx.tfc.Items.Tools.ItemFirestarter; import com.bioxx.tfc.TileEntities.TEFirepit; import com.bioxx.tfc.api.TFCBlocks; -import com.bioxx.tfc.api.TFCItems; public class BlockFirepit extends BlockTerraContainer { @@ -42,40 +44,38 @@ public BlockFirepit() @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ) { - ItemStack equippedItem = entityplayer.getCurrentEquippedItem(); - Item item; - if(equippedItem != null) - item = entityplayer.getCurrentEquippedItem().getItem(); - else - item = null; - - if(world.isRemote) + if (!world.isRemote) { - return true; - } - else if(item == TFCItems.fireStarter || item == TFCItems.flintSteel) - { - if((TEFirepit)world.getTileEntity(x, y, z) != null) + ItemStack equippedItem = entityplayer.getCurrentEquippedItem(); + if (equippedItem != null) { - TEFirepit te = (TEFirepit)world.getTileEntity(x, y, z); - if(te.fireTemp < 210 && te.fireItemStacks[5] != null) + Item item = entityplayer.getCurrentEquippedItem().getItem(); + if (item instanceof ItemFirestarter || item instanceof ItemFlintAndSteel) { - te.fireTemp = 300; - int ss = entityplayer.inventory.getCurrentItem().stackSize; - int dam = entityplayer.inventory.getCurrentItem().getItemDamage(); - entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, - new ItemStack(entityplayer.getCurrentEquippedItem().getItem(), ss, dam)); - world.setBlockMetadataWithNotify(x, y, z, 1, 3); + if ((TEFirepit) world.getTileEntity(x, y, z) != null) + { + TEFirepit te = (TEFirepit) world.getTileEntity(x, y, z); + if (te.fireTemp < 210 && te.fireItemStacks[5] != null) + { + te.fireTemp = 300; + if (item instanceof ItemFlintAndSteel) + { + Random rand = new Random(); + world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, "fire.ignite", 1.0F, rand.nextFloat() * 0.4F + 0.8F); + } + equippedItem.damageItem(1, entityplayer); + world.setBlockMetadataWithNotify(x, y, z, 1, 3); + return true; + } + } } } - return true; - } - else - { - if((TEFirepit)world.getTileEntity(x, y, z) != null) + + if ((TEFirepit) world.getTileEntity(x, y, z) != null) entityplayer.openGui(TerraFirmaCraft.instance, 20, world, x, y, z); - return true; } + + return true; } @Override @@ -107,7 +107,7 @@ public int quantityDropped(Random rand) @Override public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { - if(!world.getBlock(x, y - 1, z).isOpaqueCube()) + if (!TFC_Core.isTopFaceSolid(world, x, y - 1, z)) { ((TEFirepit)world.getTileEntity(x, y, z)).ejectContents(); world.setBlockToAir(x, y, z); diff --git a/src/Common/com/bioxx/tfc/Blocks/Devices/BlockForge.java b/src/Common/com/bioxx/tfc/Blocks/Devices/BlockForge.java index 6deff4b8c..f9f8e1d15 100644 --- a/src/Common/com/bioxx/tfc/Blocks/Devices/BlockForge.java +++ b/src/Common/com/bioxx/tfc/Blocks/Devices/BlockForge.java @@ -9,6 +9,8 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemFlintAndSteel; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; @@ -17,8 +19,6 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -27,7 +27,6 @@ import com.bioxx.tfc.Blocks.BlockTerraContainer; import com.bioxx.tfc.Core.TFC_Core; import com.bioxx.tfc.Items.Tools.ItemFirestarter; -import com.bioxx.tfc.Items.Tools.ItemFlintSteel; import com.bioxx.tfc.TileEntities.TEForge; import com.bioxx.tfc.api.TFCBlocks; @@ -45,59 +44,48 @@ public BlockForge() @Override public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ) { - //int meta = world.getBlockMetadata(i, j, k); - //int xCoord = i; - //int yCoord = j; - //int zCoord = k; - ItemStack equippedItem = entityplayer.getCurrentEquippedItem(); - - if(world.isRemote) - { - return true; - } - else if(equippedItem != null && (equippedItem.getItem() instanceof ItemFirestarter || equippedItem.getItem() instanceof ItemFlintSteel)) + if (!world.isRemote && world.getTileEntity(i, j, k) instanceof TEForge) { - if((TEForge)world.getTileEntity(i, j, k) != null) + ItemStack equippedItem = entityplayer.getCurrentEquippedItem(); + TEForge tef = (TEForge) world.getTileEntity(i, j, k); + if (equippedItem != null) { - TEForge tef = (TEForge)world.getTileEntity(i, j, k); - if (!tef.isSmokeStackValid) + Item item = equippedItem.getItem(); + if (item instanceof ItemFirestarter || item instanceof ItemFlintAndSteel) { - TFC_Core.sendInfoMessage(entityplayer, new ChatComponentTranslation("gui.forge.badChimney")); - return true; + if (!tef.isSmokeStackValid) + { + TFC_Core.sendInfoMessage(entityplayer, new ChatComponentTranslation("gui.forge.badChimney")); + return true; + } + else if (tef.fireTemp <= 0 && tef.fireItemStacks[7] != null) + { + tef.fireTemp = 10; + tef.fuelBurnTemp = 20; + tef.fuelTimeLeft = 10; + if (item instanceof ItemFlintAndSteel) + { + Random rand = new Random(); + world.playSoundEffect(i + 0.5D, j + 0.5D, k + 0.5D, "fire.ignite", 1.0F, rand.nextFloat() * 0.4F + 0.8F); + } + equippedItem.damageItem(1, entityplayer); + world.setBlockMetadataWithNotify(i, j, k, 2, 3); + return true; + } } + } - if (tef.fireTemp <= 0 && tef.fireItemStacks[7] != null) - { - tef.fireTemp = 10; - tef.fuelBurnTemp = 20; - tef.fuelTimeLeft = 10; - int ss = entityplayer.inventory.getCurrentItem().stackSize; - int dam = entityplayer.inventory.getCurrentItem().getItemDamage()+1; - - if(dam >= entityplayer.getCurrentEquippedItem().getItem().getMaxDamage()) - entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, null); - else - entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, new ItemStack(entityplayer.getCurrentEquippedItem().getItem(),ss,dam)); - - world.setBlockMetadataWithNotify(i, j, k, 2, 3); - } + if (tef.isSmokeStackValid) + { + entityplayer.openGui(TerraFirmaCraft.instance, 23, world, i, j, k); } - return true; - } - else - { - if((TEForge)world.getTileEntity(i, j, k)!=null) + else { - TEForge tef = (TEForge)world.getTileEntity(i, j, k); - if(tef.isSmokeStackValid) - { - entityplayer.openGui(TerraFirmaCraft.instance, 23, world, i, j, k); - } - else - TFC_Core.sendInfoMessage(entityplayer, new ChatComponentTranslation("gui.forge.badChimney")); + TFC_Core.sendInfoMessage(entityplayer, new ChatComponentTranslation("gui.forge.badChimney")); } - return true; } + + return true; } @Override @@ -137,37 +125,11 @@ public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { if(!world.isRemote) { - /*boolean surroundSolids = (world.getBlock(x+1, y, z).getMaterial() == Material.rock && world.getBlock(x-1, y, z).getMaterial() == Material.rock && - world.getBlock(x, y, z+1).getMaterial() == Material.rock && world.getBlock(x, y, z-1).getMaterial() == Material.rock && - world.getBlock(x, y-1, z).isNormalCube() && (world.getBlock(x+1, y, z).isNormalCube() && world.getBlock(x-1, y, z).isNormalCube() && - world.getBlock(x, y, z+1).isNormalCube() && world.getBlock(x, y, z-1).isNormalCube()));*/ - - boolean rockXP = world.getBlock(x+1, y, z) == TFCBlocks.stoneSlabs || - world.getBlock(x+1, y, z).getMaterial() == Material.rock && world.getBlock(x+1, y, z).isNormalCube(); - boolean rockXN = world.getBlock(x-1, y, z) == TFCBlocks.stoneSlabs || - world.getBlock(x-1, y, z).getMaterial() == Material.rock && world.getBlock(x-1, y, z).isNormalCube(); - boolean rockZP = world.getBlock(x, y, z+1) == TFCBlocks.stoneSlabs || - world.getBlock(x, y, z+1).getMaterial() == Material.rock && world.getBlock(x, y, z+1).isNormalCube(); - boolean rockZN = world.getBlock(x, y, z-1) == TFCBlocks.stoneSlabs || - world.getBlock(x, y, z-1).getMaterial() == Material.rock && world.getBlock(x, y, z-1).isNormalCube(); - boolean rockYN = world.getBlock(x, y-1, z ) == TFCBlocks.stoneSlabs || - world.getBlock(x, y-1, z).getMaterial() == Material.rock && world.getBlock(x, y-1,z).isNormalCube(); - - boolean validSlabs = world.isSideSolid(x, y, z + 1, ForgeDirection.NORTH) && world.isSideSolid(x, y, z - 1, ForgeDirection.SOUTH) && - world.isSideSolid(x - 1, y, z, ForgeDirection.EAST) && world.isSideSolid(x + 1, y, z, ForgeDirection.WEST); - - if (!(rockXP && rockXN && rockZP && rockZN && rockYN) || !validSlabs) + if (!TFC_Core.isSurroundedSolid(world, x, y, z) || !TFC_Core.isSurroundedStone(world, x, y, z)) { ((TEForge)world.getTileEntity(x, y, z)).ejectContents(); world.setBlockToAir(x, y, z); } - /*else - { - if(world.getTileEntity(x, y, z) != null) - { - //((TEForge)world.getBlockTileEntity(x, y, z)).isValid = false; - } - }*/ } } diff --git a/src/Common/com/bioxx/tfc/Core/TFC_Core.java b/src/Common/com/bioxx/tfc/Core/TFC_Core.java index abccc1e8f..b782573f0 100644 --- a/src/Common/com/bioxx/tfc/Core/TFC_Core.java +++ b/src/Common/com/bioxx/tfc/Core/TFC_Core.java @@ -41,7 +41,6 @@ import org.lwjgl.input.Mouse; import com.bioxx.tfc.TerraFirmaCraft; -import com.bioxx.tfc.Blocks.BlockSlab; import com.bioxx.tfc.Chunkdata.ChunkData; import com.bioxx.tfc.Chunkdata.ChunkDataManager; import com.bioxx.tfc.Core.Player.BodyTempStats; @@ -53,7 +52,6 @@ import com.bioxx.tfc.Items.ItemTerra; import com.bioxx.tfc.Items.ItemBlocks.ItemTerraBlock; import com.bioxx.tfc.TileEntities.TEMetalSheet; -import com.bioxx.tfc.TileEntities.TEPartial; import com.bioxx.tfc.WorldGen.TFCBiome; import com.bioxx.tfc.api.*; import com.bioxx.tfc.api.Constant.Global; @@ -841,11 +839,6 @@ public static boolean isTopFaceSolid(World world, int x, int y, int z) { if(world.getBlock(x, y, z).isNormalCube()) return true; - else if(world.getBlock(x, y, z) == TFCBlocks.stoneSlabs) - { - TEPartial te = (TEPartial) world.getTileEntity(x, y, z); - return BlockSlab.getTopChiselLevel(te.extraData) == 0; - } else if(world.getBlock(x, y, z) == TFCBlocks.metalSheet) { TEMetalSheet te = (TEMetalSheet) world.getTileEntity(x, y, z); @@ -859,11 +852,6 @@ public static boolean isBottomFaceSolid(World world, int x, int y, int z) { if(world.getBlock(x, y, z).isNormalCube()) return true; - else if(world.getBlock(x, y, z) == TFCBlocks.stoneSlabs) - { - TEPartial te = (TEPartial) world.getTileEntity(x, y, z); - return BlockSlab.getBottomChiselLevel(te.extraData) == 0; - } else if(world.getBlock(x, y, z) == TFCBlocks.metalSheet) { TEMetalSheet te = (TEMetalSheet) world.getTileEntity(x, y, z); @@ -878,11 +866,6 @@ public static boolean isNorthFaceSolid(World world, int x, int y, int z) Block bid = world.getBlock(x, y, z); if(bid.isNormalCube()) return true; - else if(bid == TFCBlocks.stoneSlabs) - { - TEPartial te = (TEPartial) world.getTileEntity(x, y, z); - return BlockSlab.getNorthChiselLevel(te.extraData) == 0; - } else if(bid == TFCBlocks.metalSheet) { TEMetalSheet te = (TEMetalSheet) world.getTileEntity(x, y, z); @@ -896,11 +879,6 @@ public static boolean isSouthFaceSolid(World world, int x, int y, int z) { if(world.getBlock(x, y, z).isNormalCube()) return true; - else if(world.getBlock(x, y, z) == TFCBlocks.stoneSlabs) - { - TEPartial te = (TEPartial) world.getTileEntity(x, y, z); - return BlockSlab.getSouthChiselLevel(te.extraData) == 0; - } else if(world.getBlock(x, y, z) == TFCBlocks.metalSheet) { TEMetalSheet te = (TEMetalSheet) world.getTileEntity(x, y, z); @@ -914,12 +892,6 @@ public static boolean isEastFaceSolid(World world, int x, int y, int z) { if(world.getBlock(x, y, z).isNormalCube()) return true; - else if(world.getBlock(x, y, z) == TFCBlocks.stoneSlabs) - { - TEPartial te = (TEPartial) world.getTileEntity(x, y, z); - if(BlockSlab.getEastChiselLevel(te.extraData) != 0) - return true; - } else if(world.getBlock(x, y, z) == TFCBlocks.metalSheet) { TEMetalSheet te = (TEMetalSheet) world.getTileEntity(x, y, z); @@ -933,11 +905,6 @@ public static boolean isWestFaceSolid(World world, int x, int y, int z) { if(world.getBlock(x, y, z).isNormalCube()) return true; - else if(world.getBlock(x, y, z) == TFCBlocks.stoneSlabs) - { - TEPartial te = (TEPartial) world.getTileEntity(x, y, z); - return BlockSlab.getWestChiselLevel(te.extraData) == 0; - } else if(world.getBlock(x, y, z) == TFCBlocks.metalSheet) { TEMetalSheet te = (TEMetalSheet) world.getTileEntity(x, y, z); @@ -947,6 +914,24 @@ else if(world.getBlock(x, y, z) == TFCBlocks.metalSheet) return world.getBlock(x, y, z).isSideSolid(world, x, y, z, ForgeDirection.WEST); } + public static boolean isSurroundedSolid(World world, int x, int y, int z) + { + return TFC_Core.isNorthFaceSolid(world, x, y, z + 1) && + TFC_Core.isSouthFaceSolid(world, x, y, z - 1) && + TFC_Core.isEastFaceSolid(world, x - 1, y, z) && + TFC_Core.isWestFaceSolid(world, x + 1, y, z) && + TFC_Core.isTopFaceSolid(world, x, y - 1, z); + } + + public static boolean isSurroundedStone(World world, int x, int y, int z) + { + return world.getBlock(x, y, z + 1).getMaterial() == Material.rock && + world.getBlock(x, y, z - 1).getMaterial() == Material.rock && + world.getBlock(x - 1, y, z).getMaterial() == Material.rock && + world.getBlock(x + 1, y, z).getMaterial() == Material.rock && + world.getBlock(x, y - 1, z).getMaterial() == Material.rock; + } + public static boolean isOreIron(ItemStack is) { return is.getItem() instanceof ItemOre && ((ItemOre) is.getItem()).getMetalType(is) == Global.PIGIRON; diff --git a/src/Common/com/bioxx/tfc/Items/Tools/ItemFirestarter.java b/src/Common/com/bioxx/tfc/Items/Tools/ItemFirestarter.java index 50e649326..74b5e03b7 100644 --- a/src/Common/com/bioxx/tfc/Items/Tools/ItemFirestarter.java +++ b/src/Common/com/bioxx/tfc/Items/Tools/ItemFirestarter.java @@ -15,9 +15,8 @@ import net.minecraft.util.MovingObjectPosition.MovingObjectType; import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - import com.bioxx.tfc.Core.TFCTabs; +import com.bioxx.tfc.Core.TFC_Core; import com.bioxx.tfc.Core.TFC_Sounds; import com.bioxx.tfc.Items.ItemTerra; import com.bioxx.tfc.TileEntities.TEPottery; @@ -31,7 +30,6 @@ public class ItemFirestarter extends ItemTerra private boolean canBeUsed; private boolean isCoal; private boolean isPottery; - private boolean canBlockBurn; public ItemFirestarter() { @@ -91,7 +89,7 @@ public void onUsingTick(ItemStack stack, EntityPlayer player, int count) if(count > 0 && world.isRemote) { - Boolean genSmoke = canBeUsed || isCoal || isPottery || canBlockBurn; + Boolean genSmoke = canBeUsed || isCoal || isPottery; if(genSmoke && chance > 70) world.spawnParticle("smoke", hitX, hitY, hitZ, 0.0F, 0.1F, 0.0F); @@ -152,12 +150,6 @@ else if(isPottery) } stack.damageItem(1, player); } - else if(canBlockBurn) - { - if(chance > 70) - world.setBlock(x, y + 1, z, Blocks.fire); - stack.damageItem(1, player); - } } } } @@ -165,7 +157,7 @@ else if(canBlockBurn) @Override public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player) { - if(canBeUsed || isCoal || isPottery || canBlockBurn) + if (canBeUsed || isCoal || isPottery) player.setItemInUse(is, this.getMaxItemUseDuration(is)); return is; } @@ -174,9 +166,6 @@ public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player public boolean onItemUseFirst(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { this.setFlags(player); - // If the firestarter should be used with all flammable blocks, uncomment the next line. - //canBlockBurn = side == 1 && Blocks.fire.canCatchFire(world, x, y, z, ForgeDirection.UP); - return false; } @@ -198,19 +187,10 @@ public void setFlags(EntityPlayer player) int side = mop.sideHit; Block block = world.getBlock(x, y, z); - boolean surroundSolids = world.isSideSolid(x, y, z + 1, ForgeDirection.NORTH) - && world.isSideSolid(x, y, z - 1, ForgeDirection.SOUTH) - && world.isSideSolid(x - 1, y, z, ForgeDirection.EAST) - && world.isSideSolid(x + 1, y, z, ForgeDirection.WEST); - boolean surroundRock = world.getBlock(x, y - 1, z).getMaterial() == Material.rock - && world.getBlock(x + 1, y, z).getMaterial() == Material.rock - && world.getBlock(x - 1, y, z).getMaterial() == Material.rock - && world.getBlock(x, y, z + 1).getMaterial() == Material.rock - && world.getBlock(x, y, z - 1).getMaterial() == Material.rock - && world.getBlock(x, y - 1, z).isNormalCube(); + boolean surroundSolids = TFC_Core.isSurroundedSolid(world, x, y, z); + boolean surroundRock = TFC_Core.isSurroundedStone(world, x, y, z); canBeUsed = side == 1 - && block.isNormalCube() - && block.isOpaqueCube() + && TFC_Core.isTopFaceSolid(world, x, y, z) && block.getMaterial() != Material.wood && block.getMaterial() != Material.cloth && world.isAirBlock(x, y + 1, z) @@ -220,10 +200,8 @@ public void setFlags(EntityPlayer player) isPottery = block == TFCBlocks.pottery && surroundSolids; if (isPottery) { - isPottery = false; TEPottery te = (TEPottery) world.getTileEntity(x, y, z); - if (!te.isLit() && te.wood == 8) - isPottery = true; + isPottery = !te.isLit() && te.wood == 8; } } } diff --git a/src/Common/com/bioxx/tfc/Items/Tools/ItemFlintSteel.java b/src/Common/com/bioxx/tfc/Items/Tools/ItemFlintSteel.java index d78422f87..bc7aecb92 100644 --- a/src/Common/com/bioxx/tfc/Items/Tools/ItemFlintSteel.java +++ b/src/Common/com/bioxx/tfc/Items/Tools/ItemFlintSteel.java @@ -3,11 +3,11 @@ import java.util.Iterator; import java.util.List; +import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; -import net.minecraft.init.Items; import net.minecraft.item.ItemFlintAndSteel; import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; @@ -35,22 +35,33 @@ public ItemFlintSteel() @Override public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - if(!world.isRemote) + if (!world.isRemote) { - boolean surroundSolids = TFC_Core.isNorthFaceSolid(world, x, y, z + 1) && - TFC_Core.isSouthFaceSolid(world, x, y, z - 1) && - TFC_Core.isEastFaceSolid(world, x - 1, y, z) && - TFC_Core.isWestFaceSolid(world, x + 1, y, z); - - if(side == 1 && world.getBlock(x, y, z).isNormalCube() && - world.getBlock(x, y, z).isOpaqueCube() && - world.getBlock(x, y, z).getMaterial() != Material.wood && - world.getBlock(x, y, z).getMaterial() != Material.cloth && - world.isAirBlock(x, y + 1, z) && - world.getBlock(x, y, z) != TFCBlocks.charcoal && - world.getBlock(x, y, z) != Blocks.coal_block) + Block block = world.getBlock(x, y, z); + boolean surroundSolids = TFC_Core.isSurroundedSolid(world, x, y, z); + // Attempt to create forge + if (block == TFCBlocks.charcoal && world.getBlockMetadata(x, y, z) > 6 || + block == Blocks.coal_block) + { + if (TFC_Core.isSurroundedStone(world, x, y, z) && surroundSolids) + { + triggerUse(itemstack, entityplayer, world, x, y, z); + world.setBlock(x, y, z, TFCBlocks.forge, 1, 0x2); + return true; + } + } + // Attempt to light pottery + else if (block == TFCBlocks.pottery && surroundSolids) + { + TEPottery te = (TEPottery) world.getTileEntity(x, y, z); + te.startPitFire(); + triggerUse(itemstack, entityplayer, world, x, y, z); + return true; + } + // Attempt to create fire pit + else if (side == 1 && TFC_Core.isTopFaceSolid(world, x, y, z) && world.isAirBlock(x, y + 1, z) && + block.getMaterial() != Material.wood && block.getMaterial() != Material.cloth) { - List list = world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x, y + 1, z, x + 1, y + 2, z + 1)); int numsticks = 0; @@ -58,9 +69,9 @@ public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World w { for (Iterator iterator = list.iterator(); iterator.hasNext();) { - EntityItem entity = (EntityItem)iterator.next(); + EntityItem entity = (EntityItem) iterator.next(); if (entity.getEntityItem().getItem() == TFCItems.stick) - numsticks+=entity.getEntityItem().stackSize; + numsticks += entity.getEntityItem().stackSize; } if (numsticks >= 3) @@ -68,58 +79,35 @@ public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World w for (Iterator iterator = list.iterator(); iterator.hasNext();) { EntityItem entity = (EntityItem) iterator.next(); - if (entity.getEntityItem().getItem() == TFCItems.stick) - entity.setDead(); - if (entity.getEntityItem().getItem() == Items.paper) + if (entity.getEntityItem().getItem() == TFCItems.stick || entity.getEntityItem().getItem() == TFCItems.straw) entity.setDead(); } - itemstack.damageItem(1, entityplayer); + triggerUse(itemstack, entityplayer, world, x, y, z); world.setBlock(x, y + 1, z, TFCBlocks.firepit, 1, 0x2); if (world.isRemote) world.markBlockForUpdate(x, y + 1, z); return true; } } - - itemstack.setItemDamage(itemstack.getItemDamage() + 1); - if(itemstack.getItemDamage() >= itemstack.getMaxDamage()) - itemstack.stackSize = 0; - - return true; - } - else if (world.getBlock(x, y, z) == TFCBlocks.charcoal && world.getBlockMetadata(x, y, z) > 6 || - world.getBlock(x, y, z) == Blocks.coal_block) - { - if(world.getBlock(x, y - 1, z).getMaterial() == Material.rock && - world.getBlock(x + 1, y, z).getMaterial() == Material.rock && - world.getBlock(x - 1, y, z).getMaterial() == Material.rock && - world.getBlock(x, y, z + 1).getMaterial() == Material.rock && - world.getBlock(x, y, z - 1).getMaterial() == Material.rock && - surroundSolids) - { - itemstack.damageItem(1, entityplayer); - world.setBlock(x, y, z, TFCBlocks.forge, 1, 0x2); - //TEForge te = (TEForge)world.getTileEntity(x, y, z); - return true; - } } - else if(world.getBlock(x, y, z) == TFCBlocks.pottery && surroundSolids) - { - TEPottery te = (TEPottery) world.getTileEntity(x, y, z); - te.startPitFire(); - itemstack.damageItem(1, entityplayer); - return true; - } - else if(!(world.getBlock(x,y,z)).onBlockActivated(world, x, y, z, entityplayer, side, hitX, hitY, hitZ)) + + // Only triggers if all previous attempts failed + if (!block.onBlockActivated(world, x, y, z, entityplayer, side, hitX, hitY, hitZ)) { - super.onItemUse(itemstack, entityplayer, world, x, y, z, side, hitX, hitY, hitZ); + return super.onItemUse(itemstack, entityplayer, world, x, y, z, side, hitX, hitY, hitZ); } - else - return true; } + return false; } + private void triggerUse(ItemStack is, EntityPlayer player, World world, int x, int y, int z) + { + world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F); + is.damageItem(1, player); + } + + @Override public EnumSize getSize(ItemStack is) { diff --git a/src/Common/com/bioxx/tfc/Tools/ChiselMode_Stair.java b/src/Common/com/bioxx/tfc/Tools/ChiselMode_Stair.java index 7e93425b6..e5e0ce10c 100644 --- a/src/Common/com/bioxx/tfc/Tools/ChiselMode_Stair.java +++ b/src/Common/com/bioxx/tfc/Tools/ChiselMode_Stair.java @@ -107,18 +107,27 @@ public boolean onUsedHandler(World world, EntityPlayer player, int x, int y, int te = (TEPartial)world.getTileEntity(x, y, z); world.notifyBlockChange(x, y, z, id); } - if( hitY > 0.5F ) { - if( hitX <= 0.5F && hitZ >= 0.5F && (te.extraData & 1) == 0) hit = 1; - if( hitX >= 0.5F && hitZ <= 0.5F && (te.extraData & 2) == 0) hit = 2; - if( hitX <= 0.5F && hitZ <= 0.5F && (te.extraData & 4) == 0) hit = 4; - if( hitX >= 0.5F && hitZ >= 0.5F && (te.extraData & 8) == 0) hit = 8; + if (hitY > 0.5F) + { // Top Half + if (hitX <= 0.5F && hitZ >= 0.5F && (te.extraData & 1) == 0) + hit = 1; // South West + if (hitX >= 0.5F && hitZ <= 0.5F && (te.extraData & 2) == 0) + hit = 2; // North East + if (hitX <= 0.5F && hitZ <= 0.5F && (te.extraData & 4) == 0) + hit = 4; // North West + if (hitX >= 0.5F && hitZ >= 0.5F && (te.extraData & 8) == 0) + hit = 8; // South East } - else + else // Bottom Half { - if( hitX <= 0.5F && hitZ >= 0.5F && (te.extraData & 16) == 0) hit = 16; - if( hitX >= 0.5F && hitZ <= 0.5F && (te.extraData & 32) == 0) hit = 32; - if( hitX <= 0.5F && hitZ <= 0.5F && (te.extraData & 64) == 0) hit = 64; - if( hitX >= 0.5F && hitZ >= 0.5F && (te.extraData & 128) == 0) hit = 128; + if (hitX <= 0.5F && hitZ >= 0.5F && (te.extraData & 16) == 0) + hit = 16; // South West + if (hitX >= 0.5F && hitZ <= 0.5F && (te.extraData & 32) == 0) + hit = 32; // North East + if (hitX <= 0.5F && hitZ <= 0.5F && (te.extraData & 64) == 0) + hit = 64; // North West + if (hitX >= 0.5F && hitZ >= 0.5F && (te.extraData & 128) == 0) + hit = 128; // South East } te.extraData |= hit;