Jump to content

Custom Furnace Progress Bar Works Improperly


Yoyoness_

Recommended Posts

So whenever the code I have commented out below is not commented out, the progress bar of the furnace will be completely filled while it's smelting, no matter what the progress is. However removing this code makes the progress bar work properly.

	//This method is located in the ContainerNetherForge class

	@Override
	public void detectAndSendChanges()
	{
		super.detectAndSendChanges();
		
		for (int i = 0; i < this.listeners.size(); i++)
		{
			IContainerListener listener = (IContainerListener)this.listeners.get(i);
			
//			if (this.cookTime != this.tileEntity.getField(0))
//				listener.sendWindowProperty(this, 0, this.tileEntity.getField(0));
//			if (this.totalCookTime != this.tileEntity.getField(1))
//				listener.sendWindowProperty(this, 1, this.tileEntity.getField(1));

			this.cookTime = this.tileEntity.getField(0);
			this.totalCookTime = this.tileEntity.getField(1);
		}
	}

I checked to see if the values being sent to the listener were correct, and they were. In fact, all the values in both the TileEntity and Container classes remain correct, at least on client side. The furnace operates properly, the problem is only the animation.

 

The issue is in this method. The calls to getField aren't returning the values they should be (and yes, the field IDs are correct, I checked at least 10 times). I provided a screenshot of the console to show the values that are being passed to the method.

	//This method is located in the GuiNetherForge class

	private int getCookProgressScaled(int pixels)
	{
		int currCookTime = this.tileEntity.getField(0);
		int totalCookTime = this.tileEntity.getField(1);
		System.out.println("Current cook time: "+this.tileEntity.getField(0));
		System.out.println("Total cook time: "+this.tileEntity.getField(1));
		
		if (totalCookTime != 0 && currCookTime != 0)
		{
			return currCookTime*pixels/totalCookTime;
		}
		else
		{
			return 0;
		}
	}

As you can see from the values in the picture, the issue is that getCookProgressScaled(24) (which is being called in another method) will always return 24 or more. The issue is solely the values being passed to currCookTime and totalCookTime. I have no idea how listeners work, this is just how the vanilla furnace uses them. If anyone has more knowledge about listeners and why this might be happening, please let me know.

 

- Yoyo

console.png

Edited by Yoyoness_
Link to comment
Share on other sites

1. Stop watching HarryTalk's tutorials. His videos are out dated and have very bad coding conventions. I've pointed out some of the problematic code, both style-wise and code-wise, in the comment section of his video (the custom furnace series), and hopefully he will update his videos in the future.

2. In java, a division where both sides are ints will return an int. Thus, you need to cast one value to double before performing division in your getCookProgressScaled.

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

6 minutes ago, DavidM said:

1. Stop watching HarryTalks' tutorials. His videos are out dated and have very bad coding conventions. I've pointed out all the problematic code, both style-wise and code-wise, in the comment section of his video (the custom furnace series), and hopefully he will update his videos in the future.

2. In java, a division where both sides are ints will return an int. Thus, you need to cast one value to double before performing division in your getCookProgressScaled.

Alright, noted on the first point, but the issue isn't the fact that Java is doing integer division. Like I said, it works properly when that section of code is commented out. currCookTime is being multiplied by the amount of pixels before it is divided by totalCookTime, so it will return the proper value if given the proper values. The issue lies elsewhere.

Link to comment
Share on other sites

5 hours ago, DavidM said:

In java, a division where both sides are ints will return an int. Thus, you need to cast one value to double before performing division in your getCookProgressScaled.

Usually you want a float, not a double. If you need very high precision or are dealing with longs then you need a double.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

But the issue is that the Gui class getting the wrong value from the TileEntity's fields when the field information is sent to the listeners from the Container class (the portion of code that is commented out). I'm just wondering why this is happening.

 

I've attached a picture of what the values are when that code is commented out, so I know that's the issue.

console.png

Edited by Yoyoness_
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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Your drivers are in a broken state, follow the guide in the FAQ: https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/#:~:text=How do I update my drivers%3F
    • A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffc3fe22b60, pid=15228, tid=5140 # # JRE version: OpenJDK Runtime Environment Microsoft-8035246 (17.0.8+7) (build 17.0.8+7-LTS) # Java VM: OpenJDK 64-Bit Server VM Microsoft-8035246 (17.0.8+7-LTS, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64) # Problematic frame: # C [atio6axx.dll+0x192b60] # # No core dump will be written. Minidumps are not enabled by default on client versions of Windows # # If you would like to submit a bug report, please visit: # https://aka.ms/minecraftjavacrashes # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug i have no idea why please help
    • Quick-Books is great with regards to coordinating your monetary data. You can decide to live talk with a specialist at Quick-Books to get the answer for your questions. You will actually want to get to the talk going to the landing page and call us +1855-210-1428.
    • Update: I managed to make the item not disappear after crafting, but it doesn't remove any durability. import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.enchantment.UnbreakingEnchantment; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class NuggetHammer extends Item { private boolean damage; public NuggetHammer(Properties p_i48487_1_) { super(p_i48487_1_); } @Override public int getMaxDamage(ItemStack stack) { return 54 - 1; } public boolean isBarVisible(ItemStack stack) { return false; } @Override public ItemStack getContainerItem(ItemStack stack) { ItemStack copy = stack.copy(); copy.setCount(1); if (!this.damage) return copy; int unbreaking = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.UNBREAKING, stack); for (int i = 0; i < unbreaking; i++) { if (UnbreakingEnchantment.shouldIgnoreDurabilityDrop(stack, unbreaking, random)) return copy; } copy.setDamageValue(stack.getDamageValue() + 1); if (copy.getDamageValue() > stack.getMaxDamage()) return ItemStack.EMPTY; return copy; } }  
  • Topics

×
×
  • Create New...

Important Information

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