Jump to content

Recommended Posts

Posted (edited)

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
Posted (edited)
  On 5/9/2023 at 5:00 AM, Nuclear_Shmatt said:

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

Expand  

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
Posted

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

Posted

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);
    }

 

Posted
  On 5/9/2023 at 7:39 AM, 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);
    }

 

Expand  

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

Posted

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)

Expand  

 

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.

Expand  

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.

Posted

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.

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

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