Jump to content

Server-Client side issues


DestinySpork

Recommended Posts

So I have a TileEntity which I have based off the furnace tile entity.

However, the updateEntity() is only called on the server, and so when I call getBurnTimeRemainingScaled() on the Client it always returns 0. How can I fix this, as running updateEntity() on the Client is weird and glitchy, and the numbers do not correspond to the  Server.

 

@Override
public void updateEntity(){
	if(!this.worldObj.isRemote){ //this only runs on the server, the client does not get these variables.
		if(!this.isBurning){
			ItemStack stack = this.getStackInSlot(0);
			if(this.isItemFuel(stack)){
				this.fuelBurnTime = getItemBurnTime(stack);
				this.generatorBurnTime = 0;
				this.decrStackSize(0, 1);
				this.markDirty();
				this.setBurning();
			}
		}

		if(this.isBurning){
			this.generatorBurnTime += 4;
			if(this.generatorBurnTime > this.fuelBurnTime){
				this.generatorBurnTime = 0;
				this.fuelBurnTime = 0;
				this.isBurning = false;
				}
			if(this.isBurning){}
			//this.receieveEnergy(null, 8, false); //side, amount, simulate
		}
	}

}


public int getBurnTimeRemainingScaled(int i){

	if(this.fuelBurnTime != 0){
		System.out.println("progress: "+ this.generatorBurnTime * i / this.fuelBurnTime);
		return this.generatorBurnTime * i / this.fuelBurnTime;
	}
	System.out.println("returned 0");
	return 0;
}

 

I know the Furnace tileentity has @SideOnly annotations, I left them out because I didn't know if they were the issue.

 

getBurnTimeRemainingScaled() is called from GuiGenerator on the Client side, and cannot access the server side information.

Link to comment
Share on other sites

1. Regarding SideOnly: http://www.minecraftforge.net/forum/index.php/topic,22764.0.html

2. Do you actually need those values on client?

2.1. When? In container, rendered on block, on interaction?

 

Anyway - there are few ways to approach this. You will need (if not here, then in future) packets:

http://www.minecraftforge.net/forum/index.php/topic,20135.0.html

 

You need to send value from server to client and update TileEntity at x/y/z.

Packet wil contain x/y/z and new value.

 

If you need values in e.g Gui there is other way. That later.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

So, do you have a GUI or a GUI+Container (GuiContainer.class)?

 

There is a "nice" abstraction layer that allows you to send integer values when player opens container (gui). This is specially designed to send progress bars to clients that open containers. Will your "fuel status" fit into integer?

 

If not - you need packets that will be sent to player that opens gui (you can literally send apcket with data to player (and update his opened container) whenever he opens it and then re-update him when he has it opened. To do that - you want what I linked earlier.

 

If yes - have look at those methods: (container)

On client:

@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int data)
{
// fired on client. Id is of the field you want to update, data is obvioudly integer I was talking about.
}

On server:

for (int i = 0; i < this.crafters.size(); ++i) // this = container
{
ICrafting iCrafting = (ICrafting) this.crafters.get(i); // crafters are "entites" (players) that opened this container.
iCrafting.sendProgressBarUpdate(this, id, data); // send update with some "id" and some "data".
}

This one might be usefule, but not really:

public void detectAndSendChanges()

To actually learn how it works - you need to readup some vanilla code. Nasty stuff :D But I receommend reading callbacks.

 

Point of interest:

There is an "usefule" abstraction layer in TileEntity:

getField

setFiled

Those can be used within methods in container class to make something (both use id/integer system).

 

If you have problems with anything, post code and errors. Most can be resolved on your own by experimenting. (I gave you tools).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I have a GuiContainer class and Container class, is that right?

 

public class GuiGenerator extends GuiContainer{...}

 

public class ContainerGenerator extends Container{...}

Yes. Now you just need to do what Ernio suggested: read the vanilla code for examples.

 

The furnace sends its burn progress to the GUI via the Container, so look at the furnace Container class, specifically the methods Ernio mentioned above.

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.



×
×
  • Create New...

Important Information

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