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

    • Sometimes, tweaking load order or specific configs can also help ease those conflicts.
    • I have recently tired downloading forge so i can run mods for hypixel skyblock but whenever i download forge and do it the same way as videos and tutorials forge keeps downloading as log file and doesnt download the .jar file any help will be aprecciated.
    • So I have created a Create Mod Server with my friends and i to play everyone can join play except one of my friends because when he tries to launch the game from the CurseForge Launcher it will load but never open or give him a crash report, we have tried everything from deleting CF and reinstalling it to Updating his drivers, IDK what to do if anyone can help I would be very Grateful
    • I get this error when trying to start the server for forged mods. In the code below it mentions distant horizons but no matter what mod I put in (deleting distant horizons) it still gives an error and doesn't launch Crash Report UUID: 3e91d5c7-18a7-43c2-a935-a8d28de560d1 FML: 47.3 Forge: net.minecraftforge:47.3.10[23:33:47] [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [    Distant Horizons (distanthorizons) encountered an error during the sided_setup event phase§7java.lang.ExceptionInInitializerError: null]     at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:246) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$20(ModLoader.java:210) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] {}     at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:210) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at net.minecraftforge.fml.ModLoader.lambda$loadMods$15(ModLoader.java:190) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {}     at net.minecraftforge.fml.ModLoader.loadMods(ModLoader.java:190) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at net.minecraft.server.loading.ServerModLoader.load(ServerModLoader.java:31) ~[forge-1.20.1-47.3.10-universal.jar%23108!/:?] {re:classloading}     at net.minecraft.server.Main.main(Main.java:125) ~[server-1.20.1-20230612.114412-srg.jar%23103!/:?] {re:classloading}     at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:580) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonLaunchHandler.runTarget(CommonLaunchHandler.java:111) ~[fmlloader-1.20.1-47.3.10.jar%2369!/:?] {}     at net.minecraftforge.fml.loading.targets.CommonLaunchHandler.lambda$run$1(CommonLaunchHandler.java:103) ~[fmlloader-1.20.1-47.3.10.jar%2369!/:?] {}     at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$makeService$0(CommonServerLaunchHandler.java:27) ~[fmlloader-1.20.1-47.3.10.jar%2369!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:108) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:78) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] {}  
    • This error keeps coming up after player tries to join server, doesn't happen to anyone else.  Error: Internal Exception: io.netty.handler.codec.DecoderException: java.lang.ArrayIndexOutOfBoundsException: Index 17196645 out of bounds for length 13 Heres the latest.log https://pastebin.com/uaw3KC0K  Heres the debug.log https://drive.google.com/file/d/1QzqtCMUf7ps1Iz85AOsMM7W8QhbHjBeU/view?usp=sharing
  • Topics

×
×
  • Create New...

Important Information

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