Jump to content

bcwadsworth

Forge Modder
  • Posts

    24
  • Joined

  • Last visited

Posts posted by bcwadsworth

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

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

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

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

     

     

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

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

     

     

    Stacktrace:

    at net.minecraft.item.ItemStack.getItemDamage(ItemStack.java:267)

    at net.minecraftforge.oredict.OreDictionary.registerOreImpl(OreDictionary.java:454)

    at net.minecraftforge.oredict.OreDictionary.registerOre(OreDictionary.java:432)

    at net.minecraftforge.oredict.OreDictionary.registerOre(OreDictionary.java:431)

    at bcwadsworth.bcwadsworthWorld.BcwadsworthWorld.dictRegistration(BcwadsworthWorld.java:168)

    at bcwadsworth.bcwadsworthWorld.BcwadsworthWorld.init(BcwadsworthWorld.java:65)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

    at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

    at com.google.common.eventbus.EventBus.post(EventBus.java:275)

    at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208)

    at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

    at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

    at com.google.common.eventbus.EventBus.post(EventBus.java:275)

    at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118)

    at cpw.mods.fml.common.Loader.initializeMods(Loader.java:691)

    at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:288)

    at net.minecraft.client.Minecraft.startGame(Minecraft.java:596)

     

     

     

    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.

  7. wouldn't it be a good idea to implement the IFuelHandler interface directly into the item to which it belongs to?

     

    In theory, that works, but you still have to check for the item specifically, and you still have to initialize it separately in your main mod class. Especially for mods checking for multiple things to add fuel values for, and even for mods who add one, it is better just to add a separate class for it, both for simplicity and readability sake.

  8. I was wondering- does vanilla ore generation come before forge ore generation or after forge ore generation,

     

    And if vanilla ore generation comes first, is it a good idea for me to go through each block to check if it is the block I need to swap out,

     

    And if not, what is the best way of disabling a vanilla ore generation?

  9. Thank you! I belive I have fixed my problem.

     

    In response to coolAlias, not everwhere I use BlockCompound is with Items, most of the times it is used, or planned to be used is storing block information I need without converting through item form.

  10. I am trying to get enumhelper to work, but as far as eclipse knows the import does not exist:

    using the following imports:

    import net.minecraft.item.Item.ToolMaterial;

    import net.minecraftforge.common.EnumHelper;

     

    and trying to get the following to work:

    public static ToolMaterial gemRed = new EnumHelper.addToolMaterial("gemRed", 3, 512, 10.0F, 8.0F, 5);

     

×
×
  • Create New...

Important Information

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