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.

[1.8.9][SOLVED] Tile Entity's Tank not updating (wrongly) client-side

Featured Replies

Posted

I have a tank implemented on my tile entity, but the client isn't getting updated when I remove fluid from the tank bit by bit, but it does work when I fill the tank completely from being empty.

 

Here's my update function from my TileEntity/TileInventory class.

@Override
public void update(){
	boolean hasLava = this.hasLava();
	int lavaAmount = this.tank.getFluidAmount();
	boolean needsUpdate = false;

               //When I print out "lavaAmount" here, I get either 0/1000 (empty/full) when run by the client, but the actual amount when run by the server

	/*if(this.burnTimeRemaining > 0){
		--this.burnTimeRemaining;
	}*/
	if(!this.worldObj.isRemote){
		if(!hasLava && this.forgeItemstacks[FIRST_FUEL_SLOT] != null && this.forgeItemstacks[FIRST_FUEL_SLOT].getItem() == Items.lava_bucket){//TODO Change to include all items that hold fluids
			this.fill(null, new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), true);
			this.forgeItemstacks[FIRST_FUEL_SLOT] = this.forgeItemstacks[FIRST_FUEL_SLOT].getItem().getContainerItem(forgeItemstacks[FIRST_FUEL_SLOT]);
		}
		if(/*this.secondsOfFuelRemaining() > 0*/ hasLava && this.canSmelt()){
			this.tank.drain(5, true);
			++this.cookTime;
			if(this.cookTime == COOK_TIME_FOR_COMPLETION){
				this.cookTime = 0;
				this.smeltItem();
				needsUpdate = true;
			}
		}
		if (lavaAmount != this.tank.getFluidAmount()){
			needsUpdate = true;
			//TODO BlockMaskForge.updateFurnaceBlockState(this.isBurning(), this.worldObj, this.pos.getX(), this.pos.getY(), this.pos.getX());
		}
	}

	if (needsUpdate){
		this.markDirty();
	}
}

 

Is there something I'm missing here?

I'm sure you'll probably need more information to help me solve this, just let me know what you need.

 

EDIT: Solved it myself. Turns out when I was updating the IInventory setFeild() function, I was always adding fluid rather than adding/removing depending on what it should be.

 

So I changed this:

@Override
public void setField(int id, int value){
	if(id == COOK_FIELD_ID){
		cookTime = (short)value;
	}else if(id == FUEL_AMOUNT_FIELD_ID){
		this.fill(null, new FluidStack(FluidRegistry.LAVA, value), true);
	}else{
		System.err.println("Invalid field ID in TileInventorySmelting.setField:" + id);
	}
}

 

To this:

@Override
public void setField(int id, int value){
	if(id == COOK_FIELD_ID){
		cookTime = (short)value;
	}else if(id == FUEL_AMOUNT_FIELD_ID){
		FluidStack flStack = new FluidStack(FluidRegistry.LAVA, Math.abs(this.tank.getFluidAmount() - value));
		if(value > this.tank.getFluidAmount()){
			this.fill(null, flStack, true);
		}else if(value < this.tank.getFluidAmount()){
			this.drain(null, flStack, true);
		}
	}else{
		System.err.println("Invalid field ID in TileInventorySmelting.setField:" + id);
	}
}

Of course it doesn't think there's any fluid present on the client side, your code that updates the lava tank is only run on the server side because of the

!isRemote

check. The game doesn't automatically sync your TileEntities to the client side, you need to do that yourself.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Did you read all of my post? It does show changes on clientside, but only in one circumstance.

 

Your update function still bypasses the change that doesn't get tracked on the client, on the client.

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.

  • Author

But both of the changes I make to the tank both happen within the !isRemote section.

Am I just missing something really obvious?

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.