From 3a04133f968760bdb32a27c17555e1bbcfaf837d Mon Sep 17 00:00:00 2001 From: Calclavia Date: Fri, 17 Jan 2014 19:49:40 +0800 Subject: [PATCH] Firebox now works --- build.properties | 2 +- .../archaic/blocks/BlockFirebox.java | 111 ++++++------------ .../archaic/blocks/TileFirebox.java | 32 +++-- .../archaic/crate/InventoryCrate.java | 6 +- .../archaic/crate/TileCrate.java | 4 +- .../core/prefab/tile/TileMachine.java | 10 +- 6 files changed, 69 insertions(+), 96 deletions(-) diff --git a/build.properties b/build.properties index 0a0b22896..c54c0908a 100644 --- a/build.properties +++ b/build.properties @@ -8,4 +8,4 @@ version.cclib=1.0.0.50 version.fmp=1.0.0.235 version.mod.major=0 version.mod.minor=3 -version.mod.revis=0 \ No newline at end of file +version.mod.revis=1 \ No newline at end of file diff --git a/src/main/java/resonantinduction/archaic/blocks/BlockFirebox.java b/src/main/java/resonantinduction/archaic/blocks/BlockFirebox.java index c8715ef31..d898bb5fe 100644 --- a/src/main/java/resonantinduction/archaic/blocks/BlockFirebox.java +++ b/src/main/java/resonantinduction/archaic/blocks/BlockFirebox.java @@ -4,16 +4,15 @@ import java.util.Random; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; -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.Icon; -import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import resonantinduction.core.Reference; import resonantinduction.core.prefab.block.BlockRI; +import universalelectricity.api.vector.Vector3; +import calclavia.lib.utility.inventory.InventoryUtility; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -24,7 +23,7 @@ public class BlockFirebox extends BlockRI public BlockFirebox() { - super("firebox", Material.piston); + super("firebox", Material.wood); this.setTickRandomly(true); } @@ -46,14 +45,20 @@ public class BlockFirebox extends BlockRI { TileFirebox tile = (TileFirebox) tileEntity; - if (tile.getStackInSlot(0) == null && entityPlayer.inventory.getCurrentItem() != null) + if (tile.getStackInSlot(0) == null) { - tile.setInventorySlotContents(0, entityPlayer.inventory.getCurrentItem()); - entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, null); + if (tile.canBurn(entityPlayer.inventory.getCurrentItem())) + { + tile.setInventorySlotContents(0, entityPlayer.inventory.getCurrentItem()); + entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, null); + return true; + } } else { - + InventoryUtility.dropItemStack(world, new Vector3(entityPlayer), tile.getStackInSlot(0)); + tile.setInventorySlotContents(0, null); + return true; } } @@ -83,6 +88,18 @@ public class BlockFirebox extends BlockRI return blockIcon; } + @Override + @SideOnly(Side.CLIENT) + public Icon getIcon(int side, int meta) + { + if (side == 1) + { + return topOff; + } + + return blockIcon; + } + @Override public void randomDisplayTick(World world, int x, int y, int z, Random par5Random) { @@ -97,76 +114,20 @@ public class BlockFirebox extends BlockRI float f3 = 0.52F; float f4 = par5Random.nextFloat() * 0.6F - 0.3F; - if (l == 4) - { - world.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); - world.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); - } - else if (l == 5) - { - world.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); - world.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); - } - else if (l == 2) - { - world.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D); - world.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D); - } - else if (l == 3) - { - world.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D); - world.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D); - } + world.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); + world.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); + + world.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); + world.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); + + world.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D); + world.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D); + + world.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D); + world.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D); } } - @Override - @SideOnly(Side.CLIENT) - public Icon getIcon(int side, int meta) - { - if (side == meta) - { - return topOff; - } - - return this.blockIcon; - } - - @Override - public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack stack) - { - int angle = MathHelper.floor_double((entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; - int change = 3; - - switch (angle) - { - case 0: - change = 2; - break; - - case 1: - change = 5; - break; - - case 2: - change = 3; - break; - - case 3: - change = 4; - break; - } - - world.setBlockMetadataWithNotify(x, y, z, change, 3); - world.scheduleBlockUpdate(x, y, z, blockID, 20); - } - - @Override - public void onNeighborBlockChange(World world, int x, int y, int z, int side) - { - world.scheduleBlockUpdate(x, y, z, blockID, 20); - } - @Override public TileEntity createNewTileEntity(World world) { diff --git a/src/main/java/resonantinduction/archaic/blocks/TileFirebox.java b/src/main/java/resonantinduction/archaic/blocks/TileFirebox.java index 02331a8c7..0a804f909 100644 --- a/src/main/java/resonantinduction/archaic/blocks/TileFirebox.java +++ b/src/main/java/resonantinduction/archaic/blocks/TileFirebox.java @@ -2,6 +2,7 @@ package resonantinduction.archaic.blocks; import java.util.ArrayList; +import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; @@ -15,7 +16,7 @@ import universalelectricity.api.CompatibilityModule; import universalelectricity.api.vector.Vector3; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.IPacketSender; -import calclavia.lib.prefab.tile.TileAdvancedInventory; +import calclavia.lib.prefab.tile.TileExternalInventory; import com.google.common.io.ByteArrayDataInput; @@ -25,13 +26,13 @@ import com.google.common.io.ByteArrayDataInput; * @author Calclavia * */ -public class TileFirebox extends TileAdvancedInventory implements IPacketSender, IPacketReceiver +public class TileFirebox extends TileExternalInventory implements IPacketSender, IPacketReceiver { /** * The power of the firebox in terms of thermal energy. The thermal energy can be transfered * into fluids to increase their internal energy. */ - private final int POWER = 1000; + private final int POWER = 50000; private int burnTime; @Override @@ -39,31 +40,47 @@ public class TileFirebox extends TileAdvancedInventory implements IPacketSender, { if (!worldObj.isRemote) { + int blockID = worldObj.getBlockId(xCoord, yCoord + 1, zCoord); + if (burnTime > 0) { + if (blockID == 0 && blockID != Block.fire.blockID) + { + worldObj.setBlock(xCoord, yCoord + 1, zCoord, Block.fire.blockID); + } + if (burnTime-- == 0) { worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } } + else if (blockID == Block.fire.blockID) + { + worldObj.setBlock(xCoord, yCoord + 1, zCoord, 0); + } if (canBurn(this.getStackInSlot(0))) { if (burnTime == 0) { burnTime = TileEntityFurnace.getItemBurnTime(this.getStackInSlot(0)); - decrStackSize(1, 1); + decrStackSize(0, 1); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } } } } - private boolean canBurn(ItemStack stack) + public boolean canBurn(ItemStack stack) { return TileEntityFurnace.getItemBurnTime(stack) > 0; } + public boolean isBurning() + { + return burnTime > 0; + } + @Override public Packet getDescriptionPacket() { @@ -96,9 +113,4 @@ public class TileFirebox extends TileAdvancedInventory implements IPacketSender, e.printStackTrace(); } } - - public boolean isBurning() - { - return burnTime > 0; - } } diff --git a/src/main/java/resonantinduction/archaic/crate/InventoryCrate.java b/src/main/java/resonantinduction/archaic/crate/InventoryCrate.java index e15b29042..db4d96c72 100644 --- a/src/main/java/resonantinduction/archaic/crate/InventoryCrate.java +++ b/src/main/java/resonantinduction/archaic/crate/InventoryCrate.java @@ -53,17 +53,17 @@ public class InventoryCrate extends ExternalInventory } @Override - public NBTTagCompound saveInv(NBTTagCompound nbt) + public NBTTagCompound save(NBTTagCompound nbt) { return nbt; } @Override - public void loadInv(NBTTagCompound nbt) + public void load(NBTTagCompound nbt) { if (nbt.hasKey("Items")) { - super.loadInv(nbt); + super.load(nbt); } } diff --git a/src/main/java/resonantinduction/archaic/crate/TileCrate.java b/src/main/java/resonantinduction/archaic/crate/TileCrate.java index f45991b6c..34e9407f7 100644 --- a/src/main/java/resonantinduction/archaic/crate/TileCrate.java +++ b/src/main/java/resonantinduction/archaic/crate/TileCrate.java @@ -8,7 +8,7 @@ import net.minecraftforge.common.ForgeDirection; import resonantinduction.core.ResonantInduction; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.PacketHandler; -import calclavia.lib.prefab.tile.TileAdvancedInventory; +import calclavia.lib.prefab.tile.TileExternalInventory; import calclavia.lib.utility.inventory.IExtendedStorage; import com.google.common.io.ByteArrayDataInput; @@ -21,7 +21,7 @@ import cpw.mods.fml.relauncher.Side; * * @author DarkGuardsman */ -public class TileCrate extends TileAdvancedInventory implements IPacketReceiver, IExtendedStorage +public class TileCrate extends TileExternalInventory implements IPacketReceiver, IExtendedStorage { /* * TODO diff --git a/src/main/java/resonantinduction/core/prefab/tile/TileMachine.java b/src/main/java/resonantinduction/core/prefab/tile/TileMachine.java index 2b43abe46..3fd0693d5 100644 --- a/src/main/java/resonantinduction/core/prefab/tile/TileMachine.java +++ b/src/main/java/resonantinduction/core/prefab/tile/TileMachine.java @@ -13,16 +13,16 @@ import resonantinduction.core.ResonantInduction; import universalelectricity.api.vector.Vector3; import calclavia.lib.content.IExtraInfo.IExtraTileEntityInfo; import calclavia.lib.network.PacketHandler; -import calclavia.lib.prefab.tile.TileAdvancedInventory; -import calclavia.lib.utility.inventory.IExternalInv; -import calclavia.lib.utility.inventory.IInvBox; +import calclavia.lib.prefab.tile.TileExternalInventory; +import calclavia.lib.utility.inventory.IExternalInventory; +import calclavia.lib.utility.inventory.IExternalInventoryBox; import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.network.Player; -public abstract class TileMachine extends TileAdvancedInventory implements ISidedInventory, IExternalInv, IExtraTileEntityInfo +public abstract class TileMachine extends TileExternalInventory implements ISidedInventory, IExternalInventory, IExtraTileEntityInfo { /** Number of players with the machine's gui container open */ protected int playersUsingMachine = 0; @@ -42,7 +42,7 @@ public abstract class TileMachine extends TileAdvancedInventory implements ISide protected boolean locked = false; /** Inventory manager used by this machine */ - protected IInvBox inventory; + protected IExternalInventoryBox inventory; /** Default generic packet types used by all machines */ public static enum SimplePacketTypes