Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

1.16.x Entity Attributes not being registered


Recommended Posts

Hi, I am trying to add a custom entity, however whenever I try to summon the entity I keep receiving the following error.

[10:19:35] [Server thread/WARN] [minecraft/EntityType]: Exception loading entity: 
java.lang.NullPointerException: null
	at net.minecraft.entity.ai.attributes.AttributeModifierManager.getAttributeValue(AttributeModifierManager.java:67) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.LivingEntity.getAttributeValue(LivingEntity.java:1849) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.LivingEntity.getMaxHealth(LivingEntity.java:1610) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.LivingEntity.<init>(LivingEntity.java:209) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.MobEntity.<init>(MobEntity.java:108) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.CreatureEntity.<init>(CreatureEntity.java:13) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.AgeableEntity.<init>(AgeableEntity.java:21) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.passive.AnimalEntity.<init>(AnimalEntity.java:37) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.passive.CowEntity.<init>(CowEntity.java:35) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at me.minecraft.star.entities.TestEntity.<init>(TestEntity.java:15) ~[main/:?] {re:classloading}
	at net.minecraft.entity.EntityType.create(EntityType.java:448) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.EntityType.lambda$loadEntityUnchecked$1(EntityType.java:459) ~[forge-1.16.4-35.1.4_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
//removed excess
	at net.minecraft.server.MinecraftServer.runScheduledTasks(MinecraftServer.java:721) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:667) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.lambda$startServer$0(MinecraftServer.java:233) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_282] {}
[10:19:35] [Render thread/INFO] [minecraft/NewChatGui]: [CHAT] Unable to summon entity

I have tried multiple different methods but for some reason the entity attributes are not being set correctly. I am currently using the method suggested in the topic below with no success. 

https://forums.minecraftforge.net/topic/87597-1161-custom-entity-attributes/

 

Code:

Main class:

@Mod(Main.MODID)
public class Main {
	//Removed excess
    private void setup(final FMLCommonSetupEvent event)
    {
    	LOGGER.info("STAR - Setup Complete");
    	DeferredWorkQueue.runLater(() -> {
            GlobalEntityTypeAttributes.put(EntityRegister.TESTENTITY_TYPE, TestEntity.setCustomAttributes().create());
        });
    }
	
}

Entity Class:

public class TestEntity extends CowEntity {
	//Removed Excess
	
	public static AttributeModifierMap.MutableAttribute setCustomAttributes() {
        return MobEntity.func_233666_p_().createMutableAttribute(Attributes.MOVEMENT_SPEED,  (double)0.5F).createMutableAttribute(Attributes.MAX_HEALTH, 20.0D).createMutableAttribute(Attributes.ATTACK_DAMAGE, 5.0D);
    }
}

I am using a deferred register method to register entities and it seems to be registering them successfully in the output. It also appears in the commands autofill.

Any help would be greatly appreciated :)

Link to post
Share on other sites
  • 3 weeks later...

Okay, so I've tried to add it as a subscribe event but it does not appear to exist. I'm using forge-1.16.4-35.1.4 in the eclipse IDE.

Here is the event I created:

    @SubscribeEvent
    public void entityAttributeCreationEvent(EntityAttributeCreationEvent event) { //EntityAttributeCreateEvent cannot be resolved to a type
    	
    }

There don't seem to be any import candidates.

Link to post
Share on other sites

Thanks for all your help. Here is the method that seems to register the attributes correctly.

Entity Class:

public class TestEntity extends CowEntity {

	public static final String REG = "simple_entity";
	public static final EntityType<TestEntity> TYPE = EntityType.Builder.<TestEntity>of(TestEntity::new, EntityClassification.MISC)
			.sized(0.98F, 0.7F)
			.clientTrackingRange(8)
			.build(REG);
	public static final AttributeModifierMap MAP = AttributeModifierMap.builder().add(Attributes.MAX_HEALTH, 20.0)
			.add(Attributes.MOVEMENT_SPEED, 20.0)
			.add(Attributes.FOLLOW_RANGE, 20.0)
			.build();
	
	public TestEntity(EntityType<? extends CowEntity> p_i48567_1_, World p_i48567_2_) {
		super(p_i48567_1_, p_i48567_2_);
		this.setNoAi(true);
		
	}
}	

Main Class:

@Mod(Main.MODID)
public class Main {
  	//trim
	public Main() {
		IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
		bus.register(this.getClass());
		//trim
		LOGGER.info("STAR has been initialised");
	}
	//trim

    @SubscribeEvent
	public static void entityAttributeCreationEvent(EntityAttributeCreationEvent event) {
    	LOGGER.info("STAR - Entity Attribute Event");
		event.put(TestEntity.TYPE, TestEntity.MAP);
	}

	//trim
}

Now I seem to have an error where there is no defined ai for the entity causing a ticking crash but I'll make a separate topic for that.

Link to post
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.

Guest
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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Hey, since yesterday im not able to load in an existing world anymore. I searched for some solutions, but only thing i could find is the productivebees mod, which seems to cause some problems. I havent installed this mod though. Ive attached the debug.log to this post. If you need any additional information or files please let me know!   debug-2.log.gz
    • Doing these things moves the camera. Your code subtracts the camera's position value from the MatrixStack.
    • That is just the modpack, no logs.
    • I created a modpack for me and my friends but we constantly crash after ~5 minutes of playing , Can some one help me please ? Here are the logs and the modpack : https://www.mediafire.com/file/kqnui7c0wzu8t7k/VladPack4-1.16.5.zip/file
    • I wrote a class that stores the BlockPos and BlockState of a specific block that needs to be changed into another block after a certain amount of time. So far I just coded stone bricks being changed into cracked stone bricks. In every worldtickevent I call a method called onTick in which there is a slight chance (1 in 1000) that this change will occur. The class that does this is called DecayHandler.java   DecayHandler.Java :   public class DecayHandler { public BlockState blockState; public BlockPos blockPos; public World world; private Random random; public int decayChance = 1000; private boolean decayed = false; public DecayHandler(BlockState blockState, BlockPos blockPos, World world){ this.blockState = blockState; this.blockPos = blockPos; this.world = world; random = new Random(); } public DecayHandler OnTick(){ //TODO: Refactor in other methods and implement BlockSwapper if(random.nextInt(decayChance) == 0 && !decayed){ System.out.println(this.blockPos + " Decayed"); if(world.setBlockAndUpdate(blockPos, Blocks.CRACKED_STONE_BRICKS.getBlock().defaultBlockState())){ this.blockState = Blocks.CRACKED_STONE_BRICKS.getBlock().defaultBlockState(); decayed = true; return this; } } //WorldDecayData.get(); return null; } }   This code works fine when I load in to a world and place stone bricks down. The stone bricks stay there for a couple of seconds and then they change into cracked stone bricks. The problem occurs when I save and quit to title and rejoin the same world when I placed stone brick that hadn't decayed yet. The game seems to remember what DecayHandlers were running which I guess is logical because I never closed it. So when the world is reloaded again my code stops without error and no longer functions. I can see in the terminal that the last message that was displayed was that a block decayed so I put a breakpoint on it to see what went wrong. By the way, the game keeps running just fine but my code just stops. The part where it seems to go wrong is in this line:  if(world.setBlockAndUpdate(blockPos, Blocks.CRACKED_STONE_BRICKS.getBlock().defaultBlockState())) When I try to step in to every single detail the callstack becomes insanely large and I'm unable to understand what's going on. The only thing I know is that right at the end they put my thread in to parking or something? I really don't understand what was going on. Can someone explain why this is happening? I don't have a clue of what's going on.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.