Jump to content

[SOLVED] Can't register Tile ( Forge 1.15.2 - 31.2.0 )


BastouP

Recommended Posts

Hey I am not able to register my tile entity type.

 

Here is the type:

public class ModTileTypes {
    public static final TileEntityType<?> RF_METER = TileEntityType.Builder.create(TileRFMeter::new, ModBlocks.RF_METER)
            .build(null).setRegistryName(new ResourceLocation(BPeripheralsProperties.MODID, "rf_meter"));
}

 

Here is the registration:

public class BPeripherals
{
	public BPeripherals() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onItemRegister);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onBlockRegister);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onTileRegister);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onModelRegister);

        MinecraftForge.EVENT_BUS.register(this);
    }

    ...

    public void onTileRegister(RegistryEvent.Register<TileEntityType<?>> event) {
        event.getRegistry().register( //line 45
                ModTileTypes.RF_METER
        );
    }
}

 

and here is the exception:

java.lang.ClassCastException: net.minecraft.tileentity.TileEntityType cannot be cast to net.minecraft.block.Block

and here the full stacktrace: https://pastebin.com/kudRJjxD

 

I hope someone can help me ^^

Edited by BastouP
Link to comment
Share on other sites

Howdy

you might find this example project useful

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe30_inventory_basic

 

I suspect that in your case you have either mixed up your RF_METER objects (one is a block, the other is a TileEntity) or perhaps your

public static final TileEntityType<?> RF_METER = TileEntityType.Builder.

should be

public static final TileEntityType<TileRFMeter> RF_METER = TileEntityType.Builder.

 

-TGG

Link to comment
Share on other sites

2 hours ago, TheGreyGhost said:

I suspect that in your case you have either mixed up your RF_METER objects (one is a block, the other is a TileEntity) or perhaps your


public static final TileEntityType<?> RF_METER = TileEntityType.Builder.

should be

public static final TileEntityType<TileRFMeter> RF_METER = TileEntityType.Builder.

 

 

I tried but there is still the exact same error what's weird is that it tries to Cast my tiletype to a block...

Link to comment
Share on other sites

hmm

 

I'm guessing that your snipped code

...

hides something like

    public void onTileRegister(RegistryEvent.Register<Block> event) {
        event.getRegistry().register( //line 45
                ModTileTypes.RF_METER
        );
    }

i.e. the error isn't in the code that you showed us, it's in the Block register event instead

 

Link to comment
Share on other sites

https://github.com/BastouP411/bperipherals/blob/master/src/main/java/fr/bastoup/bperipherals/BPeripherals.java#L52

  • All items need models, there is no point in attaching a "I have a model!" interface to a class that already knows it needs a model (and that interface exposes things that are already public anyway, so, double-useless).
    Also, this is 1.12 code and isn't needed any more anyway.
  • Don't create things statically, use a DeferredRegister if you want to do that.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Well I downloaded your code and ran it, and something strange is happening.

 

your onTileRegister method is being given the Block Registry event for some reason

 

    public void onTileRegister(RegistryEvent.Register<TileEntityType<?>> event) {
        event.getRegistry().register(
                ModTileTypes.RF_METER
        );
    }

my debugger tells me that event is RegistryEvent.Register<minecraft:block>

 

The same thing happens for RegistryEvent.Register<Item> event) as well.

 

This part of Forge code is particularly difficult for me to understand because it's riddled with lambdas and the code commenting is non-existent, but I really think it should not do that.  I'll keep digging and see if I can find out what's going on.

 

-TGG

 

Link to comment
Share on other sites

Howdy.

 

It seems to be a problem with using FMLJavaModLoadingContext.get().getModEventBus().addListener for your methods, it drops the generics information from the type signature.

 

If you change your code to this instead (i.e. so that your methods are detected using @SubscribeEvent), it works fine.

Probably some folks will tell you to use DeferredRegister instead, but @SubscribeEvent will also work perfectly well.

 

-TGG

 

package fr.bastoup.bperipherals;

import fr.bastoup.bperipherals.init.ModBlocks;
import fr.bastoup.bperipherals.init.ModItems;
import fr.bastoup.bperipherals.init.ModTileTypes;
import fr.bastoup.bperipherals.util.IHasModel;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntityType;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import fr.bastoup.bperipherals.util.BPeripheralsProperties;
import net.minecraftforge.fml.common.Mod;

@Mod(BPeripheralsProperties.MODID)
public class BPeripherals
{

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

  // get a reference to the event bus for this mod;  Registration events are fired on this bus.
  public static IEventBus MOD_EVENT_BUS;

  public BPeripherals() {
//        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onItemRegister);
//        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onBlockRegister);
//        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onTileRegister);
//        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onModelRegister);

//        MinecraftForge.EVENT_BUS.register(this);

      MOD_EVENT_BUS = FMLJavaModLoadingContext.get().getModEventBus();
      MOD_EVENT_BUS.register(this);
    }

  @SubscribeEvent
    public void onItemRegister(final RegistryEvent.Register<Item> event) {
        event.getRegistry().registerAll(ModItems.ITEMS.toArray(new Item[0]));
    }

  @SubscribeEvent
    public void onBlockRegister(final RegistryEvent.Register<Block> event) {
        event.getRegistry().registerAll(ModBlocks.BLOCKS.toArray(new Block[0]));
    }

  @SubscribeEvent
    public void onTileRegister(final RegistryEvent.Register<TileEntityType<?>> event) {
        event.getRegistry().register(
                ModTileTypes.RF_METER
        );
    }

  @SubscribeEvent
    public void onModelRegister(final ModelRegistryEvent event) {
        for (Item item : ModItems.ITEMS) {
            if(item instanceof IHasModel) {
                ((IHasModel) item).registerModels();
            }
        }

        for (Block block : ModBlocks.BLOCKS) {
            if(block instanceof IHasModel) {
                ((IHasModel) block).registerModels();
            }
        }
    }

	public static Logger getLogger() {
		return LOGGER;
	}
}

 

Link to comment
Share on other sites

6 hours ago, loordgek said:

should addListener throw a exception if you try to add a GenericListener ??

It probably can't. By the time the lambda is passed to the method, the fact that it was generic was probably irretrievably lost.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

17 minutes ago, diesieben07 said:

It could, by checking for the event being a GenericEvent.

I wasn't sure if there the information was accessible, or if the actual handler got wrapped in something by the JVM, effectively hiding the true signature.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

On 5/24/2020 at 7:21 PM, loordgek said:

should addListener throw a exception if you try to add a GenericListener ??

 

cpw created an issue for that a while ago, but hasn't gotten around to fixing it yet.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Turns out I was kind of right:

Quote

Sadly, it's difficult to detect the wrong addListener call being used, as genericity isn't known at the time.

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Post logs as per https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/ They may have information that will answer these questions.
    • I was left reeling when a glitch on a cryptocurrency exchange caused me to lose $166,000 worth of my hard-earned savings. It felt like my entire world had crumbled in the blink of an eye, leaving me with a sense of hopelessness. Determined not to give up, I delved into research on recovery options, unsure of what to expect. That's when I stumbled upon I was left reeling when a glitch on a cryptocurrency exchange caused me to lose $166,000 worth of my hard-earned savings. It felt like my entire world had crumbled in the blink of an eye, leaving me with a sense of hopelessness. Determined not to give up, I delved into research on recovery options, unsure of what to expect. That's when I stumbled upon DIGITAL HACK RECOVERY, a beacon of hope in my darkest hour. Despite my initial doubts, I decided to take a leap of faith and give them a shot as a final lifeline. The experts at DIGITAL HACK RECOVERY proved to be masters of their craft, guiding me through their exclusive process with precision and expertise. Utilizing cutting-edge blockchain analysis methods, they were able to track down the elusive trail of my missing funds and identify the exact point of failure. Their forensic talents were unparalleled as they tirelessly combed through the intricate web of blockchain data to locate my cryptocurrency. With each step they took, they kept me informed of their progress, never wavering in their belief that my funds could be rescued. After several painstaking weeks, DIGITAL HACK RECOVERY finally located and restored my $166,000 worth of cryptocurrency. I was awestruck that they were able to salvage what I had thought was lost forever. The whole experience restored my faith in the crypto space and proved that even in the worst situations, recovery is possible with the right experts on your side. I will be forever grateful to DIGITAL HACK RECOVERY for giving me back my life savings when I needed it most. Their tireless efforts and technical mastery turned what could have been a devastating loss into an uplifting success story. Book a time with DIGITAL HACK RECOVERY through: digital hack recovery @ techie . com &  +12018871705
    • public class ParticleReboundRecipe implements Recipe<CraftingContainer> { private List<ParticleReboundIngredient> inputs; private ParticleReboundFuel fuel; private ItemStack output; public ParticleReboundRecipe(List<ParticleReboundIngredient> inputs, ParticleReboundFuel fuel, ItemStack output) { this.inputs = inputs; this.fuel = fuel; this.output = output; } // TODO: Implement interface ... // TODO: Move to separate file if desired public record ParticleReboundIngredient(Ingredient ingredient, int count) { public static final Codec<ParticleReboundIngredient> CODEC = RecordCodecBuilder.create( builder -> builder.group( Ingredient.CODEC.fieldOf("ingredient").forGetter((i) -> i.ingredient), Codec.INT.fieldOf("count").forGetter(i -> i.count) ).apply(builder, ParticleReboundIngredient::new) ); } // TODO: Move to separate file if desired public record ParticleReboundFuel(String tag) { public static final Codec<ParticleReboundFuel> CODEC = RecordCodecBuilder.create( builder -> builder.group(Codec.STRING.fieldOf("tag").forGetter(f -> f.tag)).apply(builder, ParticleReboundFuel::new) ); public boolean isFuel(ItemStack stack) { // TODO: Check if fuel item matches the tag } } public class Serializer implements RecipeSerializer<ParticleReboundRecipe> { public static final Codec<ParticleReboundRecipe> CODEC = RecordCodecBuilder.create( builder -> builder.group( ParticleReboundIngredient.CODEC.listOf().fieldOf("inputs").forGetter(r -> r.inputs), ParticleReboundFuel.CODEC.fieldOf("fuel").forGetter(r -> r.fuel), ItemStack.CODEC.fieldOf("output").forGetter(r -> r.output) ).apply(builder, ParticleReboundRecipe::new) ); @Override public @NotNull Codec<ParticleReboundRecipe> codec() { return CODEC; } // TODO: The rest ... } }   ?
    • I'm sure load and SaveAdditional are what you are looking for, probably. Mind sharing your BE class code? You also need to override onLoad method if you haven't
  • Topics

×
×
  • Create New...

Important Information

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