Hello i am having problems with my Electric Furnace only pulling one power from my power network but i want it to use one power for each block and it is smelting one time then all of the ore's start to smelt fast after it. Works one time smelting and it does not use power for the items after the first one
public class TileEntityElectricFurnace extends TileEntity implements IEnergy, IInventory
{
private EnergyBar energyBar = new EnergyBar(45);
private ItemStack[] inventory = new ItemStack[18];
private int energyUsePerSmelt = 1;
private int defaultEnergyUsePerSmelt = 1;
public boolean isSmelting;
private int smeltStatus;
private int smeltTime = 90;
private int defaultSmeltTime = 90;
public int rotation = 3;
public boolean hasExtraInventory;
public int getCookProgressScaled(int scale)
{
return this.smeltStatus * scale / smeltTime;
}
@Override
public BlockType getTypeOfBlock()
{
return BlockType.MACHINE;
}
public Packet getDescriptionPacket()
{
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
}
public void onDataPacket(NetworkManager manager, S35PacketUpdateTileEntity packet)
{
readFromNBT(packet.func_148857_g());
}
That code is pretty specific to you. I think you just need to do standard debug -- put in a bunch of console statements (System.out.println()) at each point in the code and confirm that it is executing according to expectations. You can print out the value of variables and stuff, and particularly make sure the code is taking the conditional paths you expect.
Usually that technique will quickly show you what is going wrong.
I agree with jabelar, it's a bit too personal. We wouldn't know enough about it. Also may you do us a favor and move the code to pastebin. It's just a lot easier to read for us. Just like jabelar said, put print lines everywhere and find out what's not being called/happening.
Hello i am having problems with my Electric Furnace only pulling one power from my power network but i want it to use one power for each block and it is smelting one time then all of the ore's start to smelt fast after it. Works one time smelting and it does not use power for the items after the first one
My TileEntityElectricFurnace Class
package andrewcraft.tileentity;
import java.util.ArrayList;
import andrewcraft.block.BlockType;
import andrewcraft.damage.DamageSources;
import andrewcraft.energy.EnergyBar;
import andrewcraft.energy.IEnergy;
import andrewcraft.item.MolecularEnergyItems;
import andrewcraft.upgrade.IUpgrade;
import andrewcraft.upgrade.Upgrade;
import andrewcraft.util.InventoryUtil;
import andrewcraft.util.MachineUtil;
import andrewcraft.util.NBTUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityElectricFurnace extends TileEntity implements IEnergy, IInventory
{
private EnergyBar energyBar = new EnergyBar(45);
private ItemStack[] inventory = new ItemStack[18];
private int energyUsePerSmelt = 1;
private int defaultEnergyUsePerSmelt = 1;
public boolean isSmelting;
private int smeltStatus;
private int smeltTime = 90;
private int defaultSmeltTime = 90;
public int rotation = 3;
public boolean hasExtraInventory;
public void updateEntity()
{
updateUpgrades();
updateSmelting();
}
private void updateUpgrades()
{
int inventoryUpgrades = 0;
smeltTime = defaultSmeltTime;
energyUsePerSmelt = defaultEnergyUsePerSmelt;
energyBar.resetMaxEnergyLevel();
for (int index = 2; index < 6; index++)
{
if (inventory[index] != null && inventory[index].getItem() instanceof IUpgrade)
{
IUpgrade itemUpgrade = (IUpgrade) inventory[index].getItem();
this.energyBar.setMaxEnergyLevel(energyBar.getMaxEnergyLevel() + itemUpgrade.getUpgradeWorthness(Upgrade.STORAGE, inventory[index].getItemDamage()) * inventory[index].stackSize);
this.smeltTime -= itemUpgrade.getUpgradeWorthness(Upgrade.SPEED, inventory[index].getItemDamage()) * inventory[index].stackSize;
this.energyUsePerSmelt -= itemUpgrade.getUpgradeWorthness(Upgrade.EFFICIENCY, inventory[index].getItemDamage() * inventory[index].stackSize);
if (inventory[index].isItemEqual(new ItemStack(ModItems.UPGRADES, 1, 3)))
{
inventoryUpgrades++;
}
}
}
hasExtraInventory = inventoryUpgrades > 0;
if (energyBar.getEnergyLevel() > energyBar.getMaxEnergyLevel())
{
if (!worldObj.isRemote)
{
ArrayList<Entity> entities = (ArrayList<Entity>) worldObj.getEntitiesWithinAABB(EntityPlayer.class, getRenderBoundingBox().expand(3, 3, 3));
for (Entity entity : entities)
{
entity.attackEntityFrom(DamageSources.ELECTRICITY, (energyBar.getEnergyLevel() - energyBar.getMaxEnergyLevel()) / 100);
}
}
energyBar.setEnergyLevel(energyBar.getMaxEnergyLevel());
}
}
private void updateSmelting()
{
boolean modified = isSmelting;
this.isSmelting = canSmelt();
if (this.isSmelting)
{
this.smeltStatus += 1;
}
else
{
this.smeltStatus = 0;
}
if (this.smeltStatus >= this.smeltTime)
{
smelt();
}
if (modified != isSmelting)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
private boolean canSmelt()
{
if (inventory[0] == null) return false;
return MachineUtil.canOperate(inventory, energyBar, FurnaceRecipes.smelting().getSmeltingResult(inventory[0]), this, energyUsePerSmelt, 1);
}
private void smelt()
{
MachineUtil.operate(inventory, energyBar, FurnaceRecipes.smelting().getSmeltingResult(inventory[0]), this, smeltStatus, isSmelting, energyUsePerSmelt, 1);
}
@Override
public boolean canAddEnergyOnSide(ForgeDirection direction)
{
return true;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return true;
}
@Override
public EnergyBar getEnergyBar()
{
return energyBar;
}
@Override
public void setLastReceivedDirection(ForgeDirection direction)
{
}
@Override
public int getEnergyTransferRate()
{
return 32;
}
@Override
public int getSizeInventory()
{
return InventoryUtil.getSizeInventory(inventory);
}
@Override
public ItemStack getStackInSlot(int slot)
{
return InventoryUtil.getStackInSlot(inventory, slot);
}
@Override
public ItemStack decrStackSize(int slot, int count)
{
return InventoryUtil.decrStackSize(inventory, slot, count);
}
@Override
public ItemStack getStackInSlotOnClosing(int slot)
{
return InventoryUtil.getStackInSlotOnClosing(inventory, slot);
}
@Override
public void setInventorySlotContents(int slot, ItemStack itemstack)
{
InventoryUtil.setInventorySlotContents(this, inventory, slot, itemstack);
}
@Override
public String getInventoryName()
{
return "container.energizedFurnace";
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
return true;
}
@Override
public void openInventory()
{
}
@Override
public void closeInventory()
{
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
return true;
}
public int getCookProgressScaled(int scale)
{
return this.smeltStatus * scale / smeltTime;
}
@Override
public BlockType getTypeOfBlock()
{
return BlockType.MACHINE;
}
public Packet getDescriptionPacket()
{
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
}
public void onDataPacket(NetworkManager manager, S35PacketUpdateTileEntity packet)
{
readFromNBT(packet.func_148857_g());
}
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT(tag);
energyBar.writeToNBT(tag);
tag.setInteger("rotation", rotation);
tag.setInteger("smeltStatus", smeltStatus);
NBTUtil.writeItemStackArrayToNBT(inventory, tag);
}
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tag);
energyBar.readFromNBT(tag);
rotation = tag.getInteger("rotation");
smeltStatus = tag.getInteger("smeltStatus");
NBTUtil.readItemStackArrayFromNBT(inventory, tag);
}
}
That code is pretty specific to you. I think you just need to do standard debug -- put in a bunch of console statements (System.out.println()) at each point in the code and confirm that it is executing according to expectations. You can print out the value of variables and stuff, and particularly make sure the code is taking the conditional paths you expect.
Usually that technique will quickly show you what is going wrong.
Ok i have traced it down to my smelt method getting fired a lot from this if statement
if statement
if (this.smeltStatus >= this.smeltTime)
{
LogHelper.info("3");
smelt();
}
Smelt method
private void smelt()
{
LogHelper.info("6");
MachineUtil.operate(inventory, energyBar, FurnaceRecipes.smelting().getSmeltingResult(inventory[0]), this, smeltStatus, isSmelting, energyUsePerSmelt, 1);
}
MachineUtil
package andrewcraft.util;
import andrewcraft.energy.EnergyBar;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class MachineUtil
{
public static void operate(ItemStack[] inventory, EnergyBar energyBar, ItemStack result, IInventory inventoryClass, int grindStatus, boolean isGrinding, int energyUsePerOperation, int stackSizeToDecrease)
{
if (result != null)
{
if (inventory[1] == null)
{
inventory[1] = result.copy();
}
else if (inventory[1].isItemEqual(result))
{
inventory[1].stackSize += result.stackSize;
}
inventory[0].stackSize -= stackSizeToDecrease;
if (inventory[0].stackSize <= 0)
{
inventory[0] = null;
}
energyBar.removeEnergy(energyUsePerOperation);
}
grindStatus = 0;
isGrinding = false;
}
public static boolean canOperate(ItemStack[] inventory, EnergyBar energyBar, ItemStack result, IInventory inventoryClass, int energyUsePerOperation, int stackSizeToDecrease)
{
if (inventory[0] == null)
{
return false;
}
if (result == null) return false;
if (!energyBar.canRemoveEnergy(energyUsePerOperation)) return false;
if (inventory[1] == null) return true;
if (!inventory[1].isItemEqual(result)) return false;
if (inventory[1].stackSize + stackSizeToDecrease > inventory[1].getMaxStackSize()) return false;
int resultStack = inventory[1].stackSize + result.stackSize;
return (resultStack <= inventoryClass.getInventoryStackLimit()) && (resultStack <= result.getMaxStackSize());
}
}
I agree with jabelar, it's a bit too personal. We wouldn't know enough about it. Also may you do us a favor and move the code to pastebin. It's just a lot easier to read for us. Just like jabelar said, put print lines everywhere and find out what's not being called/happening.
Hello!
Fixed it