Jump to content

Recommended Posts

Posted

I'm trying to make an item that when thrown creates a pool of fire on impact, yet I'm confused how to get it to actually render.

 

The entity functions as it should, and it renders fine in hand/inventory.

But the entity itself just won't render.

 

I see some people say to register entities from init() and some from preInit() so I tried both, each with negative results.

 

If I call the registry in preInit() as soon as it's thrown and tries to render, the game crashes with a NullPointerException:

Spoiler

net.minecraft.util.ReportedException: Rendering entity in world
	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:432) ~[RenderManager.class:?]
	at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:374) ~[RenderManager.class:?]
	at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:655) ~[RenderGlobal.class:?]
	at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1400) ~[EntityRenderer.class:?]
	at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1312) ~[EntityRenderer.class:?]
	at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1115) ~[EntityRenderer.class:?]
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1208) ~[Minecraft.class:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_181]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_181]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:25) [start/:?]
Caused by: java.lang.NullPointerException
	at net.minecraft.client.renderer.entity.RenderSnowball.doRender(RenderSnowball.java:35) ~[RenderSnowball.class:?]
	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:390) ~[RenderManager.class:?]
	... 20 more
[21:10:42] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:629]: ---- Minecraft Crash Report ----
// Hi. I'm Minecraft, and I'm a crashaholic.

Time: 3/6/19 9:10 PM
Description: Rendering entity in world

java.lang.NullPointerException: Rendering entity in world
	at net.minecraft.client.renderer.entity.RenderSnowball.doRender(RenderSnowball.java:35)
	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:390)
	at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:374)
	at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:655)
	at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1400)
	at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1312)
	at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1115)
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1208)
	at net.minecraft.client.Minecraft.run(Minecraft.java:441)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:25)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
	at net.minecraft.client.renderer.entity.RenderSnowball.doRender(RenderSnowball.java:35)

-- Entity being rendered --
Details:
	Entity Type: lootboxes:firebomb (avrye.lootboxes.entity.EntityFirebomb)
	Entity ID: 19129
	Entity Name: entity.firebomb.name
	Entity's Exact location: 222.83, 8.55, -463.32
	Entity's Block location: World: (222,8,-464), Chunk: (at 14,0,0 in 13,-29; contains blocks 208,0,-464 to 223,255,-449), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)
	Entity's Momentum: -1.12, -0.99, -0.08
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null

-- Renderer details --
Details:
	Assigned renderer: net.minecraft.client.renderer.entity.RenderSnowball@1b22a77c
	Location: -0.34,1.23,-0.03 - World: (-1,1,-1), Chunk: (at 15,0,15 in -1,-1; contains blocks -16,0,-16 to -1,255,-1), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
	Rotation: -94.27165
	Delta: 0.29999375
Stacktrace:
	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:390)
	at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:374)
	at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:655)
	at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1400)
	at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1312)

-- Affected level --
Details:
	Level name: MpServer
	All players: 1 total; [EntityPlayerSP['Player295'/90, l='MpServer', x=223.96, y=7.99, z=-463.24]]
	Chunk stats: MultiplayerChunkCache: 621, 621
	Level seed: 0
	Level generator: ID 01 - flat, ver 0. Features enabled: false
	Level generator options: 
	Level spawn location: World: (221,4,-553), Chunk: (at 13,0,7 in 13,-35; contains blocks 208,0,-560 to 223,255,-545), Region: (0,-2; contains chunks 0,-64 to 31,-33, blocks 0,0,-1024 to 511,255,-513)
	Level time: 32987 game time, 32987 day time
	Level dimension: 0
	Level storage version: 0x00000 - Unknown?
	Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
	Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
	Forced entities: 10 total; [EntityPig['Pig'/48, l='MpServer', x=177.27, y=4.00, z=-462.62], EntityChicken['Chicken'/32, l='MpServer', x=146.52, y=4.00, z=-504.41], EntityCow['Cow'/49, l='MpServer', x=188.78, y=4.00, z=-448.85], EntityPlayerSP['Player295'/90, l='MpServer', x=223.96, y=7.99, z=-463.24], EntityCow['Cow'/50, l='MpServer', x=197.79, y=4.00, z=-437.62], EntityPig['Pig'/51, l='MpServer', x=211.54, y=4.00, z=-498.40], EntityPig['Pig'/35, l='MpServer', x=149.31, y=4.00, z=-476.41], EntityFirebomb['entity.firebomb.name'/19129, l='MpServer', x=222.83, y=8.55, z=-463.32], EntityPig['Pig'/45, l='MpServer', x=162.69, y=4.00, z=-504.46], EntityPig['Pig'/46, l='MpServer', x=160.24, y=4.00, z=-469.44]]
	Retry entities: 0 total; []
	Server brand: fml,forge
	Server type: Integrated singleplayer server
Stacktrace:
	at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:461)
	at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2888)
	at net.minecraft.client.Minecraft.run(Minecraft.java:462)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:25)

 

 

 

But if I call the registry in init() instead of crashing, everything works perfectly except that it renders as just a small white cube.

 

 

Any help?

 

Entities:

Spoiler

public class Entities
{
	public static int entityId = 0;

	public static final EntityEntry firebomb = newEntry("firebomb", EntityFirebomb.class);

	public static <E extends Entity> EntityEntry newEntry(String name, Class<? extends E> entity)
	{
		return EntityEntryBuilder.create().entity(entity).id(new ResourceLocation(Main.MODID, name), entityId++).name(name)
				.tracker(64, 5, true).build();
	}
}

 

 

Registry:

Spoiler

@EventBusSubscriber
public class Registry
{
	// item list
	// block list
	// item registry event
	// block registry event
	// itemblock registry event
	// model registry event

	@SubscribeEvent
	public static void register(Register<EntityEntry> event)
	{
		event.getRegistry().register(Entities.firebomb);
	}

        // This is called from ClientProxy
	public static void render()
	{
		RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
		RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();

		RenderingRegistry.registerEntityRenderingHandler(EntityFirebomb.class, new IRenderFactory<EntityFirebomb>()
		{
			@Override
			public Render<? super EntityFirebomb> createRenderFor(RenderManager manager)
			{
				return new RenderSnowball<EntityFirebomb>(renderManager, claybomb, renderItem);
			}
		});
	}
}

 

 

EntityFirebomb:

Spoiler

public class EntityFirebomb extends EntityThrowable
{
	private int radius, entityDamage;

	public EntityFirebomb(World world)
	{
		super(world);
	}

	public EntityFirebomb(World world, EntityLivingBase thrower, int radius, int entityDamage)
	{
		super(world, thrower);
		this.radius = radius;
		this.entityDamage = entityDamage;
	}

	public EntityFirebomb(World world, double x, double y, double z, int radius, int entityDamage)
	{
		super(world, x, y, z);
		this.radius = radius;
		this.entityDamage = entityDamage;
	}

	@Override
	protected void onImpact(RayTraceResult result)
	{
		ArrayList<BlockPos> affectedBlocks = new ArrayList<BlockPos>();
		BlockPos pos = null;

		if (result.typeOfHit == RayTraceResult.Type.BLOCK)
		{
			if (result.getBlockPos() == null || result.getBlockPos() == BlockPos.ORIGIN)
			{
				pos = this.getPosition();
			}
			else
			{
				pos = result.getBlockPos();
			}
		}
		else if (result.typeOfHit == RayTraceResult.Type.ENTITY)
		{
			if (result.entityHit != null)
			{
				result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), entityDamage);

				pos = result.entityHit.getPosition();
			}
		}

		if (pos == null || world.getBlockState(pos).getMaterial() == Material.WATER)
		{
			return;
		}

		for (int i = -radius; i < radius; i++)
		{
			for (int j = -radius; j < radius; j++)
			{
				for (int k = -radius; k < radius; k++)
				{
					affectedBlocks.add(new BlockPos(pos.getX() + i, pos.getY() + j, pos.getZ() + k));
				}
			}
		}

		Random r = new Random();
		for (BlockPos b : affectedBlocks)
		{
			if (this.world.getBlockState(b).getMaterial() == Material.AIR && this.world.getBlockState(b.down()).isFullBlock()
					&& r.nextInt(3) == 0)
			{
				this.world.setBlockState(b, Blocks.FIRE.getDefaultState());
			}
		}
		world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.PLAYERS, 0.5F,
				0.6f);

		if (!this.world.isRemote)
		{
			this.world.setEntityState(this, (byte) 3);
			this.setDead();
		}
	}
}

 

 

 

Posted

Please read https://gist.github.com/Cadiboo/fbea89dc95ebbdc58d118f5350b7ba93. Get rid of all of this

// This is called from ClientProxy
	public static void render()
	{
		RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
		RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();

		RenderingRegistry.registerEntityRenderingHandler(EntityFirebomb.class, new IRenderFactory<EntityFirebomb>()
		{
			@Override
			public Render<? super EntityFirebomb> createRenderFor(RenderManager manager)
			{
				return new RenderSnowball<EntityFirebomb>(renderManager, claybomb, renderItem);
			}
		});
	}

and replace it with something that isn't broken. You're passed a RenderManager in from createRenderFor why do you use the other one. Why does the other one even exist? Heres an example of how to register a renderer https://github.com/Cadiboo/WIPTech/blob/fb5883e9d76ef0361ec1ebbcb9c508611dd2ef6b/src/main/java/cadiboo/wiptech/client/ClientEventSubscriber.java#L137 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
7 minutes ago, Cadiboo said:

Please read https://gist.github.com/Cadiboo/fbea89dc95ebbdc58d118f5350b7ba93. Get rid of all of this


// This is called from ClientProxy
	public static void render()
	{
		RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
		RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();

		RenderingRegistry.registerEntityRenderingHandler(EntityFirebomb.class, new IRenderFactory<EntityFirebomb>()
		{
			@Override
			public Render<? super EntityFirebomb> createRenderFor(RenderManager manager)
			{
				return new RenderSnowball<EntityFirebomb>(renderManager, claybomb, renderItem);
			}
		});
	}

and replace it with something that isn't broken. You're passed a RenderManager in from createRenderFor why do you use the other one. Why does the other one even exist? Heres an example of how to register a renderer https://github.com/Cadiboo/WIPTech/blob/fb5883e9d76ef0361ec1ebbcb9c508611dd2ef6b/src/main/java/cadiboo/wiptech/client/ClientEventSubscriber.java#L137 

The RenderManager was only there because of something else I was trying that didn't work; forgot to remove it.

 

Also, changing it to this...

Spoiler

public static void render()
{
	//....
  
	RenderingRegistry.registerEntityRenderingHandler(EntityFirebomb.class, RenderFirebomb::new);
}

@SideOnly(Side.CLIENT)
public class RenderFirebomb extends Render<EntityFirebomb>
{
	protected final Item item;
	private final RenderItem itemRenderer;

	public RenderFirebomb(final RenderManager renderManager)
	{
		super(renderManager);
		this.item = Registry.claybomb;
		this.itemRenderer = Minecraft.getMinecraft().getRenderItem();
	}

	@Override
	public void doRender(EntityFirebomb entity, double x, double y, double z, float entityYaw, float partialTicks)
	{
		GlStateManager.pushMatrix();
		GlStateManager.translate((float) x, (float) y, (float) z);
		GlStateManager.enableRescaleNormal();
		GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
		GlStateManager.rotate((float) (this.renderManager.options.thirdPersonView == 2 ? -1 : 1) * this.renderManager.playerViewX, 1.0F,
				0.0F, 0.0F);
		GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
		this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

		if (this.renderOutlines)
		{
			GlStateManager.enableColorMaterial();
			GlStateManager.enableOutlineMode(this.getTeamColor(entity));
		}

		this.itemRenderer.renderItem(new ItemStack(this.item), ItemCameraTransforms.TransformType.GROUND);

		if (this.renderOutlines)
		{
			GlStateManager.disableOutlineMode();
			GlStateManager.disableColorMaterial();
		}

		GlStateManager.disableRescaleNormal();
		GlStateManager.popMatrix();
		super.doRender(entity, x, y, z, entityYaw, partialTicks);
	}

	protected ResourceLocation getEntityTexture(EntityFirebomb entity)
	{
		return TextureMap.LOCATION_BLOCKS_TEXTURE;
	}
}

 

still produces the same result. Renders a white cube instead of the item. Did I miss something?

Posted

Unless you're trying to render a white cube, it means that your renderer isn't getting registered properly. Please post your code as a working GitHub repository.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.