abused_master Posted December 29, 2016 Posted December 29, 2016 Hey guys, so im working on a furnace sort of block and an having trouble rendering the progress bar, it runs with the same ticks for each item/block as a furnace, so i thought id take a look, and tried doing what the furnace did to see if it would work but even then i cant get it to work, what iv tried public class GuiTestFurnace extends GuiContainer { public static final ResourceLocation TestFurnace = new ResourceLocation(Info.MODID, "textures/gui/test_furnace.png"); public static final int WIDTH = 176; public static final int HEIGHT = 166; TileTestFurnace testFurnace; public GuiPulverizer(TileTestFurnace tileEntity, TestFurnaceContainer container, TileEntity te) { super(container); xSize = WIDTH; ySize = HEIGHT; testFurnace= (TileTestFurnace ) tileEntity; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { mc.getTextureManager().bindTexture(TestFurnace ); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); int l = this.getCookProgressScaled(24); this.drawTexturedModalRect(guiLeft + 81, guiTop + 27, 176, 46, l + 1, 16); } private int getCookProgressScaled(int pixels) { int i = this.testFurnace.getField(0); int j = this.testFurnace.getField(1); return j != 0 && i != 0 ? i * pixels / j : 0; } } and my getField in my testFurnace is public int getField(int id) { switch (id) { case 0: return this.cookTime; case 1: return this.totalCookTime; default: return 0; } } public void setField(int id, int value) { switch (id) { case 0: this.cookTime = value; break; case 1: this.totalCookTime = value; } } Quote
Draco18s Posted December 29, 2016 Posted December 29, 2016 Are your cookTime and totalCookTime values synced to the client? Quote 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.
Alanzote Posted December 29, 2016 Posted December 29, 2016 Hi abused_master, I don't know if that's your issue, however, when I used the furnace code in GUI, It did not work for me also. So, I changed my getScaled class to something like this. private int getCookProgressScaled(int pixels) { return (this.testFurnace.getField(0) * pixels / this.testFurnace.getField(1)); } I always use this piece of code for my progress bars, It works like a charm. Edit: make sure you typed the right values in drawGuiContainerBackgroundLayer. See if it works, Alanzote. Quote
abused_master Posted December 29, 2016 Author Posted December 29, 2016 Are your cookTime and totalCookTime values synced to the client? yeah they are Hi abused_master, I don't know if that's your issue, however, when I used the furnace code in GUI, It did not work for me also. So, I changed my getScaled class to something like this. private int getCookProgressScaled(int pixels) { return (this.testFurnace.getField(0) * pixels / this.testFurnace.getField(1)); } I always use this piece of code for my progress bars, It works like a charm. Edit: make sure you typed the right values in drawGuiContainerBackgroundLayer. See if it works, Alanzote. yeah i did type the right values i tested with it, i also tried the code u gave but that didnt solve it either Quote
Alanzote Posted December 29, 2016 Posted December 29, 2016 Are you setting the variables in the TileEntity? Quote
abused_master Posted December 29, 2016 Author Posted December 29, 2016 Are you setting the variables in the TileEntity? yeah Quote
Alanzote Posted December 29, 2016 Posted December 29, 2016 What are the values you set? Can you post a picture of the result? Quote
abused_master Posted December 29, 2016 Author Posted December 29, 2016 Well the result is nothing, no progress bar is rendered, at all, just the plain gui, for the values, im using basically the same stuff the furnace is using just different recipes Quote
Alanzote Posted December 29, 2016 Posted December 29, 2016 Can you post your update() method? Maybe there is something wrong with the logic. Quote
abused_master Posted December 29, 2016 Author Posted December 29, 2016 @Override public void update() { if(!getWorld().isRemote) { PacketHandler.INSTANCE.sendToAll(new MessageTEUpdate(this)); } boolean flag1 = false; if (!this.worldObj.isRemote) { ItemStack itemstack = (ItemStack)this.testFurnaceInv.get(1); if (storage.getEnergyStored() > 50 || !itemstack.func_190926_b() && !((ItemStack)this.testFurnaceInv.get(0)).func_190926_b()) { if (!(storage.getEnergyStored() > 50) && this.canSmelt()) { if (storage.getEnergyStored() > 50) { flag1 = true; if (!itemstack.func_190926_b()) { Item item = itemstack.getItem(); itemstack.func_190918_g(1); if (itemstack.func_190926_b()) { ItemStack item1 = item.getContainerItem(itemstack); this.testFurnaceInv.set(1, item1); } } } } if (storage.getEnergyStored() > 50 && this.canSmelt()) { ++this.cookTime; if (this.cookTime == this.totalCookTime) { this.cookTime = 0; this.totalCookTime = this.getCookTime((ItemStack)this.testFurnaceInv.get(0)); this.SmeltItem(); flag1 = true; } } else { this.cookTime = 0; } } else if (!(storage.getEnergyStored() > 50) && this.cookTime > 0) { this.cookTime = MathHelper.clamp_int(this.cookTime - 2, 0, this.totalCookTime); } } if (flag1) { this.markDirty(); } } public void SmeltItem() { if (this.canPulverize()) { ItemStack itemstack = (ItemStack) this.testFurnaceInv.get(0); ItemStack itemstack1 = RecipeTestFurnace.instance().getSmeltingResult(itemstack); ItemStack itemstack2 = (ItemStack) this.testFurnaceInv.get(1); if (storage.getEnergyStored() >= 50 && !itemstack1.func_190926_b()) { storage.setEnergyStored(storage.getEnergyStored() - 50); if (itemstack2.func_190926_b()) { this.testFurnaceInv.set(1, itemstack1.copy()); } else if (itemstack2.getItem() == itemstack1.getItem()) { itemstack2.func_190917_f(itemstack1.func_190916_E()); } itemstack.func_190918_g(1); } } } Quote
Alanzote Posted December 29, 2016 Posted December 29, 2016 One of this conditions must be returning false, I recomend debugging with System.out.prinln("String"); if (storage.getEnergyStored() > 50 || !itemstack.func_190926_b() && !((ItemStack)this.testFurnaceInv.get(0)).func_190926_b()) if (storage.getEnergyStored() > 50 && this.canSmelt()) Quote
Draco18s Posted December 29, 2016 Posted December 29, 2016 I had the same problem, and I fixed it by changing drawContainerForeGroundLayer to drawContianerForegroundLayer. I see that is not the problem you have, though. And that is why you should use @Override, to catch mistakes like that. Quote 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.
abused_master Posted December 29, 2016 Author Posted December 29, 2016 So i found out *derp* that i had to sync the values with my Container aswell, so i did that public void detectAndSendChanges() { super.detectAndSendChanges(); for (int i = 0; i < this.listeners.size(); ++i) { IContainerListener icontainerlistener = (IContainerListener)this.listeners.get(i); if (this.cookTime != this.tileTestFurnace.getField(0)) { icontainerlistener.sendProgressBarUpdate(this, 2, this.tileTestFurnace.getField(0)); } if (this.totalCookTime != this.tileTestFurnace.getField(1)) { icontainerlistener.sendProgressBarUpdate(this, 3, this.tileTestFurnace.getField(1)); } } this.cookTime = this.tileTestFurnace.getField(0); this.totalCookTime = this.tileTestFurnace.getField(1); } @SideOnly(Side.CLIENT) public void updateProgressBar(int id, int data) { this.tileTestFurnace.setField(id, data); } is this the correct? Quote
Animefan8888 Posted December 29, 2016 Posted December 29, 2016 So i found out *derp* that i had to sync the values with my Container aswell, so i did that public void detectAndSendChanges() { super.detectAndSendChanges(); for (int i = 0; i < this.listeners.size(); ++i) { IContainerListener icontainerlistener = (IContainerListener)this.listeners.get(i); if (this.cookTime != this.tileTestFurnace.getField(0)) { icontainerlistener.sendProgressBarUpdate(this, 2, this.tileTestFurnace.getField(0)); } if (this.totalCookTime != this.tileTestFurnace.getField(1)) { icontainerlistener.sendProgressBarUpdate(this, 3, this.tileTestFurnace.getField(1)); } } this.cookTime = this.tileTestFurnace.getField(0); this.totalCookTime = this.tileTestFurnace.getField(1); } @SideOnly(Side.CLIENT) public void updateProgressBar(int id, int data) { this.tileTestFurnace.setField(id, data); } is this the correct? Does it work? If not I suggest changing icontainerlistener.sendProgressBarUpdate(this, 2, this.tileTestFurnace.getField(0)); // To this icontainerlistener.sendProgressBarUpdate(this, 0, this.tileTestFurnace.getField(0)); // Or this icontainerlistener.sendProgressBarUpdate(this, 2, this.tileTestFurnace.getField(2)); Do you see the difference? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
abused_master Posted December 29, 2016 Author Posted December 29, 2016 yeah i found the mistake after i posted, now what ends up happening is the progress bar flickers on sometimes the progress when working but doesnt stay on the entire time it works, example: https://gyazo.com/a5b6a3b85575992e7e9a49b2b23db499 Quote
Animefan8888 Posted December 29, 2016 Posted December 29, 2016 yeah i found the mistake after i posted, now what ends up happening is the progress bar flickers on sometimes the progress when working but doesnt stay on the entire time it works, example: https://gyazo.com/a5b6a3b85575992e7e9a49b2b23db499 How fast is the process? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
abused_master Posted December 29, 2016 Author Posted December 29, 2016 The exact same as a vanilla furnace, if u mean the flickering, its always random Quote
Animefan8888 Posted December 29, 2016 Posted December 29, 2016 The exact same as a vanilla furnace, if u mean the flickering, its always random Could you post the updated rendering code? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
abused_master Posted December 29, 2016 Author Posted December 29, 2016 sure: for the Container public void detectAndSendChanges() { super.detectAndSendChanges(); for (int i = 0; i < this.listeners.size(); ++i) { IContainerListener icontainerlistener = (IContainerListener)this.listeners.get(i); if (this.cookTime != this.tileTestFurnace.getField(0)) { icontainerlistener.sendProgressBarUpdate(this, 0, this.tileTestFurnace.getField(0)); } if (this.totalCookTime != this.tileTestFurnace.getField(1)) { icontainerlistener.sendProgressBarUpdate(this, 1, this.tileTestFurnace.getField(1)); } } this.cookTime = this.tileTestFurnace.getField(0); this.totalCookTime = this.tileTestFurnace.getField(1); } @SideOnly(Side.CLIENT) public void updateProgressBar(int id, int data) { this.tileTestFurnace.setField(id, data); } Gui: //in the drawGuiContainerBackgroundLayer int l = this.getCookProgressScaled(24); this.drawTexturedModalRect(guiLeft + 81, guiTop + 27, 176, 46, l + 1, 16); private int getCookProgressScaled(int pixels) { int i = this.tileTestFurnace.getField(0); int j = this.tileTestFurnace.getField(1); return j != 0 && i != 0 ? i * pixels / j : 0; } and the getField and setField: @Override public int getField(int id) { switch (id) { case 0: return this.cookTime; case 1: return this.totalCookTime; default: return 0; } } @Override public void setField(int id, int value) { switch (id) { case 0: this.cookTime = value; break; case 1: this.totalCookTime = value; } } @Override public int getFieldCount() { return 4; } Quote
Lambda Posted December 30, 2016 Posted December 30, 2016 Compared to my TEs, you should probably use capabilities instead of getField/setField. I don't know if it will fix your problems, but its 'good' to do it anyways. Quote Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
abused_master Posted December 30, 2016 Author Posted December 30, 2016 Tried a few different ways but nothing really worked, still randomly blinking the progress but not fully showing it, https://gyazo.com/f1a6ef32246c42b7de0741023840c2b9 Quote
Jay Avery Posted December 30, 2016 Posted December 30, 2016 Use printlns or the debugger to check: - Is getCookProgressScaled returning the expected values? - Is your TE's getField returning the expected values? - Is your TE fully synced between client and server? Quote
Recommended Posts
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.