Jump to content

Recommended Posts

Posted (edited)

Hi, I am trying to make that powered creepers could appear naturally in the world.

I did it editing the NBT Tags of the spawning creepers but I wanted to do it in a more efficient way so I tried to change directly the DataManager powered parameter to true but it raise an error.

Can you help me with this error or give me another way of doing it?

 

Here is my code:

package com.srgnis.testia;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.CreeperEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingSpawnEvent.SpecialSpawn;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod("testia")
public class TestIA
{
	private static final Logger LOGGER = LogManager.getLogger();
	public static final String MOD_ID = "testia";
	public static TestIA instance;
 
	private static final DataParameter<Boolean> POWERED = EntityDataManager.createKey(CreeperEntity.class, DataSerializers.BOOLEAN);

	public TestIA() 
	{	 
		instance = this;
		
		MinecraftForge.EVENT_BUS.register(this);
	}
	
	@SubscribeEvent
	public void onEntitySpawn(SpecialSpawn event) 
	{	
		if(event.getWorld().isRemote()) 
		{
			return;
		}
		
		Entity entity = event.getEntity();
		if (entity instanceof CreeperEntity ) { // is a creeper
			if(Math.random() > 0.3)
			{
				return;
			}
			
			CreeperEntity centity = ((CreeperEntity) entity); //cast to CreeperEntity
			
			if( !centity.func_225509_J__()) { // is not powered
				centity.getDataManager().set(POWERED, true); // set the creeper to powered
			}
		}
	}
}

 

 

 

Here is my logg:

-- Head --
Thread: Render thread
Stacktrace:
	at net.minecraft.network.datasync.DataSerializers$1.copyValue(DataSerializers.java:25)
	at net.minecraft.network.datasync.EntityDataManager$DataEntry.copy(EntityDataManager.java:299)
	at net.minecraft.network.datasync.EntityDataManager.getDirty(EntityDataManager.java:161)
	at net.minecraft.network.play.server.SEntityMetadataPacket.<init>(SEntityMetadataPacket.java:25)
	at net.minecraft.world.TrackedEntity.sendMetadata(TrackedEntity.java:265)
	at net.minecraft.world.TrackedEntity.tick(TrackedEntity.java:155)
	at net.minecraft.world.server.ChunkManager.tickEntityTracker(ChunkManager.java:998)
	at net.minecraft.world.server.ServerChunkProvider.func_217220_m(ServerChunkProvider.java:390)
	at net.minecraft.world.server.ServerChunkProvider.tick(ServerChunkProvider.java:328)
	at net.minecraft.world.server.ServerWorld.tick(ServerWorld.java:316)

-- Affected level --
Details:
	All players: 1 total; [ServerPlayerEntity['Dev'/1, l='guardar', x=8.37, y=56.00, z=7.04]]
	Chunk stats: ServerChunkCache: 2209
	Level dimension: DimensionType{minecraft:overworld}
	Level name: guardar
	Level seed: 2590508466852485413
	Level generator: ID 01 - flat, ver 0. Features enabled: true
	Level generator options: {biome:"minecraft:desert",layers:[{block:"minecraft:bedrock",height:1b},{block:"minecraft:stone",height:3b},{block:"minecraft:sandstone",height:52b}],structures:{}}
	Level spawn location: World: (8,55,8), Chunk: (at 8,3,8 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
	Level time: 421 game time, 421 day time
	Known server brands: forge
	Level was modded: true
	Level storage version: 0x04ABD - Anvil
	Level weather: Rain time: 19098 (now: false), thunder time: 52778 (now: false)
	Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:883)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:818)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:659)
	at java.lang.Thread.run(Unknown Source)

-- System Details --
Details:
	Minecraft Version: 1.15.2
	Minecraft Version ID: 1.15.2
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 1.8.0_241, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 315149192 bytes (300 MB) / 1173356544 bytes (1119 MB) up to 1890582528 bytes (1803 MB)
	CPUs: 4
	JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
	ModLauncher: 5.0.0-milestone.4+67+b1a340b
	ModLauncher launch target: fmluserdevclient
	ModLauncher naming: mcp
	ModLauncher services: 
		/eventbus-2.0.0-milestone.1-service.jar eventbus PLUGINSERVICE 
		/forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar object_holder_definalize PLUGINSERVICE 
		/forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar runtime_enum_extender PLUGINSERVICE 
		/accesstransformers-2.0.0-milestone.1-shadowed.jar accesstransformer PLUGINSERVICE 
		/forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar capability_inject_definalize PLUGINSERVICE 
		/forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar runtimedistcleaner PLUGINSERVICE 
		/forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar fml TRANSFORMATIONSERVICE 
	FML: 31.1
	Forge: net.minecraftforge:31.1.0
	FML Language Providers: 
		[email protected]
		minecraft@1
	Mod List: 
		client-extra.jar Minecraft {[email protected] DONE}
		forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar Forge {[email protected] DONE}
		main Test IA {[email protected] DONE}
	Player Count: 1 / 8; [ServerPlayerEntity['Dev'/1, l='guardar', x=8.37, y=56.00, z=7.04]]
	Data Packs: vanilla, mod:forge (incompatible), mod:testia
	Type: Integrated Server (map_client.txt)
	Is Modded: Definitely; Client brand changed to 'forge'
[m[32m[14:32:06] [Render thread/INFO] [STDOUT/]: [net.minecraft.util.registry.Bootstrap:printToSYSOUT:109]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2020-04-01_14.32.06-server.txt
[m[1;31m[14:32:06] [Server thread/ERROR] [minecraft/ChunkSerializer]: An Entity type net.minecraft.entity.EntityType@1c00d406 has thrown an exception trying to write state. It will not persist. Report this to the mod author
net.minecraft.crash.ReportedException: Saving entity NBT
	at net.minecraft.entity.Entity.writeWithoutTypeId(Entity.java:1548) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.Entity.writeUnlessRemoved(Entity.java:1453) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.Entity.writeUnlessPassenger(Entity.java:1469) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.chunk.storage.ChunkSerializer.write(ChunkSerializer.java:302) ~[?:?] {re:classloading}
	at net.minecraft.world.server.ChunkManager.func_219229_a(ChunkManager.java:688) ~[?:?] {re:classloading}
	at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source) [?:1.8.0_241] {}
	at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source) [?:1.8.0_241] {}
	at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source) [?:1.8.0_241] {}
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source) [?:1.8.0_241] {}
	at java.util.stream.AbstractPipeline.copyInto(Unknown Source) [?:1.8.0_241] {}
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) [?:1.8.0_241] {}
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source) [?:1.8.0_241] {}
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source) [?:1.8.0_241] {}
	at java.util.stream.AbstractPipeline.evaluate(Unknown Source) [?:1.8.0_241] {}
	at java.util.stream.ReferencePipeline.forEach(Unknown Source) [?:1.8.0_241] {}
	at net.minecraft.world.server.ChunkManager.save(ChunkManager.java:341) [?:?] {re:classloading}
	at net.minecraft.world.server.ServerChunkProvider.save(ServerChunkProvider.java:314) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.server.ServerWorld.save(ServerWorld.java:778) [?:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.save(MinecraftServer.java:541) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:584) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:241) [?:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:698) [?:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_241] {}
Caused by: java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Byte
	at net.minecraft.entity.MobEntity.isLeftHanded(MobEntity.java:1257) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.MobEntity.writeAdditional(MobEntity.java:398) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.monster.CreeperEntity.writeAdditional(CreeperEntity.java:101) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.entity.Entity.writeWithoutTypeId(Entity.java:1527) ~[?:?] {re:classloading,pl:accesstransformer:B}
	... 22 more

 

Edited by SrGnis
Solved
Posted

Don't create your own POWERED property, the creeper entity won't know what to do with it.

You should either go back to NBT if that was working before, or use reflection/access transformers to access the actual POWERED property in the creeper entity class.

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

Posted
2 hours ago, imacatlolol said:

Don't create your own POWERED property, the creeper entity won't know what to do with it.

You should either go back to NBT if that was working before, or use reflection/access transformers to access the actual POWERED property in the creeper entity class.

Thanks for answering, I think I'm going to stay with NBT method XD

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() ); } }  
  • Topics

×
×
  • Create New...

Important Information

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