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

    • 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.