Jump to content

Recommended Posts

Posted

I have made a tile entity that removes an item like the furnace as fuel.

But, my problem is that whenever the item gets removed the client crashes with a NPE for rendering the item.

 

Tile Entity:

public class TileEntityTemperatureControlledChamber extends GenericDuelTankTileEntity {

public boolean isUsingFire = false;
public int room_temp = 21;
public int itemMax = 60;
public boolean itemType;
public int currentItem = 0;
public int temperature = room_temp;

public static HashMap<Item, Boolean> getAllowedFuels(){
	HashMap<Item, Boolean> hmap = new HashMap<Item, Boolean>();
	hmap.put(Items.blaze_powder, true);
	hmap.put(Items.blaze_rod, true);
	hmap.put(Items.fire_charge, true);
	hmap.put(Item.getItemFromBlock(Blocks.ice), false);
	hmap.put(Item.getItemFromBlock(Blocks.packed_ice), false);
	hmap.put(Items.snowball, false);
	return hmap;
}

public TileEntityTemperatureControlledChamber() {
	super(Main.temperatureControlledChamber, 10000, Arrays.asList(Main.filteredWater));

}

@Override
public int getSizeInventory() {
	return 1;
}

@Override
public void updateEntity(){
	super.updateEntity();
	Main.network.sendToDimension(new TCCServerPacket(xCoord, yCoord, zCoord, false, false, temperature), worldObj.provider.dimensionId);
	calculateIsUsingFire();
	if(currentItem > 0){
		if(itemType && temperature < 100){
			temperature+=3;
			currentItem--;
		}
		if(!itemType && temperature > 0){
			temperature--;
			currentItem--;
		}
		if(temperature < 0) temperature = 0;
		if(temperature > 100) temperature = 100;
	}
	if(currentItem == 0){
		if(temperature < 21) temperature++;
		if(temperature > 21) temperature--;
		if(items[0] != null){
			currentItem = itemMax;
			itemType = getAllowedFuels().get(items[0].getItem());
			setInventorySlotContents(0, ISUtil.removeFromStack(1, items[0]));
		}
	}
}

private void calculateIsUsingFire(){
	if(items[0] == null || !getAllowedFuels().containsKey(items[0].getItem())) return;
	Item item = items[0].getItem();
	isUsingFire = getAllowedFuels().get(item);
}

}

 

Crashlog:

 

  Reveal hidden contents

 

Posted

It looks like somehow you have created an invalid ItemStack. Show the code that is removing the item.

 

Also, why are you sending a packet every update tick? The Container can sync variables for you via a few methods such as #detectAndSendChanges - that's how the furnace burn time is updated in the client-side GUI, for example. It's better because it only sends packets when needed, e.g. when displaying the information in the GUI. Of course, if you need temperature for rendering the block or something, then yeah, you'll want to send that packet.

Posted
  On 3/20/2016 at 1:29 AM, coolAlias said:

It looks like somehow you have created an invalid ItemStack. Show the code that is removing the item.

 

Also, why are you sending a packet every update tick? The Container can sync variables for you via a few methods such as #detectAndSendChanges - that's how the furnace burn time is updated in the client-side GUI, for example. It's better because it only sends packets when needed, e.g. when displaying the information in the GUI. Of course, if you need temperature for rendering the block or something, then yeah, you'll want to send that packet.

 

There is a detectAndSendChanges method? I wish I knew about this sooner. About the invalid itemstack, I found out what I was doing and fixed it. Thanks for the help!

 

 

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.