1
0
Fork 0

improve furnace

This commit is contained in:
Sen 2025-08-11 17:00:50 +02:00
parent cc2c78d995
commit 8f879e9932
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
13 changed files with 312 additions and 874 deletions

View file

@ -1,49 +0,0 @@
package client.gui.container;
import common.block.tech.BlockFurnace;
import common.inventory.ContainerFurnace;
import common.inventory.IInventory;
import common.entity.npc.EntityNPC;
import common.tileentity.TileEntityFurnace;
public class GuiFurnace extends GuiContainer {
private final BlockFurnace block;
private final IInventory furnace;
public GuiFurnace(EntityNPC playerInv, IInventory furnaceInv, BlockFurnace block) {
super(new ContainerFurnace(playerInv, furnaceInv));
this.block = block;
this.furnace = furnaceInv;
}
public void draw() {
super.draw();
this.rect(58, 36, 12, 14, 0x202020);
if(TileEntityFurnace.isBurning(this.furnace)) {
int burn = this.getBurnLeftScaled(13);
burn = Math.min(burn, 13);
this.rect(58, 36 + 13 - burn, 12, burn + 1, 0xff7f00);
}
int progress = this.getCookProgressScaled(24);
this.rect(79, 39, 24, 8, 0x606060);
if(progress > 0)
this.rect(79, 39, progress + 1, 8, 0xffaf00);
}
public void addElements() {
this.label(this.block.getDisplay(), 8, 16);
this.label("Inventar", 8, this.ySize - 96 + 12);
}
private int getCookProgressScaled(int pixels) {
int progress = this.furnace.getField(2);
int total = this.furnace.getField(3);
return total != 0 && progress != 0 ? progress * pixels / total : 0;
}
private int getBurnLeftScaled(int pixels) {
int total = this.furnace.getField(1);
return this.furnace.getField(0) * pixels / (total == 0 ? 200 : total);
}
}

View file

@ -12,7 +12,6 @@ import client.gui.container.GuiChest;
import client.gui.container.GuiCrafting;
import client.gui.container.GuiDispenser;
import client.gui.container.GuiEnchant;
import client.gui.container.GuiFurnace;
import client.gui.container.GuiHopper;
import client.gui.container.GuiEntity;
import client.gui.container.GuiDevice;
@ -28,7 +27,6 @@ import common.block.Block;
import common.block.tech.BlockAnvil;
import common.block.tech.BlockChest;
import common.block.tech.BlockDispenser;
import common.block.tech.BlockFurnace;
import common.block.tech.BlockWorkbench;
import common.dimension.DimType;
import common.dimension.Dimension;
@ -1107,10 +1105,6 @@ public class ClientPlayer implements IClientPlayer
{
this.gm.show(new GuiHopper(player, new InventoryBasic(slots)));
}
else if (block instanceof BlockFurnace furnace)
{
this.gm.show(new GuiFurnace(player, new LocalContainer(slots), furnace));
}
else if (block == Blocks.brewing_stand)
{
this.gm.show(new GuiBrewing(player, new LocalContainer(slots)));

View file

@ -4,18 +4,15 @@ import common.block.Block;
import common.block.ITileEntityProvider;
import common.block.Rotatable;
import common.block.Material;
import common.entity.npc.EntityNPC;
import common.entity.types.EntityLiving;
import common.init.Blocks;
import common.init.Items;
import common.item.Item;
import common.model.Model;
import common.model.Model.ModelProvider;
import common.model.ModelRotation;
import common.properties.Property;
import common.rng.Random;
import common.tileentity.TileEntity;
import common.tileentity.TileEntityFurnace;
import common.tileentity.DeviceFurnace;
import common.util.BlockPos;
import common.util.Facing;
import common.util.ParticleType;
@ -23,47 +20,41 @@ import common.world.State;
import common.world.World;
import common.world.AWorldServer;
public class BlockFurnace extends Block implements ITileEntityProvider, Rotatable
{
private final boolean isBurning;
public class BlockFurnace extends BlockMachine implements ITileEntityProvider, Rotatable {
private static boolean keepInventory;
public BlockFurnace(boolean isBurning)
{
private final boolean isBurning;
private final int burnTime;
public BlockFurnace(boolean isBurning, int burnTime) {
super(Material.SOLID);
this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH));
this.isBurning = isBurning;
this.burnTime = burnTime;
}
public void onAdded(AWorldServer worldIn, BlockPos pos, State state)
{
public void onAdded(AWorldServer worldIn, BlockPos pos, State state) {
super.onAdded(worldIn, pos, state);
this.setDefaultFacing(worldIn, pos, state);
}
private void setDefaultFacing(World worldIn, BlockPos pos, State state)
{
if (!worldIn.client)
{
private void setDefaultFacing(World worldIn, BlockPos pos, State state) {
if(!worldIn.client) {
Block block = worldIn.getState(pos.north()).getBlock();
Block block1 = worldIn.getState(pos.south()).getBlock();
Block block2 = worldIn.getState(pos.west()).getBlock();
Block block3 = worldIn.getState(pos.east()).getBlock();
Facing enumfacing = (Facing)state.getValue(FACING);
if (enumfacing == Facing.NORTH && block.isFullBlock() && !block1.isFullBlock())
{
if(enumfacing == Facing.NORTH && block.isFullBlock() && !block1.isFullBlock()) {
enumfacing = Facing.SOUTH;
}
else if (enumfacing == Facing.SOUTH && block1.isFullBlock() && !block.isFullBlock())
{
else if(enumfacing == Facing.SOUTH && block1.isFullBlock() && !block.isFullBlock()) {
enumfacing = Facing.NORTH;
}
else if (enumfacing == Facing.WEST && block2.isFullBlock() && !block3.isFullBlock())
{
else if(enumfacing == Facing.WEST && block2.isFullBlock() && !block3.isFullBlock()) {
enumfacing = Facing.EAST;
}
else if (enumfacing == Facing.EAST && block3.isFullBlock() && !block2.isFullBlock())
{
else if(enumfacing == Facing.EAST && block3.isFullBlock() && !block2.isFullBlock()) {
enumfacing = Facing.WEST;
}
@ -71,11 +62,8 @@ public class BlockFurnace extends Block implements ITileEntityProvider, Rotatabl
}
}
public void displayTick(World worldIn, BlockPos pos, State state, Random rand)
{
if (this.isBurning)
{
public void displayTick(World worldIn, BlockPos pos, State state, Random rand) {
if(this.isBurning) {
Facing enumfacing = (Facing)state.getValue(FACING);
double d0 = (double)pos.getX() + 0.5D;
double d1 = (double)pos.getY() + rand.doublev() * 6.0D / 16.0D;
@ -83,8 +71,7 @@ public class BlockFurnace extends Block implements ITileEntityProvider, Rotatabl
double d3 = 0.52D;
double d4 = rand.doublev() * 0.6D - 0.3D;
switch (enumfacing)
{
switch(enumfacing) {
case WEST:
worldIn.clientParticle(ParticleType.SMOKE, d0 - d3, d1, d2 + d4);
worldIn.clientParticle(ParticleType.FLAME, d0 - d3, d1, d2 + d4);
@ -107,97 +94,43 @@ public class BlockFurnace extends Block implements ITileEntityProvider, Rotatabl
}
}
public boolean onUse(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ)
{
if (worldIn.client)
{
return true;
}
else
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityFurnace)
{
playerIn.connection.show((TileEntityFurnace)tileentity);
// playerIn.triggerAchievement(StatRegistry.furnaceStat);
}
return true;
}
}
public static void setState(boolean active, World worldIn, BlockPos pos)
{
public static void setState(boolean active, World worldIn, BlockPos pos) {
State iblockstate = worldIn.getState(pos);
TileEntity tileentity = worldIn.getTileEntity(pos);
keepInventory = true;
if (active)
{
if(active) {
worldIn.setState(pos, Blocks.lit_furnace.getState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
worldIn.setState(pos, Blocks.lit_furnace.getState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
}
else
{
else {
worldIn.setState(pos, Blocks.furnace.getState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
worldIn.setState(pos, Blocks.furnace.getState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
}
keepInventory = false;
if (tileentity != null)
{
if(tileentity != null) {
tileentity.validate();
worldIn.setTileEntity(pos, tileentity);
}
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity()
{
return new TileEntityFurnace();
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public State getPlacedState(World worldIn, BlockPos pos, Facing facing, float hitX, float hitY, float hitZ, EntityLiving placer)
{
return this.getState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}
public void onRemoved(AWorldServer worldIn, BlockPos pos, State state)
{
if (!keepInventory)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityFurnace)
{
dropItems(worldIn, pos, (TileEntityFurnace)tileentity);
}
public TileEntity createNewTileEntity() {
return new DeviceFurnace(this.burnTime);
}
public void onRemoved(AWorldServer worldIn, BlockPos pos, State state) {
if(!keepInventory)
super.onRemoved(worldIn, pos, state);
}
public Item getItem()
{
public Item getItem() {
return Items.furnace;
}
protected Property[] getProperties()
{
return new Property[] {FACING};
}
public Model getModel(ModelProvider provider, String name, State state) {
return provider.getModel("furnace_side").add().du("furnace_top").n("furnace_front_" + (this.isBurning ? "on" : "off"))
.s().we().rotate(ModelRotation.getNorthRot(state.getValue(FACING)));
return provider.getModel("furnace_side").add().du("furnace_top").n("furnace_front_" + (this.isBurning ? "on" : "off")).s().we().rotate(ModelRotation.getNorthRot(state.getValue(FACING)));
}
protected boolean hasRegisteredItem() {

View file

@ -59,7 +59,7 @@ public abstract class BlockMachine extends Block implements Rotatable, ITileEnti
}
public State getPlacedState(World worldIn, BlockPos pos, Facing facing, float hitX, float hitY, float hitZ, EntityLiving placer) {
return this.getState().withProperty(FACING, placer.getHorizontalFacing());
return this.getState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}
protected Property[] getProperties() {

View file

@ -540,9 +540,9 @@ public abstract class BlockRegistry {
register("core", new BlockCore().setHardness(1.5F).setResistance(10.0F).setSound(SoundType.STONE).setDisplay("Chunk-Lade-Kern"));
register("mob_spawner", (new BlockMobSpawner()).setHardness(3.0F).setResistance(8.0F).setSound(SoundType.STONE).setDisplay("Mob-Spawner"));
register("workbench", (new BlockWorkbench(3)).setHardness(2.5F).setSound(SoundType.WOOD).setDisplay("Werkbank"));
register("furnace", (new BlockFurnace(false)).setHardness(3.5F).setSound(SoundType.STONE).setDisplay("Ofen")
register("furnace", (new BlockFurnace(false, 200)).setHardness(3.5F).setSound(SoundType.STONE).setDisplay("Ofen")
.setTab(CheatTab.TECHNOLOGY));
register("lit_furnace", (new BlockFurnace(true)).setHardness(3.5F).setSound(SoundType.STONE).setLight(0.875F)
register("lit_furnace", (new BlockFurnace(true, 200)).setHardness(3.5F).setSound(SoundType.STONE).setLight(0.875F)
.setDisplay("Ofen (Gefeuert)").setTab(CheatTab.TECHNOLOGY));
for(int z = 0; z < BlockAnvil.ANVILS.length; z++) {
register("anvil" + (z == 0 ? "" : "_damaged_" + z), (new BlockAnvil(z)).setHardness(5.0F).setSound(SoundType.ANVIL).setResistance(2000.0F).setDisplay((z == 0 ? "" : (z == 1 ? "Leicht beschädigter " : "Stark beschädigter ")) + "Amboss"));

View file

@ -1,166 +0,0 @@
package common.inventory;
import common.entity.npc.EntityNPC;
import common.init.SmeltingRegistry;
import common.item.ItemStack;
import common.network.IPlayer;
import common.tileentity.TileEntityFurnace;
public class ContainerFurnace extends Container
{
private final IInventory tileFurnace;
private int cookTime;
private int totalCookTime;
private int furnaceBurnTime;
private int currentItemBurnTime;
public ContainerFurnace(EntityNPC playerInventory, IInventory furnaceInventory)
{
this.tileFurnace = furnaceInventory;
this.addSlotToContainer(new Slot(furnaceInventory, 0, 56, 17));
this.addSlotToContainer(new SlotFurnaceFuel(furnaceInventory, 1, 56, 53));
this.addSlotToContainer(new SlotOutput(furnaceInventory, 2, 116, 35));
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int k = 0; k < 9; ++k)
{
this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
}
}
public void onCraftGuiOpened(IPlayer listener)
{
super.onCraftGuiOpened(listener);
listener.sendProperties(this, this.tileFurnace);
}
/**
* Looks for changes made in the container, sends them to every listener.
*/
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for (int i = 0; i < this.crafters.size(); ++i)
{
IPlayer icrafting = (IPlayer)this.crafters.get(i);
if (this.cookTime != this.tileFurnace.getField(2))
{
icrafting.sendProperty(this, 2, this.tileFurnace.getField(2));
}
if (this.furnaceBurnTime != this.tileFurnace.getField(0))
{
icrafting.sendProperty(this, 0, this.tileFurnace.getField(0));
}
if (this.currentItemBurnTime != this.tileFurnace.getField(1))
{
icrafting.sendProperty(this, 1, this.tileFurnace.getField(1));
}
if (this.totalCookTime != this.tileFurnace.getField(3))
{
icrafting.sendProperty(this, 3, this.tileFurnace.getField(3));
}
}
this.cookTime = this.tileFurnace.getField(2);
this.furnaceBurnTime = this.tileFurnace.getField(0);
this.currentItemBurnTime = this.tileFurnace.getField(1);
this.totalCookTime = this.tileFurnace.getField(3);
}
public void updateProgressBar(int id, int data)
{
this.tileFurnace.setField(id, data);
}
public boolean canInteractWith(EntityNPC playerIn)
{
return this.tileFurnace.isUseableByPlayer(playerIn);
}
/**
* Take a stack from the specified inventory slot.
*/
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 2)
{
if (!this.mergeItemStack(itemstack1, 3, 39, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (index != 1 && index != 0)
{
if (SmeltingRegistry.getResult(itemstack1) != null)
{
if (!this.mergeItemStack(itemstack1, 0, 1, false))
{
return null;
}
}
else if (TileEntityFurnace.isItemFuel(itemstack1))
{
if (!this.mergeItemStack(itemstack1, 1, 2, false))
{
return null;
}
}
else if (index >= 3 && index < 30)
{
if (!this.mergeItemStack(itemstack1, 30, 39, false))
{
return null;
}
}
else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
{
return null;
}
if (itemstack1.isEmpty())
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getSize() == itemstack.getSize())
{
return null;
}
slot.onPickupFromSlot(playerIn, itemstack1);
}
return itemstack;
}
}

View file

@ -1,28 +0,0 @@
package common.inventory;
import common.init.Items;
import common.item.ItemStack;
import common.tileentity.TileEntityFurnace;
public class SlotFurnaceFuel extends Slot
{
public SlotFurnaceFuel(IInventory inventoryIn, int slotIndex, int xPosition, int yPosition)
{
super(inventoryIn, slotIndex, xPosition, yPosition);
}
public boolean isItemValid(ItemStack stack)
{
return TileEntityFurnace.isItemFuel(stack) || isBucket(stack);
}
public int getItemStackLimit(ItemStack stack)
{
return isBucket(stack) ? 1 : super.getItemStackLimit(stack);
}
public static boolean isBucket(ItemStack stack)
{
return stack != null && stack.getItem() != null && stack.getItem() == Items.bucket;
}
}

View file

@ -87,6 +87,11 @@ public abstract class Device extends TileEntity implements IInventory, ITickable
this.progress = progress;
}
public boolean addProgress(int progress) {
this.progress += progress;
return this.progress >= this.total;
}
public int getTotal() {
return this.total;
}

View file

@ -0,0 +1,208 @@
package common.tileentity;
import common.block.tech.BlockFurnace;
import common.init.Items;
import common.init.SmeltingRegistry;
import common.inventory.ISidedInventory;
import common.item.Item;
import common.item.ItemStack;
import common.tags.TagObject;
import common.tileentity.MachineResource.Type;
import common.util.ExtMath;
import common.util.Facing;
import common.vars.Vars;
public class DeviceFurnace extends Device implements ISidedInventory
{
private static final int[] slotsTop = new int[] {0};
private static final int[] slotsBottom = new int[] {2, 1};
private static final int[] slotsSides = new int[] {1};
private final int burnTime;
public DeviceFurnace(int burnTime) {
super(2, 1, new MachineResource(Type.FUEL, "Brennzeit: $amount/$capacity t", 300, 0, 0));
this.burnTime = burnTime;
}
public boolean hasProgress() {
return true;
}
public void setInventorySlotContents(int index, ItemStack stack)
{
boolean flag = index == 0 && (stack == null || !stack.itemEquals(this.getStackInSlot(0)) || !ItemStack.dataEquals(stack, this.getStackInSlot(0)));
super.setInventorySlotContents(index, stack);
if (flag)
{
this.setTotal(this.getCookTime(stack));
this.setProgress(0);
this.markDirty();
}
}
public void readTags(TagObject compound)
{
super.readTags(compound);
this.getResource(0).setValue(getItemBurnTime(this.getStackInSlot(1)));
}
public boolean isBurning()
{
return this.getResource(0).getValue() > 0;
}
public boolean executeFunction()
{
boolean flag = this.isBurning();
boolean flag1 = false;
if (this.isBurning())
{
this.getResource(0).take(1, false);
}
if (this.isBurning() || this.getStackInSlot(1) != null && this.getStackInSlot(0) != null)
{
if (!this.isBurning() && this.canSmelt())
{
int fuel = getItemBurnTime(this.getStackInSlot(1));
this.getResource(0).setCapacity(fuel);
this.getResource(0).setValue(fuel);
if (this.isBurning())
{
flag1 = true;
if (this.getStackInSlot(1) != null)
{
if(Vars.itemExplosion && this.getStackInSlot(1).getItem().getExplosive() > 0 && !this.getStackInSlot(1).isEmpty()) {
this.worldObj.setBlockToAir(getPos());
this.worldObj.newExplosion(null, this.getXPos(), this.getYPos(), this.getZPos(), (float)this.getStackInSlot(1).getItem().getExplosive() * (1.0f + (float)(this.getStackInSlot(1).getSize() - 1) / 24.0f), true, true, true);
this.setInventorySlotContents(1, null);
return false;
}
else if (this.getStackInSlot(1).decrSize())
{
Item item = this.getStackInSlot(1).getItem().getContainerItem();
this.setInventorySlotContents(1, item != null ? new ItemStack(item) : null);
}
}
}
}
if (this.isBurning() && this.canSmelt())
{
if (this.addProgress(1))
{
this.setProgress(0);
this.setTotal(this.getCookTime(this.getStackInSlot(0)));
this.smeltItem();
flag1 = true;
}
}
else
{
this.setProgress(0);
}
}
else if (!this.isBurning() && this.getProgress() > 0)
{
this.setProgress(ExtMath.clampi(this.getProgress() - 2, 0, this.getTotal()));
}
if (flag != this.isBurning())
{
flag1 = true;
BlockFurnace.setState(this.isBurning(), this.worldObj, this.pos);
}
if (flag1)
{
this.markDirty();
}
return this.isBurning();
}
public int getCookTime(ItemStack stack)
{
return this.burnTime;
}
private boolean canSmelt()
{
if (this.getStackInSlot(0) == null)
{
return false;
}
else
{
ItemStack itemstack = SmeltingRegistry.getResult(this.getStackInSlot(0));
ItemStack out = this.getStackInSlot(2);
return itemstack == null ? false : (out == null ? true : (!out.itemEquals(itemstack) ? false : (out.getSize() < this.getInventoryStackLimit() && !out.isFull() ? true : out.getSize() < itemstack.getMaxStackSize())));
}
}
public void smeltItem()
{
if (this.canSmelt())
{
ItemStack itemstack = SmeltingRegistry.getResult(this.getStackInSlot(0));
if (this.getStackInSlot(2) == null)
{
this.setInventorySlotContents(2, itemstack.copy());
}
else if (this.getStackInSlot(2).getItem() == itemstack.getItem())
{
this.getStackInSlot(2).incrSize();
}
if (this.getStackInSlot(0).decrSize())
{
this.setInventorySlotContents(0, null);
}
}
}
public static int getItemBurnTime(ItemStack stack)
{
return stack != null ? stack.getItem().getFuelAmount() : 0;
}
public static boolean isItemFuel(ItemStack stack)
{
return getItemBurnTime(stack) > 0;
}
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return index == 2 ? false : (index != 1 ? true : isItemFuel(stack));
}
public int[] getSlotsForFace(Facing side)
{
return side == Facing.DOWN ? slotsBottom : (side == Facing.UP ? slotsTop : slotsSides);
}
public boolean canInsertItem(int index, ItemStack itemStackIn, Facing direction)
{
return this.isItemValidForSlot(index, itemStackIn);
}
public boolean canExtractItem(int index, ItemStack stack, Facing direction)
{
if (direction == Facing.DOWN && index == 1)
{
Item item = stack.getItem();
if (item != Items.bucket)
{
return false;
}
}
return true;
}
}

View file

@ -20,10 +20,6 @@ public class DeviceMobSpawner extends Device implements ITickable
private int maxSpawnDelay = 800;
private int spawnRange = 4;
public boolean hasProgress() {
return true;
}
public boolean isItemValidForSlot(int index, ItemStack stack) {
return index == 0 ? stack.getItem() instanceof ItemMobTemplate || stack.getItem() instanceof ItemCharTemplate : false;
}

View file

@ -34,10 +34,6 @@ public class DeviceTianReactor extends Device {
return this.isInputEmpty(1) ? this.rand.chance(0, 1, 3) : this.rand.range(1, 3);
}
public boolean hasProgress() {
return true;
}
public boolean isItemValidForSlot(int index, ItemStack stack) {
return index == 0 ? stack.getItem() == Items.aluminium_ingot : (index == 1 ? stack.getItem() == Items.lead_block : false);
}

View file

@ -1,451 +0,0 @@
package common.tileentity;
import common.block.tech.BlockFurnace;
import common.collect.Lists;
import common.entity.npc.EntityNPC;
import common.init.Items;
import common.init.SmeltingRegistry;
import common.inventory.Container;
import common.inventory.ContainerFurnace;
import common.inventory.IInventory;
import common.inventory.ISidedInventory;
import common.inventory.SlotFurnaceFuel;
import common.item.Item;
import common.item.ItemStack;
import common.tags.TagObject;
import java.util.List;
import common.util.ExtMath;
import common.util.Facing;
import common.vars.Vars;
public class TileEntityFurnace extends TileEntityInventory implements ITickable, ISidedInventory
{
private static final int[] slotsTop = new int[] {0};
private static final int[] slotsBottom = new int[] {2, 1};
private static final int[] slotsSides = new int[] {1};
/**
* The ItemStacks that hold the items currently being used in the furnace
*/
private ItemStack[] furnaceItemStacks = new ItemStack[3];
/** The number of ticks that the furnace will keep burning */
private int furnaceBurnTime;
/**
* The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for
*/
private int currentItemBurnTime;
private int cookTime;
private int totalCookTime;
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return this.furnaceItemStacks.length;
}
/**
* Returns the stack in the given slot.
*/
public ItemStack getStackInSlot(int index)
{
return this.furnaceItemStacks[index];
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
public ItemStack decrStackSize(int index, int count)
{
if (this.furnaceItemStacks[index] != null)
{
if (this.furnaceItemStacks[index].getSize() <= count)
{
ItemStack itemstack1 = this.furnaceItemStacks[index];
this.furnaceItemStacks[index] = null;
return itemstack1;
}
else
{
ItemStack itemstack = this.furnaceItemStacks[index].split(count);
if (this.furnaceItemStacks[index].isEmpty())
{
this.furnaceItemStacks[index] = null;
}
return itemstack;
}
}
else
{
return null;
}
}
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index)
{
if (this.furnaceItemStacks[index] != null)
{
ItemStack itemstack = this.furnaceItemStacks[index];
this.furnaceItemStacks[index] = null;
return itemstack;
}
else
{
return null;
}
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
boolean flag = stack != null && stack.itemEquals(this.furnaceItemStacks[index]) && ItemStack.dataEquals(stack, this.furnaceItemStacks[index]);
this.furnaceItemStacks[index] = stack;
if (stack != null && stack.getSize() > this.getInventoryStackLimit())
{
stack.setSize(this.getInventoryStackLimit());
}
if (index == 0 && !flag)
{
this.totalCookTime = this.getCookTime(stack);
this.cookTime = 0;
this.markDirty();
}
}
public void readTags(TagObject compound)
{
super.readTags(compound);
List<TagObject> nbttaglist = compound.getList("Items");
this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.size(); ++i)
{
TagObject nbttagcompound = nbttaglist.get(i);
int j = nbttagcompound.getByte("Slot");
if (j >= 0 && j < this.furnaceItemStacks.length)
{
this.furnaceItemStacks[j] = ItemStack.readFromTag(nbttagcompound);
}
}
this.furnaceBurnTime = compound.getShort("BurnTime");
this.cookTime = compound.getShort("CookTime");
this.totalCookTime = compound.getShort("CookTimeTotal");
this.currentItemBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
}
public void writeTags(TagObject compound)
{
super.writeTags(compound);
compound.setShort("BurnTime", (short)this.furnaceBurnTime);
compound.setShort("CookTime", (short)this.cookTime);
compound.setShort("CookTimeTotal", (short)this.totalCookTime);
List<TagObject> nbttaglist = Lists.newArrayList();
for (int i = 0; i < this.furnaceItemStacks.length; ++i)
{
if (this.furnaceItemStacks[i] != null)
{
TagObject nbttagcompound = new TagObject();
nbttagcompound.setByte("Slot", (byte)i);
this.furnaceItemStacks[i].writeTags(nbttagcompound);
nbttaglist.add(nbttagcompound);
}
}
compound.setList("Items", nbttaglist);
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return ItemStack.MAX_SIZE;
}
/**
* Furnace isBurning
*/
public boolean isBurning()
{
return this.furnaceBurnTime > 0;
}
public static boolean isBurning(IInventory p_174903_0_)
{
return p_174903_0_.getField(0) > 0;
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
boolean flag = this.isBurning();
boolean flag1 = false;
if (this.isBurning())
{
--this.furnaceBurnTime;
}
if (!this.worldObj.client)
{
if (this.isBurning() || this.furnaceItemStacks[1] != null && this.furnaceItemStacks[0] != null)
{
if (!this.isBurning() && this.canSmelt())
{
this.currentItemBurnTime = this.furnaceBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
if (this.isBurning())
{
flag1 = true;
if (this.furnaceItemStacks[1] != null)
{
if(Vars.itemExplosion && this.furnaceItemStacks[1].getItem().getExplosive() > 0 && !this.furnaceItemStacks[1].isEmpty()) {
this.worldObj.setBlockToAir(getPos());
this.worldObj.newExplosion(null, this.getXPos(), this.getYPos(), this.getZPos(), (float)this.furnaceItemStacks[1].getItem().getExplosive() * (1.0f + (float)(this.furnaceItemStacks[1].getSize() - 1) / 24.0f), true, true, true);
this.furnaceItemStacks[1] = null;
return;
}
else if (this.furnaceItemStacks[1].decrSize())
{
Item item = this.furnaceItemStacks[1].getItem().getContainerItem();
this.furnaceItemStacks[1] = item != null ? new ItemStack(item) : null;
}
}
}
}
if (this.isBurning() && this.canSmelt())
{
++this.cookTime;
if (this.cookTime == this.totalCookTime)
{
this.cookTime = 0;
this.totalCookTime = this.getCookTime(this.furnaceItemStacks[0]);
this.smeltItem();
flag1 = true;
}
}
else
{
this.cookTime = 0;
}
}
else if (!this.isBurning() && this.cookTime > 0)
{
this.cookTime = ExtMath.clampi(this.cookTime - 2, 0, this.totalCookTime);
}
if (flag != this.isBurning())
{
flag1 = true;
BlockFurnace.setState(this.isBurning(), this.worldObj, this.pos);
}
}
if (flag1)
{
this.markDirty();
}
}
public int getCookTime(ItemStack stack)
{
return 200;
}
/**
* Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't full, etc.
*/
private boolean canSmelt()
{
if (this.furnaceItemStacks[0] == null)
{
return false;
}
else
{
ItemStack itemstack = SmeltingRegistry.getResult(this.furnaceItemStacks[0]);
return itemstack == null ? false : (this.furnaceItemStacks[2] == null ? true : (!this.furnaceItemStacks[2].itemEquals(itemstack) ? false : (this.furnaceItemStacks[2].getSize() < this.getInventoryStackLimit() && !this.furnaceItemStacks[2].isFull() ? true : this.furnaceItemStacks[2].getSize() < itemstack.getMaxStackSize())));
}
}
/**
* Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
*/
public void smeltItem()
{
if (this.canSmelt())
{
ItemStack itemstack = SmeltingRegistry.getResult(this.furnaceItemStacks[0]);
if (this.furnaceItemStacks[2] == null)
{
this.furnaceItemStacks[2] = itemstack.copy();
}
else if (this.furnaceItemStacks[2].getItem() == itemstack.getItem())
{
this.furnaceItemStacks[2].incrSize();
}
// if (this.furnaceItemStacks[0].getItem() == Items.sponge && this.furnaceItemStacks[0].getMetadata() == 1 && this.furnaceItemStacks[1] != null && this.furnaceItemStacks[1].getItem() == Items.bucket)
// {
// this.furnaceItemStacks[1] = new ItemStack(Items.water_bucket);
// }
if (this.furnaceItemStacks[0].decrSize())
{
this.furnaceItemStacks[0] = null;
}
}
}
public static int getItemBurnTime(ItemStack stack)
{
return stack != null ? stack.getItem().getFuelAmount() : 0;
}
public static boolean isItemFuel(ItemStack stack)
{
return getItemBurnTime(stack) > 0;
}
/**
* Do not make give this method the name canInteractWith because it clashes with Container
*/
public boolean isUseableByPlayer(EntityNPC player)
{
return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
}
public void openInventory(EntityNPC player)
{
}
public void closeInventory(EntityNPC player)
{
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return index == 2 ? false : (index != 1 ? true : isItemFuel(stack) || SlotFurnaceFuel.isBucket(stack));
}
public int[] getSlotsForFace(Facing side)
{
return side == Facing.DOWN ? slotsBottom : (side == Facing.UP ? slotsTop : slotsSides);
}
/**
* Returns true if automation can insert the given item in the given slot from the given side. Args: slot, item,
* side
*/
public boolean canInsertItem(int index, ItemStack itemStackIn, Facing direction)
{
return this.isItemValidForSlot(index, itemStackIn);
}
/**
* Returns true if automation can extract the given item in the given slot from the given side. Args: slot, item,
* side
*/
public boolean canExtractItem(int index, ItemStack stack, Facing direction)
{
if (direction == Facing.DOWN && index == 1)
{
Item item = stack.getItem();
if (/* item != Items.water_bucket && */ item != Items.bucket)
{
return false;
}
}
return true;
}
public Container createContainer(EntityNPC playerInventory)
{
return new ContainerFurnace(playerInventory, this);
}
public int getField(int id)
{
switch (id)
{
case 0:
return this.furnaceBurnTime;
case 1:
return this.currentItemBurnTime;
case 2:
return this.cookTime;
case 3:
return this.totalCookTime;
default:
return 0;
}
}
public void setField(int id, int value)
{
switch (id)
{
case 0:
this.furnaceBurnTime = value;
break;
case 1:
this.currentItemBurnTime = value;
break;
case 2:
this.cookTime = value;
break;
case 3:
this.totalCookTime = value;
}
}
public int getFieldCount()
{
return 4;
}
public void clear()
{
for (int i = 0; i < this.furnaceItemStacks.length; ++i)
{
this.furnaceItemStacks[i] = null;
}
}
public int getColor() {
return 0xff7f00;
}
}

View file

@ -101,7 +101,7 @@ import common.tileentity.TileEntity;
import common.tileentity.TileEntityChest;
import common.tileentity.TileEntityDispenser;
import common.tileentity.TileEntityDropper;
import common.tileentity.TileEntityFurnace;
import common.tileentity.DeviceFurnace;
import common.tileentity.TileEntityHopper;
import common.tileentity.TileEntitySign;
import common.util.BlockPos;
@ -351,7 +351,7 @@ public abstract class Converter {
mapEntity(EntityHorse.class, "EntityHorse", "horse");
mapEntity(EntityRabbit.class, "Rabbit", "rabbit");
mapTile(TileEntityFurnace.class, "Furnace", "furnace");
mapTile(DeviceFurnace.class, "Furnace", "furnace");
mapTile(TileEntityChest.class, "Chest", "chest");
mapTile(TileEntityDispenser.class, "Trap", "dispenser");
mapTile(TileEntityDropper.class, "Dropper", "dropper");