• Recently Browsing

    No registered users viewing this page.

  • 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:   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.
    • Well, it should really make a better error message for that.
    • It works now, I made a stupid spelling mistake in the global_loot_modifiers.json so it wasnt registering. Thank you for trying to help despite my dumb mistake.
    • What is the full path to the loot modifier JSON?
    • Oh my god sorry for wasting your time I see the spelling mistake in global_loot_modifiers.json
  • Topics

  • Who's Online (See full list)