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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm using Modrinth as a launcher for a forge modpack on 1.20.1, and can't diagnose the issue on the crash log myself. Have tried repairing the Minecraft instillation as well as removing a few mods that have been problematic for me in the past to no avail. Crash log is below, if any further information is necessary let me know. Thank you! https://paste.ee/p/k6xnS
    • Hey folks. I am working on a custom "Mecha" entity (extended from LivingEntity) that the player builds up from blocks that should get modular stats depending on the used blocks. e.g. depending on what will be used for the legs, the entity will have a different jump strength. However, something unexpected is happening when trying to override a few of LivingEntity's functions and using my new own "Mecha" specific fields: instead of their actual instance-specific value, the default value is used (0f for a float, null for an object...) This is especially strange as when executing with the same entity from a point in the code specific to the mecha entity, the correct value is used. Here are some code snippets to better illustrate what I mean: /* The main Mecha class, cut down for brevity */ public class Mecha extends LivingEntity { protected float jumpMultiplier; //somewhere later during the code when spawning the entity, jumpMultiplier is set to something like 1.5f //changing the access to public didn't help @Override //Overridden from LivingEntity, this function is only used in the jumpFromGround() function, used in the aiStep() function, used in the LivingEntity tick() function protected float getJumpPower() { //something is wrong with this function //for some reason I can't correctly access the fields and methods from the instanciated entity when I am in one of those overridden protected functions. this is very annoying LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 0f return this.jumpMultiplier * super.getJumpPower(); } //The code above does not operate properly. Written as is, the entity will not jump, and adding debug logs shows that when executing the code, the value of this.jumpMultiplier is 0f //in contrast, it will be the correct value when done here: @Override public void tick() { super.tick(); //inherited LivingEntity logic //Custom logic LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 1.5f } } My actual code is slightly different, as the jumpMuliplier is stored in another object (so I am calling "this.legModule.getJumpPower()" instead of the float), but even using a simple float exactly like in the code above didn't help. When running my usual code, the object I try to use is found to be null instead, leading to a crash from a nullPointerException. Here is the stacktrace of said crash: The full code can be viewed here. I have found a workaround in the case of jump strength, but have already found the same problem for another parameter I want to do, and I do not understand why the code is behaving as such, and I would very much like to be able to override those methods as intended - they seemed to work just fine like that for vanilla mobs... Any clues as to what may be happening here?
    • Please delete post. Had not noticed the newest edition for 1.20.6 which resolves the issue.
    • https://paste.ee/p/GTgAV Here's my debug log, I'm on 1.18.2 with forge 40.2.4 and I just want to get it to work!! I cant find any mod names in the error part and I would like some help from the pros!! I have 203 mods at the moment.
  • Topics

×
×
  • Create New...

Important Information

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