Jump to content

(SOLVED)[1.16.4] Block entity invalid


IntentScarab

Recommended Posts

I have a block that has four different tiers (SMALL, MEDIUM, LARGE, CREATIVE), I had everything working but then I wanted to send the tier of block down the pipeline to the container where it can be used, so I'm sending the tile down.

The Tile accepts the Tier as a value to pass to its constructor, but for some reason I get an error in the console when I place any of this block that is not the CreativeTier. So if I place a Small/Medium/Large block then I get this error:

Quote

[14:50:14] [Render thread/WARN] [minecraft/TileEntity]: Block entity invalid: experienced:experience_block_creative @ BlockPos{x=-227, y=4, z=-218}
[14:50:14] [Server thread/WARN] [minecraft/TileEntity]: Block entity invalid: experienced:experience_block_creative @ BlockPos{x=-227, y=4, z=-218}

 

I've searched on here and I get not much to go on. And when I step through with the debugger, all the Tiles seem to be registered just like my Items and Blocks.

 

Code here:

My Registration Class:

public class Registration {

    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Constants.MOD_ID);
    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Constants.MOD_ID);
    public static final DeferredRegister<IRecipeSerializer<?>> RECIPES = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, Constants.MOD_ID);
    public static final DeferredRegister<TileEntityType<?>> TILES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, Constants.MOD_ID);
    public static final DeferredRegister<ContainerType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS, Constants.MOD_ID);

    public static void register(){

        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

        // The deferred registries
        BLOCKS.register(modEventBus);
        ITEMS.register(modEventBus);
        RECIPES.register(modEventBus);
        TILES.register(modEventBus);
        CONTAINERS.register(modEventBus);

        // Registry objects are registered
        ModItems.register();
        ModBlocks.register();
        ModRecipes.register();
        ModTiles.register();
        ModContainers.register();

    }
}

 

My ModTiles code:

@Mod.EventBusSubscriber(modid = Constants.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModTiles {

    public static final DeferredRegister<TileEntityType<?>> TILES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, Constants.MOD_ID);

    public static final RegistryObject<TileEntityType<ExperienceBlockTile>> EXPERIENCE_BLOCK_SMALL;
    public static final RegistryObject<TileEntityType<ExperienceBlockTile>> EXPERIENCE_BLOCK_MEDIUM;
    public static final RegistryObject<TileEntityType<ExperienceBlockTile>> EXPERIENCE_BLOCK_LARGE;
    public static final RegistryObject<TileEntityType<ExperienceBlockTile>> EXPERIENCE_BLOCK_CREATIVE;

    static {

        EXPERIENCE_BLOCK_SMALL = TILES.register("experience_block_small", ()-> TileEntityType.Builder.create(
                ()-> new ExperienceBlockTile(ExperienceBlock.Tier.SMALL), ModBlocks.EXPERIENCE_BLOCKS.get(ExperienceBlock.Tier.SMALL).get()
        ).build(null));
        EXPERIENCE_BLOCK_MEDIUM = TILES.register("experience_block_medium", ()-> TileEntityType.Builder.create(
                ()-> new ExperienceBlockTile(ExperienceBlock.Tier.MEDIUM), ModBlocks.EXPERIENCE_BLOCKS.get(ExperienceBlock.Tier.MEDIUM).get()
        ).build(null));
        EXPERIENCE_BLOCK_LARGE = TILES.register("experience_block_large", ()-> TileEntityType.Builder.create(
                ()-> new ExperienceBlockTile(ExperienceBlock.Tier.LARGE), ModBlocks.EXPERIENCE_BLOCKS.get(ExperienceBlock.Tier.LARGE).get()
        ).build(null));
        EXPERIENCE_BLOCK_CREATIVE = TILES.register("experience_block_creative", ()-> TileEntityType.Builder.create(
                ()-> new ExperienceBlockTile(ExperienceBlock.Tier.CREATIVE), ModBlocks.EXPERIENCE_BLOCKS.get(ExperienceBlock.Tier.CREATIVE).get()
        ).build(null));
    }

    public static void register() {
        TILES.register(FMLJavaModLoadingContext.get().getModEventBus());
    }
}

 

My ExperienceBlock Class just in  case:

public class ExperienceBlock extends Block {

    // The tiers of the experience block, this makes it easy to register the blocks and all that sort of stuff
    public static Tier BLOCK_TIER;

    public enum Tier {
        SMALL("small"),
        MEDIUM("medium"),
        LARGE("large"),
        CREATIVE("creative");

        final String name;

        Tier(String name){
            this.name = name;
        }

        public String getName(){
            return name;
        }
    }

    public ExperienceBlock(Tier tier) {
        super(AbstractBlock
                .Properties
                .create(Material.ROCK)
                .harvestLevel(2));
        BLOCK_TIER = tier;
    }

    //region Gui Functions

    //region Tile Entity

    @Override
    public boolean hasTileEntity(BlockState state) {
        return true;
    }

    @Nullable
    @Override
    public TileEntity createTileEntity(BlockState state, IBlockReader world) {
        return new ExperienceBlockTile(BLOCK_TIER);
    }

    //endregion

    @Nullable
    @Override
    public INamedContainerProvider getContainer(BlockState state, World worldIn, BlockPos pos) {
        TileEntity tile = worldIn.getTileEntity(pos);
        return tile instanceof INamedContainerProvider ? (INamedContainerProvider) tile : null;
    }

    //endregion

    @Override
    public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {

        if(worldIn.isRemote){
            return ActionResultType.SUCCESS;
        }

        // If the selected block has no container then one will be made for it
        INamedContainerProvider nmContainer = this.getContainer(state, worldIn, pos);
        if(nmContainer != null){

            TileEntity tile = worldIn.getTileEntity(pos);
            NetworkHooks.openGui((ServerPlayerEntity) player, nmContainer, (packetBuffer -> {}));
        }
        return ActionResultType.SUCCESS;
    }

    @Override
    public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {

        if(state.getBlock() != newState.getBlock()){
            TileEntity tile = worldIn.getTileEntity(pos);

            if(tile instanceof ExperienceBlockTile){
                ExperienceBlockTile tileEntity = (ExperienceBlockTile) tile;
                tileEntity.dropContents(worldIn, pos);
            }
            super.onReplaced(state, worldIn, pos, newState, isMoving);
        }
    }

    //region Helper Methods for Block

    // Method used to initialize the max amount of exp a certain block can hold
    // For now; Small = 30, Medium = 60, Large = 100, Creative = MAX_VALUE, and default is 0 cause that might not happen
    public static int getMaxExpFromTier(Tier tier){
        switch(tier){
            case SMALL:
                return 1395;
            case MEDIUM:
                return 8670;
            case LARGE:
                return 30970;
            case CREATIVE:
                return Integer.MAX_VALUE;
            default:
                return 0;
        }
    }

    //endregion
}

 

 

I also don't like how the registry objects are so verbose in my code tbh. I have the blocks in an EnumMap and just foreach through them all and that seems to work.

Please help me here cause I've been stuck on this for a while.

Edited by IntentScarab
Link to comment
Share on other sites

7 minutes ago, diesieben07 said:

First of all, do not put the DeferredRegister and its registry object in separate classes. You will break things.

So I should delete the DeferredRegisters in the Registration class and just keep them separate in their respective classes? So ModItems gets the DeferrefRegister and so on?

I did notice that when I changed in ModTiles from the DeferredRegister in Registration to the specific class DefReg it actually registered, so that explains something to me.

 

10 minutes ago, diesieben07 said:

Then, I'm guessing the issue is that you do not use the correct TileEntityType in your tile entity when calling the super constructor.

This is my ExperienceBlockTile constructor and the getTier method that returns the Tile:

 

public ExperienceBlockTile(ExperienceBlock.Tier tier) {
        super(getTier(tier));

        inputContents = ExperienceBlockContents.createForTileEntity(INPUT_SLOTS,
                this::canPlayerAccessInventory,
                this::markDirty);

        outputContents = ExperienceBlockContents.createForTileEntity(OUTPUT_SLOTS,
                this::canPlayerAccessInventory,
                this::markDirty);

        expBarContents = ExperienceBlockContents.createForTileEntity(EXP_BAR_SLOT,
                this::canPlayerAccessInventory,
                this::markDirty);
    }

    public static TileEntityType<ExperienceBlockTile> getTier(ExperienceBlock.Tier tier){
        switch (tier){
            case SMALL:
                return ModTiles.EXPERIENCE_BLOCK_SMALL.get();
            case MEDIUM:
                return ModTiles.EXPERIENCE_BLOCK_MEDIUM.get();
            case LARGE:
                return ModTiles.EXPERIENCE_BLOCK_LARGE.get();
            case CREATIVE:
                return ModTiles.EXPERIENCE_BLOCK_CREATIVE.get();
            default:
                throw new IllegalArgumentException("Unkown tier: " + tier);
        }
    }

 

Link to comment
Share on other sites

8 minutes ago, diesieben07 said:

Yes. A good reminder is to make DeferredReigster fields private.

Sweet, made those changes now, thank you

 

8 minutes ago, diesieben07 said:

Hm, looks alright on first glance. Please post a Git repo of your mod.

https://github.com/RhysGrabany/Experienced

Here you go, the changes I've made rn are under the tile_passing branch

Link to comment
Share on other sites

4 minutes ago, diesieben07 said:

Please learn what static means and why it is not appropriate here.

I've been coding for like four years and it seems like I still don't know what it means. I'm gonna research what it means now cause it's been too long 😅

 

I've took off the static property and commented out all the code that was complaining for the meantime.

That has cleared up the problem about the error showing.

 

Thank you for the help!!

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

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

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