Jump to content

[1.8.9][Solved] Block metadata value reverts to 0


Recommended Posts

Posted

I'm confused as to why when I place my block's item of metadata value 2, it reverts to 0. This is the same for metadata value 1.

 

ItemBlock Meta class:

 

 

package com.test.blocks;

import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

public class ItemBlockMeta extends ItemBlock
{
public ItemBlockMeta(Block block)
{
	super(block);
	if (!(block instanceof IMetaBlockName))
	{
		throw new IllegalArgumentException(String.format("The given Block %s is not an instanceof ISpecialBlockName!", block.getUnlocalizedName()));
	}

	this.setMaxDamage(0);
	this.setHasSubtypes(true);
}



public int getMetaData(int damage)
{
	return damage;
}

@Override
public String getUnlocalizedName(ItemStack stack)
{
	return super.getUnlocalizedName(stack) + "." + ((IMetaBlockName)this.block).getSpecialName(stack);
}
}

 

 

 

BlockFabric class:

 

 

package com.test.blocks;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

import com.test.Main;
import com.test.util.EnumHandler;

public class BlockFabric extends Block implements IMetaBlockName
{
public static final PropertyEnum TYPE = PropertyEnum.create("type", EnumHandler.BlockFabricTypes.class);

public BlockFabric()
{
	super(Material.cloth);
	this.setUnlocalizedName("fabric");
	this.setRegistryName("fabric");
	this.setCreativeTab(Main.tabTest);
	this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumHandler.BlockFabricTypes.DARKRED));
}

@Override
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list)
{
	list.add(new ItemStack(item, 1, 0));
	list.add(new ItemStack(item, 1, 1));
	list.add(new ItemStack(item, 1, 2));
}

@Override
protected BlockState createBlockState()
{
	return new BlockState(this, new IProperty[] { TYPE });
}

@Override
public IBlockState getStateFromMeta(int meta)
{
	if (meta == 0)
	{
		return this.getDefaultState().withProperty(TYPE, EnumHandler.BlockFabricTypes.DARKRED);
	}
	if (meta == 1)
	{
		return this.getDefaultState().withProperty(TYPE, EnumHandler.BlockFabricTypes.DARKYELLOW);
	}
	if (meta == 2)
	{
		return this.getDefaultState().withProperty(TYPE, EnumHandler.BlockFabricTypes.PALEYELLOW);
	}
	return this.getDefaultState().withProperty(TYPE, EnumHandler.BlockFabricTypes.DARKRED);
}

@Override
public int getMetaFromState(IBlockState state)
{
	EnumHandler.BlockFabricTypes type = (EnumHandler.BlockFabricTypes) state.getValue(TYPE);
	return type.getID();
}

@Override
public int damageDropped(IBlockState state)
{
	return this.getMetaFromState(state);
}

@Override
public String getSpecialName(ItemStack stack)
{
	if (stack.getItemDamage() == 0)
	{
		return "darkred";
	}
	if (stack.getItemDamage() == 1)
	{
		return "darkyellow";
	}
	if (stack.getItemDamage() == 2)
	{
		return "paleyellow";
	}
	return "darkred";
}

@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player)
{
	return new ItemStack(Item.getItemFromBlock(this), 1, this.getMetaFromState(world.getBlockState(pos)));
}
}

 

 

 

TestBlocks class:

 

 

package com.test.init;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;

import com.test.Main;
import com.test.blocks.BlockDisplaySeparator;
import com.test.blocks.BlockFabric;
import com.test.blocks.BlockFlashPortal;
import com.test.blocks.BlockGui;
import com.test.blocks.BlockHeroesPlusCrafter;
import com.test.blocks.ItemBlockMeta;
import com.test.client.Reference;
import com.test.util.EnumHandler;

public class TestBlocks
{
public static Block flashverse_rock;
public static BlockFlashPortal flashverse_portal;
/*public static Block gui_block;*/
public static Block heroes_plus_crafter;
public static Block display_separator;
public static Block fabric;

public static void main()
{
	init();
	register();
}

public static void init()
{
	flashverse_rock = new Block(Material.rock).setUnlocalizedName("flashverse_rock").setRegistryName("flashverse_rock").setCreativeTab(Main.tabTest);
	flashverse_portal = new BlockFlashPortal();
	/*gui_block = new BlockGui(Material.rock, "gui_block").setRegistryName("gui_block");*/
	heroes_plus_crafter = new BlockHeroesPlusCrafter(Material.rock);
	display_separator = new BlockDisplaySeparator("display_separator", Material.anvil).setRegistryName("display_separator").setCreativeTab(Main.tabTest);
	fabric = new BlockFabric();
}

public static void register()
{
	GameRegistry.registerBlock(flashverse_rock, flashverse_rock.getRegistryName());
	GameRegistry.registerBlock(flashverse_portal, flashverse_portal.getRegistryName());
	GameRegistry.registerBlock(heroes_plus_crafter, heroes_plus_crafter.getRegistryName());
	/*GameRegistry.registerBlock(gui_block, gui_block.getRegistryName());*/
	GameRegistry.registerBlock(display_separator, display_separator.getRegistryName());
	GameRegistry.registerBlock(fabric, ItemBlockMeta.class, "fabric");
}

public static void registerRenders()
{
	registerRender(flashverse_rock);
	registerRender(flashverse_portal);
	registerRender(heroes_plus_crafter);
	/*registerRender(gui_block);*/
	registerRender(display_separator);

	for (int i = 0; i < EnumHandler.BlockFabricTypes.values().length; i++)
	{
		registerRender(fabric, i, EnumHandler.BlockFabricTypes.values()[i].getName() + "_fabric");
	}
}

public static void registerRender(Block block)
{
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(Reference.MOD_ID + ":" + block.getUnlocalizedName().substring(5), "inventory"));
}

public static void registerRender(Block block, int meta, String fileName)
{
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), meta, new ModelResourceLocation(Reference.MOD_ID + ":" + fileName, "inventory"));
}
}

 

 

 

ClientProxy class:

 

 

package com.test.client.proxies;

import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;

import com.test.client.Reference;
import com.test.gui.GuiItem;
import com.test.init.TestBlocks;
import com.test.init.TestEntities;
import com.test.init.TestItems;

public class ClientProxy extends CommonProxy
{	
@Override
public void preInit()
{
	TestEntities.registerRenders();
}

@Override
public void init()
{
	TestBlocks.registerRenders();
	TestItems.registerRenders();
	ModelBakery.registerItemVariants(Item.getItemFromBlock(TestBlocks.fabric), new ResourceLocation(Reference.MOD_ID + ":darkred_fabric"), new ResourceLocation(Reference.MOD_ID + ":darkyellow_fabric"), new ResourceLocation(Reference.MOD_ID + ":paleyellow_fabric"));
}

@Override
public void postInit()
{
}

@Override
public void openMyGui()
{
	Minecraft.getMinecraft().displayGuiScreen(new GuiItem());
}
}

 

 

 

Main class:

 

 

package com.test;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.item.Item;
import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;

import com.test.client.Reference;
import com.test.client.tabTest;
import com.test.client.handler.IExtendedEntityPropertiesHandler;
import com.test.client.handler.SpeedforceEventHandler;
import com.test.client.proxies.CommonProxy;
import com.test.dimensions.TestBiomesRegistry;
import com.test.dimensions.TestDimensions;
import com.test.gui.GuiHandler;
import com.test.heroespluscrafter.TestRecipes;
import com.test.init.TestBlocks;
import com.test.init.TestEntities;
import com.test.init.TestItems;
import com.test.init.TestTileEntities;

@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)
public class Main
{
@Instance(Reference.MOD_ID)
public static Main instance;

@SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.SERVER_PROXY)
public static CommonProxy proxy;

public static Potion positive_speedforce;
public static Potion negative_speedforce;
public static Potion broken_speedforce;
public static Potion flight;

public static final int heroesCrafterID = 0;

public static final CreativeTabs tabTest = new tabTest("TestTab");

@EventHandler
public static void preInit(FMLPreInitializationEvent event)
{
	proxy.preInit();

	TestDimensions.init();
	TestBlocks.main();
	TestItems.main();
}

@EventHandler
public static void init(FMLInitializationEvent event)
{
	proxy.init();
	TestEntities.init();
	NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
	MinecraftForge.EVENT_BUS.register(new SpeedforceEventHandler());
	MinecraftForge.EVENT_BUS.register(new IExtendedEntityPropertiesHandler());
	positive_speedforce = new Abilities(new ResourceLocation("positive_speedforce"), false, 0).setIconIndex(0, 0).setPotionName("Speed Force").registerPotionAttributeModifier(SharedMonsterAttributes.movementSpeed, "f3f125ac-a67f-4188-aff7-24f0cf75b010", 1.0D, 2);
	negative_speedforce = new Abilities(new ResourceLocation("negative_speedforce"), false, 0).setIconIndex(0, 1).setPotionName("Negative Speed Force").registerPotionAttributeModifier(SharedMonsterAttributes.movementSpeed, "c9782a5f-67ef-49cf-b915-687ed1d9c1d8", 1.25D, 2);
	broken_speedforce = new Abilities(new ResourceLocation("broken_speedforce"), false, 0).setIconIndex(0, 2).setPotionName("Broken Speed Force").registerPotionAttributeModifier(SharedMonsterAttributes.movementSpeed, "076987f2-75e8-49cf-9996-bf818b64cb46", 1.5D, 2);
	flight = new Abilities(new ResourceLocation("flight"), false, 0).setIconIndex(1, 2).setPotionName("Flight");
}

@EventHandler
public static void postInit(FMLPostInitializationEvent event)
{
	proxy.postInit();
	TestRecipes.init();
}
}

 

 

 

Fabric.json Blockstates:

 

 

{
    "variants": {
        "type=darkred": { "model" : "test:darkred_fabric" },
        "type=darkyellow": { "model" : "test:darkyellow_fabric" },
        "type=paleyellow": { "model" : "test:paleyellow_fabric" }
    }
}

 

 

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Posted

You need to override

Item#getMetadata(int)

(not

getMeta[b]D[/b]ata

) to allow the

ItemBlock

to place block metadata values other than 0. This is why you should always annotate override methods with

@Override

.

 

The tutorial's code appears to be poorly written. In addition to not overriding the correct method, it doesn't specify the generic type argument of the

PropertyEnum

field and uses a series of

if

statements for metadata/unlocalised names instead of encapsulating them in the enum.

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

You need to override

Item#getMetadata(int)

(not

getMeta[b]D[/b]ata

) to allow the

ItemBlock

to place block metadata values other than 0. This is why you should always annotate override methods with

@Override

.

 

The tutorial's code appears to be poorly written. In addition to not overriding the correct method, it doesn't specify the generic type argument of the

PropertyEnum

field and uses a series of

if

statements for metadata/unlocalised names instead of encapsulating them in the enum.

 

Thank you! I thought the getMetadata method existed in the ItemBlock class and when I checked it, there was no method, so I was stumped. But now, I've learnt that the getMetadata method exists in the Item class. Thanks a lot!

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Posted

You need to override

Item#getMetadata(int)

(not

getMeta[b]D[/b]ata

) to allow the

ItemBlock

to place block metadata values other than 0. This is why you should always annotate override methods with

@Override

.

 

The tutorial's code appears to be poorly written. In addition to not overriding the correct method, it doesn't specify the generic type argument of the

PropertyEnum

field and uses a series of

if

statements for metadata/unlocalised names instead of encapsulating them in the enum.

 

Thank you! I thought the getMetadata method existed in the ItemBlock class and when I checked it, there was no method, so I was stumped. But now, I've learnt that the getMetadata method exists in the Item class. Thanks a lot!

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

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

    • Reach Out To Rapid Digital: What sapp Info: +1 41 4 80 7 14 85 Email INFO: rap iddi gita lrecov ery @ exe cs. com Hello, my name is Jayson, and I’m 35 years old from the United Kingdom. My family and I recently endured an incredibly challenging experience that I wouldn’t wish on anyone. We became victims of a cryptocurrency investment fraud scheme that saw us lose a staggering $807,000 in USDT and Bitcoins. The fraudsters had created a convincing facade, and we were lured into investing, only to discover later that the platform was a complete scam. We were left devastated, not just financially, but emotionally, as we had trusted these people and believed in the legitimacy of the investment. After the initial shock wore off, we desperately searched for ways to recover the lost funds. It seemed like an impossible task, and we felt as though there was no hope. That’s when, by sheer luck, we stumbled across a post about Rapid Digital Recovery, a cryptocurrency and funds recovery organization with a proven track record in cybersecurity and fraud recovery. We decided to reach out to them, and from the first interaction, we were impressed with their professionalism and transparency. They explained the recovery process in detail and reassured us that they had the skills and expertise to track down the perpetrators and recover our funds. This gave us a renewed sense of hope, something we hadn’t felt in months. What truly stood out during our experience with Rapid Digital Recovery was their dedication to the recovery process. The team went above and beyond, using sophisticated tracking tools and cyber forensics to gather critical information. Within a matter of weeks, they had successfully located the funds and traced the scam back to the fraudsters responsible. They worked with the authorities to ensure the criminals were held accountable for their actions. To our relief, the team at Rapid Digital Recovery was able to recover every single penny we had lost. The funds were returned in full, and the sense of closure we felt was invaluable. We couldn’t have imagined such a positive outcome in the early stages of our recovery journey, and we are deeply grateful for the work they did. If you ever find yourself in a similar situation, I highly recommend contacting Rapid Digital Recovery. Their expertise, transparency, and dedication to their clients make them the go-to choice for anyone seeking to recover lost cryptocurrency or funds. They truly gave us back our financial future.  
    • This is my first time modding anything, so maybe just skill issue. I'm using Forge 54.0.12 and Temurin 21.0.5+11-LTS I wanted to create a custom keybind and to check whether it works I'd like to send a chat message. I tried using Minecraft.getInstance().player.sendSystemMessage(Component.literal("test")); but IntelliJ couldnt resolve sendSystemMessage(...). Since I saw people using it in earlier versions, I tried the same thing with 1.20.6(- 50.1.0), where it works fine, now I can't figure out if this is intentional and whether there are other options for sending chat messages. On that note, is there more documentation than https://docs.minecraftforge.net/en/1.21.x/? It seems very incomplete compared to something like the Oracle Java docs
    • Hi, i'm having this error and I wanna fix it. we try: -Reload drivers -Eliminate .minecraft -Eliminate Java -Restart launcher -Verify if minecraft is using gpu -Mods  in .minecraft is empty -Install the latest and recomended version of forge idk what i have to do, help me pls. the lastest log is: https://mclo.gs/WAMao8x  
    • Read the FAQ, Rule #2. (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/)  
    • The link to your log does not work, it says it is forbidden, Error, this is a private paste or is pending moderation.
  • Topics

×
×
  • Create New...

Important Information

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