Posted May 22, 20205 yr Hey guys! I want to make something like a coverable block, that get's a texture depending on its blockstate. For that I already made a class CoverableBlock with a Property "BlockContainerProperty" extending Property<String>. The BlockContainerProperty could take every possible block (see code below), and it already works with a block of the CoverableBlock-class. So for example, if the property of the block is set to "diamond ore", it will look like diamond ore. Well, I know the basics of JSON-blockmodels and that I could manually make these models, but then I would have to create tons of similar json-files (all just differing in textures) and I guess it wouldn't work with blocks from other mods. So my question is: Is it possible that the block takes the texture of the block that is saved as a String in its property? And then how do I create the json block-models for that? I'm using Minecraft 1.15 and forge 29.0.4. Code for the BlockContainerPropertyClass: The constructor is to get all blocks from the IForgeRegistry and save them as strings in a list BLOCKS_TO_STRING public class BlockContainerProperty extends Property<String> { private static final IForgeRegistry<Block> BLOCKS = RegistryManager.ACTIVE.getRegistry(Block.class); private static List<String> BLOCKS_TO_STRING; protected BlockContainerProperty(String name) { super(name, String.class); BLOCKS_TO_STRING = new ArrayList<>(); BLOCKS_TO_STRING.add("empty"); for (Block b: BLOCKS) { BLOCKS_TO_STRING.add(Objects.requireNonNull(b.getRegistryName()).getPath().toLowerCase()); } } @Override public Collection<String> getAllowedValues() { return BLOCKS_TO_STRING; } @Override public Optional<String> parseValue(String value) { if(this.getAllowedValues().contains(value)) { return Optional.of(value); } return Optional.empty(); } @Override public String getName(String value) { return value; } public static BlockContainerProperty create(String name) { return new BlockContainerProperty(name); } } The code for the CoverableBlock - Class: public class CoverableBlock extends Block { public static final BlockContainerProperty CONTAINS = BCBlockStateProperties.CONTAINS; public CoverableBlock(Properties properties) { super(properties); this.setDefaultState(this.getDefaultState().with(CONTAINS,"empty")); } @Override protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { builder.add(CONTAINS); } } And the code for BCBlockStateProperties is just this one line, so the Property is shown as "contains:" and then the block: public static final BlockContainerProperty CONTAINS = BlockContainerProperty.create("contains"); And finally this is, how I register the block: public class BCBlocks { private static final Logger LOGGER = LogManager.getLogger(); @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) @ObjectHolder(BlockCarpentryMain.MOD_ID) public static class RegistryEvents { @SubscribeEvent public static void onRegisterBlocks(RegistryEvent.Register<Block> event) { event.getRegistry().registerAll( setup(BCBlockList.coverableBlock = new CoverableBlock(CoverableBlock.Properties.create(Material.WOOD, MaterialColor.WOOD).harvestTool(ToolType.AXE).harvestLevel(0).hardnessAndResistance(0.4f).sound(SoundType.WOOD)), "coverable_block") ); LOGGER.info("Registered all blocks from BlockCarpentry"); } public static <T extends IForgeRegistryEntry<T>> T setup(final T entry, final String name) { return setup(entry, new ResourceLocation(BlockCarpentryMain.MOD_ID, name)); } public static <T extends IForgeRegistryEntry<T>> T setup(final T entry, final ResourceLocation registryName) { entry.setRegistryName(registryName); return entry; } } } I would be very glad, if you could teach me, how to get the block to display the texture of the block that is saved as a string in its property. Sorry for bad english and grammatical errors, I've tried my best. Thanks for help in advance! ? P.S.: If you're wondering what the purpose of that is: Since "Carpenters Blocks" is not yet available for 1.15 and I still want to play the mod with friends, I try to create something similar and this is just the base.
May 22, 20205 yr Author Oh.. Okay, thank you very much. I'll try this! Have a nice day and thanks for telling me ?
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.