Jump to content

Recommended Posts

Posted

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:

wGHhpZi.png

 

In inventory:

ZtF1lPb.png

 

 

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);
	}
}

 

Posted

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

  • Like 1

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.

Posted
  On 7/9/2017 at 11: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).

Expand  

 

K, i got them working properly now. I forgot to add in that code. xD

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;
		}
		
		
	}
	
}

 

Posted
  On 7/12/2017 at 8:30 AM, xXiNightXx said:

How would I go about adding in setStepSound(material.CLOTH);  into the custom wool slab?

Expand  

 

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.

Posted (edited)
  On 7/12/2017 at 8:34 AM, xXiNightXx said:

Adding it in causes this error

Expand  

 

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

Posted
  On 7/12/2017 at 8:44 AM, 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.

Expand  

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);

 

Posted
  On 7/12/2017 at 8:57 AM, xXiNightXx said:

so the code I need to add is?

Expand  

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.

Posted
  On 7/12/2017 at 9:24 AM, 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.

Expand  

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"

Posted
  On 7/12/2017 at 9:37 AM, Animefan8888 said:

Show your new code.

Expand  

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;
		}
		
		
	}
	
}

 

Posted (edited)

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

Posted
  On 7/12/2017 at 10:19 AM, 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?

Expand  

wait im confused, what would I do to put that breakpoint in. Is it like setSoundType(SoundType.CLOTH).BREAKPOINTCODEHERE;?

Posted
  On 7/12/2017 at 10:34 AM, xXiNightXx said:

wait im confused, what would I do to put that breakpoint in. Is it like setSoundType(SoundType.CLOTH).BREAKPOINTCODEHERE;?

Expand  

 

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.

Posted
  On 7/12/2017 at 10:37 AM, 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.

Expand  

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.

Posted
  On 7/12/2017 at 11:24 AM, 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.

Expand  

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.

Posted

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.

Posted
  On 7/12/2017 at 11:37 AM, Animefan8888 said:

I seem to forget quoting people a lot. The above message is the real one.

Expand  

No problem, this site has a little notification sound when I get a reply. xD  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.

 

Posted
  On 7/12/2017 at 11:36 AM, 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.

Expand  

this is what I get when i created the breakpoint and stepped on the block while in debug mode.

IMGUR Link

E4s7xXe.png

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

    • After some time minecraft crashes with an error. Here is the log https://drive.google.com/file/d/1o-2R6KZaC8sxjtLaw5qj0A-GkG_SuoB5/view?usp=sharing
    • The specific issue is that items in my inventory wont stack properly. For instance, if I punch a tree down to collect wood, the first block I collected goes to my hand. So when I punch the second block of wood to collect it, it drops, but instead of stacking with the piece of wood already in my hand, it goes to the second slot in my hotbar instead. Another example is that I'll get some dirt, and then when I'm placing it down later I'll accidentally place a block where I don't want it. When I harvest it again, it doesn't go back to the stack that it came from on my hotbar, where it should have gone, but rather into my inventory. That means that if my inventory is full, then the dirt wont be picked up even though there should be space available in the stack I'm holding. The forge version I'm using is 40.3.0, for java 1.18.2. I'll leave the mods I'm using here, and I'd appreciate it if anybody can point me in the right direction in regards to figuring out how to fix this. I forgot to mention that I think it only happens on my server but I&#39;m not entirely sure. PLEASE HELP ME! LIST OF THE MODS. aaa_particles Adorn AdvancementPlaques AI-Improvements AkashicTome alexsdelight alexsmobs AmbientSounds amwplushies Animalistic another_furniture AppleSkin Aquaculture aquamirae architectury artifacts Atlas-Lib AutoLeveling AutoRegLib auudio balm betterfpsdist biggerstacks biomancy BiomesOPlenty blockui blueprint Bookshelf born_in_chaos Botania braincell BrassAmberBattleTowers brutalbosses camera CasinoCraft cfm (MrCrayfish’s Furniture Mod) chat_heads citadel cloth-config Clumps CMDCam CNB cobweb collective comforts convenientcurioscontainer cookingforblockheads coroutil CosmeticArmorReworked CozyHome CrabbersDelight crashexploitfixer crashutilities Create CreativeCore creeperoverhaul cristellib crittersandcompanions Croptopia CroptopiaAdditions CullLessLeaves curios curiouslanterns curiouslights Curses' Naturals CustomNPCs CyclopsCore dannys_expansion decocraft Decoration Mod DecorationDelightRefurbished Decorative Blocks Disenchanting DistantHorizons doubledoors DramaticDoors drippyloadingscreen durabilitytooltip dynamic-fps dynamiclights DynamicTrees DynamicTreesBOP DynamicTreesPlus Easy Dungeons EasyAnvils EasyMagic easy_npc eatinganimation ecologics effective_fg elevatorid embeddium emotecraft enchantlimiter EnchantmentDescriptions EnderMail engineersdecor entityculling entity_model_features entity_texture_features epicfight EvilCraft exlinefurniture expandability explosiveenhancement factory-blocks fairylights fancymenu FancyVideo FarmersDelight fast-ip-ping FastSuite ferritecore finsandtails FixMySpawnR Forge Middle Ages fossil FpsReducer2 furnish GamingDeco geckolib goblintraders goldenfood goodall H.e.b habitat harvest-with-ease hexerei hole_filler huge-structure-blocks HunterIllager iammusicplayer Iceberg illuminations immersive_paintings incubation infinitybuttons inventoryhud InventoryProfilesNext invocore ItemBorders itemzoom Jade jei (Just Enough Items) JetAndEliasArmors journeymap JRFTL justzoom kiwiboi Kobolds konkrete kotlinforforge lazydfu LegendaryTooltips libIPN lightspeed lmft lodestone LongNbtKiller LuckPerms Lucky77 MagmaMonsters malum ManyIdeasCore ManyIdeasDoors marbledsarsenal marg mcw-furniture mcw-lights mcw-paths mcw-stairs mcw-trapdoors mcw-windows meetyourfight melody memoryleakfix Mimic minecraft-comes-alive MineTraps minibosses MmmMmmMmmMmm MOAdecor (ART, BATH, COOKERY, GARDEN, HOLIDAYS, LIGHTS, SCIENCE) MobCatcher modonomicon mods_optimizer morehitboxes mowziesmobs MutantMonsters mysticalworld naturalist NaturesAura neapolitan NekosEnchantedBooks neoncraft2 nerb nifty NightConfigFixes nightlights nocube's_villagers_sell_animals NoSeeNoTick notenoughanimations obscure_api oculus oresabovediamonds otyacraftengine Paraglider Patchouli physics-mod Pillagers Gun PizzaCraft placeableitems Placebo player-animation-lib pneumaticcraft-repressurized polymorph PrettyPipes Prism projectbrazier Psychadelic-Chemistry PuzzlesLib realmrpg_imps_and_demons RecipesLibrary reeves-furniture RegionsUnexplored restrictedportals revive-me Scary_Mobs_And_Bosses selene shetiphiancore ShoulderSurfing smoothboot
    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.