Posted March 25, 20169 yr So, I have a solar panel with a GUI. Everything is working apart from one thing, theres a blank space for a sun in the GUI. That blank space is ment to go yellow when it can see the sun. Well, if there is a block covering it, it will go blank and visa versa. However, if it's nighttime, it will stay yellow. Is there any fixes? !isRemote just makes it go blank completely. TileEntitySolar: 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.gui.GUISolar; import com.koopamillion.item.Mitems; import com.koopamillion.util.LogHelper; 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.world.biome.BiomeGenDesert; import net.minecraftforge.common.util.ForgeDirection; public class TileEntitySolarPanel extends TileEntityBasicBlock implements IEnergy { private EnergyBar energyBar = new EnergyBar(4000); public boolean seesSun = false; public int time = 1; public int other; public boolean isDesert(){ return worldObj.provider.getBiomeGenForCoords(xCoord >> 4, zCoord >> 4) instanceof BiomeGenDesert; } private void updateBatteryCharge() { ItemStack itemstack = this.getStackInSlot(1); if(itemstack != null && itemstack.getItem() == Mitems.basicBattery && itemstack.getItemDamage() == 0 && energyBar.getEnergyLevel() >= 2000){ //if there is an uncharged battery then: this.setInventorySlotContents(1, new ItemStack(Mitems.basicBattery, 1, 1)); energyBar.removeEnergy(2000); } if(itemstack != null && itemstack.getItem() == Mitems.basicBattery && itemstack.getItemDamage() == 1 && energyBar.getEnergyLevel() >= 2000){ this.setInventorySlotContents(1, new ItemStack(Mitems.basicBattery, 1, 2)); energyBar.removeEnergy(2000); } if(itemstack != null && itemstack.getItem() == Mitems.basicBattery && itemstack.getItemDamage() == 2 && energyBar.getEnergyLevel() >= 2000){ this.setInventorySlotContents(1, new ItemStack(Mitems.basicBattery, 1, 3)); energyBar.removeEnergy(2000); } if(itemstack != null && itemstack.getItem() == Mitems.basicBattery && itemstack.getItemDamage() == 3 && energyBar.getEnergyLevel() >= 2000){ this.setInventorySlotContents(1, new ItemStack(Mitems.basicBattery, 1, 4)); energyBar.removeEnergy(2000); } if(itemstack != null && itemstack.getItem() == Mitems.basicBattery && itemstack.getItemDamage() == 4 && energyBar.getEnergyLevel() >= 2000){ this.setInventorySlotContents(1, new ItemStack(Mitems.basicBattery, 1, 5)); energyBar.removeEnergy(2000); } } public void updateEntity(){ updateBatteryCharge(); 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); } public boolean genSeesSun(){ if(!worldObj.isRemote){ return (worldObj.isDaytime() && ((!worldObj.isRaining() && !worldObj.isThundering()) || isDesert()) && !worldObj.provider.hasNoSky && worldObj.canBlockSeeTheSky(xCoord, yCoord + 1, zCoord)); } return true; } @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); } } GUISolar: if(this.tileentity.genSeesSun()){ this.drawTexturedModalRect(guiLeft + 117, guiTop + 63, 176, 50, 14, 14); } eKoop Creator: http://lumtech.byethost33.com/mods/eKoop/modinfo.html
March 25, 20169 yr gui rendering is client side. in your genSeesSun method you are always returning true, if world.isRemote, so you are never ever checking if it is daytime on client
March 25, 20169 yr Author So I do !world.isRemote? If so it dosen't work when I wrap the gen sees sun method in it. I did this though and it still dosent work: public boolean genSeesSun(){ if(!worldObj.isRemote){ if(worldObj.isDaytime()){ return (((!worldObj.isRaining() && !worldObj.isThundering() && worldObj.isDaytime()) || isDesert()) && !worldObj.provider.hasNoSky && worldObj.canBlockSeeTheSky(xCoord, yCoord + 1, zCoord)); } }else{ return ( worldObj.isDaytime() && ((!worldObj.isRaining() && !worldObj.isThundering() && worldObj.isDaytime()) || isDesert()) && !worldObj.provider.hasNoSky && worldObj.canBlockSeeTheSky(xCoord, yCoord + 1, zCoord)); } return ( worldObj.isDaytime() && ((!worldObj.isRaining() && !worldObj.isThundering() && worldObj.isDaytime()) || isDesert()) && !worldObj.provider.hasNoSky && worldObj.canBlockSeeTheSky(xCoord, yCoord + 1, zCoord)); } eKoop Creator: http://lumtech.byethost33.com/mods/eKoop/modinfo.html
March 25, 20169 yr > genSeesSun() is running only server side, GUI is client-side. Just do this: if(worldObj.isDaytime() && ((!worldObj.isRaining() && !worldObj.isThundering()) || isDesert()) && !worldObj.provider.hasNoSky && worldObj.canBlockSeeTheSky(xCoord, yCoord + 1, zCoord)); { this.drawTexturedModalRect(guiLeft + 117, guiTop + 63, 176, 50, 14, 14); } or insert the function in the GUI.. or make a class with some "generic" functions to use around your mod... or change getSeesSun() (probably it will fix too): public boolean genSeesSun() { return (worldObj.isDaytime() && ((!worldObj.isRaining() && !worldObj.isThundering()) || isDesert()) && !worldObj.provider.hasNoSky && worldObj.canBlockSeeTheSky(xCoord, yCoord + 1, zCoord)); } Using "side filters" ("world.isremote()", etc) can make some problems depending what you change. // BSc CIS, hardcore gamer and a big fan of Minecraft. TmzOS ::..
March 25, 20169 yr Author It didn't work. Neither of them. eKoop Creator: http://lumtech.byethost33.com/mods/eKoop/modinfo.html
March 25, 20169 yr > fixed the bold tag inside the first code -- There are any exception in the log? Did you adapted the code from the TE to the GUI (that means, "isdesert()" for example is local to the TE but not to the GUI)? Show me what you changed exactly and what is happening with the changes. // BSc CIS, hardcore gamer and a big fan of Minecraft. TmzOS ::..
March 25, 20169 yr Author I changed: What I had before in the GUI to: package com.koopamillion.gui; import java.util.Arrays; import org.lwjgl.opengl.GL11; import com.koopamillion.energy.EnergyBar; import com.koopamillion.energy.IEnergy; import com.koopamillion.inventory.ContainerEnergyStorage; import com.koopamillion.inventory.ContainerSolar; import com.koopamillion.lib.Energy; import com.koopamillion.lib.RefStrings; import com.koopamillion.tile_entity.TileEntitySolarPanel; import com.koopamillion.util.GuiUtil; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; @SideOnly(Side.CLIENT) public class GUISolar extends GuiContainer{ public final ResourceLocation GUI = new ResourceLocation(RefStrings.MODID + ":textures/gui/container/solar.png"); public final EntityPlayer player; public final World world; public final int x; public final int y; public final int z; public TileEntitySolarPanel tileentity; public boolean seesSun; public GUISolar(EntityPlayer player, World world, int x, int y, int z){ super(new ContainerSolar(player, world, x, y, z)); this.player = player; this.world = world; this.x = x; this.y = y; this.z = z; this.tileentity = (TileEntitySolarPanel) world.getTileEntity(x, y, z); } @Override protected void drawGuiContainerBackgroundLayer(float f, int x, int y){ this.mc.getTextureManager().bindTexture(GUI); GuiUtil.drawRectangle(guiLeft, guiTop, xSize, ySize, 256, 256, 0, 0); int energyBarSize = 48; this.drawTexturedModalRect(guiLeft + 80, guiTop + 7 + energyBarSize - ((IEnergy) tileentity).getEnergyBar().getEnergyLevelScaled(energyBarSize), 176, 0, 16, ((IEnergy) tileentity).getEnergyBar().getEnergyLevelScaled(energyBarSize)); if(world.isDaytime() && ((!world.isRaining() && !world.isThundering()) && !world.provider.hasNoSky && world.canBlockSeeTheSky(x, y + 1, z))){ this.drawTexturedModalRect(guiLeft + 117, guiTop + 63, 176, 50, 14, 14); } } @Override protected void drawGuiContainerForegroundLayer(int x, int y){ float scale = 0.8f; GL11.glScalef(scale, scale, scale); GL11.glScalef(1 / scale, 1 / scale, 1 / scale); drawEnergyLevel(x, y); } private void drawEnergyLevel(int x, int y){ int minX = guiLeft + 80; int maxX = guiLeft + 95; int minY = guiTop + 7; int maxY = guiTop + 54; 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); } } private void drawBurnTime(int x, int y){ int minX = guiLeft + 100; int maxX = guiLeft + 114; int minY = guiTop + 61; int maxY = guiTop + 74; } } (Ill add isDesert() later) I changed the tileentity to: 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.gui.GUISolar; import com.koopamillion.item.Mitems; import com.koopamillion.util.LogHelper; 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.world.biome.BiomeGenDesert; import net.minecraftforge.common.util.ForgeDirection; public class TileEntitySolarPanel extends TileEntityBasicBlock implements IEnergy { private EnergyBar energyBar = new EnergyBar(4000); public boolean seesSun = false; public int time = 1; public int other; public boolean isDesert(){ return worldObj.provider.getBiomeGenForCoords(xCoord >> 4, zCoord >> 4) instanceof BiomeGenDesert; } private void updateBatteryCharge() { ItemStack itemstack = this.getStackInSlot(1); if(itemstack != null && itemstack.getItem() == Mitems.basicBattery && itemstack.getItemDamage() == 0 && energyBar.getEnergyLevel() >= 2000){ //if there is an uncharged battery then: this.setInventorySlotContents(1, new ItemStack(Mitems.basicBattery, 1, 1)); energyBar.removeEnergy(2000); } if(itemstack != null && itemstack.getItem() == Mitems.basicBattery && itemstack.getItemDamage() == 1 && energyBar.getEnergyLevel() >= 2000){ this.setInventorySlotContents(1, new ItemStack(Mitems.basicBattery, 1, 2)); energyBar.removeEnergy(2000); } if(itemstack != null && itemstack.getItem() == Mitems.basicBattery && itemstack.getItemDamage() == 2 && energyBar.getEnergyLevel() >= 2000){ this.setInventorySlotContents(1, new ItemStack(Mitems.basicBattery, 1, 3)); energyBar.removeEnergy(2000); } if(itemstack != null && itemstack.getItem() == Mitems.basicBattery && itemstack.getItemDamage() == 3 && energyBar.getEnergyLevel() >= 2000){ this.setInventorySlotContents(1, new ItemStack(Mitems.basicBattery, 1, 4)); energyBar.removeEnergy(2000); } if(itemstack != null && itemstack.getItem() == Mitems.basicBattery && itemstack.getItemDamage() == 4 && energyBar.getEnergyLevel() >= 2000){ this.setInventorySlotContents(1, new ItemStack(Mitems.basicBattery, 1, 5)); energyBar.removeEnergy(2000); } } public void updateEntity(){ updateBatteryCharge(); 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); } public boolean genSeesSun(){ return (worldObj.isDaytime() && ((!worldObj.isRaining() && !worldObj.isThundering()) || isDesert()) && !worldObj.provider.hasNoSky && worldObj.canBlockSeeTheSky(xCoord, yCoord + 1, zCoord)); } @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); } } eKoop Creator: http://lumtech.byethost33.com/mods/eKoop/modinfo.html
March 25, 20169 yr If you look into isDaytime, you find that it operates on light level. Unless you care about weather effects (which can turn day into night), use world time to get canonical sunrise and sunset. There are 24000 ticks in a day, starting with dawn at time=0 on the 1st day. From that you can calculate using modulo (and remainder) arithmetic, and it even works in the nether and end (unless you test for those and rule them out). On the other hand, if your solar panel needs to respond to light levels, then you should probably use skylight directly. The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
March 25, 20169 yr Author I do mind about weather effects though... Is there any way? eKoop Creator: http://lumtech.byethost33.com/mods/eKoop/modinfo.html
March 25, 20169 yr On the other hand, if your solar panel needs to respond to light levels, then you should probably use skylight directly. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.