Jump to content

Custom Entity Attributes problem, in 1.16.5 and 1.18.2


Recommended Posts

Posted (edited)

I tried to add an custom Entity into Minecraft, but i get this error:

[16:48:36] [Server thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Server
java.lang.NullPointerException: null
	at net.minecraft.network.datasync.EntityDataManager.set(EntityDataManager.java:122) ~[forge:?] {re:classloading}
	at net.minecraft.entity.LivingEntity.setHealth(LivingEntity.java:924) ~[forge:?] {re:classloading}
	at net.minecraft.entity.LivingEntity.<init>(LivingEntity.java:207) ~[forge:?] {re:classloading}
	at net.tomschmidt.drones.entity.DroneEntity.<init>(DroneEntity.java:23) ~[?:?] {re:classloading}
	at net.tomschmidt.drones.items.DroneSpawnItem.onItemUseFirst(DroneItem.java:35) ~[?:?] {re:classloading}
	at net.minecraft.item.ItemStack.lambda$onItemUseFirst$6(ItemStack.java:191) ~[forge:?] {re:classloading,xf:fml:forge:filled_map.4,xf:fml:forge:itemstack}
	at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:202) ~[forge:?] {re:classloading,xf:fml:forge:filled_map.4,xf:fml:forge:itemstack}
	at net.minecraft.item.ItemStack.onItemUseFirst(ItemStack.java:191) ~[forge:?] {re:classloading,xf:fml:forge:filled_map.4,xf:fml:forge:itemstack}
	at net.minecraft.server.management.PlayerInteractionManager.useItemOn(PlayerInteractionManager.java:331) ~[forge:?] {re:classloading}
	at net.minecraft.network.play.ServerPlayNetHandler.handleUseItemOn(ServerPlayNetHandler.java:958) ~[forge:?] {re:classloading}
	at net.minecraft.network.play.client.CPlayerTryUseItemOnBlockPacket.handle(CPlayerTryUseItemOnBlockPacket.java:36) ~[forge:?] {re:classloading}
	at net.minecraft.network.play.client.CPlayerTryUseItemOnBlockPacket.handle(CPlayerTryUseItemOnBlockPacket.java:12) ~[forge:?] {re:classloading}
	at net.minecraft.network.PacketThreadUtil.lambda$ensureRunningOnSameThread$0(PacketThreadUtil.java:19) ~[forge:?] {re:classloading}
	at net.minecraft.util.concurrent.TickDelayedTask.run(TickDelayedTask.java:17) ~[forge:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.doRunTask(ThreadTaskExecutor.java:136) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.RecursiveEventLoop.doRunTask(RecursiveEventLoop.java:22) ~[forge:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:734) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:159) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.pollTask(ThreadTaskExecutor.java:109) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:717) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:711) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.managedBlock(ThreadTaskExecutor.java:119) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:697) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:646) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:232) ~[forge:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:750) [?:1.8.0_342] {}

(I try to spawn my Entity with an extra Item but the same happens with the summon command)

Other people in this forum had similiar errors, but they could fix it with 

    public static AttributeModifierMap.MutableAttribute setCustomAttributes() {
        return LivingEntity.createLivingAttributes()
                .add(Attributes.MAX_HEALTH, 20.0f);
    }

and

@Mod.EventBusSubscriber(modid = Drones.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModEventBusEvents {

    @SubscribeEvent
    public static void addEntityAttributes(EntityAttributeCreationEvent event) {
        CombatDrones.LOGGER.info("ID22, EntityAttributeCreationEvent"); //is executed (shows in log)
        event.put(ModEntityTypes.DRONE.get(), DroneEntity.setCustomAttributes().build());
        CombatDrones.LOGGER.info("HasSupplier: " + GlobalEntityTypeAttributes.hasSupplier(ModEntityTypes.DRONE.get())); //returns true
    }
}

But i already did this and that confuses me.

Does anyone know the solution for my problem?

PS: excuse my typos, i am not an native english speaker.

Edited by tomschmidt
Posted

My whole entity class:

package net.tomschmidt.drones.entity;

import net.tomschmidt.drones.register.ModEntityTypes;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.IPacket;
import net.minecraft.util.HandSide;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;


public class DroneEntity extends LivingEntity {
    public DroneEntity(EntityType<? extends DroneEntity> p_i48580_1_, World p_i48580_2_) {
        super(p_i48580_1_, p_i48580_2_);
    }

    public void setStartPos(double x, double y, double z) {
        this.setPos(x, y, z);
        this.setDeltaMovement(Vector3d.ZERO);
        this.xo = x;
        this.yo = y;
        this.zo = z;
    }

    @Override
    protected void defineSynchedData() {

    }

    @Override
    public Iterable<ItemStack> getArmorSlots() {
        return null;
    }

    @Override
    public ItemStack getItemBySlot(EquipmentSlotType p_184582_1_) {
        return null;
    }

    @Override
    public void setItemSlot(EquipmentSlotType p_184201_1_, ItemStack p_184201_2_) {

    }

    @Override
    public HandSide getMainArm() {
        return HandSide.RIGHT;
    }

    @Override
    public IPacket<?> getAddEntityPacket() {
        return null;
    }

    public static AttributeModifierMap.MutableAttribute setCustomAttributes() {
        return LivingEntity.createLivingAttributes()
                .add(Attributes.MAX_HEALTH, 20.0f);
    }

}

 

Posted

You have a lot of methods that return null and don't call the super of a method, which causes plenty of errors. However, the code provided is for 1.16.5, which is not supported on this forum. If you would like to provide the updated 1.18.2 code, I will give a proper answer. Otherwise, I will lock this thread since it is no longer supported.

Additionally, the answer I'll provide will not work in 1.16.5 due to the changes past 1.17.

Posted

This mod will be an addon to an existing mod, which only exists in 1.16.5 so updating is completely useless and I need a solution for this version.

If I update it to get an answer I have to backport it which not sounds like a solution.

 

Posted

Then apologies, but then we cannot help you on this forum:

The version you are using is no longer supported on this forum.

Please update to a modern version of Minecraft to receive support.

Currently supported versions are 1.19.2 (Latest) and 1.18.2 (LTS).

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Betafort Recovery has emerged as a prominent figure in the realm of cryptocurrency recovery, gaining a reputation for their exceptional ability to retrieve lost Bitcoin (BTC) and other cryptocurrencies. Their expertise and track record have made them a beacon of hope for individuals facing the distressing situation of lost or inaccessible crypto assets.  
    • When you name a method like that, with no return value, it is a constructor. The constructor must have the same name as the class it constructs, in this case, ModItems. I would strongly advise reading up on some basic Java tutorials, because you will definitely be running into a lot more issues as you go along without the basics. *I should also add that the Forge documentation is a reference, not a tutorial. Even following tutorials, you should know Java basics, otherwise the smallest of mistakes will trip you up as you copy someone elses code.
    • so, I'm starting modding and I'm following the official documantation for forge: https://docs.minecraftforge.net, but in the registries part it is not working as it is in the docs:   public class ModItems { private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, DarkStarvation.MOD_ID); public static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test_item", () -> new Item(new Item.Properties())); public DarkStarvation(FMLJavaModLoadingContext context) { ITEMS.register(context.getModEventBus()); } } in 'public DarkStarvation(...' the DarkStarvation has this error: Invalid method declaration; return type required and the getModEventBus(): Cannot resolve method 'getModEventBus' in 'FMLJavaModLoadingContext' please help, I asked gpt but it is saying that I'm using an old method, but I'm following the latest version of Forge Docs???
    • I merged your second post with the original , there is no need to post a new thread asking for an answer. If someone sees your post and can help, they will reply. If you are seeking a quicker response, you could try asking in the Minecraft Forge diacord.
    • Create a new instance and start with cobblemon - if this works, add the rest of your mods in groups   Maybe another mod is conflicting - like Sodium/Iris or Radical Cobblemon Trainers
  • Topics

×
×
  • Create New...

Important Information

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