Jump to content

defineId called for[1.16.5]


Yurim64

Recommended Posts

Hi!
I'm adding a new entities in minecraft 1.16.5, but when i spawn it, it doesn't render and on the console it send a warning:

This is the console:

[17:29:18] [Server thread/WARN] [minecraft/EntityDataManager]: defineId called for: class net.minecraft.entity.item.minecart.AbstractMinecartEntity from class com.ike.ambulancemod.entity.veichle.ambulance.AmbulanceEntity
[17:29:18] [Server thread/WARN] [minecraft/EntityDataManager]: defineId called for: class net.minecraft.entity.item.minecart.AbstractMinecartEntity from class com.ike.ambulancemod.entity.veichle.ambulance.AmbulanceEntity
[17:29:18] [Server thread/INFO] [minecraft/MinecraftServer]: [Dev: Summoned new entity.ambulance.ambulance]
[17:29:18] [Render thread/INFO] [minecraft/NewChatGui]: [CHAT] Summoned new entity.ambulance.ambulance
[17:29:34] [Server thread/INFO] [minecraft/MinecraftServer]: [Dev: Summoned new entity.ambulance.ambulance]
[17:29:34] [Render thread/INFO] [minecraft/NewChatGui]: [CHAT] Summoned new entity.ambulance.ambulance

This is the Entity Class:

public class AmbulanceEntity extends Entity {

    private int seat = 2;

    private static final DataParameter<Integer> DATA_ID_DISPLAY_BLOCK = EntityDataManager.defineId(AbstractMinecartEntity.class, DataSerializers.INT);
    private static final DataParameter<Boolean> DATA_ID_CUSTOM_DISPLAY = EntityDataManager.defineId(AbstractMinecartEntity.class, DataSerializers.BOOLEAN);

    public AmbulanceEntity(EntityType<? extends AmbulanceEntity> type, World world) {
        super(type, world);
    }

    public AmbulanceEntity(World world) {
        super(AmbulanceType.getType(), world);
    }

    //Stuff For Vehicle
    @Override
    protected void addPassenger(Entity passenger) {
        super.addPassenger(passenger);
    }

    @Override
    protected boolean canAddPassenger(Entity passenger) {
        return super.canAddPassenger(passenger);
    }

    //==================================================

    @Override
    public void load(CompoundNBT nbt) {
        super.load(nbt);
    }

    @Override
    public boolean save(CompoundNBT nbt) {
        return super.save(nbt);
    }

    @Override
    protected void defineSynchedData() {
        this.entityData.define(DATA_ID_DISPLAY_BLOCK, Block.getId(Blocks.AIR.defaultBlockState()));
        this.entityData.define(DATA_ID_CUSTOM_DISPLAY, true);
    }

    @Override
    protected void readAdditionalSaveData(CompoundNBT p_70037_1_) {

    }

    @Override
    public int getId() {
        return super.getId();
    }

    @Override
    protected void addAdditionalSaveData(CompoundNBT p_213281_1_) {

    }

    @Override
    public IPacket<?> getAddEntityPacket() {
        return new SSpawnObjectPacket(this);
    }

    @Override
    public void tick() {
        super.tick();
    }
}

This is where i add the Entity and the Model:

public class AmbulanceMod {

    public static final String MODID = "ambulance";

    private static final Logger LOGGER = LogManager.getLogger();

    public AmbulanceMod() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);

        ForgeRegistries.ENTITIES.register(AmbulanceType.getType());
    }

    private void setup(final FMLCommonSetupEvent event) {
        //TODO Add renderer
        Minecraft.getInstance().getEntityRenderDispatcher().register(AmbulanceType.getType(), new AmbulanceRenderer<>(Minecraft.getInstance().getEntityRenderDispatcher()));
    }
}

This is the renderer:

public class AmbulanceRenderer<T extends AmbulanceEntity> extends EntityRenderer<T> {

    private EntityModel model = new AmbulanceModel();

    public AmbulanceRenderer(EntityRendererManager rendererManager) {
        super(rendererManager);
    }

    @Override
    public void render(T entity, float f_1, float f_2, MatrixStack matrix, IRenderTypeBuffer buffer, int light) {
        super.render(entity, f_1, f_2, matrix, buffer, light);
        matrix.pushPose();
        IVertexBuilder ivertexbuilder = buffer.getBuffer(RenderType.armorCutoutNoCull(this.getTextureLocation(entity)));
        System.out.println("Ok");
        this.model.renderToBuffer(matrix, ivertexbuilder, light, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
        matrix.popPose();
    }

    @Override
    public ResourceLocation getTextureLocation(T p_110775_1_) {
        ResourceLocation resourceLocation = new ResourceLocation(AmbulanceMod.MODID, "model/ambulance");
        System.out.println(resourceLocation);
        return resourceLocation;
    }
}

Can someone help?

Link to comment
Share on other sites

The error is probably your entity doesn't have any attributes. But you need to provide the full debug.log if we're going to diagnose an issue as there is no error context.

 

Other questions/issues:

1 hour ago, Yurim64 said:

@Override

Why are you overriding methods you're not using or calling?

1 hour ago, Yurim64 said:

ForgeRegistries.ENTITIES.register(AmbulanceType.getType());

This makes no sense. What is getType? You have the mod event bus within the constructor, pass that around.

1 hour ago, Yurim64 said:

matrix.pushPose();

This and the pop does nothing. You're not doing any logic that requires these.

1 hour ago, Yurim64 said:

Minecraft.getInstance().getEntityRenderDispatcher().register(AmbulanceType.getType(), new AmbulanceRenderer<>(Minecraft.getInstance().getEntityRenderDispatcher()));

This is not how you should attach a renderer, use RenderingRegistry#registerEntityRenderer or something similar.

1 hour ago, Yurim64 said:

ResourceLocation resourceLocation = new ResourceLocation(AmbulanceMod.MODID, "model/ambulance");

Make this constant, don't keep reconstructing the object.

 

Link to comment
Share on other sites

Ok, thanks for the suggestions.
How can i add attributes to my entity?

I tried using RenderRegistry.registerEntityRenderingHandler ();
The "defineId called for" warning is gone, but it doesn't render the entity anyway.

Edited by Yurim64
Link to comment
Share on other sites

2 hours ago, Yurim64 said:

How can i add attributes to my entity?

You still didn't provide a debug.log, but since you don't know how to add attributes, I'm going to assume you didn't. Create an event handler on the mod bus for EntityAttributeCreationEvent. Pass in your entity type and the associated attribute map. You can look at GlobalEntityTypeAttributes for an example on how to create the attribute map. Most likely you'll chain off of some existing entity.

Link to comment
Share on other sites

Ok so,

I cleaned up the code as you advised me and now I have these classes, but despite this I can't render the model and I don't understand why.

It doesn't even show the shadow below, it has no collisions and more. How can I do? I can't find any valid tutorials for 16.5.

Here is the files:

The Entity Class: https://pastebin.com/AYZ0jN2g

The Entity Renderer: https://pastebin.com/3yYX2UxK

The Entity Model: https://pastebin.com/AvxakRaH

The Registry: https://pastebin.com/U6bE24Ts

The Main Mod Class: https://pastebin.com/rDmrLAFA

The lastest debug.log: https://pastebin.com/bGgZL408 (There is nothing strange in my opinion, the initial warning has disappeared)

 

For the Attributes, i can't use the EntityAttributeCreationEvent because i only for LivingEntity, and my TestVehicleEntity is not a subclass of LivingEntity.

Edited by Yurim64
Link to comment
Share on other sites

2 hours ago, Yurim64 said:

For the Attributes, i can't use the EntityAttributeCreationEvent because i only for LivingEntity, and my TestVehicleEntity is not a subclass of LivingEntity.

Apologies, for some reason I remembered your class extending AnimalEntity.

 

I'll address the issues now:

1. The RenderingRegistry should be called in FMLClientSetupEvent. It is running on the client only after all since the dedicated server has no concept of rendering.

2. At some point, you might want to look into lambdas. (not an issue, just me being picky)

3. TestVehicle#getAddEntityPacket should return NetworkHooks#getEntitySpawningPacket. (this is most likely the root of your cause since vanilla entities have their ids hardcoded in the packet check so your entity gets spawned only on the server)

Link to comment
Share on other sites

Thanks, now my entity is displayed.

Could I ask you for a tutorial for using ModelRenderers?

I am not a great expert in this field, and I would like to understand how they work, how to create them in a personalized way and so on.

Even the part of the texture on how it is rendered I am not familiar with it, I am going a little blind.

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.



×
×
  • Create New...

Important Information

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