Jump to content

[1.8]rotate your custome blocks based on steve facing like Furnaces do<SOLVED>


Recommended Posts

Posted

Good days

this is a little long to explain to reach where mi questions are.

 

first , the 1.8 is using a new and more simple system to change the orientation of the blocks , i gonna use the furnace to explain whath i have

 

the Block state system

it let you just define how to rotate all the faces of a block in just one single json file, this mean that i have not anymore to define manually where go all te faces of block on every case of rotation like in 1.7 whith  getIcon

 

_______________________________________________
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta) {	
   
int tex=(meta*6)+(side);

//System.out.println("side="+side+" meta="+meta+" tex="+tex);
if (tex < icons.length ){return icons[tex];}
                     else{return icons[0];}

} // fin de IIcon getIcon
_______________________________________________

 

 

now go forth to 1.8

the furnace Blockstate file define 4 posible rotations simply rotating textures on the Y axix

 

~/.minecraft/versions/1.8/1.8/assets/minecraft/blockstates/furnace.json

{
    "variants": {
        "facing=north": { "model": "furnace" },
        "facing=south": { "model": "furnace", "y": 180 },
        "facing=west":  { "model": "furnace", "y": 270 },
        "facing=east":  { "model": "furnace", "y": 90 }
    }
}

 

the mojan's store this Values  in a custom  Object named "IBlockState" and this is the center point of this post

 

 

i create a custom multitexture block named girable looks like a red dice and i copy the furnace blockstate json for this block ,

~/Modding/forge-1.8-11.14.0.1261-1.8-src/src/main/resources/assets/modmercenario/blockstates/girable.json

{
    "variants": {
        "facing=north": { "model": "modmercenario:girable" },
        "facing=south": { "model": "modmercenario:girable", "y": 180 },
        "facing=west":  { "model": "modmercenario:girable", "y": 270 },
        "facing=east":  { "model": "modmercenario:girable", "y": 90 }
    }
}

 

the blocks load and all his textures are on place when i put it on the world and is a red dice

iwant this block to behabe like te furnace seting the face number 2 looking to the player no mather if a look to south or to the east

 

there comes again the Iblockstate object

 

if i wanna set in the world a furnace looking to south  i need the blocks.furnace object + the iblockstate of the furnace looking to south =  "facing=south"

 

thats the part i dont get and find hard to explain something i dont get

 

 

 

if there is a furnace looking to south in the world i can do a

IBlockState rot = worldIn.getBlockState(pos0);  //i alredy have the coordenates of the furnace stored in pos0

 

whith this i have a objet named rot which contains the blocks.furnace + the iblockstate="facing=south"

whit this i can put it wherever i wan whit

 

worldIn.setBlockState(posX, rot);

 

 

lets say i wanna put on world a furnace looking to east but there is not another east loking furnace in the world

or mi girable block

how i load the an object of iblockstate whit the value "facing=east"

 

IBlockState east = "facing=east" ; dont work, it contains Strings but not behave like an String object

soo idont find a suitable way to load IBlockState whit a custom value

 

 

or it musb be like

¿ how i get the fourth  IBlockState objets reprensenting the four states of mi customblock girable? 

 

 

 

 

 

 

 

 

 

 

 

Posted

this cost me a lot of time to figuret out

 

cos has become very more complex of what was in 1.7

 

to spawn this block in the world i must do call

 

		
IBlockState gira = MercenaryModBlocks.girable.getDefaultState();
worldIn.setBlockState(pos , gira);

// spawn it whith a custom orientation.

//looking south
worldIn.setBlockState(pos, gira.withProperty(FACING, EnumFacing.SOUTH), 2);

//looking east
worldIn.setBlockState(pos, gira.withProperty(FACING, EnumFacing.EAST), 2);

//looking up
worldIn.setBlockState(pos , gira.withProperty(FACING, EnumFacing.UP), 2);

 

 

this is the class of one simple multitexture block

 

package mercenarymod.blocks.multitextura;

import java.util.Random;

import org.apache.logging.log4j.core.config.Property;

import mercenarymod.Mercenary;
import mercenarymod.blocks.MercenaryModBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import mercenarymod.utilidades.chat;
import net.minecraft.entity.EntityLivingBase;






public class girable extends Block
{
    public static String name = "girable";

    public static final PropertyDirection FACING = PropertyDirection.create("facing");

    public girable()
    {
    	super(Material.glass);
        setUnlocalizedName(Mercenary.MODID + "_" + name);
        GameRegistry.registerBlock(this, name);
        setCreativeTab(Mercenary.herramientas);
        //this.maxStackSize = 1;
    }

    
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return Item.getItemFromBlock(MercenaryModBlocks.girable);
    }
    
    
  //###########################################################3
    
    public boolean isOpaqueCube()
    {
        return false;
    }

   
    public boolean isFullCube()
    {
        return false;
    }
  //###########################################################3
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
    {
    	
    	
    	System.out.println("NU SE QUE SERA \n YA tengo una idea de que es ="+FACING);
    	

    	Block fur = Blocks.furnace;
    	
    	fur.getActualState(state, worldIn, pos);
    	IBlockState state1 = fur.getDefaultState();
    	    	
    	//worldIn.setBlockState(pos, state);
    	
    	
	worldIn.setBlockState(pos, state.withProperty(FACING, side), 2);
    
    	    	
    	
    return false;}
    
  //###########################################################3

    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
    {
    	
    }
    
  //###########################################################3
    
    
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
    {
        worldIn.setBlockState(pos, state.withProperty(FACING, getFacingFromEntity(worldIn, pos, placer)), 2);

     
    }
    
  //###########################################################3    
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
    {
        return this.getDefaultState().withProperty(FACING, getFacingFromEntity(worldIn, pos, placer));
    }
    
  //###########################################################3    
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);

       
            float f = 0.25F;
            EnumFacing enumfacing = (EnumFacing)iblockstate.getValue(FACING);

            if (enumfacing != null)
            {
                switch (troncoMercenario.SwitchEnumFacing.FACING_LOOKUP[enumfacing.ordinal()])
                {
                    case 1:
                        this.setBlockBounds(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
                        break;
                    case 2:
                        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
                        break;
                    case 3:
                        this.setBlockBounds(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
                        break;
                    case 4:
                        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
                        break;
                    case 5:
                        this.setBlockBounds(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
                        break;
                    case 6:
                        this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
                }
            }
        
        else
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
        }
    }

  //###########################################################3  
    public void setBlockBoundsForItemRender()
    {
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
    }    
        
  //###########################################################3  
    
    public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn)
    {
        if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F)
        {
            double d0 = entityIn.posY + (double)entityIn.getEyeHeight();

            if (d0 - (double)clickedBlock.getY() > 2.0D)
            {
                return EnumFacing.UP;
            }

            if ((double)clickedBlock.getY() - d0 > 0.0D)
            {
                return EnumFacing.DOWN;
            }
        }

        return entityIn.getHorizontalFacing().getOpposite();
    } 
  
  //###########################################################3     
    
    @SideOnly(Side.CLIENT)
    public IBlockState getStateForEntityRender(IBlockState state)
    {
        return this.getDefaultState().withProperty(FACING, EnumFacing.UP);
    }
    
    //###########################################################3
    
    protected BlockState createBlockState()
    {
        return new BlockState(this, new IProperty[] {FACING});
    }
    
    //###########################################################3
    
    public int getMetaFromState(IBlockState state)
    {
        byte b0 = 0;
        int i = b0 | ((EnumFacing)state.getValue(FACING)).getIndex();

       
        return i;
    }
    
    //###########################################################3
    
    static final class SwitchEnumFacing
    {
        static final int[] FACING_LOOKUP = new int[EnumFacing.values().length];
        private static final String __OBFID = "CL_00002037";

        static
        {
            try
            {
                FACING_LOOKUP[EnumFacing.DOWN.ordinal()] = 1;
            }
            catch (NoSuchFieldError var6)
            {
                ;
            }

            try
            {
                FACING_LOOKUP[EnumFacing.UP.ordinal()] = 2;
            }
            catch (NoSuchFieldError var5)
            {
                ;
            }

            try
            {
                FACING_LOOKUP[EnumFacing.NORTH.ordinal()] = 3;
            }
            catch (NoSuchFieldError var4)
            {
                ;
            }

            try
            {
                FACING_LOOKUP[EnumFacing.SOUTH.ordinal()] = 4;
            }
            catch (NoSuchFieldError var3)
            {
                ;
            }

            try
            {
                FACING_LOOKUP[EnumFacing.WEST.ordinal()] = 5;
            }
            catch (NoSuchFieldError var2)
            {
                ;
            }

            try
            {
                FACING_LOOKUP[EnumFacing.EAST.ordinal()] = 6;
            }
            catch (NoSuchFieldError var1)
            {
                ;
            }
        }
    }
   
    //###########################################################3
    
    
    //###########################################################3
    
    
    
    
}//fin de la clase

 

 

el blockState

girable.json

{
    "variants": {
        "normal": { "model": "modmercenario:multicara" },

"facing=north": { "model": "modmercenario:multicara" },
        "facing=south": { "model": "modmercenario:multicara", "y": 180 },
        "facing=west":  { "model": "modmercenario:multicara", "y": 270 },
        "facing=east":  { "model": "modmercenario:multicara", "y": 90 },
"facing=down":  { "model": "modmercenario:multicara", "x": 90 },
"facing=up":    { "model": "modmercenario:multicara", "x": 270 }
    
}}

 

el block model y item model

 

girable.json

{
    "parent": "modmercenario:block/cube",
    "textures": {

"down":  "modmercenario:blocks/metablockes/metablockemercenario18",
"up":    "modmercenario:blocks/metablockes/metablockemercenario19",
"north": "modmercenario:blocks/metablockes/metablockemercenario20",
"south": "modmercenario:blocks/metablockes/metablockemercenario21",
"west":  "modmercenario:blocks/metablockes/metablockemercenario22",
"east":  "modmercenario:blocks/metablockes/metablockemercenario23"

    }
}

Posted

I have yet to see any sensible reason why BlockPostion and BlockState was adopted over x/y/z and metadata.  A modder still needs to translate from block state to metadata and back (or in some cases other states modifying values in a tile entity).

 

Texturing likewise got more complicated and as of yet there's no sensible way to register textures either.  I mean seriously:

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(obliteratorAxe, 0, new ModelResourceLocation("perstools:obliteratorAxe", "inventory"));

 

WTF.

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

100% agree. I mean, I guess that it's cool someone can come along and edit the .json file and bam, suddenly your sword is 10x bigger and renders backwards, but I much preferred handling everything directly in code. Blocks are a complete nightmare now, and certainly do not appear 'optimized' - arguably the exact opposite of optimized. I'm hoping that we will see a return to common sense sometime in the future, but I fear we will be stuck with this nonsense...

Posted

E nop

i am the one suffering here but i get somethink

 

the are making it simply to not have to fuck up whith gl11 or tessellators but ,there is no documentation which would be very nice,  actualy i get the  idea, now is more simple to rotate and reescalated items, two days ago i found how to make layer textures whith the items and you can combine animated textures whith static textutes just defining in the layers in the json , i have the teory that is posible to use layers on block texturex and the key in the class snow layer but io have not realize yet how to set the layers in blocks json

 

 

suspensionderedstone.json

{
    "parent": "builtin/generated",
    "textures": {
        "layer0": "modmercenario:items/redstone/redstoneNIvel8"
        "layer1": "modmercenario:items/redstone/botellaVacia"

    },
    "display": {
        "thirdperson": {
            "rotation": [ -90, 0, 0 ],
            "translation": [ 0, 1, -3 ],
            "scale": [ 0.55, 0.55, 0.55 ]
        },
        "firstperson": {
            "rotation": [ 0, -135, 25 ],
            "translation": [ 0, 4, 2 ],
            "scale": [ 1.7, 1.7, 1.7 ]
        }
    }
}

 

 

in the other hand it will be nice if they make minecraft to atomatically register al the jsons in the models folder

and shorten the code to set which item/block has which texture in inventory

setTexture(ItemBlock,0 ,file.json);  //but this what i doit  in mi register class

Posted

100% agree. I mean, I guess that it's cool someone can come along and edit the .json file and bam, suddenly your sword is 10x bigger and renders backwards, but I much preferred handling everything directly in code. Blocks are a complete nightmare now, and certainly do not appear 'optimized' - arguably the exact opposite of optimized. I'm hoping that we will see a return to common sense sometime in the future, but I fear we will be stuck with this nonsense...

 

At least the rotation isn't handled in quaternions.

(If anyone legitimately understands how to rotate things in quaternions: you're abnormal)

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.

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

    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • 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?
  • Topics

×
×
  • Create New...

Important Information

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