Jump to content

[Solved] [1.15.2] Problems setting creepers powered


SrGnis

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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