• Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Solved Faction et les coffres custom

    1.7.x
    1.7.10
    4
    4
    997
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      thecraft38 last edited by

      Bien le bonjour, je fais mon mod et récemment j’ai fait des test sur serveur mais je rencontre un problème qui est que les coffres de mon mods peuvent êtres ouverts dans les claims du plugin faction quelqu’un auraient une solution je ne trouve pas de solution ?
      la class du coffre :

      package thecraft.mod.common.blocks;
      
      import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
      import net.minecraft.block.Block;
      import net.minecraft.block.material.Material;
      import net.minecraft.entity.EntityLivingBase;
      import net.minecraft.entity.item.EntityItem;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.item.ItemStack;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.tileentity.TileEntity;
      import net.minecraft.tileentity.TileEntityChest;
      import net.minecraft.world.World;
      import thecraft.mod.common.TileEntityEwiliteChest;
      import thecraft.mod.common.ewifaction;
      
      public class Ewilitechest extends Block
      {
      @Override
      public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitx, float hity, float hitz)
      {
      if(world.isRemote)
      {
      return true;
      }
      else
      {
      player.openGui(ewifaction.instance, 0, world, x, y, z);
      return true;
      }
      }
      public Ewilitechest()
      {
      super(Material.iron);
      this.setHarvestLevel("axe", 3);
      }
      
      @Override
      public TileEntity createTileEntity(World world, int metadata)
      {
      return new TileEntityEwiliteChest();
      }
      @Override
      public boolean hasTileEntity(int metadata)
         {
             return true;
         }
      @Override
      public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
        {
            TileEntity tileentity = world.getTileEntity(x, y, z);
      
            if(tileentity instanceof IInventory)
            {
                IInventory inv = (IInventory)tileentity;
                for(int i1 = 0; i1 < inv.getSizeInventory(); ++i1)
                {
                    ItemStack itemstack = inv.getStackInSlot(i1);
      
                    if(itemstack != 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; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem))
                        {
                            int j1 = world.rand.nextInt(21) + 10;
      
                            if(j1 > itemstack.stackSize)
                            {
                                j1 = itemstack.stackSize;
                            }
      
                            itemstack.stackSize -= j1;
                            entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.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(itemstack.hasTagCompound())
                            {
                                entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
                            }
                        }
                    }
                }
                world.func_147453_f(x, y, z, block);
            }
            super.breakBlock(world, x, y, z, block, metadata);
        }
      @Override
      public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
        {
            TileEntity tile = world.getTileEntity(x, y, z);
            if(tile instanceof TileEntityEwiliteChest)
            {
                if(stack.hasDisplayName())
                {
                    ((TileEntityEwiliteChest)tile).setCustomName(stack.getDisplayName(), textureName);
                }
            }
        }
      
      }
      

      le container :

      package thecraft.mod.common;
      
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.entity.player.InventoryPlayer;
      import net.minecraft.inventory.Container;
      import net.minecraft.inventory.Slot;
      import net.minecraft.item.ItemStack;
      
      public class ContainerEwiliteChest extends Container
      {
      
      private final TileEntityEwiliteChest tileEwilite;
      
        public ContainerEwiliteChest(TileEntityEwiliteChest tile, InventoryPlayer inventory)
        {
        this.tileEwilite = tile;
        tile.openInventory();
            for(int i = 0; i < 6; ++i)
            {
                for(int j = 0; j < 9; ++j)
                {
                    this.addSlotToContainer(new Slot(tile, j + i * 9, 8 + j * 18, 18 + i * 18));
                }
            }
            this.bindPlayerInventory(inventory);
        }
        private void bindPlayerInventory(InventoryPlayer inventory)
        {
            int i;
            for(i = 0; i < 3; ++i)
            {
                for(int j = 0; j < 9; ++j)
                {
                    this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 140 + i * 18));
                }
            }
      
            for(i = 0; i < 9; ++i)
            {
                this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 198));
            }
        }
        public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex)
        {
            ItemStack itemstack = null;
            Slot slot = (Slot)this.inventorySlots.get(slotIndex);
      
            if(slot != null && slot.getHasStack())
            {
                ItemStack itemstack1 = slot.getStack();
                itemstack = itemstack1.copy();
      
                if(slotIndex < this.tileEwilite.getSizeInventory())
                {
                    if(!this.mergeItemStack(itemstack1, this.tileEwilite.getSizeInventory(), this.inventorySlots.size(), true))
                    {
                        return null;
                    }
                }
                else if(!this.mergeItemStack(itemstack1, 0, this.tileEwilite.getSizeInventory(), false))
                {
                    return null;
                }
      
                if(itemstack1.stackSize == 0)
                {
                    slot.putStack((ItemStack)null);
                }
                else
                {
                    slot.onSlotChanged();
                }
            }
            return itemstack;
        }
        @Override
        public boolean canInteractWith(EntityPlayer player)
        {
        return this.tileEwilite.isUseableByPlayer(player);
        }
        public void onContainerClosed(EntityPlayer player)
        {
            super.onContainerClosed(player);
            this.tileEwilite.closeInventory();
        }
      }
      

      la gui :

      package thecraft.mod.common;
      
      import org.lwjgl.opengl.GL11;
      
      import net.minecraft.client.gui.inventory.GuiContainer;
      import net.minecraft.client.resources.I18n;
      import net.minecraft.entity.player.InventoryPlayer;
      import net.minecraft.inventory.Container;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.util.ResourceLocation;
      
      public class GuiEwiliteChest extends GuiContainer
      {
      private static final ResourceLocation textures = new ResourceLocation(ewifaction.MODID + ":textures/gui/ewilitechestguitex.png");
        private TileEntityEwiliteChest tileewilite;
        private IInventory playerInv;
      
        public GuiEwiliteChest(TileEntityEwiliteChest tile, InventoryPlayer inventory)
        {
            super(new ContainerEwiliteChest(tile, inventory));
            this.tileewilite = tile;
            this.playerInv = inventory;
            this.allowUserInput = false;
            this.ySize = 220;
        }
      
        @Override
        protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y)
        {
        String tileName = this.tileewilite.hasCustomInventoryName() ? this.tileewilite.getInventoryName() : I18n.format(this.tileewilite.getInventoryName());
            String invName = this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName());
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            this.mc.getTextureManager().bindTexture(textures);
            int k = (this.width - this.xSize) / 2;
            int l = (this.height - this.ySize) / 2;
            this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
        }
      }
      

      le title entity :

      package thecraft.mod.common;
      
      import ibxm.Player;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.item.ItemStack;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.nbt.NBTTagList;
      import net.minecraft.tileentity.TileEntity;
      import net.minecraft.world.World;
      import net.minecraftforge.common.util.Constants;
      
      public class TileEntityEwiliteChest extends TileEntity implements IInventory
      {
         private ItemStack[] contents = new ItemStack[54];
         private String customName;
      
         @Override
         public void readFromNBT(NBTTagCompound compound)
         {
             super.readFromNBT(compound);
             if (compound.hasKey("CustomName", Constants.NBT.TAG_STRING))
             {
                 this.customName = compound.getString("CustomName");
             }
      
             NBTTagList nbttaglist = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
             this.contents = new ItemStack[this.getSizeInventory()];
      
             for (int i = 0; i < nbttaglist.tagCount(); ++i)
             {
                 NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                 int j = nbttagcompound1.getByte("Slot") & 510;
      
                 if (j >= 0 && j < this.contents.length)
                 {
                     this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                 }
             }
         }
      
         @Override
         public void writeToNBT(NBTTagCompound compound)
         {
             super.writeToNBT(compound);
             if (this.hasCustomInventoryName())
             {
                 compound.setString("CustomName", this.customName);
             }
      
             NBTTagList nbttaglist = new NBTTagList();
      
             for (int i = 0; i < this.contents.length; ++i)
             {
                 if (this.contents* != null)
                 {
                     NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                     nbttagcompound1.setByte("Slot", (byte) i);
                     this.contents*.writeToNBT(nbttagcompound1);
                     nbttaglist.appendTag(nbttagcompound1);
                 }
             }
             compound.setTag("Items", nbttaglist);
         }
      
         @Override
         public int getSizeInventory()
         {
             return this.contents.length;
         }
      
         @Override
         public ItemStack getStackInSlot(int slotIndex)
         {
             return this.contents[slotIndex];
         }
      
         @Override
         public ItemStack decrStackSize(int slotIndex, int amount)
         {
             if (this.contents[slotIndex] != null)
             {
                 ItemStack itemstack;
      
                 if (this.contents[slotIndex].stackSize <= amount)
                 {
                     itemstack = this.contents[slotIndex];
                     this.contents[slotIndex] = null;
                     this.markDirty();
                     return itemstack;
                 }
                 else
                 {
                     itemstack = this.contents[slotIndex].splitStack(amount);
      
                     if (this.contents[slotIndex].stackSize == 0)
                     {
                         this.contents[slotIndex] = null;
                     }
                     this.markDirty();
                     return itemstack;
                 }
             }
             else
             {
                 return null;
             }
         }
      
         @Override
         public ItemStack getStackInSlotOnClosing(int slotIndex)
         {
             if (this.contents[slotIndex] != null)
             {
                 ItemStack itemstack = this.contents[slotIndex];
                 this.contents[slotIndex] = null;
                 return itemstack;
             }
             else
             {
                 return null;
             }
         }
      
         @Override
         public void setInventorySlotContents(int slotIndex, ItemStack stack)
         {
             this.contents[slotIndex] = stack;
      
             if (stack != null && stack.stackSize > this.getInventoryStackLimit())
             {
                 stack.stackSize = this.getInventoryStackLimit();
             }
      
             this.markDirty();
         }
      
         @Override
         public String getInventoryName()
         {
             return ewifaction.ewilitechest.getLocalizedName();
         }
      
         @Override
         public boolean hasCustomInventoryName()
         {
             return false;
         }
      
         @Override
         public int getInventoryStackLimit()
         {
             return 64;
         }
      
         @Override
         public boolean isUseableByPlayer(EntityPlayer player)
         {
             return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D;
         }
      
         @Override
         public void openInventory()
         {
      
         }
      
         @Override
         public void closeInventory()
         {
      
         }
      
         @Override
         public boolean isItemValidForSlot(int slotIndex, ItemStack stack)
         {
             return true;
         }
      
         public void setCustomName(String displayName, String customName)
         {
             this.customName = customName;
         }
      }
      
      

      Le GuiHandler :

      package thecraft.mod.common;
      
      import cpw.mods.fml.common.network.IGuiHandler;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.tileentity.TileEntity;
      import net.minecraft.world.World;
      import thecraft.mod.common.items.ItemBackPack;
      
      public class GuihandlerEwifaction implements IGuiHandler
      {
         @Override
         public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
         {
             TileEntity tile = world.getTileEntity(x, y, z);
             if (tile instanceof TileEntityEwiliteChest)
             {
                 return new ContainerEwiliteChest((TileEntityEwiliteChest) tile, player.inventory);
             }
             else if(tile instanceof TileEntityExoniteChest)
             {
              return new ContainerExoniteChest((TileEntityExoniteChest) tile , player.inventory);
             }
             else if(tile instanceof TileEntityEwiliteMachine)
             {
              return new ContainerEwiliteMachine((TileEntityEwiliteMachine)tile, player.inventory);
             }
             else if (player.getHeldItem() == null || !(player.getHeldItem().getItem() instanceof ItemBackPack)) return null;
             {
      return new ContainerBackPack(player.inventory, new InventoryBackPack(player.getHeldItem(), 54));
      }
      
      }
      
         @Override
         public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
         {
             TileEntity tile = world.getTileEntity(x, y, z);
             if (tile instanceof TileEntityEwiliteChest)
             {
                 return new GuiEwiliteChest((TileEntityEwiliteChest) tile, player.inventory);
             }
             else if(tile instanceof TileEntityExoniteChest)
             {
              return new GuiExoniteChest((TileEntityExoniteChest) tile, player.inventory);
             }
             else if(tile instanceof TileEntityEwiliteMachine)
             {
              return new GuiEwiliteMachine((TileEntityEwiliteMachine) tile, player.inventory);
             }
             else if (player.getHeldItem() == null || !(player.getHeldItem().getItem() instanceof ItemBackPack)) return null;
             {
          return new GuiBackPack(new InventoryBackPack(player.getHeldItem(), 54), player.inventory);
             }
      }
      }
      
      1 Reply Last reply Reply Quote 0
      • Pchom
        Pchom last edited by

        Un conseil, utilise la balise [ java ] plutôt que la balise [ code ], ça sera plus simple à lire, et tu auras plus facilement de l’aide.

        > *Si vous ne pouvez expliquer un concept à un enfant de six ans, c’est que vous ne le comprenez pas c…

        1 Reply Last reply Reply Quote 1
        • robin4002
          robin4002 Moddeurs confirmés Rédacteurs Administrateurs last edited by

          Salut,
          Il faut regarder si le plugin a une option pour ajouter des blocs custom.

          Worldguard par exemple avait une option pour ça.

          1 Reply Last reply Reply Quote 0
          • moscaphone421
            moscaphone421 last edited by

            Alors autant que je me rappel :
            Dans ton serveur tu as un dossier MSTORE et dedans plusieurs dossier, dans l’un d’eu tu as un instance.json (il y en a deux test les deux)
            Il y a un endroit ont sont liste des blocs / mobs
            AJoute ton coffre dedans

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Design by Woryk
            Contact / Mentions Légales

            MINECRAFT FORGE FRANCE © 2018

            Powered by NodeBB