Posted July 9, 20178 yr Hello, Im currently having issues with getting my custom slab to display properly in the inventory. However, they do place fine in the world. I just need to work out the kink on why the inventory ones wont load. the console displays "Caused by: java.io.FileNotFoundException: bkproject:models/item/stained_clay_slab_low.json" however the tutorial provided below does not even have those files. Used this tutorial for creating the slabs: https://github.com/Choonster-Minecraft-Mods/TestMod3 Placed in world: In inventory: The console displays this error: (Does this for both stained_clay_slab_low/high) [03:25:07] [main/ERROR] [FML] []: Exception loading model for variant bkproject:stained_clay_slab_low#inventory for item "bkproject:stained_clay_slab_low", normal location exception: net.minecraftforge.client.model.ModelLoaderRegistry$LoaderException: Exception loading model bkproject:item/stained_clay_slab_low with loader VanillaLoader.INSTANCE, skipping at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:153) ~[ModelLoaderRegistry.class:?] at net.minecraftforge.client.model.ModelLoader.loadItemModels(ModelLoader.java:297) ~[ModelLoader.class:?] at net.minecraft.client.renderer.block.model.ModelBakery.loadVariantItemModels(ModelBakery.java:175) ~[ModelBakery.class:?] at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:160) ~[ModelLoader.class:?] at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?] at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:121) [SimpleReloadableResourceManager.class:?] at net.minecraft.client.Minecraft.init(Minecraft.java:554) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:416) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?] at GradleStart.main(GradleStart.java:26) [start/:?] Caused by: java.io.FileNotFoundException: bkproject:models/item/stained_clay_slab_low.json at net.minecraft.client.resources.FallbackResourceManager.getResource(FallbackResourceManager.java:69) ~[FallbackResourceManager.class:?] at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:65) ~[SimpleReloadableResourceManager.class:?] at net.minecraft.client.renderer.block.model.ModelBakery.loadModel(ModelBakery.java:334) ~[ModelBakery.class:?] at net.minecraftforge.client.model.ModelLoader.access$1600(ModelLoader.java:126) ~[ModelLoader.class:?] at net.minecraftforge.client.model.ModelLoader$VanillaLoader.loadModel(ModelLoader.java:899) ~[ModelLoader$VanillaLoader.class:?] at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:149) ~[ModelLoaderRegistry.class:?] ... 20 more ModBlocks.java package simplexdesigns.bkproject.init; import java.util.HashSet; import java.util.Set; import com.google.common.base.Preconditions; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder; import net.minecraftforge.registries.IForgeRegistry; import simplexdesigns.bkproject.BkProject; import simplexdesigns.bkproject.block.*; import simplexdesigns.bkproject.util.Constants; @SuppressWarnings("WeakerAccess") @ObjectHolder(BkProject.MODID) public class ModBlocks { /*public static final BlockTest TESTBLOCK = new BlockTest(Material.ROCK, "Test Block");*/ public static class Slabs { public static final BlockClaySlab.ColouredSlabGroup STAINED_CLAY_SLABS = new BlockClaySlab.ColouredSlabGroup("stained_clay_slab", Material.ROCK); } @Mod.EventBusSubscriber(modid = BkProject.MODID) public static class RegistrationHandler { public static final Set<ItemBlock> ITEM_BLOCKS = new HashSet<>(); /** * Register this mod's {@link Block}s. * * @param event The event */ @SubscribeEvent public static void registerBlocks(final RegistryEvent.Register<Block> event) { final IForgeRegistry<Block> registry = event.getRegistry(); final Block[] blocks = { }; registry.registerAll(blocks); registerSlabGroup(registry, Slabs.STAINED_CLAY_SLABS.high); registerSlabGroup(registry, Slabs.STAINED_CLAY_SLABS.low); } /** * Register the {@link Block}s of a {@link BlockSlabClay.SlabGroup}. * * @param registry The registry * @param slabGroup The slab group */ private static void registerSlabGroup(final IForgeRegistry<Block> registry, final BlockSlabClay.SlabGroup<?, ?, ?> slabGroup) { registry.register(slabGroup.singleSlab); registry.register(slabGroup.doubleSlab); } /** * Register this mod's {@link ItemBlock}s. * * @param event The event */ @SubscribeEvent public static void registerItemBlocks(final RegistryEvent.Register<Item> event) { final ItemBlock[] items = { /*new ItemBlock(WATER_GRASS),*/ Slabs.STAINED_CLAY_SLABS.low.item, Slabs.STAINED_CLAY_SLABS.high.item, }; final IForgeRegistry<Item> registry = event.getRegistry(); for (final ItemBlock item : items) { final Block block = item.getBlock(); final ResourceLocation registryName = Preconditions.checkNotNull(block.getRegistryName(), "Block %s has null registry name", block); registry.register(item.setRegistryName(registryName)); ITEM_BLOCKS.add(item); } registerTileEntities(); } } private static void registerTileEntities() { } private static void registerTileEntity(final Class<? extends TileEntity> tileEntityClass, final String name) { GameRegistry.registerTileEntity(tileEntityClass, Constants.RESOURCE_PREFIX + name); } private static void registerRender(Block block){ Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory")); } } BlockClaySlab.java package simplexdesigns.bkproject.block; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumDyeColor; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.IStringSerializable; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import simplexdesigns.bkproject.util.OreDictUtils; import javax.annotation.Nullable; import java.util.Collection; import java.util.Iterator; import java.util.Optional; import java.util.function.Predicate; /** * A slab that uses vanilla's dye colours. * <p> * Test for this thread: * http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2597500-how-do-you-create-a-halfslab * * @author Choonster */ public abstract class BlockClaySlab extends BlockSlabClay<EnumDyeColor, BlockClaySlab.EnumColourGroup, BlockClaySlab> { /** * Create a coloured slab block. * * @param material The Material of this slab * @param colourGroup This slab's colour group * @param slabGroup The group this slab belongs to */ public BlockClaySlab(final Material material, final EnumColourGroup colourGroup, final SlabGroup<EnumDyeColor, EnumColourGroup, BlockClaySlab> slabGroup) { super(material, slabGroup, colourGroup); } @SuppressWarnings("deprecation") @Override public MapColor getMapColor(final IBlockState state, final IBlockAccess world, final BlockPos pos) { return MapColor.getBlockColor(state.getValue(getVariantProperty())); } @Override public String getUnlocalizedName(final int meta) { return getUnlocalizedName() + "." + getVariant(meta).getUnlocalizedName(); } /** * Get the metadata value for the specified colour * * @param colour The colour * @return The metadata value */ @Override public int getMetadata(final EnumDyeColor colour) { return variants.getOffsetMetadata(colour); } /** * Get the colour for the specified metadata value * * @param meta The metadata value * @return The colour */ @Override protected EnumDyeColor getVariant(final int meta) { return variants.byOffsetMetadata(meta); } @Override public boolean recolorBlock(final World world, final BlockPos pos, final EnumFacing side, final EnumDyeColor colour) { final IBlockState currentState = world.getBlockState(pos); return variants.isColourInGroup(colour) && currentState.getValue(getVariantProperty()) != colour && world.setBlockState(pos, currentState.withProperty(getVariantProperty(), colour)); } @Override public boolean onBlockActivated(final World worldIn, final BlockPos pos, final IBlockState state, final EntityPlayer playerIn, final EnumHand hand, final EnumFacing side, final float hitX, final float hitY, final float hitZ) { final ItemStack heldItem = playerIn.getHeldItem(hand); if (!heldItem.isEmpty()) { final Optional<EnumDyeColor> dyeColour = OreDictUtils.INSTANCE.getDyeColour(heldItem); if (dyeColour.isPresent()) { final boolean success = recolorBlock(worldIn, pos, side, dyeColour.get()); if (success) { heldItem.shrink(1); return true; } } } return false; } @Override public Comparable<?> getTypeForItem(final ItemStack stack) { return variants.byOffsetMetadata(stack.getMetadata()); } /** * A group of {@link EnumDyeColor} values. */ public enum EnumColourGroup implements Iterable<EnumDyeColor>, IStringSerializable { LOW("low", colour -> colour.getMetadata() < 8, 0), HIGH("high", colour -> colour.getMetadata() >= 8, 8); /** * The property with this group's colours as the allowed values */ public final IProperty<EnumDyeColor> property; /** * The offset to subtract from each colour's metadata value */ private final int metaOffset; /** * The name of this group */ private final String name; /** * The colours in this group */ private final Collection<EnumDyeColor> values; /** * Create a colour group * * @param name The name of this group * @param colourFilter A filter to obtain the colours in this group * @param metaOffset The offset to subtract from each colour's metadata value */ EnumColourGroup(final String name, final Predicate<EnumDyeColor> colourFilter, final int metaOffset) { this.name = name; this.property = PropertyEnum.create("colour", EnumDyeColor.class, colourFilter::test); this.metaOffset = metaOffset; this.values = this.property.getAllowedValues(); } /** * Get the metadata value of the specified colour with this group's offset. * * @param colour The colour * @return The offset metadata value */ public int getOffsetMetadata(final EnumDyeColor colour) { return colour.getMetadata() - metaOffset; } /** * Get the colour of the specified metadata value with this group's offset * * @param meta The offset metadata value * @return The colour */ public EnumDyeColor byOffsetMetadata(final int meta) { return EnumDyeColor.byMetadata(meta + metaOffset); } /** * Returns an iterator over elements of type {@code T}. * * @return an Iterator. */ @Override public Iterator<EnumDyeColor> iterator() { return values.iterator(); } @Override public String getName() { return name; } /** * Is the specified colour in this group? * * @param colour The colour * @return True if the colour is in this group */ public boolean isColourInGroup(final EnumDyeColor colour) { return values.contains(colour); } /** * Get the first group containing the specified colour. * * @param colour The colour * @return A group containing the colour, or null if there isn't one */ @Nullable public static EnumColourGroup getGroupForColour(final EnumDyeColor colour) { for (final EnumColourGroup colourGroup : values()) { if (colourGroup.isColourInGroup(colour)) { return colourGroup; } } return null; } } public static class ColouredSlabGroup { public final SlabGroup<EnumDyeColor, EnumColourGroup, BlockClaySlab> low; public final SlabGroup<EnumDyeColor, EnumColourGroup, BlockClaySlab> high; /** * Create a coloured slab group. * * @param groupName The group's name * @param material The Material of the slabs */ public ColouredSlabGroup(final String groupName, final Material material) { low = createGroup(groupName, material, EnumColourGroup.LOW); high = createGroup(groupName, material, EnumColourGroup.HIGH); } /** * Create a slab group. * * @param groupName The group's name * @param material The Material of the slabs * @param colourGroup The colour group * @return The slab group */ private SlabGroup<EnumDyeColor, EnumColourGroup, BlockClaySlab> createGroup(final String groupName, final Material material, final EnumColourGroup colourGroup) { return new SlabGroup<EnumDyeColor, EnumColourGroup, BlockClaySlab>(groupName, material, colourGroup) { @Override public BlockClaySlab createSlab(final Material material, final boolean isDouble, final EnumColourGroup colourGroup) { return new BlockClaySlab(material, colourGroup, this) { @Override public boolean isDouble() { return isDouble; } @Override public IProperty<EnumDyeColor> getVariantProperty() { return colourGroup.property; } }; } }; } /** * Get the slab group for the specified colour group. * * @param colourGroup The colour group * @return The slab group */ public SlabGroup<EnumDyeColor, EnumColourGroup, BlockClaySlab> getSlabGroupByColourGroup(final EnumColourGroup colourGroup) { return colourGroup == EnumColourGroup.LOW ? low : high; } } } BlockSlabClay.java package simplexdesigns.bkproject.block; import net.minecraft.block.BlockSlab; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemSlab; import net.minecraft.item.ItemStack; import net.minecraft.util.IStringSerializable; import net.minecraft.util.NonNullList; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import simplexdesigns.bkproject.BkProject; import simplexdesigns.bkproject.util.Constants; import java.util.Optional; import java.util.Random; import java.util.stream.Collectors; /** * Base class for this mod's slab blocks. * * @param <VARIANT> The variant type * @param <VARIANTS> The variant collection type * @param <SLAB> The slab type * @author Choonster */ public abstract class BlockSlabClay< VARIANT extends Enum<VARIANT> & IStringSerializable, VARIANTS extends Iterable<VARIANT> & IStringSerializable, SLAB extends BlockSlabClay<VARIANT, VARIANTS, SLAB> > extends BlockSlab { /** * The group this slab belongs to */ protected final SlabGroup<VARIANT, VARIANTS, SLAB> slabGroup; /** * The variants of this slab */ protected final VARIANTS variants; /** * Create a slab block. * * @param material The Material of this slab * @param slabGroup The group this slab belongs to * @param variants The variants of this slab */ public BlockSlabClay(final Material material, final SlabGroup<VARIANT, VARIANTS, SLAB> slabGroup, final VARIANTS variants) { super(material); this.slabGroup = slabGroup; this.variants = variants; // Vanilla sets this for anything that extends BlockSlab in Block.registerBlocks, // but this is run before mods are loaded; so we need to set it manually. // Thanks to HappyKiller1O1 for pointing out this field to me: // http://www.minecraftforge.net/forum/index.php/topic,36125.msg190252.html#msg190252 this.useNeighborBrightness = true; String name = slabGroup.groupName + "_" + variants.getName(); if (isDouble()) { name = "double_" + name; } setRegistryName(BkProject.MODID, name); setUnlocalizedName(Constants.RESOURCE_PREFIX + slabGroup.groupName); IBlockState iblockstate = this.blockState.getBaseState(); if (!isDouble()) { iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM); } final Optional<VARIANT> defaultVariant = getVariantProperty().getAllowedValues().stream().findFirst(); if (defaultVariant.isPresent()) { iblockstate = iblockstate.withProperty(getVariantProperty(), defaultVariant.get()); } setDefaultState(iblockstate); setCreativeTab(BkProject.creativeTab2); } /** * Get the metadata value for the specified variant * * @param variant The variant * @return The metadata value */ public abstract int getMetadata(VARIANT variant); /** * Get the variant for the specified metadata value * * @param meta The metadata value * @return The variant */ protected abstract VARIANT getVariant(int meta); @Override public Item getItemDropped(final IBlockState state, final Random rand, final int fortune) { return slabGroup.item; } @Override public abstract IProperty<VARIANT> getVariantProperty(); @SideOnly(Side.CLIENT) @Override public void getSubBlocks(final CreativeTabs tab, final NonNullList<ItemStack> list) { list.addAll(getVariantProperty().getAllowedValues().stream() .map(variant -> new ItemStack(this, 1, getMetadata(variant))) .collect(Collectors.toList())); } @SuppressWarnings("deprecation") @Override public IBlockState getStateFromMeta(final int meta) { final VARIANT variant = getVariant(meta & 7); IBlockState state = this.getDefaultState().withProperty(getVariantProperty(), variant); if (!this.isDouble()) { state = state.withProperty(HALF, (meta & 8) == 0 ? EnumBlockHalf.BOTTOM : EnumBlockHalf.TOP); } return state; } @Override public int getMetaFromState(final IBlockState state) { int meta = getMetadata(state.getValue(getVariantProperty())); if (!this.isDouble() && state.getValue(HALF) == EnumBlockHalf.TOP) { meta |= 8; } return meta; } @Override protected BlockStateContainer createBlockState() { return isDouble() ? new BlockStateContainer(this, getVariantProperty()) : new BlockStateContainer(this, HALF, getVariantProperty()); } @Override public int damageDropped(final IBlockState state) { return getMetadata(state.getValue(getVariantProperty())); } /** * A group consisting of a single and a double slab. * * @param <VARIANT> The variant type * @param <VARIANTS> The variant collection type * @param <SLAB> The slab type */ public static abstract class SlabGroup< VARIANT extends Enum<VARIANT> & IStringSerializable, VARIANTS extends Iterable<VARIANT> & IStringSerializable, SLAB extends BlockSlabClay<VARIANT, VARIANTS, SLAB> > { public final SLAB singleSlab; public final SLAB doubleSlab; public final String groupName; public final ItemSlab item; /** * Create a slab group. * * @param groupName The group's name * @param material The Material of the slabs * @param variants The variants of the slabs */ public SlabGroup(final String groupName, final Material material, final VARIANTS variants) { this.groupName = groupName; this.singleSlab = createSlab(material, false, variants); this.doubleSlab = createSlab(material, true, variants); this.item = new ItemSlab(singleSlab, singleSlab, doubleSlab); } /** * Create a slab block. * * @param material The Material * @param isDouble Is this a double slab? * @param variants The variants * @return The slab block */ public abstract SLAB createSlab(Material material, boolean isDouble, VARIANTS variants); } }
July 9, 20178 yr Don't use ItemModelMesher#register to register models, use ModelLoader.setCustomModelResourceLocation/setCustomMeshDefinition in ModelRegistryEvent. Models need to be registered in a client-only class. I use this method to register models for each SlabGroup's item. This is set up so that the item uses the models specified in the blockstates file. To be clear, my mod is meant to be an example rather than a tutorial. You need to read through the code and understand how it works, I don't explain it step-by-step (though I do try to document what most methods and classes do). Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
July 12, 20178 yr Author On 7/9/2017 at 4:01 AM, Choonster said: Don't use ItemModelMesher#register to register models, use ModelLoader.setCustomModelResourceLocation/setCustomMeshDefinition in ModelRegistryEvent. Models need to be registered in a client-only class. I use this method to register models for each SlabGroup's item. This is set up so that the item uses the models specified in the blockstates file. To be clear, my mod is meant to be an example rather than a tutorial. You need to read through the code and understand how it works, I don't explain it step-by-step (though I do try to document what most methods and classes do). K, i got them working properly now. I forgot to add in that code. How would I go about adding in setStepSound(material.CLOTH); into the custom wool slab? package simplexdesigns.bkproject.block; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumDyeColor; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.IStringSerializable; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import simplexdesigns.bkproject.util.OreDictUtils; import javax.annotation.Nullable; import java.util.Collection; import java.util.Iterator; import java.util.Optional; import java.util.function.Predicate; public abstract class BlockWoolSlab extends BlockSlabCustom<EnumDyeColor, BlockWoolSlab.EnumColourGroup, BlockWoolSlab> { public BlockWoolSlab(final Material material, final EnumColourGroup colourGroup, final SlabGroup<EnumDyeColor, EnumColourGroup, BlockWoolSlab> slabGroup) { super(material, slabGroup, colourGroup); } @SuppressWarnings("deprecation") @Override public MapColor getMapColor(final IBlockState state, final IBlockAccess world, final BlockPos pos) { return MapColor.getBlockColor(state.getValue(getVariantProperty())); } @Override public String getUnlocalizedName(final int meta) { return getUnlocalizedName() + "." + getVariant(meta).getUnlocalizedName(); } @Override public int getMetadata(final EnumDyeColor colour) { return variants.getOffsetMetadata(colour); } @Override protected EnumDyeColor getVariant(final int meta) { return variants.byOffsetMetadata(meta); } @Override public boolean recolorBlock(final World world, final BlockPos pos, final EnumFacing side, final EnumDyeColor colour) { final IBlockState currentState = world.getBlockState(pos); return variants.isColourInGroup(colour) && currentState.getValue(getVariantProperty()) != colour && world.setBlockState(pos, currentState.withProperty(getVariantProperty(), colour)); } @Override public boolean onBlockActivated(final World worldIn, final BlockPos pos, final IBlockState state, final EntityPlayer playerIn, final EnumHand hand, final EnumFacing side, final float hitX, final float hitY, final float hitZ) { final ItemStack heldItem = playerIn.getHeldItem(hand); if (!heldItem.isEmpty()) { final Optional<EnumDyeColor> dyeColour = OreDictUtils.INSTANCE.getDyeColour(heldItem); if (dyeColour.isPresent()) { final boolean success = recolorBlock(worldIn, pos, side, dyeColour.get()); if (success) { heldItem.shrink(1); return true; } } } return false; } @Override public Comparable<?> getTypeForItem(final ItemStack stack) { return variants.byOffsetMetadata(stack.getMetadata()); } public enum EnumColourGroup implements Iterable<EnumDyeColor>, IStringSerializable { LOW("low", colour -> colour.getMetadata() < 8, 0), HIGH("high", colour -> colour.getMetadata() >= 8, 8); public final IProperty<EnumDyeColor> property; private final int metaOffset; private final String name; private final Collection<EnumDyeColor> values; EnumColourGroup(final String name, final Predicate<EnumDyeColor> colourFilter, final int metaOffset) { this.name = name; this.property = PropertyEnum.create("colour", EnumDyeColor.class, colourFilter::test); this.metaOffset = metaOffset; this.values = this.property.getAllowedValues(); } public int getOffsetMetadata(final EnumDyeColor colour) { return colour.getMetadata() - metaOffset; } public EnumDyeColor byOffsetMetadata(final int meta) { return EnumDyeColor.byMetadata(meta + metaOffset); } @Override public Iterator<EnumDyeColor> iterator() { return values.iterator(); } @Override public String getName() { return name; } public boolean isColourInGroup(final EnumDyeColor colour) { return values.contains(colour); } @Nullable public static EnumColourGroup getGroupForColour(final EnumDyeColor colour) { for (final EnumColourGroup colourGroup : values()) { if (colourGroup.isColourInGroup(colour)) { return colourGroup; } } return null; } } public static class ColouredSlabGroup { public final SlabGroup<EnumDyeColor, EnumColourGroup, BlockWoolSlab> low; public final SlabGroup<EnumDyeColor, EnumColourGroup, BlockWoolSlab> high; public ColouredSlabGroup(final String groupName, final Material material) { low = createGroup(groupName, material, EnumColourGroup.LOW); high = createGroup(groupName, material, EnumColourGroup.HIGH); } private SlabGroup<EnumDyeColor, EnumColourGroup, BlockWoolSlab> createGroup(final String groupName, final Material material, final EnumColourGroup colourGroup) { return new SlabGroup<EnumDyeColor, EnumColourGroup, BlockWoolSlab>(groupName, material, colourGroup) { @Override public BlockWoolSlab createSlab(final Material material, final boolean isDouble, final EnumColourGroup colourGroup) { return new BlockWoolSlab(material, colourGroup, this) { @Override public boolean isDouble() { return isDouble; } @Override public IProperty<EnumDyeColor> getVariantProperty() { return colourGroup.property; } }; } }; } public SlabGroup<EnumDyeColor, EnumColourGroup, BlockWoolSlab> getSlabGroupByColourGroup(final EnumColourGroup colourGroup) { return colourGroup == EnumColourGroup.LOW ? low : high; } } }
July 12, 20178 yr Just now, xXiNightXx said: How would I go about adding in setStepSound(material.CLOTH); into the custom wool slab? Just add it to the constructor. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
July 12, 20178 yr Author 1 minute ago, Choonster said: Just add it to the constructor. Adding it in causes this error
July 12, 20178 yr The method was changed to Block#setSoundType(SoundType) VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
July 12, 20178 yr 9 minutes ago, xXiNightXx said: Adding it in causes this error As Animefan8888 said, the method is now called Block#setSoundType. You're trying to call the method with a Material, but it takes a SoundType argument; so your current code obviously won't compile. You need to call it with a SoundType, you can get the vanilla SoundType instances from the static fields of the SoundType class. You're also trying to access the static field Material.CLOTH from an instance of Material, which is misleading since it makes it look like an instance field. Access static fields and methods through the class, not an instance. Edited July 12, 20178 yr by Choonster Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
July 12, 20178 yr Author 13 minutes ago, Choonster said: As Animefan8888 said, the method is now called Block#setSoundType. You're trying to call the method with a Material, but it takes a SoundType argument; so your current code obviously won't compile. You need to call it with a SoundType, you can get the vanilla SoundType instances from the static fields of the SoundType class. You're also trying to access the static field Material.CLOTH from an instance of Material, which is misleading since it makes it look like an instance field. Access static fields and methods through the class, not an instance. so the code I need to add is? public static final SoundType CLOTH = new SoundType(1.0F, 1.0F, SoundEvents.BLOCK_CLOTH_BREAK, SoundEvents.BLOCK_CLOTH_STEP, SoundEvents.BLOCK_CLOTH_PLACE, SoundEvents.BLOCK_CLOTH_HIT, SoundEvents.BLOCK_CLOTH_FALL);
July 12, 20178 yr 26 minutes ago, xXiNightXx said: so the code I need to add is? No I said the method is now called setSoundType() and it takes a SoundType. Choonster said to get the sound Type reference it from the SoundType class. Not make a new instance. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
July 12, 20178 yr Author 10 minutes ago, Animefan8888 said: No I said the method is now called setSoundType() and it takes a SoundType. Choonster said to get the sound Type reference it from the SoundType class. Not make a new instance. ok that worked on my regular blocks, however adding it to my BlockClothSlab.java does not change its sound. Still sounds like stone even though i call "CLOTH"
July 12, 20178 yr Show your new code. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
July 12, 20178 yr Author 2 minutes ago, Animefan8888 said: Show your new code. K, here is the code. package simplexdesigns.bkproject.block; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.SoundEvents; import net.minecraft.item.EnumDyeColor; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.IStringSerializable; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import simplexdesigns.bkproject.util.OreDictUtils; import javax.annotation.Nullable; import java.util.Collection; import java.util.Iterator; import java.util.Optional; import java.util.function.Predicate; public abstract class BlockWoolSlab extends BlockSlabCustom<EnumDyeColor, BlockWoolSlab.EnumColourGroup, BlockWoolSlab> { public static final SoundType CLOTH = new SoundType(1.0F, 1.0F, SoundEvents.BLOCK_CLOTH_BREAK, SoundEvents.BLOCK_CLOTH_STEP, SoundEvents.BLOCK_CLOTH_PLACE, SoundEvents.BLOCK_CLOTH_HIT, SoundEvents.BLOCK_CLOTH_FALL); public BlockWoolSlab(final Material material, final EnumColourGroup colourGroup, final SlabGroup<EnumDyeColor, EnumColourGroup, BlockWoolSlab> slabGroup) { super(material, slabGroup, colourGroup); setSoundType(SoundType.CLOTH); } @SuppressWarnings("deprecation") @Override public MapColor getMapColor(final IBlockState state, final IBlockAccess world, final BlockPos pos) { return MapColor.getBlockColor(state.getValue(getVariantProperty())); } @Override public String getUnlocalizedName(final int meta) { return getUnlocalizedName() + "." + getVariant(meta).getUnlocalizedName(); } @Override public int getMetadata(final EnumDyeColor colour) { return variants.getOffsetMetadata(colour); } @Override protected EnumDyeColor getVariant(final int meta) { return variants.byOffsetMetadata(meta); } @Override public boolean recolorBlock(final World world, final BlockPos pos, final EnumFacing side, final EnumDyeColor colour) { final IBlockState currentState = world.getBlockState(pos); return variants.isColourInGroup(colour) && currentState.getValue(getVariantProperty()) != colour && world.setBlockState(pos, currentState.withProperty(getVariantProperty(), colour)); } @Override public boolean onBlockActivated(final World worldIn, final BlockPos pos, final IBlockState state, final EntityPlayer playerIn, final EnumHand hand, final EnumFacing side, final float hitX, final float hitY, final float hitZ) { final ItemStack heldItem = playerIn.getHeldItem(hand); if (!heldItem.isEmpty()) { final Optional<EnumDyeColor> dyeColour = OreDictUtils.INSTANCE.getDyeColour(heldItem); if (dyeColour.isPresent()) { final boolean success = recolorBlock(worldIn, pos, side, dyeColour.get()); if (success) { heldItem.shrink(1); return true; } } } return false; } @Override public Comparable<?> getTypeForItem(final ItemStack stack) { return variants.byOffsetMetadata(stack.getMetadata()); } public enum EnumColourGroup implements Iterable<EnumDyeColor>, IStringSerializable { LOW("low", colour -> colour.getMetadata() < 8, 0), HIGH("high", colour -> colour.getMetadata() >= 8, 8); public final IProperty<EnumDyeColor> property; private final int metaOffset; private final String name; private final Collection<EnumDyeColor> values; EnumColourGroup(final String name, final Predicate<EnumDyeColor> colourFilter, final int metaOffset) { this.name = name; this.property = PropertyEnum.create("colour", EnumDyeColor.class, colourFilter::test); this.metaOffset = metaOffset; this.values = this.property.getAllowedValues(); } public int getOffsetMetadata(final EnumDyeColor colour) { return colour.getMetadata() - metaOffset; } public EnumDyeColor byOffsetMetadata(final int meta) { return EnumDyeColor.byMetadata(meta + metaOffset); } @Override public Iterator<EnumDyeColor> iterator() { return values.iterator(); } @Override public String getName() { return name; } public boolean isColourInGroup(final EnumDyeColor colour) { return values.contains(colour); } @Nullable public static EnumColourGroup getGroupForColour(final EnumDyeColor colour) { for (final EnumColourGroup colourGroup : values()) { if (colourGroup.isColourInGroup(colour)) { return colourGroup; } } return null; } } public static class ColouredSlabGroup { public final SlabGroup<EnumDyeColor, EnumColourGroup, BlockWoolSlab> low; public final SlabGroup<EnumDyeColor, EnumColourGroup, BlockWoolSlab> high; public ColouredSlabGroup(final String groupName, final Material material) { low = createGroup(groupName, material, EnumColourGroup.LOW); high = createGroup(groupName, material, EnumColourGroup.HIGH); } private SlabGroup<EnumDyeColor, EnumColourGroup, BlockWoolSlab> createGroup(final String groupName, final Material material, final EnumColourGroup colourGroup) { return new SlabGroup<EnumDyeColor, EnumColourGroup, BlockWoolSlab>(groupName, material, colourGroup) { @Override public BlockWoolSlab createSlab(final Material material, final boolean isDouble, final EnumColourGroup colourGroup) { return new BlockWoolSlab(material, colourGroup, this) { @Override public boolean isDouble() { return isDouble; } @Override public IProperty<EnumDyeColor> getVariantProperty() { return colourGroup.property; } }; } }; } public SlabGroup<EnumDyeColor, EnumColourGroup, BlockWoolSlab> getSlabGroupByColourGroup(final EnumColourGroup colourGroup) { return colourGroup == EnumColourGroup.LOW ? low : high; } } }
July 12, 20178 yr Why do you have a SoundType field which you don't use? Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
July 12, 20178 yr You don't need to create your own SoundType instance, you can use the vanilla one stored in the SoundType.CLOTH field (Edit: It looks like you are using the vanilla instance, but still creating your own that you never use). If you put a breakpoint in Block#getSoundType(IBlockState, World, BlockPos, Entity) with the condition this instanceof BlockWoolSlab, run Minecraft in debug mode and trigger one of the block's sounds (e.g. place or break the block), what's the value of the Block#blockSoundType field? Edited July 12, 20178 yr by Choonster Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
July 12, 20178 yr Author 13 minutes ago, Choonster said: You don't need to create your own SoundType instance, you can use the vanilla one stored in the SoundType.CLOTH field (Edit: It looks like you are using the vanilla instance, but still creating your own that you never use). If you put a breakpoint in Block#getSoundType(IBlockState, World, BlockPos, Entity) with the condition this instanceof BlockWoolSlab, run Minecraft in debug mode and trigger one of the block's sounds (e.g. place or break the block), what's the value of the Block#blockSoundType field? wait im confused, what would I do to put that breakpoint in. Is it like setSoundType(SoundType.CLOTH).BREAKPOINTCODEHERE;?
July 12, 20178 yr 1 minute ago, xXiNightXx said: wait im confused, what would I do to put that breakpoint in. Is it like setSoundType(SoundType.CLOTH).BREAKPOINTCODEHERE;? Open the Block class, navigate to the getSoundType(IBlockState, World, BlockPos, Entity) method and set a breakpoint in it. If you don't know how to set breakpoints, look at your IDE's documentation or ask your search engine of choice. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
July 12, 20178 yr No, go to the Block class, then go the the getSoundType(...) method and set a breakpoint somewhere in there, with the condition of the block being an instance of your wool slab (this instanceof BlockWoolSlab) Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
July 12, 20178 yr Author 47 minutes ago, Choonster said: Open the Block class, navigate to the getSoundType(IBlockState, World, BlockPos, Entity) method and set a breakpoint in it. If you don't know how to set breakpoints, look at your IDE's documentation or ask your search engine of choice. Yeah Im gonna pass on this sound thing. Haha, its driving me nuts. Not like the sound really matters for what im using the blocks for. Sorry for the trouble, im more of a visual learner. I need to see how stuff looks in order to understand it.
July 12, 20178 yr 3 minutes ago, xXiNightXx said: Yeah Im gonna pass on this sound thing. Haha, its driving me nuts. Not like the sound really matters for what im using the blocks for. Sorry for the trouble, im more of a visual learner. I need to see how stuff looks in order to understand it. Are you using eclipse? VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
July 12, 20178 yr Setting breakpoints is very simple. Go to the right of the line you want the program to pause at and right click. Depending on how far you went and your version of eclipse you should either see a box where it gives you some options or a blue-ish circle. Now go to your slabs class and set the breakpoint just after your call setSoundType. Launch in debug mode instead of run mode with is the little bug instead of the play button at the top. If you need more ask. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
July 12, 20178 yr 8 minutes ago, xXiNightXx said: Yes I seem to forget quoting people a lot. The above message is the real one. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
July 12, 20178 yr Author Just now, Animefan8888 said: I seem to forget quoting people a lot. The above message is the real one. No problem, this site has a little notification sound when I get a reply. I will try the breakpoint after I finish adding in the last few models of stairs Im working on. Give me like 3ish min to reply back.
July 12, 20178 yr Author 13 minutes ago, Animefan8888 said: Setting breakpoints is very simple. Go to the right of the line you want the program to pause at and right click. Depending on how far you went and your version of eclipse you should either see a box where it gives you some options or a blue-ish circle. Now go to your slabs class and set the breakpoint just after your call setSoundType. Launch in debug mode instead of run mode with is the little bug instead of the play button at the top. If you need more ask. this is what I get when i created the breakpoint and stepped on the block while in debug mode. IMGUR Link
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.