-
[Solved] [1.8] Blockstates with individual names
In the minecraft code, blocks that use BlockState are able to specify an unlocalized name for each blockstate. How does one do this? My current code for the block: package cf.mcdTeam.Immersion.terrainGenerator.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.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.util.IStringSerializable; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class BlockOverworldOre extends Block { public static final PropertyEnum TYPE = PropertyEnum.create("type", BlockOverworldOre.OreType.class); public BlockOverworldOre() { super(Material.rock); this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, OreType.Iron)); this.setCreativeTab(CreativeTabs.tabBlock); this.setUnlocalizedName("overworldOre"); GameRegistry.registerBlock(this, "overworldOre"); } @SideOnly(Side.CLIENT) public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { for(OreType type : OreType.values()) { list.add(new ItemStack(this, 1, type.metadata)); } } public int getDamageValue(World worldIn, BlockPos pos) { IBlockState iblockstate = worldIn.getBlockState(pos); return iblockstate.getBlock() != this ? 0 : ((OreType)iblockstate.getValue(TYPE)).getMetadata(); } public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(TYPE, OreType.byMetadata(meta)); } public int getMetaFromState(IBlockState state) { OreType type = (OreType)state.getValue(TYPE); return type.getMetadata(); } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {TYPE}); } public int damageDropped(IBlockState state) { return getMetaFromState(state); } public static enum OreType implements IStringSerializable { Iron ("oreIron", 0, 3), Tungsten ("oreTungsten", 1, 5), Silver("oreSilver", 2, 2), Gold("oreGold", 3, 2), Mythril("oreMythril", 4, 4), Adamantium("oreAdamantium", 5, 5), Tin("oreTin", 6, 1), Copper("oreCopper", 7, 1); public final String name; public final int metadata; public final int breakvalue; private static final OreType[] METADATA_LOOKUP = new OreType[values().length]; private OreType(String name, int metadata, int breakvalue) { this.name = name; this.metadata = metadata; this.breakvalue = breakvalue; } public int getMetadata() { return this.metadata; } public String getUnlocalizedName() { return this.name; } public String toString() { return this.name; } public static OreType byMetadata(int metadata) { if (metadata < 0 || metadata >= METADATA_LOOKUP.length) { metadata = 0; } return METADATA_LOOKUP[metadata]; } public String getName() { return this.name; } static { OreType[] values = values(); int l = values.length; for (int t = 0; t < l; ++t) { OreType var3 = values[t]; METADATA_LOOKUP[var3.getMetadata()] = var3; } } } }
-
XP bar rendering
I have written the following code to replace the Experience bar with a new XP/Magic bar for my mod however, all it renders is a black rectangle. public class GuiXPMagicBar extends Gui { private Minecraft mc = Minecraft.getMinecraft(); @SubscribeEvent public void onRenderExperienceBar(RenderGameOverlayEvent event) { if (event.type == ElementType.EXPERIENCE && !mc.thePlayer.isRidingHorse()) { event.setCanceled(true); if (this.mc.playerController.gameIsSurvivalOrAdventure()) { ScaledResolution scaledresolution = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight); int w = scaledresolution.getScaledWidth(); int h = scaledresolution.getScaledHeight(); this.mc.getTextureManager().bindTexture(new ResourceLocation("immersion:textures/gui/magicbar.png")); int cap = this.mc.thePlayer.xpBarCap(); if (cap > 0) { int expl = (int)(this.mc.thePlayer.experience * (float)(183)); int x = w / 2 - 92; int y = h - 32 + 3; this.drawTexturedModalRect(x, y, 0, 0, 182, ; if (expl > 0) { this.drawTexturedModalRect(x, y, 0, 9, expl, ; } } } } } } Any help would be appreciated.
-
NBT tag problems
The actual crash comes from a ticking memory connection with a whole bunch of forge/minecraft code, but it is caused by a null pointer in stack.stackTagCompound.setTag("Ores", taglist); in the second code bit.
-
NBT tag problems
Hello everyone: I am having problems with adding and getting NBT tags off of a custom item. When a BlockOre drops this item, a HarvestDropsEvent is fired: @SubscribeEvent public void GetCorrectOreDrops(HarvestDropsEvent event) { if (event.block instanceof BlockOre) { //STOP NOW if Block is being silk touched if (event.isSilkTouching) { event.drops.clear(); event.drops.add(Stack.S(event.block)); } int nuggets = (event.world.rand.nextInt(16) + event.fortuneLevel * event.world.rand.nextInt(5) + 1); ItemStack stack = event.drops.get(0); stack = ORef.lumpOre.addOre((BlockOre) event.block, nuggets, stack); event.drops.set(0, stack); event.dropChance = 1.0F; } } This refers to a NBT adding script in the item (addOre): public ItemStack addOre(BlockOre ore, int nuggets, ItemStack stack) { NBTTagList taglist = (stack.stackTagCompound != null && stack.stackTagCompound.hasKey("Ores")) ? (NBTTagList) stack.stackTagCompound.getTag("BiggerDim") : new NBTTagList(); NBTTagCompound tag = new NBTTagCompound(); tag.setInteger("nuggets", nuggets); tag.setInteger("ore", ore.getIdFromBlock(ore)); taglist.appendTag(tag); System.out.println(tag.getInteger("ore")); stack.stackTagCompound.setTag("Ores", taglist); return stack; } Whenever I harvest the block, the game crashes. What am I missing?
-
Is this the right way to check if the item in an ItemStack is an Item or a Block
It may be easier to do ItemStack.getItem() and check if it is an instance of ItemBlock. If it is, it is a block, if not it is an item. if (result.getItem() instanceof ItemBlock) { //Code if the item is a block } else { //Code if the item is an item }
-
[Unsolved] How to get/set the NBT tag from a tile entity?
What if the tile entity will not exist at the previous location when I click?
-
[Unsolved] How to get/set the NBT tag from a tile entity?
I think I am asking the wrong question. I need a way to write a tile entity to a nbt tag on an itemstack.
-
[Unsolved] How to get/set the NBT tag from a tile entity?
How do people get or set the nbt tag from a tile entity? I already know how to get the tileentity from the world, but I need a way to read/write the nbt tag to the tileentity itself.
-
OreDictionary
This should help: http://www.minecraftforge.net/wiki/Common_Oredict_names In general do itemType such as ingotCopper or gemDiamond or woodDark
-
Assigning multiple tool types to a singular item?
In your code override the ItemTool Function Set<String> getToolClasses(ItemStack stack) The code checks every one of the string tool types in the list to determine if the tool is effective against that block. Since hoes have their separate handler I think that hoe is not a valid tool type. You could have right click functionality though. (onItemRightClick...)
-
Furnace fuel that does not destroy itself when burned
I have an item which stores "furnace power" and is supposed to give the power to the furnace 100 ticks at a time, but not use itself up. Instead an NBT tag is decremented by 100. How do I tell the furnace not to consume my item, yet have it gain the fuel ticks.
-
Ore Dictionary Problems
For no apparent reason, the problem has fixed itself! Thanks to all of you who tried!
-
Ore Dictionary Problems
My registration to the dictionary goes in init. It is in the correct place unless it needs to go into post-init. EDIT: I tried using ore dictionary in post-init, this gave the same error.
-
Ore Dictionary Problems
Hello! I have been trying to register my ore into the ore dictionary. When I try to run minecraft, the following stacktrace for the error appears: The code I use to register into the dictionary is OreDictionary.registerOre("oreGemEnd", ORef.oreGemEnd); ORef is where I keep all the references to my items. I think this is a forge error, but I cannot be certain.
-
[SOLVED] Ore generation question
Then I will just deal with it. Thank you all!
IPS spam blocked by CleanTalk.