Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

(SOLVED)[1.16.4] Block entity invalid


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 post
Share on other sites

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

 

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

Link to post
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 post
Share on other sites
1 minute ago, IntentScarab said:

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?

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

 

2 minutes ago, IntentScarab said:

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

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

Link to post
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 post
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 post
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.

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



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • So I had no clue what topic to put this under because its not really modding with forge but modding forge itself. So I have terrain generation mods that are only server side and Bungeecord that has Geyser packet translator so people on bedrock edition can play as well, but when a bedrock player connects it gets a unknown packet error. I tested the proxy on a Spigot server verifying it was forge. With no mods installed I still get the error. I got a wireshark log of it all and I found the packet where it aborts the connection due to the invalid packet but I have no clue how to stop it. When I still had the mods installed I disabled the forge handshake protocol but it did not fix the issue. If you know what part of forge is doing this or a way to fix it all together that would be awesome. I know modifying forge can end really baddy (definitely the handshake protocol) but I think that is my only fix here. Im open to any suggestions tho. I have run out of ideas to fix it so any help would be nice. Also it seems the packet id causing the connection error is 0xFE but im not sure cause the client also sends back a packet with that ID. I have a whole bunch of info collected so if you need any more information on the issue, I willing to give it, just not the ips on the wireshark log.
    • Okay, I got it working correctly now, but I'm not sure how to make it work with multiple blocks.   My Block Code:   package expanded.blocks; import javax.annotation.Nullable; import expanded.VanillaBuildingBlocks; import net.minecraft.block.BlockState; import net.minecraft.block.RotatedPillarBlock; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.ToolType; public class CustomLog extends RotatedPillarBlock {            public CustomLog(Properties properties) {         super(properties);     }      @Override     @Nullable     public BlockState getToolModifiedState(BlockState state, World world, BlockPos pos, PlayerEntity player, ItemStack stack, ToolType toolType) {         return toolType == ToolType.AXE ? VanillaBuildingBlocks.acacia_log.defaultBlockState() : null;     } }
    • ? Registering the block and overriding a function inside the class are two completely different things
    • Ya but I'm not sure how I would actually add/implement it into the class correctly, and then registering the block correctly in my register class.
    • This tutorial from 1.12.2 is as easy as anyone could possibly explain it, it hasn't changed much til now except some slight changes here and there for you to figure out, it's pretty straightforward (https://www.planetminecraft.com/blog/forge-tutorial-capability-system/). Obviously instead of mana you'd just replace it with whatever else you're doing. All a capability is in essence is the ability to serialize/deserialize standard data types to an entity. When the player dies the game creates a new instance of a PlayerEntity object so your data won't automatically "transfer" over to that new object unless as you say, you copy the data over in an event hook. After you have this set up, if you want to access the data you store in player capabilities you create a class with a static get function that retrieves it.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.