Jump to content

[1.8] block state only updates when GUI open


danielm59

Recommended Posts

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

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.