Jump to content

Recommended Posts

Posted (edited)

This is the crash report I've been getting

Spoiler

---- Minecraft Crash Report ----
// Quite honestly, I wouldn't worry myself about that.

Time: 5/2/18 7:44 PM
Description: Ticking player

java.lang.NullPointerException: Ticking player
    at net.minecraft.world.Teleporter.placeInExistingPortal(Teleporter.java:136)
    at net.minecraft.world.Teleporter.placeInPortal(Teleporter.java:36)
    at net.minecraft.server.management.PlayerList.transferEntityToWorld(PlayerList.java:748)
    at net.minecraft.server.management.PlayerList.transferPlayerToDimension(PlayerList.java:655)
    at net.minecraft.server.management.PlayerList.changePlayerDimension(PlayerList.java:642)
    at net.minecraft.entity.player.EntityPlayerMP.changeDimension(EntityPlayerMP.java:745)
    at com.camellias.voidictrans.util.handlers.RegistryHandler.PlayerHurtEvent(RegistryHandler.java:59)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_4_RegistryHandler_PlayerHurtEvent_LivingHurtEvent.invoke(.dynamic)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
    at net.minecraftforge.common.ForgeHooks.onLivingHurt(ForgeHooks.java:574)
    at net.minecraft.entity.player.EntityPlayer.damageEntity(EntityPlayer.java:1217)
    at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:1030)
    at net.minecraft.entity.player.EntityPlayer.attackEntityFrom(EntityPlayer.java:1127)
    at net.minecraft.entity.player.EntityPlayerMP.attackEntityFrom(EntityPlayerMP.java:692)
    at net.minecraft.entity.EntityLivingBase.outOfWorld(EntityLivingBase.java:1748)
    at net.minecraft.entity.Entity.onEntityUpdate(Entity.java:582)
    at net.minecraft.entity.EntityLivingBase.onEntityUpdate(EntityLivingBase.java:277)
    at net.minecraft.entity.Entity.onUpdate(Entity.java:465)
    at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2313)
    at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:272)
    at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:423)
    at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:185)
    at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:212)
    at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:307)
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:197)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:863)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590)
    at java.lang.Thread.run(Unknown Source)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Server thread
Stacktrace:
    at net.minecraft.world.Teleporter.placeInExistingPortal(Teleporter.java:136)
    at net.minecraft.world.Teleporter.placeInPortal(Teleporter.java:36)
    at net.minecraft.server.management.PlayerList.transferEntityToWorld(PlayerList.java:748)
    at net.minecraft.server.management.PlayerList.transferPlayerToDimension(PlayerList.java:655)
    at net.minecraft.server.management.PlayerList.changePlayerDimension(PlayerList.java:642)
    at net.minecraft.entity.player.EntityPlayerMP.changeDimension(EntityPlayerMP.java:745)
    at com.camellias.voidictrans.util.handlers.RegistryHandler.PlayerHurtEvent(RegistryHandler.java:59)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_4_RegistryHandler_PlayerHurtEvent_LivingHurtEvent.invoke(.dynamic)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
    at net.minecraftforge.common.ForgeHooks.onLivingHurt(ForgeHooks.java:574)
    at net.minecraft.entity.player.EntityPlayer.damageEntity(EntityPlayer.java:1217)
    at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:1030)
    at net.minecraft.entity.player.EntityPlayer.attackEntityFrom(EntityPlayer.java:1127)
    at net.minecraft.entity.player.EntityPlayerMP.attackEntityFrom(EntityPlayerMP.java:692)
    at net.minecraft.entity.EntityLivingBase.outOfWorld(EntityLivingBase.java:1748)
    at net.minecraft.entity.Entity.onEntityUpdate(Entity.java:582)
    at net.minecraft.entity.EntityLivingBase.onEntityUpdate(EntityLivingBase.java:277)
    at net.minecraft.entity.Entity.onUpdate(Entity.java:465)
    at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2313)
    at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:272)

-- Player being ticked --
Details:
    Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
    Entity ID: 247
    Entity Name: Player635
    Entity's Exact location: 0.00, -64.55, 0.00
    Entity's Block location: World: (0,-65,0), Chunk: (at 0,-5,0 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Entity's Momentum: 0.00, -1.36, 0.00
    Entity's Passengers: []
    Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
    at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:423)
    at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:185)
    at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:212)
    at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:307)

-- Ticking connection --
Details:
    Connection: net.minecraft.network.NetworkManager@10ad151b
Stacktrace:
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:197)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:863)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590)
    at java.lang.Thread.run(Unknown Source)

-- System Details --
Details:
    Minecraft Version: 1.12.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_152, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 645481944 bytes (615 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
    JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
    IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
    FML: MCP 9.42 Powered by Forge 14.23.1.2607 5 mods loaded, 5 mods active
    States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

    | State     | ID          | Version      | Source                           | Signature |
    |:--------- |:----------- |:------------ |:-------------------------------- |:--------- |
    | UCHIJAAAA | minecraft   | 1.12.2       | minecraft.jar                    | None      |
    | UCHIJAAAA | mcp         | 9.42         | minecraft.jar                    | None      |
    | UCHIJAAAA | FML         | 8.0.99.99    | forgeSrc-1.12.2-14.23.1.2607.jar | None      |
    | UCHIJAAAA | forge       | 14.23.1.2607 | forgeSrc-1.12.2-14.23.1.2607.jar | None      |
    | UCHIJAAAA | voidictrans | 0.1          | bin                              | None      |

    Loaded coremods (and transformers): 
    GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
    Profiler Position: N/A (disabled)
    Player Count: 1 / 8; [EntityPlayerMP['Player635'/247, l='New World', x=0.00, y=-64.55, z=0.00]]
    Type: Integrated Server (map_client.txt)
    Is Modded: Definitely; Client brand changed to 'fml,forge'

Then, I was given someone else's post who's been having the same error, and the fix was putting

player.getEntityLiving().setPortal(player.getEntityLiving().getPosition());

inside the teleport.

 

However, this, as I had expected, causes a nether portal to be created, which, at least in creative, causes me to teleport straight to the nether after going to my dimension. The dimension is accessed by going 64 blocks beneath bedrock. Any idea how to fix the crash, without spawning the nether portal in the world?

 

Here's my code. The related classes are ModDimensions, ChunkGeneratorVoid, DimensionVoid, and RegistryHandler.

 

EDIT:

I just tested it in survival, and it seems to enjoy slowly killing me with fall damage, since I misjudged part of my code.

Edited by Daring Do

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted (edited)
1 hour ago, #ÖCT said:

I think your Entity is null...

I don't think I quite understand what you mean. Where would the entity be called? Only place I can think of would be under the PlayerHurtEvent in the RegistryHandler, which I'm pretty sure I called correctly, but I could definitely be wrong. 

Edited by Daring Do

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted
1 minute ago, quadraxis said:

You should probably be using your own teleporter here, rather than vanilla's.

Yeah, probably. I might fight it to make it work later, if there isn't an easier fix. 

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted (edited)
3 hours ago, quadraxis said:

You should probably be using your own teleporter here, rather than vanilla's.

So, just a question, but how do I force it to use my teleporter now? Do I need to register the teleporter somewhere? Or would I just call it in the RegistryHandler for the teleport?

Edited by Daring Do

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted (edited)

Changing dimensions is done with PlayerList#transferPlayerToDimension, which you get from WorldServer and it requires a Teleporter as a parameter. Make a class which extends Teleporter and then do something like this

WorldServer world = (WorldServer) player.getEntityWorld();
PlayerList playerList = world.getMinecraftServer().getPlayerList();

playerList.transferPlayerToDimension(player, <dimensionID>, new CustomTeleporter(params....));

 

Edited by Terrails
made it make more sense and added an example
Posted
22 minutes ago, Terrails said:

Changing dimensions is done with PlayerList#transferPlayerToDimension, which you get from WorldServer and it requires a Teleporter as a parameter. Make a class which extends Teleporter and then do something like this


WorldServer world = (WorldServer) player.getEntityWorld();
PlayerList playerList = world.getMinecraftServer().getPlayerList();

playerList.transferPlayerToDimension(player, <dimensionID>, new CustomTeleporter(params....));

 

Yeah, I already have that done, now. However, I also made some other edits, and it no longer tries to teleport the player... I've updated the repository.

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted (edited)

Just tried it myself and it crashes me when it starts 

placeInExistingPortal(Entity entityIn, float rotationYaw);

in placeInPortal method. If you want to use that you need to override it and make it work for you... also I suggest adding BlockPos to the constructor and then accessing it in

placeInPortal(Entity entity, float rotationYaw);

I do something like this (You could also use Entity#setLocationAndAngles, but I prefer it this way):

    @Override
    public void placeInPortal(Entity entity, float rotationYaw) {
        entity.setPosition(this.pos.getX() + 0.5, this.pos.getY(), this.pos.getZ() + 0.5);
        entity.motionX = 0.0f;
        entity.motionY = 0.0f;
        entity.motionZ = 0.0f;
    }

Also don't forget to add

@Override

to your methods

Edited by Terrails
Posted
5 minutes ago, Terrails said:

Just tried it myself and it crashes me when it starts 


Teleporter#placeInExistingPortal(Entity entityIn, float rotationYaw);

in placeInPortal method. If you want to use that you need to override it and make it work for you... also I suggest adding BlockPos to the constructor and then accessing it in


placeInPortal(Entity entity, float rotationYaw);

I do something like this (You could also use Entity#setLocationAndAngles, but I prefer it this way):


    @Override
    public void placeInPortal(Entity entity, float rotationYaw) {
        entity.setPosition(this.pos.getX() + 0.5, this.pos.getY(), this.pos.getZ() + 0.5);
        entity.motionX = 0.0f;
        entity.motionY = 0.0f;
        entity.motionZ = 0.0f;
    }

Also don't forget to add


@Override

to your methods

The thing is, I don't want to to spawn a portal, which is what I've been having issues with. At this point, I've actually gotten a bit ahead, as by the time you responded, I had already updated the repository 1 or 2 times ^^;

 

Though, at this rate, I'm beginning to think it would be easier to raise each chunk up a bit, and raise the build limit. 

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted
1 minute ago, Terrails said:

the portal doesn't get created actually, it only just teleports the player if you use my example of placeInPortal.

Ah, okay

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted (edited)
2 hours ago, Terrails said:

the portal doesn't get created actually, it only just teleports the player if you use my example of placeInPortal.

It is 100% on this line right here, and 100% me not initializing the variable correctly. Sadly, I don't know what it wants

: /

Edited by Daring Do

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted (edited)

Make sure to the the world is on server...

if (!world.isRemote) {
     // Code
}

If that doesn't still do it (which it should) try something like this:

if (!world.isRemote) {
	((WorldServer) world).getMinecraftServer().getPlayerList().transferPlayerToDimension(
					(EntityPlayerMP) player.getEntity(), 100, 
					new TeleporterVoid(world.getMinecraftServer().getWorld(100)));
}

Also you should probably use the entity world for the teleporter

Edited by Terrails
Posted
6 minutes ago, Terrails said:

Make sure to the the world is on server...


if (!world.isRemote) {
     // Code
}

If that doesn't still do it (which it should) try something like this:


if (!world.isRemote) {
	((WorldServer) world).getMinecraftServer().getPlayerList().transferPlayerToDimension(
					(EntityPlayerMP) player.getEntity(), 100, 
					new TeleporterVoid(world.getMinecraftServer().getWorld(100)));
}

Also you should probably use the entity world for the teleporter

Oh. Okay then. I'll give it a go in about an hour when I'm on my computer again. Here's to hoping that fixes that problem. 

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted (edited)
1 hour ago, Terrails said:

Make sure to the the world is on server...


if (!world.isRemote) {
     // Code
}

If that doesn't still do it (which it should) try something like this:


if (!world.isRemote) {
	((WorldServer) world).getMinecraftServer().getPlayerList().transferPlayerToDimension(
					(EntityPlayerMP) player.getEntity(), 100, 
					new TeleporterVoid(world.getMinecraftServer().getWorld(100)));
}

Also you should probably use the entity world for the teleporter

So, small problem, but that's in a Subscribe Event, meaning I can't have more than the one parameter, which in order to do if(!world.isRemote) I would need a second one. Unless you were telling me to test if the world server is remote, in which case, it doesn't work.

 

Actually, it also doesn't like the ((WorldServer) world)... bit either, apparently

Edited by Daring Do

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted

You shouldn't be using that world in your class (what are you even doing with it).... Use the world you get from the event

event.getEntityLiving().getEntityWorld()

also make sure to check this

if (event.getEntityLiving() instanceof EntityPlayerMP) {
}

you don't need world.isRemote then since you already know its on server since its the server player.

Posted
2 hours ago, Terrails said:

You shouldn't be using that world in your class (what are you even doing with it).... Use the world you get from the event


event.getEntityLiving().getEntityWorld()

also make sure to check this


if (event.getEntityLiving() instanceof EntityPlayerMP) {
}

you don't need world.isRemote then since you already know its on server since its the server player.

So no matter what I seemed to do, it wouldn't function properly. Maybe it's because it's over my head, but I settled on a different compromise for this. Thanks for at least trying to help.

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

Posted
Just now, Daring Do said:

So no matter what I seemed to do, it wouldn't function properly. Maybe it's because it's over my head, but I settled on a different compromise for this. Thanks for at least trying to help.

This is all you need... like for real:

    @SubscribeEvent
    public static void hurtEvent(LivingHurtEvent event) {
        if (event.getEntityLiving() instanceof EntityPlayerMP) {
            EntityPlayerMP player = (EntityPlayerMP) event.getEntityLiving();

            PlayerList playerList = player.getEntityWorld().getMinecraftServer().getPlayerList();
            playerList.transferPlayerToDimension(player, <dimension>, new TeleporterVoid((WorldServer) player.getEntityWorld()));
        }
    }

 

Posted
7 minutes ago, Terrails said:

This is all you need... like for real:


    @SubscribeEvent
    public static void hurtEvent(LivingHurtEvent event) {
        if (event.getEntityLiving() instanceof EntityPlayerMP) {
            EntityPlayerMP player = (EntityPlayerMP) event.getEntityLiving();

            PlayerList playerList = player.getEntityWorld().getMinecraftServer().getPlayerList();
            playerList.transferPlayerToDimension(player, <dimension>, new TeleporterVoid((WorldServer) player.getEntityWorld()));
        }
    }

 

I realized I can just make it turn a piece of bedrock at y = 0 into an invisible portal block that teleports you as soon as you pass through it, though. Which is what I've already done, just haven't updated the repository. It also solves my fall damage issue, that I've been unsure if I solved. 

Gne9eza.png

 

"Be patient with me, because I'm an absolute moron half the time."

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.