Jump to content

Recommended Posts

Posted

I don't really feel like this needs much of an explanation...

 

Model as it appears in Techne (sorry, dropbox images broke, have to post links):

 

https://www.dropbox.com/s/xcpuvz0stihu4s2/meh.PNG

 

Model as it appears in-game:

 

https://www.dropbox.com/s/rxk5klq65lvtvtd/javaw%202014-06-13%2000-35-48-151.png

 

And my code:

 

Model

public class ModelGoblinModel extends ModelBase
{
  //fields
    ModelRenderer Head;
    ModelRenderer RightEar;
    ModelRenderer LeftEar;
    ModelRenderer Nose;
    ModelRenderer NosePart2;
    
    ModelRenderer UpperArm2;
    ModelRenderer UpperArm1;
    ModelRenderer LowerArm2;
    ModelRenderer LowerArm1;
    
    ModelRenderer UpperBody;
    ModelRenderer LowerBody;
    
    ModelRenderer Leg2;
    ModelRenderer Leg1;
    ModelRenderer Foot2;
    ModelRenderer Foot1;
    ModelRenderer UpperLeg1;
    ModelRenderer UpperLeg2;
    
    ModelRenderer hilt;
    ModelRenderer CrossGuard;
    ModelRenderer CrossGuardLeft;
    ModelRenderer CrossGuardRight;
    ModelRenderer Blade;
    ModelRenderer BladePart3;
    ModelRenderer BladePart2;
  
  public ModelGoblinModel()
  {
    textureWidth = 64;
    textureHeight = 32;
    
      Head = new ModelRenderer(this, 42, 0);
      Head.addBox(-3F, -5F, -2.5F, 6, 5, 5);
      Head.setRotationPoint(0F, 5F, 0F);
      Head.setTextureSize(64, 32);
      setRotation(Head, 0F, 0F, 0F);
      
      Nose = new ModelRenderer(this, 50, 26);
      Nose.addBox(-0.5F, -0.5F, -1F, 1, 1, 1);
      Nose.setRotationPoint(0F, 3F, -2F);
      Nose.setTextureSize(64, 32);
      setRotation(Nose, 0.1745329F, 0F, 0F);
      Head.addChild(Nose);
      
      NosePart2 = new ModelRenderer(this, 50, 29);
      NosePart2.addBox(-0.5F, -0.5F, -1F, 1, 2, 1);
      NosePart2.setRotationPoint(0F, 3.7F, -2.5F);
      NosePart2.setTextureSize(64, 32);
      setRotation(NosePart2, -0.5948578F, 0F, 0F);
      Nose.addChild(NosePart2);
      
      RightEar = new ModelRenderer(this, 54, 29);
      RightEar.addBox(-4F, -1F, -0.5F, 4, 2, 1);
      RightEar.setRotationPoint(-2.5F, 2F, 0F);
      RightEar.setTextureSize(64, 32);
      setRotation(RightEar, 0.3490659F, 0.7853982F, 0.3490659F);
      Head.addChild(RightEar);
      
      LeftEar = new ModelRenderer(this, 54, 26);
      LeftEar.addBox(0F, -1F, -0.5F, 4, 2, 1);
      LeftEar.setRotationPoint(2.5F, 2F, 0F);
      LeftEar.setTextureSize(64, 32);
      setRotation(LeftEar, 0.3490659F, -0.7853982F, -0.3490659F);
      Head.addChild(LeftEar);
      
      UpperArm2 = new ModelRenderer(this, 28, 24);
      UpperArm2.addBox(-1F, 0F, -1.5F, 2, 5, 3);
      UpperArm2.setRotationPoint(3F, 5F, 0.5F);
      UpperArm2.setTextureSize(64, 32);
      setRotation(UpperArm2, 0.4014257F, 0.1483529F, -0.3665191F);
      
      UpperArm1 = new ModelRenderer(this, 38, 24);
      UpperArm1.addBox(-1F, 0F, -1.5F, 2, 5, 3);
      UpperArm1.setRotationPoint(-3F, 5F, 0.5F);
      UpperArm1.setTextureSize(64, 32);
      setRotation(UpperArm1, 0.4014257F, -0.1483529F, 03665191F);
      
      LowerArm2 = new ModelRenderer(this, 26, 6);
      LowerArm2.addBox(-1F, 0F, -1F, 2, 6, 2);
      LowerArm2.setRotationPoint(3F, 10F, 0.5F);
      LowerArm2.setTextureSize(64, 32);
      setRotation(LowerArm2, -0.7853981F, 0F, 0F);
      UpperArm2.addChild(LowerArm2);
      
      LowerArm1 = new ModelRenderer(this, 34, 6);
      LowerArm1.addBox(-1F, 0F, -1F, 2, 6, 2);
      LowerArm1.setRotationPoint(-3F, 10F, 0.5F);
      LowerArm1.setTextureSize(64, 32);
      setRotation(LowerArm1, -0.7853981F, 0F, 0F);
      UpperArm1.addChild(LowerArm1);
      
      UpperLeg1 = new ModelRenderer(this, 26, 0);
      UpperLeg1.addBox(-1F, 0F, -1F, 2, 4, 2);
      UpperLeg1.setRotationPoint(-2F, 15F, 0.5F);
      UpperLeg1.setTextureSize(64, 32);
      setRotation(UpperLeg1, -0.5235988F, 0F, 0F);
      
      Leg1 = new ModelRenderer(this, 30, 14);
      Leg1.addBox(-1F, 0F, -1F, 2, 6, 2);
      Leg1.setRotationPoint(-2F, 18F, -1.5F);
      Leg1.setTextureSize(64, 32);
      setRotation(Leg1, 0.4014257F, 0F, 0F);
      UpperLeg1.addChild(Leg1);
      
      Foot1 = new ModelRenderer(this, 20, 29);
      Foot1.addBox(-1F, 0F, -1F, 2, 1, 2);
      Foot1.setRotationPoint(-2F, 23F, -0.5F);
      Foot1.setTextureSize(64, 32);
      setRotation(Foot1, 0F, 0F, 0F);
      
      UpperLeg2 = new ModelRenderer(this, 34, 0);
      UpperLeg2.addBox(-1F, 0F, -1F, 2, 4, 2);
      UpperLeg2.setRotationPoint(2F, 15F, 0.5F);
      UpperLeg2.setTextureSize(64, 32);
      setRotation(UpperLeg2, -0.5235988F, 0F, 0F);
      
      Leg2 = new ModelRenderer(this, 38, 14);
      Leg2.addBox(-1F, 0F, -1F, 2, 6, 2);
      Leg2.setRotationPoint(2F, 18F, -1.5F);
      Leg2.setTextureSize(64, 32);
      setRotation(Leg2, 0.4014257F, 0F, 0F);
      UpperLeg2.addChild(Leg2);
      
      Foot2 = new ModelRenderer(this, 20, 26);
      Foot2.addBox(-1F, 0F, -1F, 2, 1, 2);
      Foot2.setRotationPoint(2F, 23F, -0.5F);
      Foot2.setTextureSize(64, 32);
      setRotation(Foot2, 0F, 0F, 0F);
      Leg2.addChild(Foot2);
      
      UpperBody = new ModelRenderer(this, 46, 10);
      UpperBody.addBox(-3F, -5F, -1F, 6, 5, 3);
      UpperBody.setRotationPoint(0F, 10F, 0F);
      UpperBody.setTextureSize(64, 32);
      setRotation(UpperBody, 0F, 0F, 0F);
      
      LowerBody = new ModelRenderer(this, 48, 18);
      LowerBody.addBox(-2.5F, -2F, -1F, 5, 5, 3);
      LowerBody.setRotationPoint(0F, 12F, 0F);
      LowerBody.setTextureSize(64, 32);
      setRotation(LowerBody, 0F, 0F, 0F);
      
      hilt = new ModelRenderer(this, 0, 28);
      hilt.addBox(0F, 0F, 0F, 1, 1, 3);
      hilt.setRotationPoint(-4F, 14F, -1F);
      hilt.setTextureSize(64, 32);
      setRotation(hilt, 0F, 0F, 0F);
      LowerArm1.addChild(hilt);
      
      CrossGuard = new ModelRenderer(this, 0, 0);
      CrossGuard.addBox(0F, 0F, 0F, 1, 3, 1);
      CrossGuard.setRotationPoint(-4F, 13F, -2F);
      CrossGuard.setTextureSize(64, 32);
      setRotation(CrossGuard, 0F, 0F, 0F);
      hilt.addChild(CrossGuard);
      
      CrossGuardLeft = new ModelRenderer(this, 8, 26);
      CrossGuardLeft.addBox(0F, 0F, 0F, 1, 2, 1);
      CrossGuardLeft.setRotationPoint(-4F, 15.4F, -1.7F);
      CrossGuardLeft.setTextureSize(64, 32);
      setRotation(CrossGuardLeft, -0.5948578F, 0F, 0F);
      CrossGuard.addChild(CrossGuardLeft);
      
      Blade = new ModelRenderer(this, 0, 11);
      Blade.addBox(0F, 0F, 0F, 1, 3, 12);
      Blade.setRotationPoint(-4F, 13F, -14F);
      Blade.setTextureSize(64, 32);
      setRotation(Blade, 0F, 0F, 0F);
      CrossGuard.addChild(Blade);
      
      CrossGuardRight = new ModelRenderer(this, 8, 29);
      CrossGuardRight.addBox(0F, 0F, 0F, 1, 2, 1);
      CrossGuardRight.setRotationPoint(-4F, 13.1F, -0.9F);
      CrossGuardRight.setTextureSize(64, 32);
      setRotation(CrossGuardRight, 3.735005F, 0F, 0F);
      CrossGuard.addChild(CrossGuardRight);
      
      BladePart3 = new ModelRenderer(this, 15, 4);
      BladePart3.addBox(0F, 0F, 0F, 1, 1, 1);
      BladePart3.setRotationPoint(-4F, 12F, -13F);
      BladePart3.setTextureSize(64, 32);
      setRotation(BladePart3, 0F, 0F, 0F);
      Blade.addChild(BladePart3);
      
      BladePart2 = new ModelRenderer(this, 4, 0);
      BladePart2.addBox(0F, 0F, 0F, 1, 2, 1);
      BladePart2.setRotationPoint(-4F, 11F, -14F);
      BladePart2.setTextureSize(64, 32);
      setRotation(BladePart2, 0F, 0F, 0F);
      Blade.addChild(BladePart2);
  }
  
  @Override
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    Head.render(f5);
    Nose.render(f5);
    UpperArm2.render(f5);
    UpperArm1.render(f5);
    LowerArm2.render(f5);
    LowerArm1.render(f5);
    Leg2.render(f5);
    Leg1.render(f5);
    LowerBody.render(f5);
    Foot2.render(f5);
    UpperLeg1.render(f5);
    UpperLeg2.render(f5);
    UpperBody.render(f5);
    hilt.render(f5);
    CrossGuard.render(f5);
    CrossGuardLeft.render(f5);
    RightEar.render(f5);
    LeftEar.render(f5);
    Blade.render(f5);
    CrossGuardRight.render(f5);
    NosePart2.render(f5);
    Foot1.render(f5);
    BladePart3.render(f5);
    BladePart2.render(f5);
  }
  
  protected void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  @Override
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
  {
    super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    
    this.Head.rotateAngleY = f3 / (180F / (float)Math.PI);
    this.Head.rotateAngleX = f3 / (180F / (float)Math.PI);

    this.UpperArm1.rotateAngleX = MathHelper.cos(f * 0.6662F + (float)Math.PI) * 2.0F * f1 * 0.5F;
    this.UpperArm2.rotateAngleX = MathHelper.cos(f * 0.6662F) * 2.0F * f1 * 0.5F;
    this.UpperArm1.rotateAngleZ = 0.0F;
    this.UpperArm2.rotateAngleZ = 0.0F;
    
    this.UpperLeg1.rotateAngleX = MathHelper.cos(f * 0.6662F) * 1.4F * f1;
    this.UpperLeg2.rotateAngleX = MathHelper.cos(f * 0.6662F + (float)Math.PI) * 1.4F * f1;
    this.UpperLeg1.rotateAngleY = 0.0F;
    this.UpperLeg2.rotateAngleY = 0.0F;

    float f6;
    float f7;
  }

}

 

Renderer:

public class GoblinRenderer extends RenderLiving {

private static final ResourceLocation texLoc = new ResourceLocation(Reference.MODID + ":" + "textures/models/goblin.png");

public GoblinRenderer(ModelGoblinModel model, float shadowSize)
{
	super(model, shadowSize);
}

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

}

 

 

Posted

eugh what a mess :)

 

It looks to me like the body parts aren't grouping together correctly, so whenever you rotate bits of the model, they don't stay stuck together.  Or something to do with the choice of rotation points perhaps.

 

I've never used Techne so I can't be of much help.  Trial and error on a simpler model might help, i.e. start from a very simple base that works, then add one bit at a time - for example just the nose - and tweak either your Techne model or the generated code until the nose moves properly with the head rotation. 

 

-TGG

Posted

@TheGreyGhost I already have another custom model working fine, but it does seem to be the addChild part which is breaking things. What you can't see in the image is that it's actually cloned some parts of the model 2-3 times under the ground.

 

@jabelar I already took a look at that, not entirely sure which part you're referring to.

Posted

I had a similar problem, but I solved it by removing some animations. Under setRotationAngles try removing different lines of code and see if it fixes the problem.

Developer of the WIP Rubies mod.

Posted

@TheGreyGhost I already have another custom model working fine, but it does seem to be the addChild part which is breaking things. What you can't see in the image is that it's actually cloned some parts of the model 2-3 times under the ground.

 

@jabelar I already took a look at that, not entirely sure which part you're referring to.

 

Well, for example the part where I mention that if you use addChild() you should only render the parent.  In your case, you are rendering the children like the ears and such.  That will cause a double rendering effect (or triple if they are children of children) and each render will be offset by the relative rotation point).

 

So my first suggestion is that you should only be rendering the parent parts -- the children get rendered automatically.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Depending on how you are moving things around, it also matter what order you make things children.

 

I found the angles and the way it works shift around if you do tail1, tail2, tail3 vs tail3, tail2, tail1.

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

Alright, I'm putting this on a back burner for now and focusing on other things - I just tried a very simple model, just adding one cube to the head of a biped and adding it as a child, but every time I add a child it messes it up in-game

 

Posted

it may be tedious but this might help

rightleg.setRotationPoint(-2F, 12F, 0F);

the first float determins the left and right positions of the model, the second determins the height, and the third determines depth, you could try use these to position the parts where you want, you may be better not rendering the parts all at once but one at a time and positioning them until everyone is loaded and in place.

Posted

Alright, I'm putting this on a back burner for now and focusing on other things - I just tried a very simple model, just adding one cube to the head of a biped and adding it as a child, but every time I add a child it messes it up in-game

 

There are only two things that can really mess up.  Once you get the idea it will be easy.

 

First, you should not render the child if you render the parent.  Rendering both will cause duplicate in different positions.

 

The second thing is that the rotation point of the child has to be *relative* to the parent's rotation point.  So if you made a Techne model that had the parent rotation point at (0, 12, 0) then in Java you have to subtract that amount from the rotation point of the child's rotation point (if you got the values from Techne).

 

The other tip I will give you is to ensure that the rotation points in Techne are correct (i.e. at the joint or connection point that you want) because a lot of people erroneously use offsets to make it look right but then it will go really wrong when you rotate.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

the rotation point of the child has to be *relative* to the parent's rotation point.

 

Now this I did not know. Thanks so much for that, just adjusted the rotation points of the arms and it's fixed it.

 

LAST UPDATE: Yup. Fixed now, thanks to Jabelar. Just a thought, you might want to put that thing about offsetting the rotation point relative to that of the parents in your tutorial if it's not already on there (not sure, was 3am when I read it). Anyway, the final, less possessed/deformed product:

 

J3iJHKt.jpg

Posted

Good.

 

Yeah, I think the concept of what a child is needs more explaining.  I'm actually going to do more to add the convertToChild() method that I came up with while helping delpi on a similar issue.

 

I really wish Techne just handled child parts better...  Techne is so close to being fully useful, but their Java export has a few nagging issues.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

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