Jump to content

[1.7.2] [NEED HELP!!!!] Problem with energy variable


Jacky2611

Recommended Posts

After i finally got my dimension working i started to add some fancy feature to my mod (plants, more blocks...) and now i want to add a gui to one of my main Blocks. So I created a TileEntity, a GuiHandler, a Container and, big surprise, it worked :) ...first.  Then i saw the endereye that was placed in the upper slot and the enderpearl in the bottom one.  :'(

 

(This is what my gui looks like:)

 

 

dNymS5e.png

 

 

 

My goal is to get energy from the items in the bottom slots in my energy var. Right now the energy simply keeps increasing (even if i take out the pregenerated enderpearl) and if i try to take out the endereye my game crashes.

 

 

Now going to open gui

Energy stored: 91

Energy stored: 14

Energy stored: 92

Energy stored: 15

Energy stored: 93

Energy stored: 16

Energy stored: 94

Energy stored: 17

Energy stored: 95

Energy stored: 18

Energy stored: 96

Energy stored: 19

Energy stored: 97

Energy stored: 20

Energy stored: 98

Energy stored: 21

Energy stored: 99

Energy stored: 22

Energy stored: 100

Energy stored: 23

Energy stored: 101

Energy stored: 24

Energy stored: 102

Energy stored: 25

Energy stored: 103

Energy stored: 26

Energy stored: 104

Energy stored: 27

Energy stored: 105

Energy stored: 28

Energy stored: 106

Energy stored: 29

[20:29:16] [server thread/ERROR]: Encountered an unexpected exception

net.minecraft.util.ReportedException: Ticking block entity

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:745) ~[MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:650) ~[MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120) ~[integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:528) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:787) [MinecraftServer$2.class:?]

Caused by: java.lang.NullPointerException

at net.dimensionshift.mod.tileentity.TileEntitySimpleController.getFuelValue(TileEntitySimpleController.java:245) ~[TileEntitySimpleController.class:?]

at net.dimensionshift.mod.tileentity.TileEntitySimpleController.updateEntity(TileEntitySimpleController.java:69) ~[TileEntitySimpleController.class:?]

at net.minecraft.world.World.updateEntities(World.java:2148) ~[World.class:?]

at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:536) ~[WorldServer.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:739) ~[MinecraftServer.class:?]

... 4 more

[20:29:16] [server thread/ERROR]: This crash report has been saved to: /Users/USER/Desktop/modding/1.7.2 gradle/forge/eclipse/./crash-reports/crash-2014-04-07_20.29.16-server.txt

[20:29:16] [server thread/INFO]: Stopping server

[20:29:16] [server thread/INFO]: Saving players

[20:29:16] [server thread/INFO]: Saving worlds

[20:29:16] [server thread/INFO]: Saving chunks for level 'New World'/Overworld

---- Minecraft Crash Report ----

// I blame Dinnerbone.

 

Time: 07.04.14 20:29

Description: Ticking block entity

 

java.lang.NullPointerException: Ticking block entity

at net.dimensionshift.mod.tileentity.TileEntitySimpleController.getFuelValue(TileEntitySimpleController.java:245)

at net.dimensionshift.mod.tileentity.TileEntitySimpleController.updateEntity(TileEntitySimpleController.java:69)

at net.minecraft.world.World.updateEntities(World.java:2148)

at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:536)

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:739)

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:650)

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:528)

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:787)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at net.dimensionshift.mod.tileentity.TileEntitySimpleController.getFuelValue(TileEntitySimpleController.java:245)

at net.dimensionshift.mod.tileentity.TileEntitySimpleController.updateEntity(TileEntitySimpleController.java:69)

 

-- Block entity being ticked --

Details:

Name: tileEntitySimpleController // net.dimensionshift.mod.tileentity.TileEntitySimpleController

Block type: ID #169 (tile.blockSimpleControllerActive // net.dimensionshift.mod.block.BlockSimpleController)

Block data value: 5 / 0x5 / 0b0101

Block location: World: (21,63,15), Chunk: (at 5,3,15 in 1,0; contains blocks 16,0,0 to 31,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)

Actual block type: ID #169 (tile.blockSimpleControllerActive // net.dimensionshift.mod.block.BlockSimpleController)

Actual block data value: 5 / 0x5 / 0b0101

Stacktrace:

at net.minecraft.world.World.updateEntities(World.java:2148)

at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:536)

 

-- Affected level --

Details:

Level name: New World

All players: 1 total; [EntityPlayerMP['Jacky2611'/244, l='New World', x=23,62, y=63,00, z=14,06]]

Chunk stats: ServerChunkCache: 626 Drop: 0

Level seed: -7693605276550308881

Level generator: ID 00 - default, ver 1. Features enabled: true

Level generator options:

Level spawn location: World: (0,64,0), Chunk: (at 0,4,0 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)

Level time: 4703 game time, 4703 day time

Level dimension: 0

Level storage version: 0x04ABD - Anvil

Level weather: Rain time: 129776 (now: false), thunder time: 96144 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true

Stacktrace:

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:739)

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:650)

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:528)

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:787)

 

-- System Details --

Details:

Minecraft Version: 1.7.2

Operating System: Mac OS X (x86_64) version 10.9.2

Java Version: 1.6.0_65, Apple Inc.

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Apple Inc.

Memory: 842950392 bytes (803 MB) / 1060372480 bytes (1011 MB) up to 1060372480 bytes (1011 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

AABB Pool Size: 3059 (171304 bytes; 0 MB) allocated, 2738 (153328 bytes; 0 MB) used

IntCache: cache: 0, tcache: 0, allocated: 29, tallocated: 77

FML: MCP v9.01-pre FML v7.2.116.1024 Minecraft Forge 10.12.0.1024 4 mods loaded, 4 mods active

mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

FML{7.2.116.1024} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.0.1024.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Forge{10.12.0.1024} [Minecraft Forge] (forgeSrc-1.7.2-10.12.0.1024.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

dimensionshift{Beta v0.100} [DimensionShift] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Profiler Position: N/A (disabled)

Vec3 Pool Size: 1074 (60144 bytes; 0 MB) allocated, 746 (41776 bytes; 0 MB) used

Player Count: 1 / 8; [EntityPlayerMP['Jacky2611'/244, l='New World', x=23,62, y=63,00, z=14,06]]

Type: Integrated Server (map_client.txt)

Is Modded: Definitely; Client brand changed to 'fml,forge'

#@!@# Game crashed! Crash report saved to: #@!@# ./crash-reports/crash-2014-04-07_20.29.16-server.txt

[20:29:16] [Client Shutdown Thread/INFO]: Stopping server

[20:29:16] [Client Shutdown Thread/INFO]: Saving players

 

 

 

My TileEntity:

 

 

package net.dimensionshift.mod.tileentity;

 

import cpw.mods.fml.common.FMLCommonHandler;

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.relauncher.Side;

import net.dimensionshift.mod.DimensionShift;

import net.dimensionshift.mod.Fuel;

import net.dimensionshift.mod.block.BlockSimpleController;

import net.dimensionshift.mod.blockplacing.TeleportSimpleController;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.inventory.ISidedInventory;

import net.minecraft.item.ItemStack;

import net.minecraft.server.MinecraftServer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

 

public class TileEntitySimpleController extends TileEntity implements ISidedInventory{

 

private String localizedName;

 

//What slots can be accesed from which side?

private static final int[] slots_top = new int[]{0};

//first take out items from slot 1, than from slot number 0

private static final int[] slots_bottom = new int[]{1, 0};

private static final int[] slots_sides = new int[]{};

 

private ItemStack[] fuel=new ItemStack[]{new ItemStack(Items.ender_pearl), new ItemStack(Items.ender_eye)};

 

 

 

//How many Slots does Block have

private ItemStack[] slots=getFuels();

 

 

//stored energy

public int energy;

 

//energy to has to be stored yet

public int charging=0;

 

//time until tp

public int tpTime = 1000;

 

//how long it is already preparing for tp

public int timeUntillTp;

 

 

 

private boolean active;

 

@Override

public void updateEntity(){

 

boolean flag1=false;

 

 

//converting item to energy

if(charging>0) {

this.energy++;

this.charging--;

 

System.out.println("Energy stored: " + energy);

}

if (!this.worldObj.isRemote) {

if(this.charging==0 && slots[1]!=null && getFuelValue(slots[1])>0)

System.out.println("adding energy to charging and removing item from slot");

this.charging=getFuelValue(slots[1]);

this.slots[1].stackSize--;

 

if(this.slots[1].stackSize == 0){

this.slots[1].getItem().getContainerItem(this.slots[1]);

}

 

}

 

if(this.active != this.charging>0) {

BlockSimpleController.updateBlockType(this.charging>0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);

}

this.active = this.charging>0;

 

 

 

}

 

 

private boolean isTeleporting() {

return this.timeUntillTp>0;

}

 

private boolean canTeleport() {

if(this.slots[0] == null) {

return false;

} else {

return true;

}

}

 

 

public int getSizeInventory(){

return this.slots.length;

}

 

 

public boolean isInvNameLocalized() {

return this.localizedName!=null && this.localizedName.length() > 0;

}

 

public String getInvName() {

return this.isInvNameLocalized() ? this.localizedName : "container.simpleController";

}

 

public void setGuiDisplayName(String displayName) {

this.localizedName = displayName;

}

 

public ItemStack getStackInSlot(int i) {

return this.slots;

}

 

public ItemStack decrStackSize(int i, int j) {

if(this.slots != null){

ItemStack itemstack;

 

if(this.slots.stackSize<=j) {

itemstack = this.slots;

 

this.slots = null;

return itemstack;

} else {

itemstack=this.slots.splitStack(j);

 

if(this.slots.stackSize==0){

this.slots=null;

}

return itemstack;

}

}

return null;

}

 

public ItemStack getStackInSlotOnClosing(int i) {

if(this.slots != null){

ItemStack itemstack = this.slots;

this.slots=null;

return itemstack;

}

return null;

}

 

public void setInventorySlotContents(int i, ItemStack itemstack) {

this.slots = itemstack;

 

if(itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) {

itemstack.stackSize = this.getInventoryStackLimit();

}

}

 

public String getInventoryName() {

return null;

}

 

public boolean hasCustomInventoryName() {

return false;

}

 

public int getInventoryStackLimit() {

return 64;

}

 

public boolean isUseableByPlayer(EntityPlayer player) {

return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;

}

 

public void openInventory() {

 

}

 

public void closeInventory() {

 

}

 

public boolean isItemValidForSlot(int i, ItemStack item) {

boolean isValid=false;

if (i==0) { //id card

 

isValid=true;

} else if(i==1) {  //fuel

isValid=isItemFuel(item);

}

return isValid;

}

 

private boolean isItemFuel(ItemStack item) {

boolean isFuel=false;

 

 

for (ItemStack item1 : fuel) {

    if (item1.equals(item)) {

    isFuel=true;

        break;

    }

}

 

 

return isFuel;

}

 

 

 

public int[] getAccessibleSlotsFromSide(int side) {

return side == 0 ? slots_bottom : (side == 1 ? slots_top : slots_sides);

}

 

public boolean canInsertItem(int i, ItemStack item, int side) {

return this.isItemValidForSlot(i, item);

}

 

public boolean canExtractItem(int i, ItemStack item, int side) {

//if extracts from down slot 1(fuel) than true

return side == 0 || i== 1;

}

 

 

 

 

public static ItemStack[] getFuels(){

ItemStack[] fuels=new ItemStack[6];

fuels[0] = new ItemStack(Items.ender_pearl);

fuels[1] = new ItemStack(Items.ender_eye);

fuels[3] = new ItemStack(Items.nether_star);

fuels[4] = new ItemStack(Blocks.dragon_egg);

 

fuels[5] = new ItemStack(DimensionShift.itemEnderCrystal);

//fuels[6] = new ItemStack(DimensionShift.itemEnderDust);

 

 

return fuels;

}

 

public static int getFuelValue(ItemStack itemstack) {

int fuelValue=0;

 

if (itemstack.getItem()==DimensionShift.itemEnderDust) fuelValue=1000;

if (itemstack.getItem()==DimensionShift.itemEnderDust) fuelValue=1500;

 

if (itemstack.getItem()==Items.ender_eye) fuelValue=800;

if (itemstack.getItem()==Items.ender_pearl) fuelValue=300;

if (itemstack.getItem()==Items.nether_star) fuelValue=5000;

 

if (itemstack==new ItemStack(Blocks.dragon_egg)) fuelValue=5500;

 

 

return fuelValue;

}

 

 

}

 

 

 

and my container:

 

 

package net.dimensionshift.mod.container;

 

import net.dimensionshift.mod.tileentity.TileEntitySimpleController;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.Container;

import net.minecraft.inventory.ICrafting;

import net.minecraft.inventory.Slot;

import net.minecraft.item.ItemStack;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class ContainerSimpleController extends Container{

 

private TileEntitySimpleController simpleController;

 

//stored energy

public int energy;

//energy to be stored

public int charging=0;

//time until tp

public int tpTime = 1000;

//how long it is already preparing for tp

public int timeUntillTp;

//is just teleporting?

public boolean isTeleporting=false;

 

 

 

 

 

public ContainerSimpleController(InventoryPlayer inventory, TileEntitySimpleController entity){

this.simpleController = entity;

 

//goal Entity, SlotID, x and y Coordinates

this.addSlotToContainer(new Slot(entity, 0, 44, 58));

this.addSlotToContainer(new Slot(entity, 1, 62, 20));

 

 

//top Player Inventory

for (int i=0; i<3; i++) {

for (int j=0; j<9; j++) {

this.addSlotToContainer(new Slot(inventory, j+i*9+9, 8 + 18*j, 84 + 18*i));

}

}

//bottom Player Inventory

for (int i=0; i<9; i++) {

this.addSlotToContainer(new Slot(inventory, i, 8 + 18*i, 142));

}

 

}

/*

public void addCraftingToCrafters(ICrafting icrafting) {

super.addCraftingToCrafters(icrafting);

icrafting.sendProgressBarUpdate(this, 1, this.simpleController.energy);

icrafting.sendProgressBarUpdate(this, 0, this.simpleController.timeUntillTp);

 

}

*/

 

public void detectAndSendChanges(){

super.detectAndSendChanges();

}

 

/*

@SideOnly(Side.CLIENT)

public void updateEnergyBar(int slot, int value){

if(slot==1)this.simpleController.energy=value;

if(slot==0)this.simpleController.timeUntillTp=value;

}

*/

 

@Override

public ItemStack transferStackInSlot(EntityPlayer player, int slot){

return null;

 

 

}

 

public boolean canInteractWith(EntityPlayer player) {

// TODO Auto-generated method stub

return this.simpleController.isUseableByPlayer(player);

}

 

}

 

 

 

Here could be your advertisement!

Link to comment
Share on other sites

Hey,

 

Your problem is that you are initializing your inventory slots to your fuel list which is what is giving you your error.

 

Change:

 

private ItemStack[] slots=getFuels();

to

  private ItemStack[] slots= new ItemStack[iNVENTORY_SIZE];

 

Not only that but your ItemStack[] for your fuels list is initialized to two item stacks and not the entire fuel list.

 

Change:

 

private ItemStack[] fuel=new ItemStack[]{new ItemStack(Items.ender_pearl), new ItemStack(Items.ender_eye)};

to

private ItemStack[] fuel=getFuels();

 

Along with that in your Container you have the top slot in your gui mapped to slot 0 and the bottom one mapped to slot 1, not sure if this is a bug but that is how it is.

Link to comment
Share on other sites

width=50 height=37http://i266.photobucket.com/albums/ii269/theogrit/sign%20or%20English%20smilies/2sgn030thanks.gif[/img]

 

EDIT: Ok now i tried to add:

@SideOnly(Side.CLIENT)
public int getDimensionEnergyScaled(int heightDimensionEnergyBar) { 
    	int res = this.dimensionEnergy * heightDimensionEnergyBar / this.requiredDimensionEnergy;
    	System.out.println("resscaled is:  dimensionEnergy(" + this.dimensionEnergy + ") * heightDimensionEneryBar(" + heightDimensionEnergyBar + ") / this.requiredDimensionEnergy(" + this.requiredDimensionEnergy + ")");
	return res;
}

 

and it looks like my dimensionEnergy(new name for energy) i never really set (According to output it is 0) but my onupdatething says that it is increasing.

Not sure whats i have done wrong...

 

 

And have i done something wrong in my lang file?

 

tried to add "container.simpleController.name=Simple Controller" but the name still is container.simpleController.

 

 

 

My Gui:

 

 

package net.dimensionshift.mod.gui;

 

import org.lwjgl.opengl.GL11;

 

import net.dimensionshift.mod.DimensionShift;

import net.dimensionshift.mod.container.ContainerSimpleController;

import net.dimensionshift.mod.tileentity.TileEntitySimpleController;

import net.minecraft.client.Minecraft;

import net.minecraft.client.gui.inventory.GuiContainer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.util.ResourceLocation;

import net.minecraft.client.resources.I18n;

 

 

public class GuiSimpleController extends GuiContainer{

 

public static final ResourceLocation texture = new ResourceLocation(DimensionShift.MODID, "textures/gui/simpleController.png");

 

public TileEntitySimpleController simpleController;

 

 

public GuiSimpleController(InventoryPlayer inventory, TileEntitySimpleController entity) {

super(new ContainerSimpleController(inventory, entity));

 

this.simpleController=entity;

 

this.xSize = 176;

this.ySize = 166;

}

 

@Override

public void drawGuiContainerForegroundLayer(int par1, int par2) {

String name= this.simpleController.isInvNameLocalized() ? this.simpleController.getInvName() : I18n.format(this.simpleController.getInvName(), new Object[0]);

 

//Block Inventory Name

this.fontRendererObj.drawString(name, this.xSize/2-fontRendererObj.getStringWidth(name), 6, 4210752);

 

//Player Inventory Title

this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize-96, 4210752);

}

 

@Override

public void drawGuiContainerBackgroundLayer(float var1, int var2,int var3) {

/**

* coords are x from left border and y from !!!!top!!!!

*

*

* this.drawTexturedModalRect(where to draw lefttop corner X, where to draw lefttop corner Y, From where to take image lefttop corner X,  From where to take image lefttop corner Y, image width, image height

*

*

*

*/

 

 

 

 

GL11.glColor4f(1F, 1F, 1F, 1F);

 

Minecraft.getMinecraft().getTextureManager().bindTexture(texture);

        int k = (this.width - this.xSize) / 2;

        int l = (this.height - this.ySize) / 2;

       

       

       

       

this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);

 

//dimensionEnergy energy bar...

 

//heightDimensionEnergyBar is how height the dimension energy display is, needed for scaling

int heightDimensionEnergyBar = 54;

//width...

int widthDimensionEnergyBar = 20;

 

 

int currentDimensionEnergy = this.simpleController.getDimensionEnergyScaled(heightDimensionEnergyBar);

 

this.drawTexturedModalRect(guiLeft + 15, guiTop+20+heightDimensionEnergyBar-currentDimensionEnergy, 176, heightDimensionEnergyBar-currentDimensionEnergy, widthDimensionEnergyBar, currentDimensionEnergy);

 

 

 

// TODO Auto-generated method stub

 

}

 

}

 

 

Here could be your advertisement!

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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