Jump to content

Spawning player clone 1.19.2


ixDarkLorD

Recommended Posts

I want to make a player clone to spawn it in the world, but I can't figure it out.
When I spawn the entity, the model doesn't render.

So this is the player clone class:

public class PlayerClone extends AbstractClientPlayer {
    public PlayerReplacement() {
        super(Minecraft.getInstance().level,
              Minecraft.getInstance().player.getGameProfile(),
              Minecraft.getInstance().player.getProfilePublicKey());
    }

    @Override
    public boolean isModelPartShown(@NotNull PlayerModelPart part) {
        return Minecraft.getInstance().player != null && Minecraft.getInstance().player.isModelPartShown(part);
    }
}

And this is the way I used to spawn the Entity:
 

@SubscribeEvent
    public static void onPlayerBreak(BlockEvent.BreakEvent event) {
        PlayerClone clone = new PlayerClone();
        clone.readAdditionalSaveData(Minecraft.getInstance().player.saveWithoutId(new CompoundTag()));

        BlockPos pos = event.getPos().above(1);
        clone.setPos(pos.getX(), pos.getY(), pos.getZ());

        Minecraft.getInstance().level.addPlayer(clone.getId(), clone);
    }


In the console, I get this warn: Duplicate entity UUID 180df9z1-fs03-344c-a080-009bad2a9z4a: PlayerReplacment['Dev'/641, l='ClientLevel', x=279.00, y=68.00, z=295.00]

Link to comment
Share on other sites

You need to know a lot more about how minecraft works to  attempt what you are trying to do. 

 

Obvious errors in just one line code:

Quote

Minecraft.getInstance().level.addPlayer(clone.getId(), clone);

You are adding a player to the client side in an event that happens on the server.

You are doing it with an id that is already used.

The entity on the client will be a "phantom" since it has no corresponding entity on the server.

If it is not a real player you need to create a proper entity and use ServerLevel.addFreshEntity() on the server. i.e. the entity will be controlled by the server and not by some real person playing the game.

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Yeah, I got what you are saying.
But the thing that I'm trying to do is to add the player replica entity to the client side so can only the same player who initiates the summoning can see it.
It doesn't matter if it's a phantom, Because I will not save any data in it.
I just want it for client camera manipulation.


I think what I got wrong is using an id that already used and unproper player replica entity class.
As for my use of the BlockEvent, I used a packet sent from the server to client to add the entity for the player.

Link to comment
Share on other sites

  • 1 month later...

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.