Different Hardness pour metadata



  • Yop!
    Bon depuis un moment,j'essaye de ne pas abuser sur le ids… ducoup j'ai mon block de minerai avec plusieurs meta.
    Mais a chaque fois que je tente de mettre en place plusieurs hardness pour chaque meta,mon minecraft crash..
    J'ai essayé de passer par un switch ou par une séries de if else mais ça crash toujours au meme endroits...
    Je sais que j'ai modifier mon constructeur et du coup ça me fait un variable null qui cause un NPE

    package block;
    
    import java.util.List;
    
    import main.TAqmod2;
    import net.minecraft.block.Block;
    import net.minecraft.block.material.Material;
    import net.minecraft.client.renderer.texture.IIconRegister;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.Entity;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.IIcon;
    import net.minecraft.world.*;
    
    public class oreBlockTAq extends Block
    {
    
       public static ItemStack getMeta(String name)
       {
           return getMeta(name);
       }
    
       public static String[] subBlock = new String[] {"oreCopper", "oreTin", "oreDoxis", "oreLaciris"};
       public IIcon[] iconArray = new IIcon[subBlock.length];
    
       public oreBlockTAq(Block block,World world,int x, int y, int z)
       {
    
           super(Material.rock);
               this.setHardness(getHardness(block, world , 0, 0, 0));
    
       }
    
       public float getHardness(Block block,World world,int x,int y,int z){
          int metadata = world.getBlockMetadata(x, y, z);
         if(metadata == 0){
             this.blockHardness = 1.5F;    
         } else if(metadata == 1){
             this.blockHardness = 1.5F;
         } else if(metadata == 2){
             this.blockHardness = 6.5F;
         } else if(metadata == 3){
             this.blockHardness = 7.5F;
         } else{
             this.blockHardness = 0.5F;
         }
             return 0.25F;
     }
    
       public void registerBlockIcons(IIconRegister iconRegister)
       {
           for(int i = 0; i < subBlock.length; i++)
           {
               this.iconArray* = iconRegister.registerIcon(TAqmod2.MODID + ":blockore/" + subBlock*);
           }
       }
    
       public void getSubBlocks(Item item, CreativeTabs tabs, List list)
       {
           for(int i = 0; i < subBlock.length; i++)
           {
               list.add(new ItemStack(item, 1, i));
           }
       }
    
       public IIcon getIcon(int side, int metadata)
       {
           if(metadata >= 0 && metadata < subBlock.length)
           {
               return this.iconArray[metadata];
           }
           return this.iconArray[0];
       }
    
       public int damageDropped(int metadata)
       {
           return metadata;
       }
    
    }
    
    

    Mon main

    
           package main;
    
    import gui.GuiHandler;
    import block.LaserCutterMachine;
    import block.blockCasing;
    import block.itemBlockMetadataOreTAq;
    import block.oreBlockTAq;
    import net.minecraft.block.Block;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.init.Blocks;
    import proxy.CommonProxy;
    import tileEntity.TileEntityLaserCutterMachine;
    import cpw.mods.fml.common.Mod;
    import cpw.mods.fml.common.Mod.EventHandler;
    import cpw.mods.fml.common.Mod.Instance;
    import cpw.mods.fml.common.SidedProxy;
    import cpw.mods.fml.common.event.FMLInitializationEvent;
    import cpw.mods.fml.common.event.FMLPostInitializationEvent;
    import cpw.mods.fml.common.event.FMLPreInitializationEvent;
    import cpw.mods.fml.common.network.NetworkRegistry;
    import cpw.mods.fml.common.registry.GameRegistry;
    
    @Mod(modid = "taq2", name = "aqwerftech2", version = "0.1a")
    public class TAqmod2
    {
       public static final String MODID = "taq2";
       public static Block blockCasing;
       public static Block oreBlockTAq;
    
       public static Block laserCutter;
    
       public static CreativeTabs tAqItemTabs;
       public static CreativeTabs tAqBlockTabs;
    
       @Instance("taq2")
       public static TAqmod2 instance;
       public static final int guiIdLaserCutter = 0;
    
       @SidedProxy(clientSide = "proxy.ClientProxy", serverSide = "proxy.CommonProxy")
       public static CommonProxy proxy;
    
       @EventHandler
       public void preInit(FMLPreInitializationEvent event)
       {
           tAqItemTabs = new tAqItemTabs("AqwerfNet_techmod2item");
           tAqBlockTabs = new tAqBlockTabs("AqwerfNet_techmod2block");
    
           blockCasing = new blockCasing().setBlockName("block.casing").setBlockTextureName(TAqmod2.MODID + ":/blockmachine/blockplate").setCreativeTab(tAqBlockTabs);
           GameRegistry.registerBlock(blockCasing, "block.casing");
    
           oreBlockTAq = new oreBlockTAq(this.oreBlockTAq, null, 0, 0, 0).setBlockName("oreTAq").setCreativeTab(TAqmod2.tAqBlockTabs).setResistance(3.0F);
           GameRegistry.registerBlock(oreBlockTAq, itemBlockMetadataOreTAq.class, "block.ore");
    
           laserCutter = new LaserCutterMachine(false).setBlockName("block.machine.lasercutter").setCreativeTab(tAqBlockTabs).setHardness(3.0F).setResistance(2.0F).setBlockTextureName(TAqmod2.MODID + ":/blockmachine/blocklasercutter");
           GameRegistry.registerTileEntity(TileEntityLaserCutterMachine.class, "taq2:block.machine.lasercutter");
           GameRegistry.registerBlock(laserCutter, "block.machine.lasercutter");
    
       }
    
       @EventHandler
       public void init(FMLInitializationEvent event)
       {
           proxy.registerRender();
    
           GameRegistry.registerTileEntity(TileEntityLaserCutterMachine.class, "taq2:LaserCutterMachine");
           NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
       }
    
       @EventHandler
       public void PostInit(FMLPostInitializationEvent event)
       {
    
       }
    }
    
    

    Merci d'avance!


  • Administrateurs

       public float getBlockHardness(World world, int x, int y, int z)
       {
            int metadata = world.getBlockMetadata(x, y, z);
            if(metadata == 0){
                return 1.5F;    
            }
            else if(metadata == 1){
                return 1.5F;
            }
            else if(metadata == 2){
                return 6.5F;
            }
            else if(metadata == 3){
                return  7.5F;
            }
            else{
                return 0.5F;
            }
            return 0.25F;
       }
    

    Et dans le constructeur vires la fonction            this.setHardness(getHardness(block, world , 0, 0, 0));



  • ok Sa marche merci ^^