Jump to content

Recommended Posts

Posted

So what i'm trying to do is rendering a backpack when held.

I have multiple working IItemrenderers that work fine.

I noticed how those IItemrenderers work only when they render blocks with tileentities, while they don't work on items.

 

RenderItemBackpack:

package coalpower.client.render.item;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
import net.minecraftforge.client.IItemRenderer.ItemRendererHelper;

import org.lwjgl.opengl.GL11;

import coalpower.client.model.ModelBackpackHandheld;
import coalpower.lib.render.Texture;

public class RenderItemBackpack implements IItemRenderer {

private ModelBackpackHandheld backpacks;
private Texture texture = Texture.BACKPACK;

public RenderItemBackpack() {
		backpacks = new ModelBackpackHandheld();
}

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
	return true;
}

@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
	return true;
}

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
	switch (type) {
		case ENTITY: {			
			texture.bind();
			GL11.glPushMatrix();
			GL11.glTranslatef(0F, 1F, 0F);
			GL11.glRotatef(180, 1, 0, 0);
			GL11.glRotatef(-90, 0, 1, 0);
			backpacks.render((Entity)data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
			GL11.glPopMatrix();
			break;
		}

		case EQUIPPED: {
			texture.bind();
			GL11.glPushMatrix();
			GL11.glTranslatef(0.5F, 1.5F, 0.5F);
			GL11.glRotatef(180, 1, 0, 0);
			GL11.glRotatef(-90, 0, 1, 0);
			backpacks.render((Entity)data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
			GL11.glPopMatrix();
			break;
		}

		case EQUIPPED_FIRST_PERSON: {
			texture.bind();
			GL11.glPushMatrix();
			GL11.glTranslatef(1F, 2F, 1F);
			GL11.glRotatef(180, 1, 0, 0);
			GL11.glRotatef(-90, 0, 1, 0);
			backpacks.render((Entity)data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
			GL11.glPopMatrix();
			break;
		}

		default:
			break;
	}
}

}

 

ClientProxy

MinecraftForgeClient.registerItemRenderer(Config.itemBackpackID, new RenderItemBackpack());		

 

This is how I did it for every other block, and it works fine, so I don't know what to do..

I try my best, so apologies if I said something obviously stupid!

Posted

Hi

 

I noticed how those IItemrenderers work only when they render blocks with tileentities, while they don't work on items.

 

I really don't understand what you mean by that.  IItemRenderer is designed for use with Items, and once the renderItem is called, you can render it any way you want.

 

What do you mean that this code doesn't work?  Do you see nothing at all, or do you see something but it is wrong?

Have you tried inserting breakpoint or System.out.println into renderItem or backpacks.render to see if it's called?

 

The problem might be what you're doing with (Entity)data[1]

 

eg for equipped it's the entity holding the item, not the item itself (since there is no entity for the item itself when it's being held)

        /** 
         * Called to render an item currently held in-hand by a living entity. If
         * rendering as a 3D block, the item will be rotated to a 45-degree angle.
         * To render a 2D texture with some thickness (like default items), see
         * net.minecraft.src.ItemRenderer. In either case, rendering should be done
         * in local coordinates from (0,0,0)-(1,1,1).
         * 
         * Data parameters:
         * RenderBlocks render - The RenderBlocks instance
         * EntityLiving entity - The entity holding this item
         */
        EQUIPPED, 

 

Some more info on IItemRenderer here,

http://greyminecraftcoder.blogspot.com.au/p/list-of-topics.html

see the Item Rendering sections

 

-TGG

Posted

What I mean by that is that only blocks with TileEntities get rendered as 3d items with IItemRenderer whereas items (Such as my backpack) don't get renderer at all. All I can see is the item texture in my hand, just like every other item instead of a custom model

 

So for instance I have a Pipe which has got a TileEntity. This pipe gets rendered with IItemRenderer.

Backpack won't get rendered at all.

 

Example of what I'm trying to explain:

7ERtx.jpg

 

This is not what I want. The backpack should not be a plain texture but a custom model

 

I try my best, so apologies if I said something obviously stupid!

Posted

Even If this is not required, since other IItemRenderers are registered in this way and work properly, It doesn't hurt me to.

 

Main Class (Commented out everything so yuo can understand what's going on)

package coalpower;


import net.minecraft.util.DamageSource;
import net.minecraftforge.common.MinecraftForge;
import coalpower.addon.AddonManager;
import coalpower.core.CPKeyBindings;
import coalpower.core.Config;
import coalpower.enchantment.EnchantmentTimedDamage;
import coalpower.info.dev.CapeHandler;
import coalpower.lib.core.AchievementLoader;
import coalpower.lib.handler.CPEventHandler;
import coalpower.lib.handler.GuiHandler;
import coalpower.lib.handler.PacketHandler;
import coalpower.lib.handler.SoundHandler;
import coalpower.lib.world.BiomeLoader;
import coalpower.lib.world.CPLoot;
import coalpower.lib.world.RadiationDamageSource;
import coalpower.network.proxy.ICPProxy;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;

@Mod(modid = CoalPower.modid, name = CoalPower.modid, version = CoalPower.version)
@NetworkMod(clientSideRequired = true, serverSideRequired = false, channels={ CoalPower.channel }, packetHandler = PacketHandler.class)


public class CoalPower 
{
@Instance("CoalPower")
public static CoalPower instance;
public static final String modid = "CoalPower";
public static final String version = "0.0.1";
public static final String channel = "coalPower";

public static AchievementLoader achievements;

public static EnchantmentTimedDamage coalTouch = new EnchantmentTimedDamage(100, 1, "Coal Touch");

public static GuiHandler guiHandler = new GuiHandler();
public static DamageSource radiation = new RadiationDamageSource("radiation").setDamageBypassesArmor();

@SidedProxy(clientSide = "coalpower.network.proxy.ClientProxy", serverSide = "coalpower.network.proxy.CommonProxy")
public static ICPProxy proxy;

@EventHandler
public void PreInit(FMLPreInitializationEvent event)
{
	//Config for ids
	Config.preInit(event);
	//Capes
	CapeHandler.registerCapesFromList(CapeHandler.devList, CapeHandler.devCape);
	//Achievements
	achievements = new AchievementLoader();
	//Events and sounds
	MinecraftForge.EVENT_BUS.register(new CPEventHandler());
	MinecraftForge.EVENT_BUS.register(new SoundHandler());
	//KeyBindings
	if (FMLCommonHandler.instance().getEffectiveSide().isClient())
		CPKeyBindings.init();
}

@EventHandler
public void load(FMLInitializationEvent event) 
{	
	//Blocks, items, entites, custom dungeon chests and proxy registrations
        CPLoader.load();
        CPLoot.init();
	proxy.init();			
}

@EventHandler
public void PostInit(FMLPostInitializationEvent event)
{
	//Addons and biomes
	AddonManager.loadAddons();
	AddonManager.init();

	BiomeLoader biomes = new BiomeLoader();
	biomes.register();
}

}

 

ClientProxy

package coalpower.network.proxy;

import java.util.Random;

import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.world.World;
import net.minecraft.world.WorldType;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.BiomeManager;
import coalpower.client.render.block.RenderAlloyFurnace;
import coalpower.client.render.block.RenderGas;
import coalpower.client.render.blockitem.RenderItemCrusher;
import coalpower.client.render.blockitem.RenderItemGasPipe;
import coalpower.client.render.blockitem.RenderItemSawmill;
import coalpower.client.render.blockitem.RenderItemSprinkler;
import coalpower.client.render.entity.RenderBee;
import coalpower.client.render.item.RenderItemBackpack;
import coalpower.client.render.machine.RenderCrusher;
import coalpower.client.render.machine.RenderSawmill;
import coalpower.client.render.machine.RenderSprinkler;
import coalpower.client.render.machine.pipe.RenderPipeGas;
import coalpower.core.Config;
import coalpower.entity.EntityBee;
import coalpower.entity.fx.EntitySparkFX;
import coalpower.entity.fx.EntityWoodDustFX;
import coalpower.lib.core.FXType;
import coalpower.tileentity.TileEntityHeatConductant;
import coalpower.tileentity.furnace.TileEntityAlloyFurnace;
import coalpower.tileentity.machine.TileEntityCrusher;
import coalpower.tileentity.machine.TileEntityPoweredFurnace;
import coalpower.tileentity.machine.TileEntityProjectTable;
import coalpower.tileentity.machine.TileEntitySawmill;
import coalpower.tileentity.machine.TileEntitySprinkler;
import coalpower.tileentity.machine.conductor.TileEntityGasPipe;
import coalpower.world.GenerationManager;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.registry.GameRegistry;

public class ClientProxy extends CommonProxy
{	
@Override
public void init(){
	super.init();
	this.registerEntities();
	this.registerGeneric();
	this.registerRenderers();
	this.registerTileEntities();
	this.registerWorldFeatures();
}


@Override
public void registerRenderers()
{
	super.registerRenderers();

	//Entities
	RenderingRegistry.registerEntityRenderingHandler(EntityBee.class, new RenderBee());

	//Blocks / Items
	RenderingRegistry.registerBlockHandler(renderGasBlock, new RenderGas());
	RenderingRegistry.registerBlockHandler(renderAlloyFurnace, RenderAlloyFurnace.INSTANCE);

	MinecraftForgeClient.registerItemRenderer(Config.machineCrusherID, new RenderItemCrusher());
	MinecraftForgeClient.registerItemRenderer(Config.machineSawmillID, new RenderItemSawmill());
	MinecraftForgeClient.registerItemRenderer(Config.pipeGasID, new RenderItemGasPipe());
	MinecraftForgeClient.registerItemRenderer(Config.machineSprinklerID, new RenderItemSprinkler());
	MinecraftForgeClient.registerItemRenderer(Config.itemBackpackID, new RenderItemBackpack());		

	//TileEntities
   	 	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCrusher.class, new RenderCrusher());
   	 	ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySawmill.class, new RenderSawmill());
   	 	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityGasPipe.class, new RenderPipeGas());
   	 	ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySprinkler.class, new RenderSprinkler());
   	 	

}

@Override 
public void registerWorldFeatures(){
	super.registerWorldFeatures();
        GameRegistry.registerWorldGenerator(GenerationManager.instance);

}

@Override 
public void registerTileEntities(){
	super.registerTileEntities();

	GameRegistry.registerTileEntity(TileEntityAlloyFurnace.class, "FurnaceAlloy");
	GameRegistry.registerTileEntity(TileEntityPoweredFurnace.class, "FurnacePowered");
	GameRegistry.registerTileEntity(TileEntityProjectTable.class, "BlockProjectTable");
	GameRegistry.registerTileEntity(TileEntityCrusher.class, "MachineCrusher");
	GameRegistry.registerTileEntity(TileEntitySawmill.class, "MachineSawmill");
	GameRegistry.registerTileEntity(TileEntityGasPipe.class, "PipeGas");
	GameRegistry.registerTileEntity(TileEntitySprinkler.class, "MachineSprinkler");

}




@Override
 public void spawnParticle(String s, double d, double d1, double d2, double d3, double d4, double d5, World worldObj, int opt)
     {
	super.spawnParticle(s, d, d1, d2, d3, d4, d5, worldObj, opt);
             Minecraft mc = Minecraft.getMinecraft();
             if (mc == null || mc.renderViewEntity == null || mc.effectRenderer == null) {
                     return;
             }
             int i = mc.gameSettings.particleSetting;
             if (i == 1 && worldObj.rand.nextInt(3) == 0) {
                     i = 2;
             }
             double d6 = mc.renderViewEntity.posX - d;
             double d7 = mc.renderViewEntity.posY - d1;
             double d8 = mc.renderViewEntity.posZ - d2;
             EntityFX obj = null;
             double d9 = 16D;
             if (d6 * d6 + d7 * d7 + d8 * d8 > d9 * d9) {
                     return;
             }
             if (i > 1) {
                     return;
             }
             
             if (s.equals("wooddust"))
                     obj = new EntityWoodDustFX(worldObj, d, d1, d2, (float)d3, (float)d4, (float)d5);
             else if(s.equals("spark"))
            	 obj = new EntitySparkFX(worldObj, d, d1, d2, false);
             else if(s.equals("randomspark"))
            	 obj = new EntitySparkFX(worldObj, d, d1, d2, true);
            
             if (obj != null) {
                     mc.effectRenderer.addEffect((EntityFX)obj);
                     FMLClientHandler.instance().getClient().effectRenderer.addEffect(obj);
             }
     }



@Override
public void addBiome(final BiomeGenBase biome){

	final WorldType[] worldTypes = { WorldType.DEFAULT, WorldType.LARGE_BIOMES };

	for(final WorldType worldType : worldTypes){
		worldType.addNewBiome(biome);
	}		
}

@Override
public void addSpawnBiome(final BiomeGenBase biome){
	BiomeManager.addSpawnBiome(biome);
}

}

I try my best, so apologies if I said something obviously stupid!

Posted

Did you even write your backpacks.render function to expect a an EntityLiving as it's argument. Since you are casting it down to Entity, I suspect that isn't true. The player in the EntityLiving, not the backpack. I'd suggest you use the object you get to get the held item, then render that with the view transformations of the player (1st argument). Maybe it should work as written, but I'd set a breakpoint there and see what is happening.

Posted

Hi

 

It looks to me like your backpack is rendering fine, it's just that it's using the vanilla renderer instead of your custom renderer.  This probably means you haven't registered the renderer properly.

 

MinecraftForgeClient.registerItemRenderer(Config.itemBackpackID, new RenderItemBackpack());

 

Is Config.itemBackpackID correct?

 

Did you try our suggestion of putting a breakpoint or System.out.println in your RenderItemBackpack methods?

 

-TGG

 

Posted

Yes, the config id is correct, since I tried rendering other items, but none of them work.

I'm setting breakpoints right now, I'll let you know

 

 

So, if I set the breakpoint in the renderItem function, It's not even getting called. The class's constructor obviously is, so I don't know what's happening..

I try my best, so apologies if I said something obviously stupid!

Posted

Hi

 

In that case, I suggest you try to trace through the vanilla code when it goes to render your item.

This diagram for 1.6.4 might help you.

http://greyminecraftcoder.blogspot.com.au/2013/08/rendering-first-person-view-items.html

 

ItemRenderer::
    // JAVADOC METHOD $$ renderItem
    public void renderItem(EntityLivingBase par1EntityLivingBase, ItemStack par2ItemStack, int par3, ItemRenderType type)
    {
        GL11.glPushMatrix();
        TextureManager texturemanager = this.mc.getTextureManager();
        Item item = par2ItemStack.getItem();
        Block block = Block.getBlockFromItem(item);

        IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(par2ItemStack, type);  // breakpoint here
        if (customRenderer != null)

 

If customRenderer comes back null, you've got a registration problem.  By inspecting customItemRenderers in MinecraftForgeClient you should be able to figure out what you've done wrong.

 

-TGG

 

-TGG

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.