Jump to content

1.7.10 - Problem syncing entity client- vs server-side with NBT loaded params


Recommended Posts

Posted

Hello

  So I'm trying to access the entity I'm rendering, espiecially I want to access her fields. I did stuff according to this tutorial : http://jabelarminecraft.blogspot.com/p/creating-custom-entities.html

I'm pretty green to Java so perhaps its something simple. No errors pop-up. The problem is the entity is empty and all fields come up as null, even though entities themselves behave properly.

 

public class HumanRenderer extends RenderBiped {

protected ResourceLocation texture;
protected final ResourceLocation male_smallfolk = new ResourceLocation(Constants.MODID+":"+"textures/models/male/Smallfolk.png");
protected final ResourceLocation female_smallfolk = new ResourceLocation(Constants.MODID+":"+"textures/models/female/Smallfolk.png");

public HumanRenderer(ModelBiped p_i1261_1_, float p_i1261_2_) {
	super((ModelBiped) p_i1261_1_, p_i1261_2_);
	texture = new ResourceLocation(Constants.MODID+":"+"textures/models/Brigand.png");
}

protected void setEntityTexture(){}

@Override
protected void preRenderCallback(EntityLivingBase entity, float f) {
	callback((HumanEntity) entity,f);
}

protected void callback(HumanEntity human, float f){
	System.out.println("Rendering "+human.firstName+" "+human.familyName+" male ? : "+String.valueOf(human.isMale)+" | ");
}

@Override
protected ResourceLocation getEntityTexture(Entity entity) {
	return texture;
}

}

 

Any ideas please ?

 

EDIT:

The entity in question is a mob. I've found then when interacting with it, I get a double response, one is an empty entity and second is the one I expect. What did I screw up then ? Which piece of code do You need to see ? Is it perhaps due to the server/client issues ?

Posted

Yes, one is client, and one is server, I looked closely now and that is true. I did Register my Renderer and the rendering is more or less correct. I believe my problem is that server side has proper data and client side, does not. The parameters in my Entity are loaded through NBT... where should I look then ?

 

EDIT:

I checked now more thoroughly and entity's readEntityFromNBT() is called on the server only

Posted

You have to sync the variables from server->client. You can probably use the DataWatcher for that.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Well, I dont think Datawatcher is what is appropriate here, the fields in question are defined when entity is spawned and only then (I dont plan to enable sex changes), so I guess IExtendedEntityProperties is the way to go ?

 

I was going gray and bald, and then I found this :

http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571567-forge-1-6-4-1-8-eventhandler-and?comment=2

 

I bet the answer is there, but I'm none the wiser... its so freaking convoluted... code for 1.6.4 then updated for 1.7.2 with examples out of context... nightmare...

 

I managed to save/load my data with IEntityExtendedParameters, but client is still out of sync with server... :(

Posted

And it ALWAYS will be. All NBT-reading happens always on Server thread. Client can't have them (data inside) if you don't synchronize it. You will need to send packets.

 

About packets:

http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-2-customizing-packet-handling-with

Or bit simplier: www.minecraftforge.net/forum/index.php/topic,20135.0.html

 

As for your "the fields in question are defined when entity is spawned" you could use something called IEntityAdditionalSpawnData.

But then you won't be updating it, its only added on spawning new entities.

 

Btw. Polak? ("Bardzo" = "very" in Polish)

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

Posted

And it ALWAYS will be. All NBT-reading happens always on Server thread. Client can't have them (data inside) if you don't synchronize it. You will need to send packets.

Yeah, I figured as much already...

 

About packets:

http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-2-customizing-packet-handling-with

Or bit simplier: www.minecraftforge.net/forum/index.php/topic,20135.0.html

Many thanks :)

 

As for your "the fields in question are defined when entity is spawned" you could use something called IEntityAdditionalSpawnData.

But then you won't be updating it, its only added on spawning new entities.

I want those entities to be persistent in the game, so I implemented IExtendedEntityProperties, yet it does nothing to inform the client about that data, or perhaps my implementation is wrong. Should IExtendedEntityProperties be updating client info ? Or is it just designed for persistence on the server ?

 

Btw. Polak? ("Bardzo" = "very" in Polish)

Affirmative :)
Posted

Allright, thats probably obvious, but :

- I have a persistent entity that is loaded, upon loading I want to send a packet to a client. So I'm sending a packet, to a player. How do I know which player should I send it to ? Send it to everyone and check if a player is aware of entity's existence ?

 

EDIT:

That wont work since server will load entity's data before client is even ready. I'll have to have client request missing data and hope for response, and the whole thing gets hopelessly convoluted in the process...

Posted

Since I am around stuff you want to use you can call me on Skype: ernio333 (I jak jeszcze nie oczywiste to Polak)

 

As for "figure it on your own".

 

IEEP is (should be) assigned to entity in EntityConstructingEvent, hence it will exist on Client and Server thread (unless you ofc don't want it to). Then - on Server (since its the side handling/saving data it will call read/write NBT).

About synchro:

There is a thing called EntityTracker - each player has a tracker. Inside tracker there is set of entities that given player should be informed about. To simplify: If there is something in your (player's) "tracking" range (which is msot of the time about 64 blocks - visible range) that that means that the server will add this entity to your tracker and you will receive data packet about it - movements, everything.

 

In case you didn't know: Server keeps ALL entities for ALL worlds. Client only has entities that are being tracket by client-player (which means that if something is out of your vision, it's entity will be finalized (deconstructed)). Logically - if something is added to your tracker, your client will construct it. That means that every time someone is added to your tracker, you will need to resynchronize ALL data (since old one is lost).

 

How-to:

PlayerLoggedInEvent - use to send syncho-data after you logged in, use this rather (ofc not always) for your player (e.g you want Client to know that he's level = 10).

PlayerRespawnedEvent - same as above but called after respawn (after client has your PlayerEntity constructed)

PlayerChangedDimensionEvent - same, but other situation

 

PlayerEvent.StartTracking - this is called when an event.target is added to event.player EntityTracker. You can use it for e.g - when you event.player starts "seeing" some Entity, you can send IEEP packet to event.player with update regarding event.target.

PlayerEvent.StopTracking - same, but stop.

 

As for other stuff - sending packets every tick is almost dumb - use dataWatcher (upating stuff like mana, special-shield, stuff)

As for making changes to some entity  and synchronizing it with other clients - e.g Player sees some Entity, but this entity's IEEP will suddenly change some value (ofc Server-side). You will need to send update to all trackers (players that are seeing this entity).

Use:

EntityTracker et = ((WorldServer)this.player.worldObj).getEntityTracker();
		et.func_151248_b(this.player, PacketDispatcher.getInstance().getPacketFrom(new PacketSendLevel(this.player, this.getLevel())));

this.player - owner of my IEEP.

func_151248_b - tracker send update to all tracking entities AND player himself.

 

This probably exhausted thread, any questions? :)

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

Posted

Nice summary there Ernio!

 

For entities that implement IEntityAdditionalSpawnData, is that data not also sent to the client when they start tracking, since the client version of the entity must be constructed?

 

If your data doesn't change, then, I would expect that to be sufficient - you shouldn't even need IExtendedEntityProperties unless you want the data to be applied to vanilla / other mod's entities.

Posted

That clouds up my mind even further... so lets take a wider perspective then.

 

There is a Entity, Entity is a Human, so it has a name, surname and sex. Those are given to it on first spawn, and will not change during the game (lets assume that).

- should it then be enough to use IEntityAdditionalSpawnData ?

- does it require IExtendedEntityProperties ?

- or perhaps it needs additional playing around with packets to get synced ?

 

perhaps I'm creating my entity wrong then, for those parameters to be given to the entity, what is the good place to do it ? Constructor ? "init()" ?

 

By the way "init()" function within Entity declaration, what does it do exacly ? In human comprehendible way I mean ?

Posted

As Ernio said, you would need IEEP and some packet synchronizations.

(or, it would be better to use DataWatcher.)

 

and, the init method will, of course, "initialize" the entity, like initializing datas, IEEP, and so on.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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.