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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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