Koopamillion Posted March 21, 2016 Share Posted March 21, 2016 So, I've added electricity and stuff. Anyway, the generator generates power fine, just like the solar panel, however, when I plug the generator's electricity into a machine, the energy bar on the side goes up, and when I put in something to smelt, the progress shows fine. BUT!!! When I plug in the solar panels electricity, it dosen't increase the energy bar, (IN THE GUI, IT IS ACTUALLY ADDING POWER BUT JUST NOT SHOWING), the progress dosen't show at all, however it still smelts items. This isn't just the machines, the energy storage's gui dosen't update either unless it's connected to a generator. Is it the gui not updating? A method i've done wrong? Thanks In advance: The solar panel has no gui/container btw. ALL CODE: Generator TileEntity: package com.koopamillion.tile_entity; import com.koopamillion.blocks.BlockType; import com.koopamillion.energy.EnergyBar; import com.koopamillion.energy.EnergyNet; import com.koopamillion.energy.IEnergy; import com.koopamillion.util.InventoryUtil; import com.koopamillion.util.NBTUtil; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; 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.minecraft.tileentity.TileEntityFurnace; import net.minecraftforge.common.util.ForgeDirection; public class TileEntityCoalGenerator extends TileEntity implements IEnergy, IInventory, ISidedInventory{ private EnergyBar energyBar = new EnergyBar(12000); //how much it holds private ItemStack[] inventory = new ItemStack[7]; public int burnTime; public int currentItemBurnTime; public int rotation = 3; private float modifier = 17.5f; private float defaultModifier = 17.5f; public int burnTimeRemovedPerTick = 3; public void updateEntity(){ updateGenerating(); } private void updateGenerating(){ boolean modified = burnTime > 0; if(burnTime > 0){ if(burnTime > burnTimeRemovedPerTick){ burnTime -= burnTimeRemovedPerTick; energyBar.addEnergyWithRemaining(burnTimeRemovedPerTick); }else{ energyBar.addEnergyWithRemaining(burnTime); burnTime = 0; }}else{ if(burnTime > 0){ energyBar.addEnergyWithRemaining(burnTime); burnTime = 0; } } if(burnTime == 0 &&(TileEntityFurnace.isItemFuel(inventory[0]) || TileEntityFurnace.isItemFuel(inventory[5]) || TileEntityFurnace.isItemFuel(inventory[6]))){ currentItemBurnTime = burnTime += (int) (TileEntityFurnace.getItemBurnTime(inventory[0]) * modifier) + (int) (TileEntityFurnace.getItemBurnTime(inventory[6]) * modifier); if(inventory[0] != null){ inventory[0].stackSize--; if(inventory[0].stackSize <= 0){ inventory[0] = null; } } if(inventory[5] != null){ inventory[5].stackSize--; if(inventory[5].stackSize <= 0){ inventory[5] = null; } } if(inventory[6] != null){ inventory[6].stackSize--; if(inventory[6].stackSize <= 0){ inventory[6] = null; } } } EnergyNet.distributeEnergyToSurrounding(worldObj, xCoord, yCoord, zCoord, energyBar); if(modified != burnTime > 0){ worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } } @Override public boolean canAddEnergyOnSide(ForgeDirection direction){ //accept energy? return false; //no defaultly for generators } @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 10; } 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()); } @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.powerGenerator"; } @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){ switch(slot){ case 0: return TileEntityFurnace.isItemFuel(itemstack); } return false; } public int getBurnTime(){ return burnTime; } public boolean isBurning(){ return burnTime > 0; } public int getBurnTimeScaled(int scale){ return burnTime * scale / currentItemBurnTime; } @Override public int[] getAccessibleSlotsFromSide(int slot){ return new int[] {0}; } @Override public boolean canInsertItem(int slot, ItemStack itemstack, int side){ return isItemValidForSlot(slot, itemstack); } @Override public boolean canExtractItem(int slot, ItemStack itemstack, int side){ return false; } @Override public BlockType getTypeOfBlock(){ return BlockType.MACHINE; } public void writeToNBT(NBTTagCompound tag){ super.writeToNBT(tag); energyBar.writeToNBT(tag); tag.setInteger("rotation", rotation); tag.setInteger("burnTime", burnTime); tag.setInteger("currentItemBurnTime", currentItemBurnTime); NBTUtil.writeItemStackArrayToNBT(inventory, tag); } public void readFromNBT(NBTTagCompound tag){ super.readFromNBT(tag); energyBar.readFromNBT(tag); rotation = tag.getInteger("rotation"); burnTime = tag.getInteger("burnTime"); currentItemBurnTime = tag.getInteger("currentItemBurnTime"); NBTUtil.readItemStackArrayFromNBT(inventory, tag); } } Solar Tileentity: package com.koopamillion.tile_entity; import com.koopamillion.blocks.BlockType; import com.koopamillion.energy.EnergyBar; import com.koopamillion.energy.EnergyNet; import com.koopamillion.energy.IEnergy; import com.koopamillion.util.LogHelper; 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.world.biome.BiomeGenDesert; import net.minecraftforge.common.util.ForgeDirection; public class TileEntitySolarPanel extends TileEntityBasicBlock implements IEnergy { private EnergyBar energyBar = new EnergyBar(12000); public boolean seesSun = false; public int time = 1; public boolean isDesert(){ return worldObj.provider.getBiomeGenForCoords(xCoord >> 4, zCoord >> 4) instanceof BiomeGenDesert; } public void updateEntity(){ if(!worldObj.isRemote){ if(worldObj.isDaytime() && ((!worldObj.isRaining() && !worldObj.isThundering()) || isDesert()) && !worldObj.provider.hasNoSky && worldObj.canBlockSeeTheSky(xCoord, yCoord + 1, zCoord)){ seesSun = true; energyBar.addEnergyWithRemaining(time); }else{ seesSun = false; } } worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); EnergyNet.distributeEnergyToSurrounding(worldObj, xCoord, yCoord, zCoord, energyBar); } @Override public boolean canAddEnergyOnSide(ForgeDirection direction) { return false; } @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 10; } @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); } public void readFromNBT(NBTTagCompound tag){ super.readFromNBT(tag); energyBar.readFromNBT(tag); } } Machine TileEntity: package com.koopamillion.tile_entity; import com.koopamillion.blocks.BlockType; import com.koopamillion.energy.EnergyBar; import com.koopamillion.energy.IEnergy; import com.koopamillion.util.InventoryUtil; import com.koopamillion.util.MachineUtil; import com.koopamillion.util.NBTUtil; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ICrafting; 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.world.World; import net.minecraftforge.common.util.ForgeDirection; public class TileEntityElectricFurnace extends TileEntityBasicBlock implements IEnergy, IInventory{ private EnergyBar energyBar = new EnergyBar(1200); private ItemStack[] inventory = new ItemStack[18]; private int energyUsePerSmelt = 300; private int defaultEnergyPerSmelt = 300; public int rotation = 3; public boolean isSmelting; private int smeltStatus; private int smeltTime = 80; private int defaultSmeltTime = 80; //UPGRADE INFO: //Speed Upgrade: -5 SmeltTime, + 50 EUS; Stackable: 12 (-60 SmeltTime) (+600 EUS) //Eco Upgrade: - 20 EUS; + 5 SmeltTime; Stackable : 12 (-240 EUS) (+60 SmeltTime) //Battery Upgrade: + 200 EnergyStorage; Stackable : 36 (+7200 ES) public void updateEntity(){ updateSmelting(); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } 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(); this.smeltStatus = 0; } if(modified != isSmelting){ worldObj.markBlockForUpdate(xCoord, yCoord, xCoord); } } 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 100; } @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.electricFurnace"; } @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 getCookProgress(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(); } 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); } } The machine's gui + container: package com.koopamillion.gui; import java.util.Arrays; import com.koopamillion.energy.EnergyBar; import com.koopamillion.energy.IEnergy; import com.koopamillion.inventory.ContainerElectricFurnace; import com.koopamillion.lib.Energy; import com.koopamillion.lib.RefStrings; import com.koopamillion.tile_entity.TileEntityElectricFurnace; import com.koopamillion.util.GuiUtil; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; public class GuiElectricFurnace extends GuiContainer{ private static final ResourceLocation GUI = new ResourceLocation(RefStrings.MODID + ":textures/gui/container/eFurnace.png"); public final EntityPlayer player; public final World world; public final int x; public final int y; public final int z; public TileEntityElectricFurnace tileentity; public GuiElectricFurnace(EntityPlayer player, World world, int x, int y, int z) { super(new ContainerElectricFurnace(player, world, x, y, z)); this.player = player; this.world = world; this.x = x; this.y = y; this.z = z; this.tileentity = (TileEntityElectricFurnace) world.getTileEntity(x, y, z); } @Override protected void drawGuiContainerBackgroundLayer(float f, int x, int y) { xSize = 176; this.mc.getTextureManager().bindTexture(GUI); GuiUtil.drawRectangle(guiLeft, guiTop, 176, ySize, 256, 256, 0, 0); int energyBarSize = 48; this.drawTexturedModalRect(guiLeft + 8, guiTop + 8 + energyBarSize - ((IEnergy) tileentity).getEnergyBar().getEnergyLevelScaled(energyBarSize), 176, 31, 16, ((IEnergy) tileentity).getEnergyBar().getEnergyLevelScaled(energyBarSize)); int middleX = (this.width - this.xSize) / 2; int middleY = (this.height - this.ySize) / 2; if(this.tileentity.isSmelting){ this.drawTexturedModalRect(middleX + 56, middleY + 36 + 18, 176, 0, 14, 14); } int scale = this.tileentity.getCookProgress(24); this.drawTexturedModalRect(middleX + 79, middleY + 34, 176, 14, scale + 1, 16); } @Override public void drawGuiContainerForegroundLayer(int x, int y){ drawEnergyLevel(x, y); } private void drawEnergyLevel(int x, int y){ int minX = guiLeft + 8; int maxX = guiLeft + 8 + 15; int minY = guiTop + 8; int maxY = guiTop + 8 + 47; EnergyBar energyBar = ((IEnergy) tileentity).getEnergyBar(); if(x >= minX && x <= maxX && y >= minY && y <= maxY){ this.drawHoveringText(Arrays.asList(energyBar.getEnergyLevel() + " /" + energyBar.getMaxEnergyLevel() + " " + Energy.Koops.getName()), x - guiLeft - 6, y - guiTop, fontRendererObj); } } } package com.koopamillion.inventory; import com.koopamillion.slot.SlotOutput; import com.koopamillion.tile_entity.TileEntityElectricFurnace; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.world.World; public class ContainerElectricFurnace extends Container{ public final EntityPlayer player; public final World world; public final int x; public final int y; public final int z; public TileEntityElectricFurnace tileentity; public static final int INPUT = 0, OUTPUT = 1; public ContainerElectricFurnace(EntityPlayer player, World world, int x, int y, int z){ this.player = player; this.world = world; this.x = x; this.y = y; this.z = z; this.tileentity = (TileEntityElectricFurnace) world.getTileEntity(x, y, z); this.detectAndSendChanges(); updateSlots(); } public boolean canInteractWith(EntityPlayer player){ return tileentity.isUseableByPlayer(player); } public void updateSlots(){ this.inventorySlots.clear(); this.addSlotToContainer(new Slot(tileentity, INPUT, 56, 35)); this.detectAndSendChanges(); this.addSlotToContainer(new SlotOutput(player, tileentity, OUTPUT, 116, 35)); for(int i = 0; i < 3; ++i){ for(int j = 0; j < 9; ++j){ this.addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for(int i = 0; i < 9; ++i){ this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 142)); //ep 33 to watch } } public ItemStack transferStackInSlot(EntityPlayer player, int slotId) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(slotId); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); // If itemstack is in Output stack if (slotId == OUTPUT) { // try to place in player inventory / action bar; add 36+1 because mergeItemStack uses < index, // so the last slot in the inventory won't get checked if you don't add 1 if (!this.mergeItemStack(itemstack1, OUTPUT+1, OUTPUT+36+1, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } // itemstack is in player inventory, try to place in appropriate furnace slot else if (slotId != INPUT) { // if it can be smelted, place in the input slots if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null) { // try to place in either Input slot; add 1 to final input slot because mergeItemStack uses < index if (!this.mergeItemStack(itemstack1, INPUT, INPUT+1, false)) { return null; } } // item in player's inventory, but not in action bar else if (slotId >= OUTPUT+1 && slotId < OUTPUT+28) { // place in action bar if (!this.mergeItemStack(itemstack1, OUTPUT+28, OUTPUT+37, false)) { return null; } } // item in action bar - place in player inventory else if (slotId >= OUTPUT+28 && slotId < OUTPUT+37 && !this.mergeItemStack(itemstack1, OUTPUT+1, OUTPUT+28, false)) { return null; } } // In one of the infuser slots; try to place in player inventory / action bar else if (!this.mergeItemStack(itemstack1, OUTPUT+1, OUTPUT+37, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } if (itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(player, itemstack1); } return itemstack; } } Quote eKoop Creator: http://lumtech.byethost33.com/mods/eKoop/modinfo.html Link to comment Share on other sites More sharing options...
Koopamillion Posted March 21, 2016 Author Share Posted March 21, 2016 bomp Quote eKoop Creator: http://lumtech.byethost33.com/mods/eKoop/modinfo.html Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.