Skip to content

Commit

Permalink
Logic of checking for solid blocks around forge is now consistent acr…
Browse files Browse the repository at this point in the history
…oss 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.
  • Loading branch information
Kittychanley committed May 20, 2016
1 parent 83c3e2a commit 99b8735
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 237 deletions.
26 changes: 18 additions & 8 deletions src/Common/com/bioxx/tfc/Blocks/BlockStair.java
Expand Up @@ -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;
}
}

Expand Down
58 changes: 29 additions & 29 deletions src/Common/com/bioxx/tfc/Blocks/Devices/BlockFirepit.java
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
110 changes: 36 additions & 74 deletions src/Common/com/bioxx/tfc/Blocks/Devices/BlockForge.java
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}*/
}
}

Expand Down

0 comments on commit 99b8735

Please sign in to comment.