Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

A block in my mod has a texture for on and off but it will only update when the GUI is open.

 

the block code can be found here: https://github.com/danielm59/Fast-Food/blob/master/src/main/java/danielm59/fastfood/block/BlockChurn.java

 

the tile entity code can be found here: https://github.com/danielm59/Fast-Food/blob/master/src/main/java/danielm59/fastfood/tileentity/TileEntityChurn.java

 

Hi

 

The rendering instructions for Blocks are only updated when necessary.  If you update the information, you need to trigger a block update.  Or alternatively, if your blockstate is only used for rendering, change the rendering to a TileEntitySpecialRenderer instead of a BlockModel.

 

For more information see here (first few paragraphs)

http://greyminecraftcoder.blogspot.com.au/2014/12/block-rendering-18.html

 

-TGG

Hi

 

This snippet should do the trick I think

 

worldObj.markBlockForUpdate(blockPos);

 

You should only call it when something is changed.

 

-TGG

  • Author

I already have that line in my TE update code but only get called when the GUI is open, where else should i have.

I already have that line in my TE update code but only get called when the GUI is open, where else should i have.

Whenever something turns your block on or off, at a guess.  Or have I misunderstood your question?

 

-TGG

  • Author

I have code I think should work which uses the function you said but I can not work out why it only updates when the GUI is open.

Have you verified that your update code is being called and the right parts are being executed (especially - the call to worldObj.markBlockForUpdate(blockPos));  i.e. using System.out.println() ?

 

-TGG

  • Author

using debug mode i have seen that the code is only run when the GUI is open but don't know why. I can't do any work with the code until tomorrow evening due to work commitments.

yes, that should be the right place I think.  I'm not sure why update() would only be called when the GUI is open, doesn't make sense to me at all.

 

-TGG

  • Author

It looks like my currentProcessTime does not update when the GUI is closed. Do I need to use a packet?

dHi

 

I added some troubleshooting code

    @Override
    public void update() {    	
    	System.out.println("TileEntityChurn.update(): side:" + (worldObj.isRemote ? "client" : "server")
                         + " currentProcessTime:" + currentProcessTime);

protected void checkUpdate() {
    System.out.print("   TileEntityChurn.checkUpdate(): isActive()=" + isActive() + ", activeUpdate=" + activeUpdate);
	if (isActive() != activeUpdate) {
		activeUpdate = isActive();
      System.out.print(" -> block updated");

 

update() is called fine on both client and server.  The problem is in your client <--> server logic; see the debug output here

 

 

 

[10:52:53] [server thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:server currentProcessTime:96

[10:52:53] [Client thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:client currentProcessTime:25

  TileEntityChurn.checkUpdate(): isActive()=true, activeUpdate=true

[10:52:53] [server thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:server currentProcessTime:97

[10:52:53] [Client thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:client currentProcessTime:25

  TileEntityChurn.checkUpdate(): isActive()=true, activeUpdate=true

[10:52:53] [server thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:server currentProcessTime:98

[10:52:53] [Client thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:client currentProcessTime:25

  TileEntityChurn.checkUpdate(): isActive()=true, activeUpdate=true

[10:52:53] [Client thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:client currentProcessTime:25

  TileEntityChurn.checkUpdate(): isActive()=true, activeUpdate=true

[10:52:53] [server thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:server currentProcessTime:99

[10:52:54] [server thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:server currentProcessTime:0

[10:52:54] [Client thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:client currentProcessTime:25

  TileEntityChurn.checkUpdate(): isActive()=true, activeUpdate=true

[10:52:54] [server thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:server currentProcessTime:0

[10:52:54] [Client thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:client currentProcessTime:25

  TileEntityChurn.checkUpdate(): isActive()=true, activeUpdate=true

[10:52:54] [server thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:server currentProcessTime:0

[10:52:54] [Client thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:client currentProcessTime:25

  TileEntityChurn.checkUpdate(): isActive()=true, activeUpdate=true

[10:52:54] [Client thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:client currentProcessTime:25

  TileEntityChurn.checkUpdate(): isActive()=true, activeUpdate=true

[10:52:54] [server thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:server currentProcessTime:0

[10:52:54] [server thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:server currentProcessTime:0

[10:52:54] [Client thread/INFO] [sTDOUT]: [danielm59.fastfood.tileentity.TileEntityChurn:update:31]: TileEntityChurn.update(): side:client currentProcessTime:25

  TileEntityChurn.checkUpdate(): isActive()=true, activeUpdate=true

 

 

You update the server currentProcessTime but not the client, but only the client does anything about it.  markDirty is no guarantee.  even markBlockForUpdate on the server doesn't automatically update the client immediately.

 

I suggest you put the incrementing logic on the client side as well.  Actually I think it could probably be identical to the server side, since the containers will re-sync when you open them to retrieve your butter.  Try it and see? I've committed my modified forked version and it seems to work fine.

 

-TGG

 

  • Author

That doesn't work when you put milk or butter in with a hopper. The client is not updating.

 

My code is in the churn texture branch

I updated the churn texture branch of my fork (master too, by mistake). 

 

See this commit

https://github.com/TheGreyGhost/Fast-Food/commit/e6c13294fc40a5e81c29665a8caa496d99ce8a4e

 

It works fine for me.  When I put either milk or butter into the churn, close the GUI, and wait for a few seconds, the top of the block changes from yellow/white back to black.

 

copied code:

package danielm59.fastfood.tileentity;

import danielm59.fastfood.recipe.ChurnRecipe;
import danielm59.fastfood.recipe.ChurnRegistry;
import net.minecraft.item.ItemStack;
import net.minecraft.server.gui.IUpdatePlayerListBox;



public class TileEntityChurn extends TileEntityFF implements IUpdatePlayerListBox {

public int currentProcessTime;
public boolean activeUpdate;

public TileEntityChurn() {

	super();
	inventory = new ItemStack[2];

}

@Override
public String getName() {

	return "Churn";

}
    
    @Override
    public void update() {    	
    	System.out.println("TileEntityChurn.update(): side:" + (worldObj.isRemote ? "client" : "server")
                         + " currentProcessTime:" + currentProcessTime);
    	if (true) {// (!worldObj.isRemote) {
       	ChurnRecipe recipe = ChurnRegistry.getInstance().getMatchingRecipe(inventory[0], inventory[1]);
  			if (recipe != null) {
        		 if (++currentProcessTime >= 100) {
        			this.markDirty();
        			 currentProcessTime = 0;
                     if (inventory[1] != null) {
                    	 inventory[1].stackSize += recipe.getOutput().stackSize;
                     } else {
                    	 inventory[1] = recipe.getOutput().copy();
                     }
                     if (inventory[0].getItem().hasContainerItem())
                     {
                    	 setInventorySlotContents(0, new ItemStack(inventory[0].getItem().getContainerItem()));
                     }
                     else
                     {
                    	 decrStackSize(0, 1);
                     }
                 }
             } else {
                 currentProcessTime = 0;
             }
         } else {

//        	 checkUpdate();
         }
      checkUpdate();
    }
    
protected void checkUpdate() {
    System.out.print("   TileEntityChurn.checkUpdate(): isActive()=" + isActive() + ", activeUpdate=" + activeUpdate);
	if (isActive() != activeUpdate) {
		activeUpdate = isActive();
      System.out.print(" -> block updated");

		worldObj.notifyBlockOfStateChange(pos, worldObj.getBlockState(pos).getBlock());
		worldObj.markBlockForUpdate(pos);
	}
    System.out.println();
}
    
    public boolean isActive() {
	boolean active = (currentProcessTime>0);
    	return active;	
}

public float getProgress() {
    	
    	return (float) currentProcessTime/100;
    	
    }

}

 

-TGG

  • Author

That is what I tried but when you use a hopper to input the item the texture only updates once the GUI has been opened.

Hi

 

Hmmm, sounds like the hopper is doing something on the server but not communicating it to the client.  I don't know how hoppers work, sorry, you could try putting a breakpoint into

TileEntityHopper.func_145883_k() to see what happens when the hopper inserts an object into your inventory, and figure out how to make it update the blockstate on the client so you can see it.

 

-TGG

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.