Jump to content

1.5.2 IC2 API - Energy is always 0


danbka33

Recommended Posts

import ic2.api.energy.EnergyNet;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySink;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.FMLCommonHandler;

public class SCoreEntityTileWorkbench extends TileEntity implements IEnergySink, IInventory {


double energy;
double maxenergy = 50000;
boolean init;

boolean work = true;

private ItemStack[] inv;

public SCoreEntityTileWorkbench()
{
	inv = new ItemStack[9];
}

 @Override
    public void updateEntity() {

	 	super.updateEntity();

        if (!init && !FMLCommonHandler.instance().getEffectiveSide().isClient()) {

            MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
            init = true;
        }
    }

 @Override
 public void invalidate() {

        if (init) {
            MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));

            init = false;
        }
 }
 @Override
    public void readFromNBT(NBTTagCompound nbttagcompound) {
        super.readFromNBT(nbttagcompound);    


            this.energy = nbttagcompound.getDouble("energy");

        

    }
 @Override
    public void writeToNBT(NBTTagCompound nbttagcompound) {
        super.writeToNBT(nbttagcompound);    

        nbttagcompound.setDouble("energy", this.energy);
    }

@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) {
	return true;
}

@Override
public double demandedEnergyUnits() {
	return Math.max(0, this.getMaxEnergy() - this.getEnergy());
}

@Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
{
	if(this.getEnergy() >= this.getMaxEnergy()) return amount;

	double openenergy = this.getMaxEnergy() - this.getEnergy();

	if(openenergy >= amount)
	{
		return this.energy += amount;		
	}
	else if(amount >= openenergy)
	{
		this.energy = this.maxenergy;
		return amount - openenergy;
	}

	return 0;
}

@Override
public int getMaxSafeInput() {
	return EnergyNet.instance.getPowerFromTier(2);
}

public int getScaledLevel(int i)
    {
	return (int) Math.floor(this.getEnergy() * i / (this.getMaxEnergy()));
    }

@Override
public int getSizeInventory()
{
	return inv.length;
}

@Override
    public void setInventorySlotContents(int slot, ItemStack stack)
{
        inv[slot] = stack;
        
        if (stack != null && stack.stackSize > getInventoryStackLimit())
        {
        	stack.stackSize = getInventoryStackLimit();
        }               
    }

    @Override
    public ItemStack decrStackSize(int slot, int amt)
    {
        ItemStack stack = getStackInSlot(slot);
        
        if (stack != null)
        {
            if (stack.stackSize <= amt) {
                    setInventorySlotContents(slot, null);
            }
            else
            {
                stack = stack.splitStack(amt);
                
                if (stack.stackSize == 0)
                {
                        setInventorySlotContents(slot, null);
                }
            }
        }
        
        return stack;
    }

    @Override
    public ItemStack getStackInSlotOnClosing(int slot)
    {
            ItemStack stack = getStackInSlot(slot);
            
            if (stack != null)
            {
                    setInventorySlotContents(slot, null);
            }
            
            return stack;
    }
    
    @Override
    public int getInventoryStackLimit() {
            return 64;
    }

    @Override
    public boolean isUseableByPlayer(EntityPlayer player)
    {
            return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this &&
            player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
    }

    @Override
    public void openChest() {}

    @Override
    public void closeChest() {}

    @Override
    public String getInvName()
    {
            return "Space workbench";
    }

@Override
public ItemStack getStackInSlot(int i)
{
	return inv[i];
}

@Override
public boolean isInvNameLocalized()
{
	return false;
}

@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
	return false;
}

public double getEnergy()
{
	return this.energy;
}

public double getMaxEnergy()
{
	return this.maxenergy;
}
}

 

If I click on the block, then displays the correct value.

 

public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    {
	SCoreEntityTileWorkbench tile = (SCoreEntityTileWorkbench) par1World.getBlockTileEntity(par2, par3, par4);

	if(tile == null)
	{
		par5EntityPlayer.addChatMessage("Tile is null");
		return true;
	}

	if(par5EntityPlayer.isSneaking() && tile != null)
	{
		par5EntityPlayer.addChatMessage("Current energy: " + tile.getEnergy());
		return true;
	}

	par5EntityPlayer.openGui(SpaceCore.instance, SCoreConfigManager.idGuiWorkbench, par1World, par2, par3, par4);

        return false;
    }

 

But if I will put it in the Gui always displays 0.

 

package nuclear.mods.atisot.space.client.gui;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import nuclear.mods.atisot.space.SLog;
import nuclear.mods.atisot.space.SpaceCore;
import nuclear.mods.atisot.space.inventory.SCoreWorkbenchContainer;
import nuclear.mods.atisot.space.tile.SCoreEntityTileWorkbench;

import org.lwjgl.opengl.GL11;

public class SCoreWorkbenchGui extends SCoreGuiContainer {

private static final ResourceLocation distributorTexture = new ResourceLocation(SpaceCore.ASSET_DOMAIN, "textures/gui/spaceworkbench.png");

private SCoreInfoRegion electricInfoRegion = new SCoreInfoRegion((this.width - this.xSize) / 2 + 4, (this.height - this.ySize) / 2 + 55, 4, 60, new ArrayList<String>(), this.width, this.height);

SCoreEntityTileWorkbench workbench;

    public SCoreWorkbenchGui(InventoryPlayer inventoryPlayer, SCoreEntityTileWorkbench tileEntity){
    	super(new SCoreWorkbenchContainer(inventoryPlayer, tileEntity));
    	this.workbench = tileEntity;
    	this.ySize = 160;
}
    
    @Override
    public void initGui()
    {
        super.initGui();
        
        List<String> electricityDesc = new ArrayList<String>();
        electricityDesc.add("Electrical Storage");
        electricityDesc.add("Energy: " + ((int) Math.floor(this.workbench.getEnergy()) + " / " + (int) Math.floor(this.workbench.getMaxEnergy())));
        this.electricInfoRegion.tooltipStrings = electricityDesc;
        this.electricInfoRegion.xPosition = (this.width - this.xSize) / 2 + 13;
        this.electricInfoRegion.yPosition = (this.height - this.ySize) / 2 + 16;
        this.electricInfoRegion.parentWidth = this.width;
        this.electricInfoRegion.parentHeight = this.height;
        this.infoRegions.add(this.electricInfoRegion);
    }
    
    
    @Override
    protected void drawGuiContainerForegroundLayer(int param1, int param2) {
            //draw text and stuff here
            //the parameters for drawString are: string, x, y, color
            fontRenderer.drawString("Space Workbench", 30, 10, 4210752);
            //draws "Inventory" or your regional equivalent
            fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 30, ySize - 90 + 2, 4210752);
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {    	
    	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(distributorTexture);
        final int var5 = (this.width - this.xSize) / 2;
        final int var6 = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(var5, var6 + 5, 0, 0, this.xSize, 181);
        
        if (this.workbench != null)
        {
        	int scale = this.workbench.getScaledLevel(55);
        	
        	SLog.info("" + scale);
        	SLog.info("" + this.workbench.getEnergy());
        	
            this.drawTexturedModalRect(var5 + 12, var6 + 20, 176, 0, Math.min(scale, 55), 7);
            
//            if (this.workbench.getEnergy() > 0)
//            {
//            	this.drawTexturedModalRect(var5 + 12, var6 + 20, 176, 0, 4, 55);
//            }
//            
            
        }
    } 

}

 

width=180 height=102http://s24.postimg.org/9wzykqbj5/2014_03_17_19_41_08.png[/img]

 

width=180 height=102http://s24.postimg.org/yc86lsag1/2014_03_17_19_41_11.png[/img]

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Okay I got on the discord server and followed there steps and got it to start working, however the log is constantly being filled with this error code. It is creating additional copies of the config file, up to 5 copies.
    • I would like to force the pose of a living entity to a standing position (i.e. Pose.STANDING) when it is riding a certain vehicle. I have tried to call Entity#setPose every tick via LivingTickEvent, but the living entity remains in a sitting position. Here is my code: // I made it a low-priority event because I was wondering if the code should be executed at the end of each tick. @SubscribeEvent(priority = EventPriority.LOWEST) public static void livingTickEvent(LivingEvent.LivingTickEvent event) { LivingEntity livingEntity = event.getEntity(); if (!livingEntity.level.isClientSide && livingEntity.getVehicle() instanceof TheVehicle) { livingEntity.setPose(Pose.STANDING); } }   By the way, I am aware there is a setForcedPose method, but it's only for the Player class.
    • I am trying to get a Private Vault Hunters 3rd edition up and running. The server launched fine before I pasted the Vault+Hunters+3rd+Edition-Update-10.0.1_Server-Files Contents into the file I made for the server info. Then after I pasted it I get the log information in the spoiler. I don't understand what I'm looking at. I'm using Forge 1.18.2, I also downloaded the most recent version of JDK.
    • Hey, my friends put together a custom modpack to use and asked me to set up a server to run it. Problem is, they didn't think to log which mods where client side only and which worked server side. Naturally, I only found this out when I actually attempted to run said server. There's quite a long list of them and, frankly, I have no idea which are causing the problem. I just run servers and install modpacks, not curate them. If anyone could help me identify the problem and what's causing the error, it would be greatly appreciated.   To make things a bit easier, I'm running the server in a docker container on a Ubuntu 20.04 server installation. Also, I'm using Java 17 and Forge ver 1.19.2 release 43.2.8 as that is the same version as the modpack, so everything should be working. Again, any help would be really appreciated. latest log: https://pastebin.com/f95NC0X7 All mods installed: https://pastebin.com/xy8d55kJ
    • I'm trying to install Forge for 1.12.2. The installer runs properly and says it installed forged succesfully, but when I go into the launcher there is no Forge profile and forge isn't in the version list when cresting a custom profile. In the versions folder in .minecraft the forge 1.12.2 folder is there, but it only has the .json file, it seems that the installer is not actually getting the .jar file. I tried with both the recommended and latest installers. I also tried downloading the universal .jar directly and pasting it into the versions folder but that didn't work either.   Installer log: JVM info: Oracle Corporation - 1.8.0_371 - 25.371-b11 java.net.preferIPv4Stack=true Found java version 1.8.0_371 Extracting json Considering minecraft client jar Downloading libraries Found 0 additional library directories Considering library net.minecraftforge:forge:1.12.2-14.23.5.2859   File exists: Checksum validated. Considering library org.ow2.asm:asm-debug-all:5.2   File exists: Checksum validated. Considering library net.minecraft:launchwrapper:1.12   File exists: Checksum validated. Considering library org.jline:jline:3.5.1   File exists: Checksum validated. Considering library com.typesafe.akka:akka-actor_2.11:2.3.3   File exists: Checksum validated. Considering library com.typesafe:config:1.2.1   File exists: Checksum validated. Considering library org.scala-lang:scala-actors-migration_2.11:1.1.0   File exists: Checksum validated. Considering library org.scala-lang:scala-compiler:2.11.1   File exists: Checksum validated. Considering library org.scala-lang.plugins:scala-continuations-library_2.11:1.0.2_mc   File exists: Checksum validated. Considering library org.scala-lang.plugins:scala-continuations-plugin_2.11.1:1.0.2_mc   File exists: Checksum validated. Considering library org.scala-lang:scala-library:2.11.1   File exists: Checksum validated. Considering library org.scala-lang:scala-parser-combinators_2.11:1.0.1   File exists: Checksum validated. Considering library org.scala-lang:scala-reflect:2.11.1   File exists: Checksum validated. Considering library org.scala-lang:scala-swing_2.11:1.0.1   File exists: Checksum validated. Considering library org.scala-lang:scala-xml_2.11:1.0.2   File exists: Checksum validated. Considering library lzma:lzma:0.0.1   File exists: Checksum validated. Considering library java3d:vecmath:1.5.2   File exists: Checksum validated. Considering library net.sf.trove4j:trove4j:3.0.3   File exists: Checksum validated. Considering library org.apache.maven:maven-artifact:3.5.3   File exists: Checksum validated. Considering library net.sf.jopt-simple:jopt-simple:5.0.3   File exists: Checksum validated. Considering library org.apache.logging.log4j:log4j-api:2.15.0   File exists: Checksum validated. Considering library org.apache.logging.log4j:log4j-core:2.15.0   File exists: Checksum validated. Considering library org.apache.logging.log4j:log4j-slf4j18-impl:2.15.0   File exists: Checksum validated. Building Processors Injecting profile Finished!
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.