Jump to content

[1.12.2] Creating fuel that takes damage


V0idN0ise

Recommended Posts

Hello everyone,

I'm currently updating my old project and I got kinda stuck on this problem:
My mod included new coals that took damage when put into the fuel slot of furnaces.

I used the Item#getContainerItem(ItemStack stack) for it and worked with this (very old code):

public class ItemChargedCoal extends Item {
	
	public ItemChargedCoal(int meta){
		setMaxStackSize(1);
		switch(meta){
		case 0:
			setUnlocalizedName("charged_coal");
			setMaxDamage(64);
			break;
		case 1:
			setUnlocalizedName("charged_supercoal");
			setMaxDamage(512);
			break;
		}
		...
	}
	
	@Override
	public ItemStack getContainerItem(ItemStack stack) {
		if(stack.getItemDamage() < stack.getMaxDamage()){
			stack.setItemDamage(stack.getItemDamage()+1);
			stack.stackSize++;
			setContainerItem(stack.getItem());
		}
		if(stack.getItemDamage() >= stack.getMaxDamage()){
			setContainerItem(Item.getItemFromBlock(Blocks.air));
			return null;
		}
		return stack;
	}
  ...
}

 

After updating to 1.12.2, the file looks like this currently:

(IFuelHandler was removed so I added getItemBurnTime, which doesn't have anything to do with the problem though.

public class ItemChargedCoal extends Item {
	
	public ItemChargedCoal(int meta){
		setMaxStackSize(1);
		switch(meta){
		case 0:
			setUnlocalizedName("charged_coal");
			setRegistryName("charged_coal");
			setMaxDamage(64);
			break;
		case 1:
			setUnlocalizedName("charged_supercoal");
			setRegistryName("charged_supercoal");
			setMaxDamage(512);
			break;
		}
		...
	}
	
	@Override
	public int getItemBurnTime(ItemStack fuelItem) {
		ItemStack fuel = fuelItem.copy();
		
		if(fuel.getItem() == RememberMe2018.instance.chargedCoal){
			return 200;
		}
		if(fuel.getItem() == RememberMe2018.instance.chargedSupercoal){
			return 200;
		}
		return 0;
	}
	
	@Override
	public boolean hasContainerItem(ItemStack stack) {
		return true;
	}
	
	@Override
	public ItemStack getContainerItem(ItemStack stack) {
		ItemStack stack2 = stack.copy();
		
		System.out.println("Test " + stack2.getItem() + ", " + stack2.getItemDamage());
		
		if(stack2.getItemDamage() < stack2.getMaxDamage()){
			stack2.setItemDamage(stack2.getItemDamage()+1);
			//setContainerItem(stack.getItem());
		} else if(stack2.getItemDamage() >= stack2.getMaxDamage()){
			return new ItemStack(Item.getItemFromBlock(Blocks.AIR));
		}
		return stack2;
	}
}

 

Is there any way to get this working again in 1.12? I don't really want the coal to just have higher burn time, I want the item to stay in the fuel slot and just take damage until it's used.
I also couldn't find any solution, the only thing I found out is that getContainerItem apparently gets fired when I put the coal in the fuel slot, but the stack passed is Air. While that doesn't seem to work, the method instead "works" in crafting which should not happen in that case.
Short: Crafting with the coal should use up the item directly and not damage it, putting it in a furnace as fuel should damage the item instead of burning the item instantly.

Link to comment
Share on other sites

6 hours ago, diesieben07 said:

For some reason the furnace first shrinks the stack and then grabs the container item (as opposed to the crafting table). You have to just ignore the fact that you are getting passed an air stack (it's not really air, it's a stack of your item but with size 0). Calling grow(1) on a copy should make things work.

Unfortunately, that doesn't work as well. I still get Air as result, the size stays 0 and the damage/meta as well. I even tried creating a new ItemStack with my coal and just passing the count/damage values, but Minecraft doesn't seem to like that, the item turns to the purple-black texture and hovering the item crashes the game.
The problem is, even if it would work somehow, I don't want it to affect the coal while crafting with it, since the "Charged Supercoal" is crafted from 4 Charged Coals + Redstoneblock and there the stack grows from 1 to 2 and also gets damaged.
The issue seems to be the instant burning in the furnace which turns the item into Air... 

Link to comment
Share on other sites

2 hours ago, diesieben07 said:

You cannot have different container items in furnace and crafting table.

Well, yeah, I could've guessed that. I just thought there was a way to "test" for the specific container the item is in, but whatever, that's not the main problem.

At least I want it to work in the furnace as intended and I'm kinda out of ideas, I can't find any related topic or question anywhere and there doesn't seem to be an up-to-date video about fuel used that way either.

Maybe you got another idea, considering the stuff I already tried?

Link to comment
Share on other sites

9 minutes ago, diesieben07 said:

@Override
	public ItemStack getContainerItem(ItemStack stack) {
		ItemStack stack2 = stack.copy();
		
		stack2.grow(1);

		System.out.println("Test " + stack2.getItem() + ", Count: " + stack2.getCount() + ", Dmg: " + stack2.getItemDamage());
		
		if(stack2.getItemDamage() < stack2.getMaxDamage()){
			stack2.setItemDamage(stack2.getItemDamage()+1);
			//setContainerItem(stack.getItem());
		} else if(stack2.getItemDamage() >= stack2.getMaxDamage()){
			return new ItemStack(Item.getItemFromBlock(Blocks.AIR));
		}
		return stack2;
	}

The chat output still remains the same as without the "stack2.grow(1)", the stack count is 0, no matter what and the item also stays air.

 

output.PNG

Link to comment
Share on other sites

Just now, diesieben07 said:

I honestly do not see how that is possible.

Yeah, I'm out of ideas as well. Somehow the furnace instantly burns the item so even the container item outputs air. Although in crafting the code does exactly what I wrote. 

Link to comment
Share on other sites

Alright, another test, I'll try some more, but maybe you'll get another idea with this.
I tried .getContainerItem() on that Item and the output before growing shows "null", while after growing it shows "Air".

@Override
	public ItemStack getContainerItem(ItemStack stack) {
		ItemStack stack2 = stack.copy();

		System.out.println("Test1 " + "Container: " + stack2.getItem().getContainerItem() + ", Item: " + stack2.getItem() + ", Count: " + stack2.getCount() + ", Dmg: " + stack2.getItemDamage());
		stack2.grow(1);
		stack2.getItem().setContainerItem(stack.getItem());
		stack2.grow(1);
		System.out.println("Test2 " + "Container: " + stack2.getItem().getContainerItem() + ", Item: " + stack2.getItem() + ", Count: " + stack2.getCount() + ", Dmg: " + stack2.getItemDamage());
		
		if(stack2.getItemDamage() < stack2.getMaxDamage()){
			stack2.setItemDamage(stack2.getItemDamage()+1);
			//setContainerItem(stack.getItem());
		} else if(stack2.getItemDamage() >= stack2.getMaxDamage()){
			return new ItemStack(Item.getItemFromBlock(Blocks.AIR));
		}
		return stack2;
	}

 

outputnew.PNG

Link to comment
Share on other sites

That is not how you use setContainerItem

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.

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.



×
×
  • Create New...

Important Information

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