Jump to content

Recommended Posts

Posted

I try to create a mob that forms herds with one leader. For troubleshooting in future, I tried to visualize with lines which mobs the herd follows, so who is the leader. Problem is, that getting Entitys form Serverside to clientside is a bit difficult. I know, that i can use UUID to store data in DataParameters, but ClientSide uuids dont work and I am not sure, if simple Id work properly on Server too. So I used UUIDs and made some networking to get the entity from the UUID on the client, but this seems not to be the right way to me, especially because the updating via network is not possible from the Goal, that creates the Link between the mobs, because this is missing the player to send the datas to. I attached all files needet, I guess an a picture how it looks like at the moment. It is ok that way, but it isn't the right way, so maybe anyone can tell me what I am doing wrong or has an idea of how I can do it better.

 

Thanks for any help and happy new year everyone

2021-01-02_22.07.12.jpg

Herd_Mob.java JoinHerdGoal.java HerdMobRenderer.java

Posted

Ok. My problem is, that I need to save the herd for the leader and the leader for the members of the herd as UUIDs so they don't mess up serverside. But in the renderer I don't have access to serverside to transform the UUID to the entity ID. How can I cross this border? Do I need 2 DataParameters, one with UUID and one with ID or should I only use the IDs?

Posted

Just a final question because I never did something like this and dont want to search endless if you know the answer instant. If not, I will search on my own. How can I check if F3 mod is activ, coodinates etc., because it should only render then

 

Posted (edited)

One last Question:

Syncing the IDs and the UUIDs is required when I load the world. Problem is, that the entitys are not loaded, when they load to sync. Is there a way to sync after the load of every entity so they already exist? Otherwise I get errors.

 

Maybe hocking to the JoinWorldEvent? Or adding an extra goal for that? But this seems not right to me, more like a stopgap.

Edited by Anubis
own idea
Posted

Its not about the spawn of the entity. Its about reload after saving world. I saved the UUIDs via write and get them via read. But I need to sync the IDs when the player has joined with the UUIDs but that only works when all the enititys that are linked with UUID already exist/are loaded, otherwise they cant be referenced for getting the ID

Posted

I tried using Bi-Directional links, but I cant use the read methode to sync them, because they dont exist at this moment. What method is usable to put the Sync methods so the other entitys might be loadet? He acctually has the refrenced UUIDs via read, but he cant find the entitys because they dont exist when read is called.

 

The read method:

    @Override
    public void read(CompoundNBT compound) {
	// TODO Auto-generated method stub
	super.read(compound);
	if (compound.contains("age")) {
	    age = compound.getLong("age");
	} else {
	    age = 0;
	}
	if (compound.contains("hasHerd")) {
	    setHasHerd(compound.getBoolean("hasHerd"));
	} else {
	    setHasHerd(false);
	}
	if (compound.contains("herd")) {
	    INBT nInbt = compound.get("herd");
	    if (nInbt instanceof CompoundNBT) {
		this.dataManager.set(HERD_UUID, (CompoundNBT) nInbt);
	    }
	}
	if (compound.contains("leaderMost")) {
	    this.dataManager.set(LEADER, Optional.ofNullable(compound.getUniqueId("leader")));
	}
	if (compound.contains("isleader")) {
	    this.dataManager.set(IS_LEADER, compound.getBoolean("isleader"));
	    if (this.dataManager.get(IS_LEADER) == true) {
		syncId();
	    }else {
		updateLeaderfromFollower();
	    }
	}

	//syncId(); //not working here because entitys not loaded here

    }

 

 

The code I am calling for the leader:

    public void syncId() {
	if (isServerWorld()) {
	    ServerWorld serverWorld = (ServerWorld) world;
	    CompoundNBT UUIDCompound = this.dataManager.get(HERD_UUID);
	    ArrayList<UUID> uuids = CompoundNBT_Helper.readUUIDList("member", UUIDCompound);
	    ArrayList<Integer> ids = new ArrayList<Integer>();
	    uuids.forEach((uuid) -> {
		Entity entity = serverWorld.getEntityByUuid(uuid);
		if(entity !=null) {
		    ids.add(entity.getEntityId());
		}

	    });
	    CompoundNBT IDCompound = new CompoundNBT();
	    IDCompound = CompoundNBT_Helper.writeIntergerList("member", ids, IDCompound);
	    this.dataManager.set(HERD_ID, IDCompound);
	}

    }

 

The code I use for the followers:

    public boolean updateLeaderfromFollower() {	
	if(world instanceof ServerWorld) {
	    ServerWorld serverWorld = (ServerWorld) world;
	    if(this.dataManager.get(LEADER).isPresent()) {
		Entity entity = serverWorld.getEntityByUuid(this.dataManager.get(LEADER).get());
		if (entity != null) {
		    if (entity instanceof Herd_Mob) {
			((Herd_Mob) entity).syncId();
		    }
		}	  
	    }
	}
	return false;
    }

 

Posted (edited)

Ok, did something similar, but hoped, there was a better way

 

Ok, I added a variable isSynced to the mob, wich is not stored in the read and write methode, so it resets when the entity is loaded and check this variable in tick and when it is false I sync the Entitys and set it to true so it isn't synced in the following ticks. This works but I don't know if it will cause issues in the future.

Seams also to work if one player leaves the area. Dont know, if multiplayer will cause issues

 

Edited by Anubis
Update

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.