Jump to content

Recommended Posts

  • Replies 67
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Posted

Use the debugger.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
On 4/5/2018 at 8:26 PM, Draco18s said:

Use the debugger.

Ok. I managed to get it working using the debugger.. Sort of. But the one issue that I have is that it does not go through the entire recipe, and it does not let me use the recipe twice, I assume because it still thinks it has more stuff in it but idk. Say the recipe calls for WAX and a SNOWBALL. Once I throw in the Wax, it instantly thinks its a complete recipe and outputs the correct item. That is not what I am aiming for. Here is my code, really would appreciate one last consultation to tell me what is going wrong because I cannot figure that out.

 

Cauldron Recpies

Spoiler

package emeraldjelly.mystica.util.recipe.cauldron;

import emeraldjelly.mystica.api.ICauldronRecipe;
import emeraldjelly.mystica.blocks.tileentity.TileEntitySorcerersCauldron;
import emeraldjelly.mystica.init.ModItems;
import emeraldjelly.mystica.util.recipe.recipetypes.CauldronRecipe;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import paulscode.sound.ICodec;

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

public class CauldronRecipes {

    public static void init() {
        RECIPES.add(EMPTYLACRIMA);
    }

    public static List<ICauldronRecipe> RECIPES = new ArrayList<ICauldronRecipe>();

    public static final CauldronRecipe EMPTYLACRIMA = new CauldronRecipe(new ArrayList<Item>
            (Arrays.asList(ModItems.WAX, ModItems.LACRIMITESHARDS)), new ItemStack(ModItems.EMPTYLACRIAMA));


    public static ItemStack getResult(List<Item> items) {
        for (ICauldronRecipe recipe : RECIPES) {
            if (items.isEmpty()) {
                return ItemStack.EMPTY;
            }
            if (recipe.matches(items)) {
                CauldronRecipe.items.clear();
                if (recipe.getCraftingResult() != null) {
                    TileEntitySorcerersCauldron.items.clear();

                    return new ItemStack(recipe.getCraftingResult().getItem());
                }
            }
        }
        return ItemStack.EMPTY;
    }
}

 

 

TE

Spoiler

package emeraldjelly.mystica.blocks.tileentity;
import emeraldjelly.mystica.api.ICauldronRecipe;
import emeraldjelly.mystica.blocks.SorcerersCauldron;
import emeraldjelly.mystica.util.recipe.cauldron.CauldronRecipes;
import emeraldjelly.mystica.util.recipe.recipetypes.CauldronRecipe;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.items.ItemStackHandler;
import org.lwjgl.Sys;

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

public class TileEntitySorcerersCauldron extends TileEntity implements ITickable { //Do i need to Implement anything else?

    public static List<Item> items = new ArrayList<>();

    private int cooldown;
    private ItemStackHandler handler;

    public TileEntitySorcerersCauldron() {
        this.cooldown = 0;
        this.handler = new ItemStackHandler(5);
    }

    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
        compound.setInteger("Cooldown", this.cooldown);
        compound.setTag("ItemStackHandler", this.handler.serializeNBT());
        return super.writeToNBT(compound);
    }

    @Override
    public void readFromNBT(NBTTagCompound compound) {
        this.cooldown = compound.getInteger("Cooldown");
        this.handler.deserializeNBT(compound.getCompoundTag("ItemStackHandler"));
        super.readFromNBT(compound);
    }

    @Override
    public void update() {
        this.cooldown++;
        this.cooldown %= 100;

    }

    public void onCollideAddItems(EntityItem item) {
        items.add(item.getItem().getItem());
        item.setDead();
        checkAndCraft(items);
    }

    public void checkAndCraft(List<Item> itemsList) {
        EntityItem entityItem = new EntityItem(world, Minecraft.getMinecraft().player.getPosition().getX(),
                Minecraft.getMinecraft().player.getPosition().getY(),
                Minecraft.getMinecraft().player.getPosition().getZ(), CauldronRecipes.getResult(itemsList));
            spawnItem(entityItem);
    }

    public void spawnItem(EntityItem entityItem) {
        if (!world.isRemote) {
            Minecraft.getMinecraft().world.spawnEntity(entityItem);
        }
    }

    @Override
    public SPacketUpdateTileEntity getUpdatePacket() {
        NBTTagCompound nbt = new NBTTagCompound();
        this.writeToNBT(nbt);
        int metadata = getBlockMetadata();
        return new SPacketUpdateTileEntity(this.pos, metadata, nbt);
    }

    @Override
    public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
        this.readFromNBT(pkt.getNbtCompound());
    }

    @Override
    public NBTTagCompound getUpdateTag() {
        NBTTagCompound nbt = new NBTTagCompound();
        this.writeToNBT(nbt);
        return nbt;
    }

    @Override
    public void handleUpdateTag(NBTTagCompound tag) {
        this.readFromNBT(tag);
    }

    @Override
    public NBTTagCompound getTileData() {
        NBTTagCompound nbt = new NBTTagCompound();
        this.writeToNBT(nbt);
        return nbt;
    }
}

 

 

 

Cauldron Recipe

Spoiler

package emeraldjelly.mystica.util.recipe.recipetypes;
;
import emeraldjelly.mystica.api.ICauldronRecipe;
import emeraldjelly.mystica.init.ModItems;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

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


public class CauldronRecipe implements ICauldronRecipe { //What am  Missing in this class? Where do I make all of this code happen?

    public static ItemStack resultItem = ItemStack.EMPTY;
    public static List<Item> items = new ArrayList<Item>();

    public  CauldronRecipe(List<Item> items, ItemStack output) {
       this.resultItem = output;
       this.items = items;
    }

    @Override
    public boolean matches(List<Item> itemStacks) {
        List<Item> items1 = items;
        for (int i = 0; i < itemStacks.size(); i++) {
            Item itemstack = itemStacks.get(i);
            if (itemstack != null) {
                boolean flag = false;
                for (Item itemstack1 : items1) {
                    if (itemstack == itemstack1 && (
                            itemstack1.getMetadata(new ItemStack(itemstack1)) == OreDictionary.WILDCARD_VALUE ||
                                    itemstack.getMetadata(new ItemStack(itemstack)) == itemstack1.getMetadata(new ItemStack(itemstack1)))) {
                        flag = true;
                        itemStacks.remove(itemstack1);
                        break;
                    }
                }
                if (!flag) {
                    return false;
                }
            }
        }
        return itemStacks.isEmpty();
    }

    @Override
    public ItemStack getCraftingResult() {
        return resultItem;
    }

}

 

 

 

Block Class

Spoiler

package emeraldjelly.mystica.blocks;

import emeraldjelly.mystica.blocks.tileentity.TileEntitySorcerersCauldron;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;

import javax.annotation.Nullable;


public class SorcerersCauldron extends BlockBase implements ITileEntityProvider {

    public static AxisAlignedBB AABB = new AxisAlignedBB(0, 0, 0, 1, 0.5625D, 1);

    public SorcerersCauldron(String name, Material material) {
        super(name, material);
        setHardness(3F);
        setResistance(3F);
        setHarvestLevel("pickaxe", 3);
    }

    @Override
    public TileEntity createNewTileEntity(World worldIn, int meta) {
        return new TileEntitySorcerersCauldron();
    }

    @Override
    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
        super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);
        if (entityIn instanceof EntityItem) {
            TileEntitySorcerersCauldron tile = (TileEntitySorcerersCauldron) worldIn.getTileEntity(pos);
            tile.onCollideAddItems((EntityItem) entityIn);
            ((EntityItem) entityIn).lifespan = 0;
        }
    }

    @Override
    public boolean isTopSolid(IBlockState state) {
        return false;
    }

    @Override
    public boolean isFullCube(IBlockState state) {
        return false;
    }

    @Override
    public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
        return AABB;
    }

    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
        return AABB;
    }

    @Override
    public boolean isOpaqueCube(IBlockState state) {
        return false;
    }

    @Override
    public boolean isFullBlock(IBlockState state) {
        return false;
    }

    public static AxisAlignedBB getAABB() {
        return AABB;
    }
}

 

 

Posted
21 minutes ago, EmeraldJelly said:

List<Item> items1 = items;

This is not how you clone a list. Both of these variables reference the SAME list: if you modify one...

22 minutes ago, EmeraldJelly said:

itemStacks.remove(itemstack1);

...you modify the other.

 

Plus, you aren't modifying the right list anyway. By removing any of the recipe items from the list given, you...

23 minutes ago, EmeraldJelly said:

return itemStacks.isEmpty();

Which it is, as it contains zero items. But you didn't see the second item in the recipe! This is why it is so important to clone and modify the ingredients required list.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
1 hour ago, Draco18s said:

Plus, you aren't modifying the right list anyway. By removing any of the recipe items from the list given, you...

1 hour ago, EmeraldJelly said:

return itemStacks.isEmpty();

Which it is, as it contains zero items. But you didn't see the second item in the recipe! This is why it is so important to clone and modify the ingredients required list.

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
7 minutes ago, Draco18s said:

you (still) aren't modifying the right list

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Hit the debugger again, try and figure out what piece of logic isn't doing what you expect.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
46 minutes ago, Draco18s said:

Hit the debugger again, try and figure out what piece of logic isn't doing what you expect.

In the time it took you to respond I did, I still do not have any clue what it's doing, its being weird... Can't explain it.. Ill send the code that has changed.

 

Spoiler

package emeraldjelly.mystica.util.recipe.recipetypes;
;
import emeraldjelly.mystica.api.ICauldronRecipe;
import emeraldjelly.mystica.init.ModItems;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

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


public class CauldronRecipe implements ICauldronRecipe { //What am  Missing in this class? Where do I make all of this code happen?

    public static ItemStack resultItem = ItemStack.EMPTY;
    public static List<Item> items = new ArrayList<Item>();

    public  CauldronRecipe(List<Item> items, ItemStack output) {
       this.resultItem = output;
       this.items = items;
    }

    @Override
    public boolean matches(List<Item> itemStacks) {
        List<Item> items1 = ((List) ((ArrayList) items).clone());
        for (int i = 0; i < itemStacks.size(); i++) {
            Item itemstack = itemStacks.get(i);
            if (itemstack != null) {
                boolean flag = false;
                for (Item itemstack1 : items1) {
                    if (itemstack == itemstack1 && (
                            itemstack1.getMetadata(new ItemStack(itemstack1)) == OreDictionary.WILDCARD_VALUE ||
                                    itemstack.getMetadata(new ItemStack(itemstack)) == itemstack1.getMetadata(new ItemStack(itemstack1)))) {
                        flag = true;
                        itemStacks.remove(itemStacks);
                        break;
                    }
                }
                if (!flag) {
                    return false;
                }
            }
        }
        return itemStacks.isEmpty();
    }

    @Override
    public ItemStack getCraftingResult() {
        return resultItem;
    }

}

 

Posted
35 minutes ago, EmeraldJelly said:

itemStacks.remove(itemStacks);

 

2 hours ago, Draco18s said:

you (still) aren't modifying the right list

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

You remember the one you clone? You want to remove items from the clone, then check if you've removed everything.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

ItemStack does not override Equals or HashCode, so you need to remove the object that's actually in the list. itemstack1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
3 minutes ago, Draco18s said:

ItemStack does not override Equals or HashCode, so you need to remove the object that's actually in the list. itemstack1

Yeah ok I did that, still does not work.

Posted

in the method checkAndCraft you do is client side that will not work

the TileEntity already has the world and the pos.

 

and for the recipe take a look at this NOTE this is code form 1.7.10

 

https://github.com/BCA-Team/Buildcraft-Additions/blob/2.2.x/src/main/java/buildcraftAdditions/recipe/refinery/RefineryRecipe.java

https://github.com/BCA-Team/Buildcraft-Additions/blob/2.2.x/src/main/java/buildcraftAdditions/recipe/refinery/RefineryRecipeManager.java

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.