Posted May 22, 20205 yr 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 May 24, 20205 yr by BastouP
May 23, 20205 yr 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
May 23, 20205 yr Author 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...
May 23, 20205 yr 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 Â
May 23, 20205 yr Author Here is the repo : https://github.com/BastouP411/bperipherals  The code that throws the error is on line 45 in class fr.bastoup.bperipherals.BPeripherals
May 23, 20205 yr 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.
May 23, 20205 yr Author Yup, that's indeed 1.12 code as I'm currently upgrading my code ^^ And about the IHasModel I just read about it this morning. Dou you think it comes from it ?
May 24, 20205 yr 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 Â
May 24, 20205 yr 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; } } Â
May 24, 20205 yr Author OK that's strange but everything seems to be loading. So we can say it works ! Thanks a lot
May 24, 20205 yr 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.
May 24, 20205 yr 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.
May 25, 20205 yr 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.
May 25, 20205 yr 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.
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.