Jump to content

Recommended Posts

Posted (edited)

Hi,

 

I've got a problem with the code for my energy network. As soon as I build the system to be larger than a some really small value my FPS

drops significantly from over 100 to 15-24fps.

The size of the network I tested it currently was 11x6.

 

Layer 1: 11x6 solar panels

Layer 2: 11x6 transfer pipes

Layer 3: 11x6 cables

Layer 4: 1x1 transfer pipe

Layer 5: 1x1 machine

 

I don't know what exactly causes the problem, but it's not the machine block, as the energy doesn't even reach this block. 

And from my 66 solar panels, the energy storage of 56 of them is full while the energy storage of the last 10 is empty and stays empty.

 

public class TileEntityPipeTransferEnergy extends TileEntityEnergy {
    
    private boolean flag = false;
    private HashMap<BlockPos, EnumFacing> connected = new HashMap<>(); // without pre-calculated weight
    
    public boolean shouldRecalculate = false;
    
    public TileEntityPipeTransferEnergy() {
        super(10, 10);
        this.container.setTransferMode(EnergyTransfer.PRODUCER);
    }
    
    @Override
    public void update() {
        this.flag = false;
        if(this.shouldRecalculate || this.connected.isEmpty()) {
            this.shouldRecalculate = false;
            this.findTransferPipes();
            this.flag = true;
        }
        
        this.connected.forEach((pos, side) -> {
            final TileEntity tile = this.getWorld().getTileEntity(pos);
            if(tile == null) return;
            
            IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, side);
            if(storage == null)
                storage = tile.getCapability(CapabilityEnergy.ENERGY, null);
            
            if(storage != null) {
                storage.receiveEnergy(this.container.extractEnergy((int)(10 / this.connected.size()), false), false);
                this.flag = true; // flag has to be a class member because of inner classes
            }
        });
        
        if(this.flag)
            this.markDirty();
    }
    
    private void findTransferPipes() {
        if(this.connected.size() > 0)
            this.connected.clear();
        
        // we want to store the facing and the position
        Queue<Pair<BlockPos, EnumFacing>> toSearch = new ArrayDeque<>();
        HashSet<BlockPos> scanned = new HashSet<BlockPos>();
        scanned.add(this.getPos());
        
        if(toSearch.isEmpty() || toSearch.peek() == null)
            this.getBlocksToScan(toSearch, scanned, this.getPos());
        
        // temp object because we poll stuff out of the list
        Pair<BlockPos, EnumFacing> pair = null;
        BlockPos current = null;
        EnumFacing face = null;
        
        while(toSearch.peek() != null) {
            pair = toSearch.poll();
            current = pair.getLeft();
            face = pair.getRight();
            scanned.add(current);
            
            if(this.getWorld().getTileEntity(current) instanceof TileEntityPipeEnergy) // check cable connection
                this.getBlocksToScan(toSearch, scanned, current);
            else if(this.getWorld().getTileEntity(current) instanceof TileEntityPipeTransferEnergy &&
                    !this.getPos().equals(current) && !this.connected.containsKey(current))
                this.connected.put(current, face); // found end of line
        }
    }
    
    private void getBlocksToScan(Queue<Pair<BlockPos, EnumFacing>> toSearch, HashSet<BlockPos> scanned, BlockPos pos) {
        // EnumSet.allOf(EnumFacing.class) does not include the null, so machines which don't require a specific
        // site will be ignored
        for(EnumFacing face : EnumFacing.VALUES) {
            // same as pos.north(), just for all directions
            BlockPos offset = pos.offset(face);
            if(!scanned.contains(offset))
                // create a new pair and add it to the list
                // a pair is just some class which holds two fields
                toSearch.add(Pair.of(offset, face.getOpposite()));
        }
    }
    
    @Override
    public void readFromNBT(NBTTagCompound compound) {
        super.readFromNBT(compound);
    	if(compound.hasKey("connection")) {
            NBTTagList list = compound.getTagList("connection", Constants.NBT.TAG_COMPOUND);
            for(int i = 0; i <= list.tagCount(); i++) {
                NBTTagCompound com = list.getCompoundTagAt(i);
                if(com.hasKey("posX") && com.hasKey("posY") && com.hasKey("posZ")
                        && com.hasKey("facing")) {
                    
                    this.connected.put(
                            new BlockPos(
                                    com.getInteger("posX"),
                                    com.getInteger("posY"),
                                    com.getInteger("posZ")), 
                            EnumFacing.byName(com.getString("facing")));
                }
            }
        }
    }
    
    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    	NBTTagList list = new NBTTagList();
        this.connected.forEach((pos, side) -> {
            NBTTagCompound com = new NBTTagCompound();
            com.setInteger("posX", pos.getX());
            com.setInteger("posY", pos.getY());
            com.setInteger("posZ", pos.getZ());
            com.setString("facing", side.getName());
            list.appendTag(com);
        });
        compound.setTag("connection", list);
        
        return super.writeToNBT(compound);
    }
    
    @Override
    public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
        super.onDataPacket(net, pkt);
        this.readFromNBT(pkt.getNbtCompound());
    }
}

 

The code of the cable:

public class TileEntityPipeEnergy extends TileEntity {
	
    private HashSet<BlockPos> connected_machines = new HashSet<>();
    
    public void searchNetwork() {
        if(this.connected_machines.size() > 0)
            this.connected_machines.clear();
        
        ArrayDeque<BlockPos> toSearch = new ArrayDeque<>();
        HashSet<BlockPos> scanned = new HashSet<>();
        
        if(toSearch.isEmpty() || toSearch.peek() == null)
            this.getBlocksToScan(toSearch, scanned, this.getPos());
        
        BlockPos current = null;
        
        while(toSearch.peek() != null) {
            current = toSearch.pop();
            scanned.add(current);
            
            TileEntity tile = this.getWorld().getTileEntity(current);
            if(tile != null) {
                if(tile instanceof TileEntityPipeEnergy)
                    this.getBlocksToScan(toSearch, scanned, current);
                else if(tile instanceof TileEntityPipeTransferEnergy)
                    this.connected_machines.add(current);
            }
        }
    }
    
    private void getBlocksToScan(ArrayDeque<BlockPos> toSearch, HashSet<BlockPos> scanned, BlockPos pos) {
        for(EnumFacing face : EnumSet.allOf(EnumFacing.class)) {
            // same as pos.north(), just for all directions
            BlockPos offset = pos.offset(face);
            if(!scanned.contains(offset))
                toSearch.add(offset);
        }
    }
    
    public void informNetwork() {
        this.connected_machines.forEach(pos -> {
            TileEntity tile = this.getWorld().getTileEntity(pos);
            // make sure the tile entity at 'pos' is really the one we think it is
            if(tile != null && tile instanceof TileEntityPipeTransferEnergy) {
                TileEntityPipeTransferEnergy transfer = (TileEntityPipeTransferEnergy) tile;
                transfer.shouldRecalculate = true;
            }
        });
    }
    
    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
        NBTTagList list = new NBTTagList();
        for(BlockPos pos : this.connected_machines) {
            NBTTagCompound com = new NBTTagCompound();
            com.setInteger("posX", pos.getX());
            com.setInteger("posY", pos.getY());
            com.setInteger("posZ", pos.getZ());
            list.appendTag(com);
        }
        compound.setTag("machines", list);
        
        return super.writeToNBT(compound);
    }
    
    @Override
    public void readFromNBT(NBTTagCompound compound) {
        super.readFromNBT(compound);
        
        if(compound.hasKey("machines")) {
            NBTTagList list = compound.getTagList("machines", Constants.NBT.TAG_COMPOUND);
            for(int i = 0; i <= list.tagCount(); i++) {
                NBTTagCompound com = list.getCompoundTagAt(i);
                if(com.hasKey("posX") && com.hasKey("posY") && com.hasKey("posZ")) {
                    
                    this.connected_machines.add(
                            new BlockPos(
                                    com.getInteger("posX"),
                                    com.getInteger("posY"),
                                    com.getInteger("posZ"))
                            );
                }
            }
        }
    }
}

 

The code of my solar panel:

public class TileEntitySolarPanel extends TileEntityEnergy {
    
[...]
    
    @Override
    public void update() {
        super.update();
      
      [...]
        
        this.container.receiveEnergy(this.inputRate, false);
        
        if(this.world.getTileEntity(this.getPos().down()) != null) {
            int received = sendEnergy(this, this.world.getTileEntity(this.getPos().down()), EnumFacing.DOWN, 10);
            if(received > 0) flag = true;
        }
        
        if(flag) {
            this.getWorld().notifyBlockUpdate(this.getPos(), this.getWorld().getBlockState(this.getPos()), this.getWorld().getBlockState(this.getPos()), 3);
            this.markDirty();
        }
    }
  
    public static int sendEnergy(@Nullable TileEntityEnergy from, @Nullable TileEntity sendTo, EnumFacing orientation, int transferAmount) {
        if(from == null || sendTo == null)
            return 0;
        
        EnumFacing side = orientation.getOpposite();

        if(sendTo.hasCapability(CapabilityEnergy.ENERGY, side)) { // Forge Energy Support
            IEnergyStorage storage = sendTo.getCapability(CapabilityEnergy.ENERGY, side);
            if(storage != null && storage.canReceive() && from.container.canExtract())
                return storage.receiveEnergy(from.container.extractEnergy(transferAmount, false), false);
        }
        return 0;
    }
    
    @Override
    public SPacketUpdateTileEntity getUpdatePacket() {
        return new SPacketUpdateTileEntity(this.getPos(), 3, this.getUpdateTag());
    }
    
    @Override
    public NBTTagCompound getUpdateTag() {
        return this.writeToNBT(new NBTTagCompound());
    }
    
    @Override
    public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
        super.onDataPacket(net, pkt);
        this.handleUpdateTag(pkt.getNbtCompound());
    }
}

 

The debug mode of eclipse also showed me the information that in TileEntityPipeTransferEnergy the shouldRecalculate value is set to false and the connected list also contains data.

 

So it must have something to do with the energy transfer from one block to anther, thought I'm not sure what could cause the problem there. 

I just suspect that my solar panels are transfering the energy between themselves instead of putting it into the machine, but I don't see why this would cause

a significantly fps drop.

 

Also to note: for rendering I'm just using a default json file with a texture. So nothing really special about it. The RAM stays with about 1.5GB of 3GB available and the chunk updates are above 200.

 

Thx in advance.

Bektor

 

EDIT: further note: I had no problems before having so many solar panels, so I think its a problem with the cable network

Edited by Bektor

Developer of Primeval Forest.

Posted

Generally the only thing that can take a lot of time are loops, especially ones like while loops which are waiting for a condition that might not be there. So I would suspect it is your while loop in your cable class.

 

When looking at performance problems like this, it can be useful to printout actual timestamps or use a real profiler to time each part of your code. It is usually pretty easy at that point to determine what is taking the most time and then inspection of that code usually quickly leads to realizing what the problem is.

 

Once you isolate the problem, you need to think about alternative techniques that might be more efficient. For example, imagine if you have a bunch of nested if statements you should order them so the least likely thing is tested first. For example, imagine if you wanted something to happen if the player was holding a certain item at night time -- you could first check for holding the item but that would be wasteful because daytime happens half the time in a game whereas holding a specific item might never happen for some players.

 

Sometimes algorithms just don't scale well. In math there are a lot of cases, particularly in networking (which is basically what your energy network is implementing) that don't scale well. In other words there is usually a max size for networks. In fact I think that is why redstone has limited ability to propagate and why entity pathfinding is limited in total area that it checks. In cases where the overall size of the network is limited by the algorithm, you can still improve performance by reducing the frequency of the update operations. That is why "random ticking" is useful -- you don't need leaves on trees to get updated every tick, but you still want them updated sometimes. So you could do the same with your network. For example, you could randomly update each tile entity. Or you could update cables on a different tick than the solar panels which are on a different tick from the machines. 

 

Overall though, pretty much every network will be hit a limit where performance doesn't scale well after a certain size.

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

Posted
15 hours ago, jabelar said:

use a real profiler to time each part of your code

As I've never used an profiler before, which one would you suggest to use?

15 hours ago, jabelar said:

printout actual timestamps

I don't think this would work as I've got 66 blocks and even with less than those blocks, it would just be a mess to read the data out.

 

15 hours ago, jabelar said:

For example, you could randomly update each tile entity.

This would not work for my part as my system is build upon the idea that a machine gets every tick its energy, like in other energy mods itself.

But I have a system in place which might work a bit like this and this is the process to build up the energy network as it doesn't run every tick, it just checks if it needs to run every tick and if it

doesn't then it stops there, otherwhise the whole data will be updated, like when a new block is placed and thus the network changed.

15 hours ago, jabelar said:

Overall though, pretty much every network will be hit a limit where performance doesn't scale well after a certain size.

Yeah, that clear, but it shouldn't hit the limit with only 66 blocks.

Developer of Primeval Forest.

Posted

Ok, I've now used VisualVM and got the following results:

Spoiler

It might also be noted that after removing everything and building it again(this time larger) I've got 120fps. Well, as long as I didn't placed a block, this got me an fps drop.

 

tttt.png

Developer of Primeval Forest.

Posted
On 8/11/2017 at 2:51 PM, Bektor said:

FPS drops significantly from over 100 to 15-24fps.

Your FPS shouldn't be consistently low unless you are handling all of this on the client side as well as the server side which is entirely unnecessary.

 

On 8/11/2017 at 2:51 PM, Bektor said:

@Override
    public void update() {
        this.flag = false;
        if(this.shouldRecalculate || this.connected.isEmpty()) {
            this.shouldRecalculate = false;
            this.findTransferPipes();
            this.flag = true;
        }

 

Also calling findTransferPipes() in an update method is rather ridiculous. Adding things to the network could simply be done in the Block.onBlockPlaced and Block.breakBlock, or Block.onNeighborChanged. And instead of storing the network in the pipes/energy tileentities. You could store it in a WorldSavedData and simply reference it when ever you have a World instance. And then you update the network in a world tick event.

 

Not sure if this is the problem, but it could be.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
9 hours ago, Animefan8888 said:

And instead of storing the network in the pipes/energy tileentities. You could store it in a WorldSavedData and simply reference it when ever you have a World instance.

The problem I see with this is when multiply players build up their networks and these networks aren't connected to each other.

 

9 hours ago, Animefan8888 said:

Adding things to the network could simply be done in the Block.onBlockPlaced and Block.breakBlock, or Block.onNeighborChanged

Here we have the problem that when adding blocks simply to the network in those methods: How do you know they are really connected to the network? Who tells you that they are connected to other cables? How do you know they are connected to other cables and those cables are part of the network and not some random cables in the world connected to no network??

 

9 hours ago, Animefan8888 said:

Your FPS shouldn't be consistently low unless you are handling all of this on the client side as well as the server side which is entirely unnecessary.

 

Well, looking at the code, I guess this one if-check got lost in the endless code updates. ^^

 

Edited by Bektor

Developer of Primeval Forest.

Posted
2 hours ago, Bektor said:

The problem I see with this is when multiply players build up their networks and these networks aren't connected to each other.

Simple solution; multiple 'network' instances/multiple lists/maps.

2 hours ago, Bektor said:

Here we have the problem that when adding blocks simply to the network in those methods: How do you know they are really connected to the network? Who tells you that they are connected to other cables? How do you know they are connected to other cables and those cables are part of the network and not some random cables in the world connected to no network??

You would check around for blocks that should be connected to the network and then get their network from them or search for a network with that BlockPos. Of course with this you would also need to check for connecting two networks together.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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