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.

Announcements



×
×
  • Create New...

Important Information

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