Jump to content

Recommended Posts

Posted

[11:57:59] [server thread/ERROR] [FML]: A TileEntity type com.zombiesurvival.tileentity.GoldChestTileEntity has throw an exception trying to write state. It will not persist. Report this to the mod author
java.lang.RuntimeException: class com.zombiesurvival.tileentity.GoldChestTileEntity is missing a mapping! This is a bug!
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:93) ~[TileEntity.class:?]
at com.zombiesurvival.tileentity.GoldChestTileEntity.writeToNBT(GoldChestTileEntity.java:197) ~[GoldChestTileEntity.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:410) [AnvilChunkLoader.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:193) [AnvilChunkLoader.class:?]
at net.minecraft.world.gen.ChunkProviderServer.saveChunkData(ChunkProviderServer.java:266) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:332) [ChunkProviderServer.class:?]
at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:976) [WorldServer.class:?]
at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:419) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:454) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:356) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:593) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]

GoldChest Tile Entity

package com.zombiesurvival.tileentity;

import java.util.ArrayList;

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.server.gui.IUpdatePlayerListBox;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;

public class GoldChestTileEntity extends TileEntity implements IUpdatePlayerListBox, IInventory
{
//Declaring Variables
private boolean aBoolean;
private byte aByte;
private short aShort;
private int anInt;
private long aLong;
private float aFloat;
private double aDouble;
private String aString;
private byte[] aByteArray;
private int[] anIntArray;
private ItemStack anItemStack;
private ArrayList aList = new ArrayList();

private ItemStack[] inv;
private String test;

public GoldChestTileEntity()
{
	this.inv = new ItemStack[this.getSizeInventory()];
}
public String getCustomName()
{
	return this.test;
}
public void setCustomName(String test)
{
	this.test = test;
}
@Override
public String getName()
{
	return this.hasCustomName() ? this.test : "container.goldchest_tile_entity";
}

@Override
public boolean hasCustomName()
{
	return this.test != null && !this.test.equals("");
}
@Override
public IChatComponent getDisplayName()
{
	return this.hasCustomName() ? new ChatComponentText(this.getName()) : new ChatComponentTranslation(this.getName());
}
@Override
public int getSizeInventory()
{
	return 9;
}
@Override
public ItemStack getStackInSlot(int index)
{
	if(index < 0 || index >= this.getSizeInventory())
		return null;
	return this.inv[index];
}
@Override
public ItemStack decrStackSize(int index, int count)
{
	if(this.getStackInSlot(index) != null)
	{
		ItemStack itemstack;

	if(this.getStackInSlot(index).stackSize <= count)
	{
		itemstack = this.getStackInSlot(index);
		this.setInventorySlotContents(index, null);
		this.markDirty();
		return itemstack;
	}
	else
	{
		itemstack = this.getStackInSlot(index).splitStack(count);
		if(this.getStackInSlot(index).stackSize <= 0)
		{
			this.setInventorySlotContents(index, null);

		}
		else
		{
			//Just to show that changes happened
			this.setInventorySlotContents(index, this.getStackInSlot(index));
		}
		this.markDirty();
		return itemstack;

	}

	}
	else
	{
		return null;
	}
}

@Override
public ItemStack getStackInSlotOnClosing(int index)
{
	ItemStack stack = this.getStackInSlot(index);
	this.setInventorySlotContents(index, null);
	return stack;
}
@Override
public void setInventorySlotContents(int index, ItemStack stack)
{
	if(index < 0 || index >= this.getSizeInventory())
		return;
	if(stack != null && stack.stackSize > this.getInventoryStackLimit())
		stack.stackSize = this.getInventoryStackLimit();
	if(stack != null && stack.stackSize == 0)
		stack = null;
	this.inv[index] = stack;
	this.markDirty();
}
@Override 
public int getInventoryStackLimit()
{
	return 64;
}
@Override 
public boolean isUseableByPlayer(EntityPlayer p)
{
	return this.worldObj.getTileEntity(this.getPos()) == this && p.getDistanceSq(this.pos.add(0.5,0.5,0.5)) <= 64;

}
@Override
public void openInventory(EntityPlayer p)
{

}
@Override
public void closeInventory(EntityPlayer p)
{

}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack)
{
	return true;

}
@Override
public int getField(int id)
{
	return 0;
}
@Override
public void setField(int id, int value)
{

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

@Override
public void clear()
{
	for(int i =0; i < this.getSizeInventory(); i++)
		this.setInventorySlotContents(i, null);

}

@Override
public void update()
{

}





@Override
public void writeToNBT(NBTTagCompound c)
{
	super.writeToNBT(c);
/**	
	//Primitives
	c.setBoolean("aBoolean", this.aBoolean);
	c.setByte("aByte", this.aByte);
	c.setShort("aShort", this.aShort);
	c.setInteger("anInt", this.anInt);
	c.setLong("aLong", this.aLong);
	c.setFloat("aFloat", this.aFloat);
	c.setDouble("aDouble", this.aDouble);
	c.setString("aString", this.aString);
	c.setByteArray("aByteArray", this.aByteArray);
	c.setIntArray("anIntArray", this.anIntArray);

	//Item Stack
	NBTTagCompound s = new NBTTagCompound();
	this.anItemStack.writeToNBT(s);
	c.setTag("anItemStack", s);

	//TagList of Integer Tags
	NBTTagList l = new NBTTagList();
	for(int i = 0; i < this.aList.size(); i++)
	{
	NBTTagCompound n = new NBTTagCompound();
	n.setInteger("id", i);
	n.setInteger("value", (Integer) this.aList.get(i));
	l.appendTag(n);

	}
	c.setTag("aList", l);*/

	NBTTagList list= new NBTTagList();
	for (int i =0; i <this.getSizeInventory(); ++i)
	{
		if(this.getStackInSlot(i)!= null)
		{
			NBTTagCompound stackTag = new NBTTagCompound();
			stackTag.setByte("Slot1", (byte)i) ;
			this.getStackInSlot(i).writeToNBT(stackTag);
			list.appendTag(stackTag);
		}
	}
}

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

	/**Primitives
	this.aBoolean = c.getBoolean("aBoolean");
	this.aByte = c.getByte("aByte");
	this.aShort = c.getShort("aShort");
	this.anInt = c.getInteger("aInt");
	this.aLong = c.getLong("aLong");
	this.aFloat = c.getFloat("aFloat");
	this.aDouble = c.getDouble("aDouble");
	this.aString = c.getString("aString");
	this.aByteArray = c.getByteArray("aByteArray");
	this.anIntArray = c.getIntArray("anIntArray");

	//ItemStack
	this.anItemStack = ItemStack.loadItemStackFromNBT(c.getCompoundTag("anItemStack"));

	//TagList of IntegerTags
	NBTTagList l = c.getTagList("aList", 10);
	this.aList.clear();
	for(int i = 0; i < l.tagCount(); i++)
	{
		NBTTagCompound n = l.getCompoundTagAt(i);
		int id = n.getInteger("id");
		int value = n.getInteger("value");
		this.aList.ensureCapacity(id);
		this.aList.set(id, value);
	}
	*/
	NBTTagList list = nbt.getTagList("Items", 10);
	for(int i = 0; i < list.tagCount(); ++i)
	{
		NBTTagCompound stackTag = list.getCompoundTagAt(i);
		int slot = stackTag.getByte("Slot") & 255;
		this.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(stackTag));

	}
	if(nbt.hasKey("gold", 9))
	{
		this.setCustomName(nbt.getString("gold"));
	}
}

}

ModTileEntities <- Where TileEntities Are Registered

package com.zombiesurvival.tileentity;

import com.zombiesurvival.power.pipes.TileEntityPipe;

import net.minecraftforge.fml.common.registry.GameRegistry;

public final class ModTileEntities
{
public static void init()
{
	GameRegistry.registerTileEntity(IronChestTileEntity.class, "ironchest_tile_entity");
	GameRegistry.registerTileEntity(IronChestTileEntity.class, "goldchest_tile_entity");
	GameRegistry.registerTileEntity(LargeBackpackTileEntity.class, "largebackpack_tile_entity");
	GameRegistry.registerTileEntity(ElectricFurnaceTileEntity.class, "electric_furnace_tile_entity");
	GameRegistry.registerTileEntity(TileEntityPipe.class, "pipe_tile_entity");
}
}

 

 

Main Class

package com.zombiesurvival;

import com.zombiesurvival.blocks.ModBlocks;
import com.zombiesurvival.gui.handlers.EventHandlerOverlay;
import com.zombiesurvival.gui.handlers.ModGuiHandler;
import com.zombiesurvival.gui.hud.ItemHUDactivator;
import com.zombiesurvival.gui.hud.StatusBarRenderer;
import com.zombiesurvival.items.ModItems;
import com.zombiesurvival.proxy.CommonProxy;
import com.zombiesurvival.utils.FuelManager;
import com.zombiesurvival.utils.KeyBindings;
import com.zombiesurvival.utils.KeyInputHandler;
import com.zombiesurvival.utils.crafting.CraftingManager;

import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@Mod(modid=Main.MODID, name=Main.MODNAME, version=Main.MODVER) 
public class Main 
{
/**TODO: 
* WINDMILLS (3D Modeled with Spinning Rotor).
* Power Systems
* Energy Pipes
* Item Pipes
* Fluid Pipes
* Energy Cables
*/
    public static final String MODID = "zombiesurvival";
    //Set the "Name" of the mod.
    public static final String MODNAME = "Main";
    //Set the version of the mod.
    public static final String MODVER = "0.0.1 Alpha";
    
    @Instance(value = Main.MODID)
    public static Main instance;
    //Items
    public static Item rifle22;
    public static Item bullets22;
    public static Item steelIngot;
    public static Item brassIngot;
    public static Item nickelIngot;
    public static Item bronzeIngot;
    //Creative Tabs
    public static CreativeTabs test = new CreativeTabs("Test") {
        @Override
        @SideOnly(Side.CLIENT)
        public Item getTabIconItem() {
            return Items.iron_ingot;
        }
    };
    public static ItemHUDactivator itemHUDactivator; 
@SidedProxy(clientSide="com.zombiesurvival.proxy.ClientProxy", serverSide="com.zombiesurvival.proxy.CommonProxy")
public static CommonProxy proxy;
    @EventHandler
    public void preInit(FMLPreInitializationEvent e)
    {
    	FMLCommonHandler.instance().bus().register(new KeyInputHandler());
    	KeyBindings.init();
    	ModItems.init();
    	ModBlocks.init();
    	CraftingManager.init();
    	proxy.registerRenderers();
    	GameRegistry.registerFuelHandler(new FuelManager());

    	/**
    	 * to fix
    	 */
    //	EntityRegistrar.init();
    }
    
    @EventHandler
    public void Init(FMLInitializationEvent e)
    {
    	NetworkRegistry.INSTANCE.registerGuiHandler(Main.instance, new ModGuiHandler());
    	
    }
    private static StatusBarRenderer statusBarRenderer;
    @EventHandler
    public void postInit(FMLPostInitializationEvent e)
    {

    }
    


}

 

 

 

Why am i getting the error i'm really confused.

Posted

Hey Lord, I know this isn't on topic with this thread but would you be able to give me asome pointers about creating a simple energy system, i just want to be able to connect a pipe to a stone block and then if its connected to my block (named test) it to just say hi in console. I've gave it a go but im a bit stuck. Any help would be lovelyyyyyyyy.

Posted

Ok so I created a block called PowerTest.

Please bare in mind im not the best modder out there im still learning im making this mod to learn more :P.


package com.zombiesurvival.blocks;

import com.zombiesurvival.power.pipes.BlockPipe;
import com.zombiesurvival.tileentity.PowerTestTileEntity;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;

public class PowerTest extends BlockContainer 
{

public PowerTest(String unlocalizedName, Material mat) {
	super(Material.iron);
	this.setCreativeTab(CreativeTabs.tabBlock);
	this.setUnlocalizedName(unlocalizedName);
}
public boolean activated = false;

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) 
{
	return new PowerTestTileEntity();
}
public void onNeighborBlockChange(World w, BlockPos pos, IBlockState state, Block nb)
{
	if (!w.isRemote)
        {
		//TODO: If Power is already on then it cannot be turned on again
		if(nb != ModBlocks.pipe)
				{
					System.out.println("Power On");
					if(BlockPipe.isPoweredGlobal == true)
					{
						System.out.println(" We Have Power");
					}
					else if(BlockPipe.isPoweredGlobal == false)
					{
						System.out.println(" We Don't Have Power");
					}
					else
					{
						System.out.println(" Error");
					}
				}
		//TODO Change to Else If Statement to check for errors else then it's an error
				else
				{
					System.out.println("Power off");
				}
        }
}
public boolean pipeNext(World w,int x,int y,int z)
{


	return activated;


}
public void onBlockActivated()
{

}

}

 

I kow that the stuff im doing in onNeighborBlockChange should be in a method that checks for updates on every tick but it was for testing.

In My Block Pipes i created 2 booleans one that's static, (probably so wrong)

I honestly think  i should be saving this boolean somewhere else but i don't know how/ where.

package com.zombiesurvival.power.pipes;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockPipe extends BlockContainer
{
public boolean isPowered;
public static boolean isPoweredGlobal;
public BlockPipe(String unlocalizedName, Material mat) 
{
	super(mat);
	float pixel = 1F/16F;
	//Minx,miny,minz,maxx,maxy,maxz
	this.setBlockBounds(11*pixel/2,11*pixel/2, 11*pixel/2, 1-11*pixel/2, 1-11*pixel/2, 1-11*pixel/2);
	this.setCreativeTab(CreativeTabs.tabBlock);
	this.setUnlocalizedName(unlocalizedName);
}

public int getRenderType()
{
	return -1;
}
public boolean isOpaqueCube()
{
	return false;
}
public boolean renderAsNormalBlock()
{
	return false;
}
public TileEntity createNewTileEntity(World w, int i)
{
	return new TileEntityPipe();
}
@SideOnly(Side.CLIENT)
    public EnumWorldBlockLayer getBlockLayer()
    {
        return EnumWorldBlockLayer.CUTOUT;
    }
public void onNeighborBlockChange(World w, BlockPos pos, IBlockState state, Block nb)
{
	if (!w.isRemote)
        {
		//TODO: If Power is already on then it cannot be turned on again
		if(nb == Blocks.stone)
				{

					isPowered = true;
					if(isPowered = true)
					{

						isPoweredGlobal = true;
						System.out.println("Pipe has Power");
					}


				}
		//TODO Change to Else If Statement to check for errors else then it's an error
				else if (nb != Blocks.stone)
				{

					isPowered = false;
					if(isPowered = false)
					{
						System.out.println("Pipe doesn't have Power ");
						isPoweredGlobal = false;
					}
					else
					{
						//System.out.println("Pipe has Power");
						//isPoweredGlobal = true;
					}
				}
        }
}

}

 

 

So yeah Thats the code. :D

Posted

never. ever. under no circumstance. save that bool in the block class. every single block u place shares the same instance of block. if u want to save different values u need to use the tileentity, u can access that via world.getTileEntity

Guest
This topic is now closed to further replies.

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.