Jump to content

Recommended Posts

Posted

Hi! I have a stupid question... One day I was working on a "custom furnace" and everything was ok! But now, the client does not get an update on the GUI...

 

I have this (for testing only - this is not the actual method):

 

    @Override
    public void updateEntity() {
        if (!worldObj.isRemote) {
            if (getStackInSlot(0) != null) {
                setInventorySlotContents(1, getStackInSlot(0));
                setInventorySlotContents(0, null);
            }
        }
    }

 

The markDirty() is on the setInventorySlotContents()... I cannot make the client being updated when this part is done... If tryed with packets, but to be honest, I actually need help in this and if someone can help me, I'll be very happy!

 

Thanks,

João Fernandes

Thanks :)

João Fernandes

Posted

Okay I am not 100% sure about this. I took this code from a custom smelter of mine. I think (think im not sure) that the addCraftingToCrafters is a way to tell Minecraft "look on this inventory, if something changes please inform the client" , so I guess u are not adding ur inventory to a listener, which means no1 is syncing client and server.

 

@Override
public void addCraftingToCrafters(ICrafting listener) {
	// TODO Auto-generated method stub
	super.addCraftingToCrafters(listener);
	listener.func_175173_a(this, smelter.inventory);

}

Posted

So, I did this:

 

    @Override
    public void addCraftingToCrafters(ICrafting p_75132_1_) {
        super.addCraftingToCrafters(p_75132_1_);

        p_75132_1_.sendContainerAndContentsToPlayer(this, this.getInventory());
    }

 

And the result was the same :\

Thanks :)

João Fernandes

Posted

Maybe with this, is better to people help me... This is my TileEntityClass...

package jtmnf.forestryextension.tileentity;

import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyHandler;
import forestry.api.recipes.ICentrifugeRecipe;
import forestry.api.recipes.RecipeManagers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;

public class CentrifugeTileEntity extends TileEntity implements IInventory, ICentrifugeRecipe, IEnergyHandler {
    private ItemStack[] items;
    private boolean isCombThere = true;
    private boolean active = false;

    public int time;
    public static int TIME_TO_PROCESS_COMBS = 24 * 8; //24 ticks per second * 8 seconds = 192 ticks;

    public EnergyStorage energyStorage;
    public static int COST_PER_COMB = 3500;
    public boolean isEnergy = false;

    /* =================================================================================== */
    /* =================================== Constructor =================================== */
    /* =================================================================================== */
    public CentrifugeTileEntity() {
        items = new ItemStack[8];

        energyStorage = new EnergyStorage(1000000);
        energyStorage.setMaxReceive(10000);
        energyStorage.setEnergyStored(0);
    }

    /* ================================================================================== */
    /* =================================== IInventory =================================== */
    /* ================================================================================== */
    @Override
    public int getSizeInventory() {
        return items.length;
    }

    @Override
    public ItemStack getStackInSlot(int slot) {
        return items[slot];
    }

    @Override
    public ItemStack decrStackSize(int i, int count) {
        ItemStack itemstack = getStackInSlot(i);

        if (itemstack != null) {
            if (itemstack.stackSize <= count) {
                setInventorySlotContents(i, null);
            }else{
                itemstack = itemstack.splitStack(count);
                markDirty();
            }
        }

        return itemstack;
    }

    @Override
    public ItemStack getStackInSlotOnClosing(int slot) {
        if (this.items[slot] != null)
        {
            ItemStack itemstack = this.items[slot];
            this.items[slot] = null;
            return itemstack;
        }
        else
        {
            return null;
        }
    }

    @Override
    public void setInventorySlotContents(int slot, ItemStack itemStack) {
        items[slot] = itemStack;

        if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()){
            itemStack.stackSize = getInventoryStackLimit();
        }

        markDirty();
    }

    @Override
    public String getInventoryName() {
        return null;
    }

    @Override
    public boolean hasCustomInventoryName() {
        return false;
    }

    @Override
    public int getInventoryStackLimit() {
        return 64;
    }

    @Override
    public boolean isUseableByPlayer(EntityPlayer player) {
        return player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) <= 64;
    }

    @Override
    public void openInventory() {

    }

    @Override
    public void closeInventory() {

    }

    @Override
    public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
        return true;
    }

    @Override
    public void updateEntity() {
        if(!worldObj.isRemote){
            if(getStackInSlot(0) != null){
                setInventorySlotContents(1, getStackInSlot(0));
                setInventorySlotContents(0, null);
            }
        }

        /*if(getStackInSlot(0) != null && isCombThere && !worldObj.isRemote) {
            ItemStack itemStack = getStackInSlotOnClosing(0);
            Object[] products = getProductsByComb(itemStack);

            if((COST_PER_COMB * itemStack.stackSize) > energyStorage.getEnergyStored() && !active){
                isEnergy = true;
                isCombThere = false;
                return ;
            }
            else{
                isEnergy = false;
                active = true;
            }

            if (products != null) {
                if ((time / TIME_TO_PROCESS_COMBS) != 1) {
                    time++;

                    active = true;
                    energyStorage.setEnergyStored(energyStorage.getEnergyStored() - ((COST_PER_COMB * itemStack.stackSize)/TIME_TO_PROCESS_COMBS));
                } else {
                    for (int i = 0; i < products.length; ++i) {
                        active = false;

                        boolean isInserted = false;

                        boolean isEverythingOk = simulate((ItemStack) products[i], itemStack.stackSize);
                        if (!isEverythingOk || products == null) {
                            isCombThere = false;
                            return ;
                        }

                        for (int j = 1; j < getSizeInventory() && !isInserted; ++j) {
                            ItemStack product = (ItemStack) products[i];

                            if (getStackInSlot(j) == null) {
                                setInventorySlotContents(j, new ItemStack(product.getItem(), itemStack.stackSize));
                                isInserted = true;
                            } else {
                                ItemStack stack = getStackInSlot(j);

                                if (stack.getUnlocalizedName().equals(product.getUnlocalizedName()) && stack.stackSize < 64) {
                                    int stackSize = stack.stackSize;

                                    if ((stackSize + itemStack.stackSize) > 64) {
                                        setInventorySlotContents(j, new ItemStack(product.getItem(), 64));

                                        for (int z = 1; z < getSizeInventory() && !isInserted; ++z) {
                                            if (getStackInSlot(z) == null) {
                                                setInventorySlotContents(z, new ItemStack(product.getItem(), (stackSize + itemStack.stackSize) - 64));
                                                isInserted = true;
                                            }
                                        }
                                    } else {
                                        setInventorySlotContents(j, new ItemStack(product.getItem(), (stackSize + itemStack.stackSize)));
                                        isInserted = true;
                                    }
                                }
                            }
                        }
                    }

                    setInventorySlotContents(0, null);
                    isCombThere = false;

                    LogHelper.info("Tell me that this works...");
                    markDirty();
                }
            }
        }
        else if(getStackInSlot(0) == null && !worldObj.isRemote){
            isCombThere = true;
        }*/
    }

    /* ================================================================================= */
    /* =================================== NBT Stuff =================================== */
    /* ================================================================================= */
    @Override
    public void writeToNBT(NBTTagCompound compound) {
        super.writeToNBT(compound);

        NBTTagList items = new NBTTagList();

        for(int i = 0; i < getSizeInventory(); ++i){
            ItemStack itemStack = getStackInSlot(i);

            if(itemStack != null){
                NBTTagCompound item = new NBTTagCompound();
                item.setByte("Slot", (byte) i);

                itemStack.writeToNBT(item);
                items.appendTag(item);
            }
        }

        compound.setTag("Items", items);
        energyStorage.writeToNBT(compound);
    }

    @Override
    public void readFromNBT(NBTTagCompound compound) {
        super.readFromNBT(compound);

        NBTTagList items = compound.getTagList("Items", compound.getId());

        for (int i = 0; i < items.tagCount(); i++) {
            NBTTagCompound item = items.getCompoundTagAt(i);

            int slot = item.getByte("Slot");

            if(slot >= 0 && slot < getSizeInventory()){
                setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));
            }
        }

        energyStorage.readFromNBT(compound);
    }

    /* ================================================================================= */
    /* =================================== markDirty =================================== */
    /* ================================================================================= */
    @Override
    public void markDirty() {
        if(getStackInSlot(0) == null){
            time = 0;
        }
        isCombThere = true;
    }

    /* ========================================================================================= */
    /* =================================== ICentrifugeRecipe =================================== */
    /* ========================================================================================= */
    @Override
    public ItemStack getInput() {
        return null;
    }

    @Override
    public int getProcessingTime() {
        return 0;
    }

    @Override
    public Collection<ItemStack> getProducts(Random random) {
        return null;
    }

    @Override
    public Map<ItemStack, Float> getAllProducts() {
        return null;
    }

    /* ======================================================================================= */
    /* =================================== ProperFunctions =================================== */
    /* ======================================================================================= */
    private Object[] getProductsByComb(ItemStack itemStack){
         Iterator<Map.Entry<Object[], Object[]>> iterator = RecipeManagers.centrifugeManager.getRecipes().entrySet().iterator();
        while(iterator.hasNext()){
            Map.Entry<Object[], Object[]> aux = iterator.next();

            ItemStack product = (ItemStack) aux.getKey()[0];

            if(product.getUnlocalizedName().equals(itemStack.getUnlocalizedName())){
                return aux.getValue();
            }
        }

        return null;
    }

    /**
     * @param product item to be analyzed
     * @return true if can proceed correctly, false if there is something wrong
     */
    private boolean simulate(ItemStack product, int number){
        for(int i = 1; i < getSizeInventory(); ++i){
            ItemStack itemStack = getStackInSlot(i);

            if(itemStack == null){
                return true;
            }
            else{
                if(itemStack.getUnlocalizedName().equals(product.getUnlocalizedName())){
                    if((itemStack.stackSize + number) <= 64){
                        return true;
                    }
                    else{
                        for(int z = 1; z < getSizeInventory(); ++z){
                            if(getStackInSlot(z) == null){
                                return true;
                            }
                        }
                    }
                }
            }
        }

        return false;
    }

    /* ====================================================================================== */
    /* =================================== IEnergyHandler =================================== */
    /* ====================================================================================== */

    @Override
    public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
        return energyStorage.receiveEnergy(maxReceive, simulate);
    }

    @Override
    public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
        return 0;
    }

    @Override
    public int getEnergyStored(ForgeDirection from) {
        return energyStorage.getEnergyStored();
    }

    @Override
    public int getMaxEnergyStored(ForgeDirection from) {
        return energyStorage.getMaxEnergyStored();
    }

    @Override
    public boolean canConnectEnergy(ForgeDirection from) {
        return true;
    }
}

 

Container:

package jtmnf.forestryextension.containers;

import jtmnf.forestryextension.containers.slots.SlotZero;
import jtmnf.forestryextension.tileentity.CentrifugeTileEntity;
import jtmnf.forestryextension.util.LogHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

import java.util.ArrayList;
import java.util.List;

public class CentrifugeContainer extends Container {
    private CentrifugeTileEntity machine;
    public static int energy;
    public static boolean isEnergy;

    public CentrifugeContainer(InventoryPlayer inventoryPlayer, CentrifugeTileEntity centrifugeTileEntity) {
        this.machine = centrifugeTileEntity;

        for(int i = 0; i < 9; ++i){
            addSlotToContainer(new Slot(inventoryPlayer, i, 20 + 18*i, 107));
        }

        for(int i = 0; i < 3; ++i){
            for(int j = 0; j < 9; ++j){
                addSlotToContainer(new Slot(inventoryPlayer, j + i*9 + 9, 20 + 18*j, 49 + i*18));
            }
        }

        addSlotToContainer(new Slot(machine, 0, 20, 18));

        addSlotToContainer(new SlotZero(machine, 1, 56, );
        addSlotToContainer(new SlotZero(machine, 2, 75, );
        addSlotToContainer(new SlotZero(machine, 3, 94, );

        addSlotToContainer(new SlotZero(machine, 4, 56, 27));
        addSlotToContainer(new SlotZero(machine, 5, 75, 27));
        addSlotToContainer(new SlotZero(machine, 6, 94, 27));

        addSlotToContainer(new Slot(machine, 7, 164, );
    }

    @Override
    public boolean canInteractWith(EntityPlayer player) {
        return machine.isUseableByPlayer(player);
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer player, int i) {
        return null;
    }

    @Override
    public void addCraftingToCrafters(ICrafting p_75132_1_) {
        super.addCraftingToCrafters(p_75132_1_);
        p_75132_1_.sendContainerAndContentsToPlayer(this, this.getInventory());
    }
}

 

 

Thanks :)

João Fernandes

Posted

Not the kind of thing where I am pro at but.. I think u dont need to call this.getInventory, u need to add machine there, which means the call could be

 

p_75132_1_.sendContainerAndContentsToPlayer(this, machine);

 

If this doesnt helps im clueless, sorry

Posted

wrong function then that explains it.

u want a function with the args Container and IInventory .

 

this is the obfuscated one in 1.8

void func_175173_a(Container p_175173_1_, IInventory p_175173_2_);

Posted

The (ICrafting p_75132_1_) does not have anything like that! Am I doing something wrong?

 

Only these 3:

void sendContainerAndContentsToPlayer(Container p_71110_1_, List p_71110_2_);

void sendSlotContents(Container p_71111_1_, int p_71111_2_, ItemStack p_71111_3_);

void sendProgressBarUpdate(Container p_71112_1_, int p_71112_2_, int p_71112_3_);

Thanks :)

João Fernandes

Posted

Don't worry :) you tryed to help me and I like that :) Thanks ^^ maybe somebody else can look at my code and say "this guy is stupid, look at that error there"...

Thanks :)

João Fernandes

Posted

The problem with the ContainerFurnace is that it only uses sendProgressBarUpdate()... That means that is something in the TileEntity or GUI that I'm missing, but I'm actually not discovering what is it :\

Thanks :)

João Fernandes

Posted

normally detectAndSendChanges does that for you. This is from the vanilla Container code.

 

/**
     * Looks for changes made in the container, sends them to every listener.
     */
    public void detectAndSendChanges()
    {
        for (int i = 0; i < this.inventorySlots.size(); ++i)
        {
            ItemStack itemstack = ((Slot)this.inventorySlots.get(i)).getStack();
            ItemStack itemstack1 = (ItemStack)this.inventoryItemStacks.get(i);

            if (!ItemStack.areItemStacksEqual(itemstack1, itemstack))
            {
                itemstack1 = itemstack == null ? null : itemstack.copy();
                this.inventoryItemStacks.set(i, itemstack1);

                for (int j = 0; j < this.crafters.size(); ++j)
                {
                    ((ICrafting)this.crafters.get(j)).sendSlotContents(this, i, itemstack1);
                }
            }
        }
    }

 

 

The super.addCraftingToCrafters should normally add the Crafter to the list so they gut updated

Posted

You want to laught a bit? You know what my problem was? I saw it in your post... Do you see that line with the super.detectAndSendChanges();?

 

    @Override
    public void detectAndSendChanges() {
        super.detectAndSendChanges();
    }

 

Well... In my code you couldn't see it because I erase it... Don't ask me why... I personally don't know either...

Now it's working ^^ thanks :)

Thanks :)

João Fernandes

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.