diff --git a/src/main/java/noppes/npcs/blocks/BlockCampfire.java b/src/main/java/noppes/npcs/blocks/BlockCampfire.java index b995bf1f2..56d718863 100644 --- a/src/main/java/noppes/npcs/blocks/BlockCampfire.java +++ b/src/main/java/noppes/npcs/blocks/BlockCampfire.java @@ -41,8 +41,7 @@ public class BlockCampfire extends BlockLightable{ int meta = world.getBlockMetadata(x, y, z); if((item.getItem() == Items.flint || item.getItem() == Items.flint_and_steel) && unlitBlock() == this){ - if(world.rand.nextInt(3) == 0 && !world.isRemote) - super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9); + super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9); CustomNpcs.proxy.spawnParticle("largesmoke", x + 0.5f, y + 0.5f, z + 0.5f, 0.0D, 0.0D, 0.0D, 2); if(item.getItem() == Items.flint) NoppesUtilServer.consumeItemStack(1, player); diff --git a/src/main/java/noppes/npcs/blocks/BlockLightable.java b/src/main/java/noppes/npcs/blocks/BlockLightable.java index b0e8383e2..7c478b300 100644 --- a/src/main/java/noppes/npcs/blocks/BlockLightable.java +++ b/src/main/java/noppes/npcs/blocks/BlockLightable.java @@ -6,33 +6,49 @@ import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import java.util.Random; -public abstract class BlockLightable extends BlockRotated{ +public abstract class BlockLightable extends BlockRotated { protected BlockLightable(Block block, boolean lit) { super(block); - + if (lit) this.setLightLevel(1.0F); } public abstract Block unlitBlock(); public abstract Block litBlock(); - + @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){ - TileEntity tile = world.getTileEntity(x, y, z); - if(litBlock() == this) - world.setBlock(x, y, z, unlitBlock(), world.getBlockMetadata(x, y, z), 2); - else - world.setBlock(x, y, z, litBlock(), world.getBlockMetadata(x, y, z), 2); - tile.validate(); - world.setTileEntity(x, y, z, tile); + // Get the current tile entity and store its NBT + TileEntity oldTile = world.getTileEntity(x, y, z); + NBTTagCompound compound = new NBTTagCompound(); + oldTile.writeToNBT(compound); + + // Determine which block to set (lit/unlit) based on the current one + Block newBlock = (litBlock() == this ? unlitBlock() : litBlock()); + int meta = world.getBlockMetadata(x, y, z); + + // Change the block; this creates a new tile entity instance + world.setBlock(x, y, z, newBlock, meta, 2); + + // Get the new tile and load the stored NBT + TileEntity newTile = world.getTileEntity(x, y, z); + if(newTile != null){ + newTile.readFromNBT(compound); + newTile.markDirty(); + } + + world.markBlockForUpdate(x, y, z); + world.notifyBlockOfNeighborChange(x, y, z, newBlock); + return true; } diff --git a/src/main/java/noppes/npcs/blocks/tiles/TileCampfire.java b/src/main/java/noppes/npcs/blocks/tiles/TileCampfire.java index e0e50f6ba..17871fef0 100644 --- a/src/main/java/noppes/npcs/blocks/tiles/TileCampfire.java +++ b/src/main/java/noppes/npcs/blocks/tiles/TileCampfire.java @@ -1,6 +1,9 @@ package noppes.npcs.blocks.tiles; +import net.minecraft.block.Block; +import net.minecraft.world.World; +import noppes.npcs.CustomItems; import noppes.npcs.CustomNpcs; import java.util.Random; @@ -53,6 +56,7 @@ public class TileCampfire extends TileColorable { public boolean isLit() { - return this.getBlockMetadata() == 0; + Block block = this.getBlockType(); + return block == CustomItems.campfire; } } diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockCampfireRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockCampfireRenderer.java index 9b98638d1..a1b2328fd 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockCampfireRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockCampfireRenderer.java @@ -19,7 +19,7 @@ import noppes.npcs.config.ConfigClient; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; -public class BlockCampfireRenderer extends BlockRendererInterface{ +public class BlockCampfireRenderer extends BlockRendererInterface { // Legacy private final ModelCampfire legacy_model = new ModelCampfire();