• S'inscrire
    • Se connecter
    • Recherche
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes

    Résolu Problème GUI

    1.7.x
    1.7.2
    3
    4
    789
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • bin4r1s
      bin4r1s dernière édition par

      Bonjour, 
      J’ai créé 2 blocs avec un GUI mais, après avoir ajouté le 2eme bloc, le GUI du 1er ne marchait plus.

      Pouvez-vous m’aider ?

      BlockCrusher.java

      
      package fr.MrBlockTNT.NewOres.Basic.crusher;
      
      import java.util.List;
      import java.util.Random;
      
      import net.minecraft.block.Block;
      import net.minecraft.client.renderer.texture.IIconRegister;
      import net.minecraft.creativetab.CreativeTabs;
      import net.minecraft.entity.EntityLivingBase;
      import net.minecraft.entity.item.EntityItem;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.inventory.Container;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.item.Item;
      import net.minecraft.item.ItemStack;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.tileentity.TileEntity;
      import net.minecraft.util.IIcon;
      import net.minecraft.util.MathHelper;
      import net.minecraft.world.IBlockAccess;
      import net.minecraft.world.World;
      import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
      import cpw.mods.fml.relauncher.Side;
      import cpw.mods.fml.relauncher.SideOnly;
      import fr.MrBlockTNT.NewOres.Basic.Basic;
      import fr.MrBlockTNT.NewOres.Basic.BasicBlock;
      
      public class BlockCrusher extends BasicBlock
      {
      public static String[] subBlock = new String[] {"copper", "bronze", "steel"};
      private IIcon[][] iconArray = new IIcon[subBlock.length][3];
      private IIcon[] on_state = new IIcon[subBlock.length];
      private static boolean field_149934_M;
      
      public void registerBlockIcons(IIconRegister iconRegister)
      {
      for(int i = 0; i < subBlock.length; i++)
      {
      this.iconArray*[0] = iconRegister.registerIcon("neworesbasic:" + subBlock* + "_crusher_top");
      this.iconArray*[1] = iconRegister.registerIcon("neworesbasic:" + subBlock* + "_crusher_front");
      this.iconArray*[2] = iconRegister.registerIcon("neworesbasic:" + subBlock* + "_crusher_side");
      this.on_state* = iconRegister.registerIcon("neworesbasic:" + subBlock* + "_crusher_front_active");
      }
      }
      
      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 int damageDropped(int metadata)
      {
      return metadata;
      }
      
      @SideOnly(Side.CLIENT)
      public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
      {
      int metadata = world.getBlockMetadata(x, y, z);
      TileEntity tile = world.getTileEntity(x, y, z);
      if(side == 1) // UP
         {
          return this.iconArray[metadata][0];
         }
      else if(tile instanceof TileEntityCrusher)
              {
      TileEntityCrusher crusher = (TileEntityCrusher)tile;
                  byte direction = ((TileEntityCrusher)tile).getDirection();
                  switch(direction)
      {
      case 0:
      return side == 3 ? (crusher.isActive() ? this.on_state[metadata] : this.iconArray[metadata][1]) : this.iconArray[metadata][2];
      case 1:
      return side == 4 ? (crusher.isActive() ? this.on_state[metadata] : this.iconArray[metadata][1]) : this.iconArray[metadata][2];
      case 2:
      return side == 2 ? (crusher.isActive() ? this.on_state[metadata] : this.iconArray[metadata][1]) : this.iconArray[metadata][2];
      case 3:
      return side == 5 ? (crusher.isActive() ? this.on_state[metadata] : this.iconArray[metadata][1]) : this.iconArray[metadata][2];
      }
              }
         else
         {
          return this.iconArray[metadata][2];
         }
      return getIcon(side, world.getBlockMetadata(x, y, z));
      }
      
      @SideOnly(Side.CLIENT)
      public IIcon getIcon(int side, int metadata)
      {
      if(side == 1) // UP
         {
          return this.iconArray[metadata][0];
         }
         else if(side == 3) // FRONT : 3
         {
          return this.iconArray[metadata][1];
         }
         else
         {
          return this.iconArray[metadata][2];
         }
      }
      
      public BlockCrusher()
      {
      this.setCreativeTab(Basic.BasicTab);
      }
      
      @Override
          public TileEntity createTileEntity(World world, int metadata)
          {
              return new TileEntityCrusher();
          }
      
          @Override
          public boolean hasTileEntity(int metadata)
          {
              return true;
          }
      
          public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
      {
          FMLNetworkHandler.openGui(player, Basic.instance, 0, world, x, y, z);
      return true;
      }
      
          public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
      {
      TileEntity te = world.getTileEntity(x, y, z);
      if(te != null && te instanceof TileEntityCrusher && stack.hasDisplayName())
      {
      ((TileEntityCrusher)te).setCustomGuiName(stack.getDisplayName());
      }
      if(te instanceof TileEntityCrusher)
      {
      int direction = MathHelper.floor_double((double)(living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
                  ((TileEntityCrusher)te).setDirection((byte)direction);
      }
      }
      
          public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
          {
          dropContainerItem(world, x, y, z);
              super.breakBlock(world, x, y, z, block, metadata);
          }
      
          protected void dropContainerItem(World world, int x, int y, int z)
          {
          TileEntityCrusher tecrusher = (TileEntityCrusher)world.getTileEntity(x, y, z);
      
              if (tecrusher != null)
              {
                  for (int slotId = 0; slotId < tecrusher.getSizeInventory(); slotId++)
                  {
                      ItemStack stack = tecrusher.getStackInSlot(slotId);
      
                      if (stack != null)
                      {
                          float f = world.rand.nextFloat() * 0.8F + 0.1F;
                          float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
                          EntityItem entityitem;
      
                          for (float f2 = world.rand.nextFloat() * 0.8F + 0.1F; stack.stackSize > 0; world.spawnEntityInWorld(entityitem))
                          {
                              int k1 = world.rand.nextInt(21) + 10;
      
                              if (k1 > stack.stackSize)
                              {
                                  k1 = stack.stackSize;
                              }
      
                              stack.stackSize -= k1;
                              entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(stack.getItem(), k1, stack.getItemDamage()));
                              float f3 = 0.05F;
                              entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3);
                              entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 + 0.2F);
                              entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3);
      
                              if (stack.hasTagCompound())
                              {
                                  entityitem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
                              }
                          }
                      }
                  }
              }
          }
      
          public static void updateCrusherBlockState(boolean p_149931_0_, World world, int x, int y, int z)
          {
              int l = world.getBlockMetadata(x, y, z);
              TileEntity tileentity = world.getTileEntity(x, y, z);
              field_149934_M = true;
              int metadata = world.getBlockMetadata(x, y, z);
      
              /*if (p_149931_0_)
              {
                  world.setBlock(x, y, z, Basic.crusher_active, metadata, 0); // In-crushing block
              }
              else
              {
                  world.setBlock(x, y, z, Basic.crusher, metadata, 0);
              }*/
      
              field_149934_M = false;
              world.setBlockMetadataWithNotify(x, y, z, l, 2);
      
              if (tileentity != null)
              {
                  tileentity.validate();
                  world.setTileEntity(x, y, z, tileentity);
              }
          }
      
          public boolean hasComparatorInputOverride()
          {
              return true;
          }
      
          public int getComparatorInputOverride(World p_149736_1_, int p_149736_2_, int p_149736_3_, int p_149736_4_, int p_149736_5_)
          {
              return Container.calcRedstoneFromInventory((IInventory)p_149736_1_.getTileEntity(p_149736_2_, p_149736_3_, p_149736_4_));
          }
      
          @SideOnly(Side.CLIENT)
          public void randomDisplayTick(World world, int x, int y, int z, Random rand)
      {
          TileEntity tile = world.getTileEntity(x, y, z);
          if(tile instanceof TileEntityCrusher && ((TileEntityCrusher)tile).isActive())
          {
          for(int i = 0; i < rand.nextInt(8); i++)
      {
      float f = (float)x + 0.4F + rand.nextFloat() * 6.0F / 16.0F;
              float f1 = (float)y + 1.1F;
              float f2 = (float)z + 0.4F;
              float f3 = 0.52F;
              float f4 = rand.nextFloat() * 0.6F - 0.3F;
      
      world.spawnParticle("smoke", (double)f, (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
      }
          }
      }
      
          @SideOnly(Side.CLIENT)
      public int getLightValue(IBlockAccess world, int x, int y, int z)
      {
      TileEntity te = world.getTileEntity(x, y, z);
      if(te instanceof TileEntityCrusher && ((TileEntityCrusher)te).isActive())
      {
      return 13;
      }
      return super.getLightValue(world, x, y, z);
      }
      
      }
      
      

      TileEntityCrusher.java :

      
      package fr.MrBlockTNT.NewOres.Basic.crusher;
      
      import net.minecraft.block.Block;
      import net.minecraft.block.material.Material;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.init.Blocks;
      import net.minecraft.init.Items;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.item.Item;
      import net.minecraft.item.ItemBlock;
      import net.minecraft.item.ItemHoe;
      import net.minecraft.item.ItemStack;
      import net.minecraft.item.ItemSword;
      import net.minecraft.item.ItemTool;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.nbt.NBTTagList;
      import net.minecraft.network.NetworkManager;
      import net.minecraft.network.Packet;
      import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
      import net.minecraft.tileentity.TileEntity;
      import cpw.mods.fml.common.registry.GameRegistry;
      import cpw.mods.fml.relauncher.Side;
      import cpw.mods.fml.relauncher.SideOnly;
      
      public class TileEntityCrusher extends TileEntity implements IInventory
      {
      private static final int[] slotsTop = new int[] {0};
          private static final int[] slotsBottom = new int[] {2, 1};
          private static final int[] slotsSides = new int[] {1};
      
      private ItemStack[] inventory = new ItemStack[3];
      private String customName;
      
      public int crusherCrushTime;
          public int currentItemPowerTime;
          public int crusherResultCrushTime;
      
          public int maxCrushTime = 200;
          public static float powerMultiplier = 1F;
      
          private byte direction;
          private boolean active;
      
      @Override
      public void readFromNBT(NBTTagCompound nbttag)
          {
      super.readFromNBT(nbttag);
      this.direction = nbttag.getByte("Direction");
              NBTTagList nbttaglist = nbttag.getTagList("Items", 10);
              this.inventory = new ItemStack[this.getSizeInventory()];
      
              for (int i = 0; i < nbttaglist.tagCount(); ++i)
              {
                  NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                  byte b0 = nbttagcompound1.getByte("Slot");
      
                  if (b0 >= 0 && b0 < this.inventory.length)
                  {
                      this.inventory[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                  }
              }
      
              this.crusherCrushTime = nbttag.getShort("CrushTime");
              this.crusherResultCrushTime = nbttag.getShort("CrushResultTime");
              this.currentItemPowerTime = getItemPowerTime(this.inventory[1]);
      
              if (nbttag.hasKey("CustomName", 8))
              {
                  this.customName = nbttag.getString("CustomName");
              }
              this.active = nbttag.getBoolean("Active");
          }
      
      @Override
          public void writeToNBT(NBTTagCompound nbttag)
          {
      super.writeToNBT(nbttag);
      nbttag.setByte("Direction", this.direction);
      nbttag.setShort("CrushTime", (short)this.crusherCrushTime);
      nbttag.setShort("CrushResultTime", (short)this.crusherResultCrushTime);
              NBTTagList nbttaglist = new NBTTagList();
      
              for (int i = 0; i < this.inventory.length; ++i)
              {
                  if (this.inventory* != null)
                  {
                      NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                      nbttagcompound1.setByte("Slot", (byte)i);
                      this.inventory*.writeToNBT(nbttagcompound1);
                      nbttaglist.appendTag(nbttagcompound1);
                  }
              }
      
              nbttag.setTag("Items", nbttaglist);
      
              if (this.hasCustomInventoryName())
              {
              nbttag.setString("CustomName", this.customName);
              }
              nbttag.setBoolean("Active", this.active);
          }
      
      public boolean isActive()
      {
      return this.active;
      }
      
      public byte getDirection()
          {
              return direction;
          }
      
      public void setDirection(byte direction)
      {
      this.direction = direction;
      this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
      }
      
      public Packet getDescriptionPacket()
          {
              NBTTagCompound nbttagcompound = new NBTTagCompound();
              this.writeToNBT(nbttagcompound);
              return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbttagcompound);
          }
      
          public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
          {
              this.readFromNBT(pkt.func_148857_g());
              this.worldObj.markBlockRangeForRenderUpdate(this.xCoord, this.yCoord, this.zCoord, this.xCoord, this.yCoord, this.zCoord);
          }
      
         @Override
      public int getSizeInventory()
      {
      return inventory.length;
      }
      
      public ItemStack getStackInSlot(int par1)
      {
      return this.inventory[par1];
      }
      
         @Override
          public ItemStack decrStackSize(int slotId, int quantity)
          {
        if (this.inventory[slotId] != null)
             {
                 ItemStack itemstack;
      
                 if (this.inventory[slotId].stackSize <= quantity)
                 {
                     itemstack = this.inventory[slotId];
                     this.inventory[slotId] = null;
                     return itemstack;
                 }
                 else
                 {
                     itemstack = this.inventory[slotId].splitStack(quantity);
      
                     if (this.inventory[slotId].stackSize == 0)
                     {
                         this.inventory[slotId] = null;
                     }
      
                     return itemstack;
                 }
             }
             else
             {
                 return null;
             }
          }
      
      @Override
      public ItemStack getStackInSlotOnClosing(int slotId)
      {
              if (this.inventory[slotId] != null)
              {
                  ItemStack itemstack = this.inventory[slotId];
                  this.inventory[slotId] = null;
                  return itemstack;
              }
              else
              {
                  return null;
              }
      }
      
      @Override
      public void setInventorySlotContents(int slotId, ItemStack stack)
      {
              this.inventory[slotId] = stack;
      
              if (stack != null && stack.stackSize > this.getInventoryStackLimit())
              {
                  stack.stackSize = this.getInventoryStackLimit();
              }
      
              this.markDirty();
      }
      
      @Override
      public String getInventoryName()
      {
      return this.hasCustomInventoryName() ? this.customName : "container.crusher";
      }
      
      @Override
      public boolean hasCustomInventoryName()
      {
              return this.customName != null && this.customName.length() > 0;
      }
      
         public void setCustomGuiName(String name)
         {
             this.customName = name;
         }
      
         @Override
      public int getInventoryStackLimit()
      {
      return 64;
      }
      
         @Override
      public boolean isUseableByPlayer(EntityPlayer player)
      {
      return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
      }
      
         @Override
         public boolean isItemValidForSlot(int par1, ItemStack par2ItemStack)
         {
             return par1 == 2 ? false : (par1 == 1 ? isItemFuel(par2ItemStack) : true);
         }
      
         @Override
         public void openInventory()
         {
         }
      
         @Override
         public void closeInventory() 
         {
         }
      
         @SideOnly(Side.CLIENT)
         public int getCrushProgressScaled(int speed)
         {
             return this.crusherResultCrushTime * speed/ this.maxCrushTime;
         }
      
         @SideOnly(Side.CLIENT)
         public int getCrushTimeRemainingScaled(int p_145955_1_)
         {
             if (this.currentItemPowerTime == 0)
             {
                 this.currentItemPowerTime = this.maxCrushTime;
             }
      
             return this.crusherCrushTime * p_145955_1_ / this.currentItemPowerTime;
         }
      
         public boolean isCrushing()
         {
             return this.crusherCrushTime > 0;
         }
      
         public void updateEntity()
         {
        this.active = this.crusherCrushTime > 0;
        if(this.getBlockMetadata() == 0)
             {
            this.maxCrushTime = 200;
            this.powerMultiplier = 1.0F;
             }
             else if(this.getBlockMetadata() == 1)
             {
            this.maxCrushTime = 190;
            this.powerMultiplier = 1.1F;
             }
             else if(this.getBlockMetadata() == 2)
             {
            this.maxCrushTime = 150;
            this.powerMultiplier = 1.3F;
             }
      
             boolean flag1 = false;
      
             if (this.crusherCrushTime > 0)
             {
                 –this.crusherCrushTime;
             }
      
             if (!this.worldObj.isRemote)
             {
                 if (this.crusherCrushTime == 0 && this.canCrush())
                 {
                     this.currentItemPowerTime = this.crusherCrushTime = getItemPowerTime(this.inventory[1]);
      
                     if (this.crusherCrushTime > 0)
                     {
                         flag1 = true;
      
                         if (this.inventory[1] != null)
                         {
                             –this.inventory[1].stackSize;
      
                             if (this.inventory[1].stackSize == 0)
                             {
                                 this.inventory[1] = inventory[1].getItem().getContainerItem(inventory[1]);
                             }
                         }
                     }
                 }
      
                 if (this.isCrushing() && this.canCrush())
                 {
                     ++this.crusherResultCrushTime;
      
                     if (this.crusherResultCrushTime == maxCrushTime)
                     {
                         this.crusherResultCrushTime = 0;
                         this.crushItem();
                         flag1 = true;
                     }
      
                     /**
                      * <todo>*/
                 }
                 else
                 {
                     this.crusherResultCrushTime = 0;
                 }
      
                 if(active != this.crusherCrushTime > 0)
      {
      flag1 = true;
      this.active = this.crusherCrushTime > 0;
      if(!this.worldObj.isRemote)
      {
      this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
      }
      }
             }
      
             if (flag1)
             {
                 this.markDirty();
             }
         }
      
         private boolean canCrush()
         {
             if (this.inventory[0] == null)
             {
                 return false;
             }
             else
             {
                 ItemStack itemstack = CrusherRecipes.crushing().getCrushingResult(this.inventory[0]);
                 if (itemstack == null) return false;
                 if (this.inventory[2] == null) return true;
                 if (!this.inventory[2].isItemEqual(itemstack)) return false;
                 int result = inventory[2].stackSize + itemstack.stackSize;
                 return result <= getInventoryStackLimit() && result <= this.inventory[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
             }
         }
      
         public void crushItem()
         {
             if (this.canCrush())
             {
                 ItemStack itemstack = CrusherRecipes.crushing().getCrushingResult(this.inventory[0]);
      
                 if (this.inventory[2] == null)
                 {
                     this.inventory[2] = itemstack.copy();
                 }
                 else if (this.inventory[2].getItem() == itemstack.getItem())
                 {
                     this.inventory[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items
                 }
      
                 –this.inventory[0].stackSize;
      
                 if (this.inventory[0].stackSize <= 0)
                 {
                     this.inventory[0] = null;
                 }
             }
         }
      
         public static int getItemPowerTime(ItemStack p_145952_0_)
         {
             if (p_145952_0_ == null)
             {
                 return 0;
             }
             else
             {
                 Item item = p_145952_0_.getItem();
      
                 if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air)
                 {
                     Block block = Block.getBlockFromItem(item);
      
                     if (block == Blocks.wooden_slab)
                     {
                         return Integer.valueOf((int) (150 * powerMultiplier));
                     }
      
                     if (block.getMaterial() == Material.wood)
                     {
                         return Integer.valueOf((int) (300 * powerMultiplier));
                     }
      
                     if (block == Blocks.coal_block)
                     {
                         return Integer.valueOf((int) (16000 * powerMultiplier));
                     }
                 }
      
                 if (item instanceof ItemTool && ((ItemTool)item).getToolMaterialName().equals("WOOD")) return Integer.valueOf((int) (200 * powerMultiplier));
                 if (item instanceof ItemSword && ((ItemSword)item).getToolMaterialName().equals("WOOD")) return Integer.valueOf((int) (200 * powerMultiplier));
                 if (item instanceof ItemHoe && ((ItemHoe)item).getToolMaterialName().equals("WOOD")) return Integer.valueOf((int) (200 * powerMultiplier));
                 if (item == Items.stick) return Integer.valueOf((int) (100 * powerMultiplier));
                 if (item == Items.coal) return Integer.valueOf((int) (1600 * powerMultiplier));
                 if (item == Items.lava_bucket) return Integer.valueOf((int) (20000 * powerMultiplier));
                 if (item == Item.getItemFromBlock(Blocks.sapling)) return Integer.valueOf((int) (100 * powerMultiplier));
                 if (item == Items.blaze_rod) return Integer.valueOf((int) (2400 * powerMultiplier));
                 return GameRegistry.getFuelValue(p_145952_0_);
             }
         }
      
         public static boolean isItemFuel(ItemStack p_145954_0_)
         {
             return getItemPowerTime(p_145954_0_) > 0;
         }
      
         public boolean canInsertItem(int par1, ItemStack par2ItemStack, int par3)
         {
             return this.isItemValidForSlot(par1, par2ItemStack);
         }
      
         public boolean canExtractItem(int par1, ItemStack par2ItemStack, int par3)
         {
             return par3 != 0 || par1 != 1 || par2ItemStack.getItem() == Items.bucket;
         }
      }
      
      

      BlockCompressor.java :

      
      package fr.MrBlockTNT.NewOres.Basic.compressor;
      
      import java.util.List;
      import java.util.Random;
      
      import net.minecraft.block.Block;
      import net.minecraft.client.renderer.texture.IIconRegister;
      import net.minecraft.creativetab.CreativeTabs;
      import net.minecraft.entity.EntityLivingBase;
      import net.minecraft.entity.item.EntityItem;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.inventory.Container;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.item.Item;
      import net.minecraft.item.ItemStack;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.tileentity.TileEntity;
      import net.minecraft.util.IIcon;
      import net.minecraft.util.MathHelper;
      import net.minecraft.world.IBlockAccess;
      import net.minecraft.world.World;
      import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
      import cpw.mods.fml.relauncher.Side;
      import cpw.mods.fml.relauncher.SideOnly;
      import fr.MrBlockTNT.NewOres.Basic.Basic;
      import fr.MrBlockTNT.NewOres.Basic.BasicBlock;
      
      public class BlockCompressor extends BasicBlock
      {
      public static String[] subBlock = new String[] {"copper", "bronze", "steel"};
      private IIcon[][] iconArray = new IIcon[subBlock.length][3];
      private IIcon[] on_state = new IIcon[subBlock.length];
      private static boolean field_149934_M;
      
      public void registerBlockIcons(IIconRegister iconRegister)
      {
      for(int i = 0; i < subBlock.length; i++)
      {
      this.iconArray*[0] = iconRegister.registerIcon("neworesbasic:" + subBlock* + "_compressor_top");
      this.iconArray*[1] = iconRegister.registerIcon("neworesbasic:" + subBlock* + "_compressor_front");
      this.iconArray*[2] = iconRegister.registerIcon("neworesbasic:" + subBlock* + "_crusher_side");
      this.on_state* = iconRegister.registerIcon("neworesbasic:" + subBlock* + "_compressor_front_active");
      }
      }
      
      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 int damageDropped(int metadata)
      {
      return metadata;
      }
      
      @SideOnly(Side.CLIENT)
      public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
      {
      int metadata = world.getBlockMetadata(x, y, z);
      TileEntity tile = world.getTileEntity(x, y, z);
      if(side == 1) // UP
         {
          return this.iconArray[metadata][0];
         }
      else if(tile instanceof TileEntityCompressor)
              {
      TileEntityCompressor compressor = (TileEntityCompressor)tile;
                  byte direction = ((TileEntityCompressor)tile).getDirection();
                  switch(direction)
      {
      case 0:
      return side == 3 ? (compressor.isActive() ? this.on_state[metadata] : this.iconArray[metadata][1]) : this.iconArray[metadata][2];
      case 1:
      return side == 4 ? (compressor.isActive() ? this.on_state[metadata] : this.iconArray[metadata][1]) : this.iconArray[metadata][2];
      case 2:
      return side == 2 ? (compressor.isActive() ? this.on_state[metadata] : this.iconArray[metadata][1]) : this.iconArray[metadata][2];
      case 3:
      return side == 5 ? (compressor.isActive() ? this.on_state[metadata] : this.iconArray[metadata][1]) : this.iconArray[metadata][2];
      }
              }
         else
         {
          return this.iconArray[metadata][2];
         }
      return getIcon(side, world.getBlockMetadata(x, y, z));
      }
      
      @SideOnly(Side.CLIENT)
      public IIcon getIcon(int side, int metadata)
      {
      if(side == 1) // UP
         {
          return this.iconArray[metadata][0];
         }
         else if(side == 3) // FRONT : 3
         {
          return this.iconArray[metadata][1];
         }
         else
         {
          return this.iconArray[metadata][2];
         }
      }
      
      public BlockCompressor()
      {
      this.setCreativeTab(Basic.BasicTab);
      }
      
      @Override
          public TileEntity createTileEntity(World world, int metadata)
          {
              return new TileEntityCompressor();
          }
      
          @Override
          public boolean hasTileEntity(int metadata)
          {
              return true;
          }
      
          public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
      {
          FMLNetworkHandler.openGui(player, Basic.instance, 1, world, x, y, z);
      return true;
      }
      
          public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
      {
      TileEntity te = world.getTileEntity(x, y, z);
      if(te != null && te instanceof TileEntityCompressor && stack.hasDisplayName())
      {
      ((TileEntityCompressor)te).setCustomGuiName(stack.getDisplayName());
      }
      if(te instanceof TileEntityCompressor)
      {
      int direction = MathHelper.floor_double((double)(living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
                  ((TileEntityCompressor)te).setDirection((byte)direction);
      }
      }
      
          public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
          {
          dropContainerItem(world, x, y, z);
              super.breakBlock(world, x, y, z, block, metadata);
          }
      
          protected void dropContainerItem(World world, int x, int y, int z)
          {
          TileEntityCompressor tecompressor = (TileEntityCompressor)world.getTileEntity(x, y, z);
      
              if (tecompressor != null)
              {
                  for (int slotId = 0; slotId < tecompressor.getSizeInventory(); slotId++)
                  {
                      ItemStack stack = tecompressor.getStackInSlot(slotId);
      
                      if (stack != null)
                      {
                          float f = world.rand.nextFloat() * 0.8F + 0.1F;
                          float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
                          EntityItem entityitem;
      
                          for (float f2 = world.rand.nextFloat() * 0.8F + 0.1F; stack.stackSize > 0; world.spawnEntityInWorld(entityitem))
                          {
                              int k1 = world.rand.nextInt(21) + 10;
      
                              if (k1 > stack.stackSize)
                              {
                                  k1 = stack.stackSize;
                              }
      
                              stack.stackSize -= k1;
                              entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(stack.getItem(), k1, stack.getItemDamage()));
                              float f3 = 0.05F;
                              entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3);
                              entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 + 0.2F);
                              entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3);
      
                              if (stack.hasTagCompound())
                              {
                                  entityitem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
                              }
                          }
                      }
                  }
              }
          }
      
          public static void updateCompressorBlockState(boolean p_149931_0_, World world, int x, int y, int z)
          {
              int l = world.getBlockMetadata(x, y, z);
              TileEntity tileentity = world.getTileEntity(x, y, z);
              field_149934_M = true;
              int metadata = world.getBlockMetadata(x, y, z);
      
              /*if (p_149931_0_)
              {
                  world.setBlock(x, y, z, Basic.compressor_active, metadata, 0); // In-compressing block
              }
              else
              {
                  world.setBlock(x, y, z, Basic.compressor, metadata, 0);
              }*/
      
              field_149934_M = false;
              world.setBlockMetadataWithNotify(x, y, z, l, 2);
      
              if (tileentity != null)
              {
                  tileentity.validate();
                  world.setTileEntity(x, y, z, tileentity);
              }
          }
      
          public boolean hasComparatorInputOverride()
          {
              return true;
          }
      
          public int getComparatorInputOverride(World p_149736_1_, int p_149736_2_, int p_149736_3_, int p_149736_4_, int p_149736_5_)
          {
              return Container.calcRedstoneFromInventory((IInventory)p_149736_1_.getTileEntity(p_149736_2_, p_149736_3_, p_149736_4_));
          }
      
          @SideOnly(Side.CLIENT)
          public void randomDisplayTick(World world, int x, int y, int z, Random rand)
      {
          TileEntity tile = world.getTileEntity(x, y, z);
          if(tile instanceof TileEntityCompressor && ((TileEntityCompressor)tile).isActive())
          {
          for(int i = 0; i < rand.nextInt(8); i++)
      {
      float f = (float)x + 0.4F + rand.nextFloat() * 6.0F / 16.0F;
              float f1 = (float)y + 1.1F;
              float f2 = (float)z + 0.4F;
              float f3 = 0.52F;
              float f4 = rand.nextFloat() * 0.6F - 0.3F;
      
      world.spawnParticle("smoke", (double)f, (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
      }
          }
      }
      
          @SideOnly(Side.CLIENT)
      public int getLightValue(IBlockAccess world, int x, int y, int z)
      {
      TileEntity te = world.getTileEntity(x, y, z);
      if(te instanceof TileEntityCompressor && ((TileEntityCompressor)te).isActive())
      {
      return 13;
      }
      return super.getLightValue(world, x, y, z);
      }
      
      }
      
      

      TileEntityCompressor.java :

      
      package fr.MrBlockTNT.NewOres.Basic.compressor;
      
      import net.minecraft.block.Block;
      import net.minecraft.block.material.Material;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.init.Blocks;
      import net.minecraft.init.Items;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.item.Item;
      import net.minecraft.item.ItemBlock;
      import net.minecraft.item.ItemHoe;
      import net.minecraft.item.ItemStack;
      import net.minecraft.item.ItemSword;
      import net.minecraft.item.ItemTool;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.nbt.NBTTagList;
      import net.minecraft.network.NetworkManager;
      import net.minecraft.network.Packet;
      import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
      import net.minecraft.tileentity.TileEntity;
      import cpw.mods.fml.common.registry.GameRegistry;
      import cpw.mods.fml.relauncher.Side;
      import cpw.mods.fml.relauncher.SideOnly;
      
      public class TileEntityCompressor extends TileEntity implements IInventory
      {
      private static final int[] slotsTop = new int[] {0};
          private static final int[] slotsBottom = new int[] {2, 1};
          private static final int[] slotsSides = new int[] {1};
      
      private ItemStack[] inventory = new ItemStack[3];
      private String customName;
      
      public int compressorCompressTime;
          public int currentItemPowerTime;
          public int compressorResultCompressTime;
      
          public int maxCompressTime = 200;
          public static float powerMultiplier = 1F;
      
          private byte direction;
          private boolean active;
      
      @Override
      public void readFromNBT(NBTTagCompound nbttag)
          {
      super.readFromNBT(nbttag);
      this.direction = nbttag.getByte("Direction");
              NBTTagList nbttaglist = nbttag.getTagList("Items", 10);
              this.inventory = new ItemStack[this.getSizeInventory()];
      
              for (int i = 0; i < nbttaglist.tagCount(); ++i)
              {
                  NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                  byte b0 = nbttagcompound1.getByte("Slot");
      
                  if (b0 >= 0 && b0 < this.inventory.length)
                  {
                      this.inventory[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                  }
              }
      
              this.compressorCompressTime = nbttag.getShort("CompressTime");
              this.compressorResultCompressTime = nbttag.getShort("CompressResultTime");
              this.currentItemPowerTime = getItemPowerTime(this.inventory[1]);
      
              if (nbttag.hasKey("CustomName", 8))
              {
                  this.customName = nbttag.getString("CustomName");
              }
              this.active = nbttag.getBoolean("Active");
          }
      
      @Override
          public void writeToNBT(NBTTagCompound nbttag)
          {
      super.writeToNBT(nbttag);
      nbttag.setByte("Direction", this.direction);
      nbttag.setShort("CompressTime", (short)this.compressorCompressTime);
      nbttag.setShort("CompressResultTime", (short)this.compressorResultCompressTime);
              NBTTagList nbttaglist = new NBTTagList();
      
              for (int i = 0; i < this.inventory.length; ++i)
              {
                  if (this.inventory* != null)
                  {
                      NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                      nbttagcompound1.setByte("Slot", (byte)i);
                      this.inventory*.writeToNBT(nbttagcompound1);
                      nbttaglist.appendTag(nbttagcompound1);
                  }
              }
      
              nbttag.setTag("Items", nbttaglist);
      
              if (this.hasCustomInventoryName())
              {
              nbttag.setString("CustomName", this.customName);
              }
              nbttag.setBoolean("Active", this.active);
          }
      
      public boolean isActive()
      {
      return this.active;
      }
      
      public byte getDirection()
          {
              return direction;
          }
      
      public void setDirection(byte direction)
      {
      this.direction = direction;
      this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
      }
      
      public Packet getDescriptionPacket()
          {
              NBTTagCompound nbttagcompound = new NBTTagCompound();
              this.writeToNBT(nbttagcompound);
              return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbttagcompound);
          }
      
          public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
          {
              this.readFromNBT(pkt.func_148857_g());
              this.worldObj.markBlockRangeForRenderUpdate(this.xCoord, this.yCoord, this.zCoord, this.xCoord, this.yCoord, this.zCoord);
          }
      
         @Override
      public int getSizeInventory()
      {
      return inventory.length;
      }
      
      public ItemStack getStackInSlot(int par1)
      {
      return this.inventory[par1];
      }
      
         @Override
          public ItemStack decrStackSize(int slotId, int quantity)
          {
        if (this.inventory[slotId] != null)
             {
                 ItemStack itemstack;
      
                 if (this.inventory[slotId].stackSize <= quantity)
                 {
                     itemstack = this.inventory[slotId];
                     this.inventory[slotId] = null;
                     return itemstack;
                 }
                 else
                 {
                     itemstack = this.inventory[slotId].splitStack(quantity);
      
                     if (this.inventory[slotId].stackSize == 0)
                     {
                         this.inventory[slotId] = null;
                     }
      
                     return itemstack;
                 }
             }
             else
             {
                 return null;
             }
          }
      
      @Override
      public ItemStack getStackInSlotOnClosing(int slotId)
      {
              if (this.inventory[slotId] != null)
              {
                  ItemStack itemstack = this.inventory[slotId];
                  this.inventory[slotId] = null;
                  return itemstack;
              }
              else
              {
                  return null;
              }
      }
      
      @Override
      public void setInventorySlotContents(int slotId, ItemStack stack)
      {
              this.inventory[slotId] = stack;
      
              if (stack != null && stack.stackSize > this.getInventoryStackLimit())
              {
                  stack.stackSize = this.getInventoryStackLimit();
              }
      
              this.markDirty();
      }
      
      @Override
      public String getInventoryName()
      {
      return this.hasCustomInventoryName() ? this.customName : "container.compressor";
      }
      
      @Override
      public boolean hasCustomInventoryName()
      {
              return this.customName != null && this.customName.length() > 0;
      }
      
         public void setCustomGuiName(String name)
         {
             this.customName = name;
         }
      
         @Override
      public int getInventoryStackLimit()
      {
      return 64;
      }
      
         @Override
      public boolean isUseableByPlayer(EntityPlayer player)
      {
      return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
      }
      
         @Override
         public boolean isItemValidForSlot(int par1, ItemStack par2ItemStack)
         {
             return par1 == 2 ? false : (par1 == 1 ? isItemFuel(par2ItemStack) : true);
         }
      
         @Override
         public void openInventory()
         {
         }
      
         @Override
         public void closeInventory() 
         {
         }
      
         @SideOnly(Side.CLIENT)
         public int getCompressProgressScaled(int speed)
         {
             return this.compressorResultCompressTime * speed/ this.maxCompressTime;
         }
      
         @SideOnly(Side.CLIENT)
         public int getCompressTimeRemainingScaled(int p_145955_1_)
         {
             if (this.currentItemPowerTime == 0)
             {
                 this.currentItemPowerTime = this.maxCompressTime;
             }
      
             return this.compressorCompressTime * p_145955_1_ / this.currentItemPowerTime;
         }
      
         public boolean isCompressing()
         {
             return this.compressorCompressTime > 0;
         }
      
         public void updateEntity()
         {
        this.active = this.compressorCompressTime > 0;
        if(this.getBlockMetadata() == 0)
             {
            this.maxCompressTime = 200;
            this.powerMultiplier = 1.0F;
             }
             else if(this.getBlockMetadata() == 1)
             {
            this.maxCompressTime = 190;
            this.powerMultiplier = 1.1F;
             }
             else if(this.getBlockMetadata() == 2)
             {
            this.maxCompressTime = 150;
            this.powerMultiplier = 1.3F;
             }
      
             boolean flag1 = false;
      
             if (this.compressorCompressTime > 0)
             {
                 –this.compressorCompressTime;
             }
      
             if (!this.worldObj.isRemote)
             {
                 if (this.compressorCompressTime == 0 && this.canCompress())
                 {
                     this.currentItemPowerTime = this.compressorCompressTime = getItemPowerTime(this.inventory[1]);
      
                     if (this.compressorCompressTime > 0)
                     {
                         flag1 = true;
      
                         if (this.inventory[1] != null)
                         {
                             –this.inventory[1].stackSize;
      
                             if (this.inventory[1].stackSize == 0)
                             {
                                 this.inventory[1] = inventory[1].getItem().getContainerItem(inventory[1]);
                             }
                         }
                     }
                 }
      
                 if (this.isCompressing() && this.canCompress())
                 {
                     ++this.compressorResultCompressTime;
      
                     if (this.compressorResultCompressTime == maxCompressTime)
                     {
                         this.compressorResultCompressTime = 0;
                         this.compressItem();
                         flag1 = true;
                     }
                 }
                 else
                 {
                     this.compressorResultCompressTime = 0;
                 }
      
                 if(active != this.compressorCompressTime > 0)
      {
      flag1 = true;
      this.active = this.compressorCompressTime > 0;
      if(!this.worldObj.isRemote)
      {
      this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
      }
      }
             }
      
             if (flag1)
             {
                 this.markDirty();
             }
         }
      
         private boolean canCompress()
         {
             if (this.inventory[0] == null)
             {
                 return false;
             }
             else
             {
                 ItemStack itemstack = CompressorRecipes.compressing().getCompressingResult(this.inventory[0]);
                 if (itemstack == null) return false;
                 if (this.inventory[2] == null) return true;
                 if (!this.inventory[2].isItemEqual(itemstack)) return false;
                 int result = inventory[2].stackSize + itemstack.stackSize;
                 return result <= getInventoryStackLimit() && result <= this.inventory[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
             }
         }
      
         public void compressItem()
         {
             if (this.canCompress())
             {
                 ItemStack itemstack = CompressorRecipes.compressing().getCompressingResult(this.inventory[0]);
      
                 if (this.inventory[2] == null)
                 {
                     this.inventory[2] = itemstack.copy();
                 }
                 else if (this.inventory[2].getItem() == itemstack.getItem())
                 {
                     this.inventory[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items
                 }
      
                 –this.inventory[0].stackSize;
      
                 if (this.inventory[0].stackSize <= 0)
                 {
                     this.inventory[0] = null;
                 }
             }
         }
      
         public static int getItemPowerTime(ItemStack p_145952_0_)
         {
             if (p_145952_0_ == null)
             {
                 return 0;
             }
             else
             {
                 Item item = p_145952_0_.getItem();
      
                 if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air)
                 {
                     Block block = Block.getBlockFromItem(item);
      
                     if (block == Blocks.wooden_slab)
                     {
                         return Integer.valueOf((int) (150 * powerMultiplier));
                     }
      
                     if (block.getMaterial() == Material.wood)
                     {
                         return Integer.valueOf((int) (300 * powerMultiplier));
                     }
      
                     if (block == Blocks.coal_block)
                     {
                         return Integer.valueOf((int) (16000 * powerMultiplier));
                     }
                 }
      
                 if (item instanceof ItemTool && ((ItemTool)item).getToolMaterialName().equals("WOOD")) return Integer.valueOf((int) (200 * powerMultiplier));
                 if (item instanceof ItemSword && ((ItemSword)item).getToolMaterialName().equals("WOOD")) return Integer.valueOf((int) (200 * powerMultiplier));
                 if (item instanceof ItemHoe && ((ItemHoe)item).getToolMaterialName().equals("WOOD")) return Integer.valueOf((int) (200 * powerMultiplier));
                 if (item == Items.stick) return Integer.valueOf((int) (100 * powerMultiplier));
                 if (item == Items.coal) return Integer.valueOf((int) (1600 * powerMultiplier));
                 if (item == Items.lava_bucket) return Integer.valueOf((int) (20000 * powerMultiplier));
                 if (item == Item.getItemFromBlock(Blocks.sapling)) return Integer.valueOf((int) (100 * powerMultiplier));
                 if (item == Items.blaze_rod) return Integer.valueOf((int) (2400 * powerMultiplier));
                 return GameRegistry.getFuelValue(p_145952_0_);
             }
         }
      
         public static boolean isItemFuel(ItemStack p_145954_0_)
         {
             return getItemPowerTime(p_145954_0_) > 0;
         }
      
         public boolean canInsertItem(int par1, ItemStack par2ItemStack, int par3)
         {
             return this.isItemValidForSlot(par1, par2ItemStack);
         }
      
         public boolean canExtractItem(int par1, ItemStack par2ItemStack, int par3)
         {
             return par3 != 0 || par1 != 1 || par2ItemStack.getItem() == Items.bucket;
         }
      }
      
      

      Basic.java :

      
      // Tile Entity
      
      GameRegistry.registerTileEntity(TileEntityCrusher.class, "neworesbasic:crusher");
      GameRegistry.registerTileEntity(TileEntityCompressor.class, "neworesbasic:compressor");
      
      // Gui Handler
      NetworkRegistry.INSTANCE.registerGuiHandler(this.instance, new GuiHandlerCrusher());
      NetworkRegistry.INSTANCE.registerGuiHandler(this.instance, new GuiHandlerCompressor());
      ```</todo>

      Mes mods:

      • New Ores
      • More Dragons
      1 réponse Dernière réponse Répondre Citer 0
      • Diangle
        Diangle dernière édition par

        Je t’aide une fois que tu as mis le code formater.

        1 réponse Dernière réponse Répondre Citer 0
        • robin4002
          robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

          NetworkRegistry.INSTANCE.registerGuiHandler(this.instance, new GuiHandlerCrusher());
          NetworkRegistry.INSTANCE.registerGuiHandler(this.instance, new GuiHandlerCompressor());

          Ça fait la deuxième fois que je vois la même connerie u_U
          [size=xx-largeUN MOD = UN GUI HANDLER]

          Ce n’est pourtant pas compliqué, il suffit de mettre des conditions dans le gui handler pour chaque gui / container …

          1 réponse Dernière réponse Répondre Citer 0
          • bin4r1s
            bin4r1s dernière édition par

            Ah pardon… Sujet résolu.

            Mes mods:

            • New Ores
            • More Dragons
            1 réponse Dernière réponse Répondre Citer 0
            • 1 / 1
            • Premier message
              Dernier message
            Design by Woryk
            Contact / Mentions Légales

            MINECRAFT FORGE FRANCE © 2018

            Powered by NodeBB