Jump to content

Custom TNT - Cannot Resolve Constructor


Nuclear_Shmatt

Recommended Posts

I've been trying to create custom TNT, and it keeps saying "Cannot resolve constructor" in the RegistryObject:

The custom TNT class:

package net.nuclear_shmatt.yournewmod.entity.item.custom;

import net.minecraft.world.entity.*;
import net.minecraft.world.entity.item.PrimedTnt;
import net.minecraft.world.level.Level;
import net.nuclear_shmatt.yournewmod.entity.ModEntityTypes;

import javax.annotation.Nullable;

public class PrimedLumeniteTnt extends PrimedTnt {
    @Nullable
    private LivingEntity owner;

    public PrimedLumeniteTnt(EntityType<? extends PrimedLumeniteTnt> type, Level level) {
        super(type, level);
    }

    public PrimedLumeniteTnt(Level level, double x, double y, double z, @Nullable LivingEntity igniter) {
        this(ModEntityTypes.LUMENITE_TNT.get(), level);
        this.setPos(x, y, z);
        double d0 = level.random.nextDouble() * (double)((float)Math.PI * 2F);
        this.setDeltaMovement(-Math.sin(d0) * 0.02D, (double)0.2F, -Math.cos(d0) * 0.02D);
        this.setFuse(80);
        this.xo = x;
        this.yo = y;
        this.zo = z;
        this.owner = igniter;
    }

    @Nullable
    public LivingEntity getOwner() {
        return this.owner;
    }

    @Override
    protected void explode() {
        float f = 4.0F;
        this.level.explode(this, this.getX(), this.getY(0.0625D), this.getZ(), f, Level.ExplosionInteraction.TNT);
    }
}


And this is the registry:

package net.nuclear_shmatt.yournewmod.entity;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import net.nuclear_shmatt.yournewmod.YourNewMod;
import net.nuclear_shmatt.yournewmod.entity.item.custom.PrimedLumeniteTnt;

public class ModEntityTypes {
    public static final DeferredRegister<EntityType<?>> ENTITY_TYPES =
            DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, YourNewMod.MODID);
    public static final RegistryObject<EntityType<? extends PrimedLumeniteTnt>> LUMENITE_TNT = ENTITY_TYPES.register("lumenite_tnt",
        () -> EntityType.Builder.of(PrimedLumeniteTnt::new, MobCategory.MISC)
                .fireImmune()
                .sized(0.98F, 0.98F)
                .build(new ResourceLocation(YourNewMod.MODID, "lumenite_tnt").toString()));

    public static void register(IEventBus eventBus) {
        ENTITY_TYPES.register(eventBus);
    }
}

"PrimedLumenite::new", new is underlined with red.

Edited by Nuclear_Shmatt
Link to comment
Share on other sites

Just now, Nuclear_Shmatt said:

"PrimedLumenite::new", new is underlined with red.

Its not happy with the constructor you currently have, delete it and when it suggests to create a constructor in the registry just create it there and see if it works. I wouldn't know what the correct constructor would be since I've never worked with PrimedTnt before.

Edited by sFXprt
Link to comment
Share on other sites

I went out of my way to debug it for you, I got the error to go away. Here is your final Code

PrimedLumeniteTnt

public class PrimedLumeniteTnt extends PrimedTnt {
    @Nullable
    private LivingEntity owner;

    public PrimedLumeniteTnt(Level level, double x, double y, double z, @Nullable LivingEntity igniter) {
        this(EntityInit.LUMENITE_TNT.get(), level);
        this.setPos(x, y, z);
        double d0 = level.random.nextDouble() * (double)((float)Math.PI * 2F);
        this.setDeltaMovement(-Math.sin(d0) * 0.02D, (double)0.2F, -Math.cos(d0) * 0.02D);
        this.setFuse(80);
        this.xo = x;
        this.yo = y;
        this.zo = z;
        this.owner = igniter;
    }

    public PrimedLumeniteTnt(EntityType<Entity> entityEntityType, Level level) {
        super((EntityType<? extends PrimedTnt>) entityEntityType, level);
    }

    @Nullable
    public LivingEntity getOwner() {
        return this.owner;
    }

    @Override
    protected void explode() {
        float f = 4.0F;
        this.level.explode(this, this.getX(), this.getY(0.0625D), this.getZ(), f, Explosion.BlockInteraction.BREAK);
    }
}

 

And here is where you register it

public static final RegistryObject<EntityType<Entity>> LUMENITE_TNT = ENTITY_TYPES.register("lumenite_tnt",
            () -> EntityType.Builder.of(PrimedLumeniteTnt::new, MobCategory.MISC)
                    .fireImmune()
                    .sized(0.98F, 0.98F)
                    .build(new ResourceLocation(Main.MOD_ID, "lumenite_tnt").toString()));

 

I think what happened here is when you tried to extend your tnt class when in fact you should've just put <Entity> since PrimedTnt is extending Entity

Link to comment
Share on other sites

Well, that has resolved that.
Now a new problem has showed up:
Overlayed on "(EntityType<? extends PrimedTnt> type)", it says "Unchecked cast: 'net.minecraft.world.entity.EntityType<net.minecraft.world.entity.Entity>' to 'net.minecraft.world.entity.EntityType<? extends net.minecraft.world.entity.item.PrimedTnt>' "

    public PrimedLumeniteTnt(EntityType<Entity> type, Level level) {
        super((EntityType<? extends PrimedTnt>) type, level);
    }

 

Link to comment
Share on other sites

Just now, Nuclear_Shmatt said:

Well, that has resolved that.
Now a new problem has showed up:
Overlayed on "(EntityType<? extends PrimedTnt> type)", it says "Unchecked cast: 'net.minecraft.world.entity.EntityType<net.minecraft.world.entity.Entity>' to 'net.minecraft.world.entity.EntityType<? extends net.minecraft.world.entity.item.PrimedTnt>' "

    public PrimedLumeniteTnt(EntityType<Entity> type, Level level) {
        super((EntityType<? extends PrimedTnt>) type, level);
    }

 

I made a mistake, Im currently not at an IDE right but can you just pass in ur Entity.get() thru ur init?

Link to comment
Share on other sites

From what I understand (I didn't look that closely) the original code was correct except it lacked the usual type parameter needed for the builder?

This is because the compiler can't infer the type in that code so you have to tell it.

Something like this untested code:

Quote

public static final RegistryObject<EntityType<? extends PrimedLumeniteTnt>> LUMENITE_TNT = ENTITY_TYPES.register("lumenite_tnt", () -> EntityType.Builder.<PrimedLumeniteTnt>of(PrimedLumeniteTnt::new, MobCategory.MISC)

 

But note the subtile of this forum. If you are posting compiler errors, you are in the wrong place. You really want a learning java forum.

Quote

This is the support section for those modding with Forge. Help with modding goes in here, however, please keep in mind that this is not a Java school. You are expected to have basic knowledge of Java before posting here.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Well, I somehow fixed the issue by just removing the constructor and rewriting the same thing.
I don't understand but I'm okay with this.

    public PrimedLumeniteTnt(EntityType<? extends PrimedLumeniteTnt> entityType, Level level) {
        super(entityType, level);
    }

So, my issue is solved.

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.