perromercenary00 Posted October 21, 2015 Posted October 21, 2015 good days as in the title explain i wanna make an inventory whith a gui in which you just can interacc whith the enable itemSlots is becose i make a gui that allow acces to mobs inventory things like armours and held item , and i dont wanna have player exploting this to dissarm armed mobs or pillage expensive items from mobs or other players Quote
perromercenary00 Posted October 21, 2015 Author Posted October 21, 2015 yes but i want them to be visible and you can not move this items anywhere the other tink i notice is that aparently you can not change the declared container on the fly and i need someting like that but is little hars to explain in english and tats gonna need video but no time now Quote
WeiseGuy Posted October 21, 2015 Posted October 21, 2015 Only the slots that you actually register via addSlotToContainer in your Container class will be usable by the player. IInventory has a "isUsableByplayer" method right? Or is that on Container? Either way, override it to false and/or some method to check if they can edit or not and you should be fine, no? By default its true, or its something like: @Override public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { return true; } Sometimes people use this to determine if player is within 8 blocks of the object: @Override public boolean isUseableByPlayer(EntityPlayer playerIn) { return worldObj.getTileEntity(pos) != this ? false : playerIn.getDistanceSq(pos.getX()+0.5D, pos.getY()+0.5D, pos.getZ()+0.5D) <= 64.0D; } Isn't that checking if the player is able to utilize the inventory, as in, modify it? Quote www.YouTube.com/WeiseGamer www.twitter.com/WeiseGamer
WeiseGuy Posted October 21, 2015 Posted October 21, 2015 That would be for the whole container though. True, if the slots are all assigned to the same IInventory. this.addSlotToContainer(new Slot(IInventory, slotIndex, xPos, yPos)) Make the "enable slots" have their own IInventory? Or make a custom Slot called "enableSlot" and @Override onSlotClicked. I feel there are a few ways of doing what he wants, but its a little hard to understand the expected result. Or add an IF statement that checks the slotClicked on isUsableByPlayer (I can't recall if the slot is passed into this class or not). Quote www.YouTube.com/WeiseGamer www.twitter.com/WeiseGamer
perromercenary00 Posted October 23, 2015 Author Posted October 23, 2015 good nigths sorry i been working on this and forget all about the post I found its posible to, on the fly change the Container and the the gui background using a trick calling again the gui handler, in mi case player.openGui(Mercenary.instance, guiHandlers.GUIMERCENARIA00, worldIn, 0, 0, 0); but must be done in the rigth moment and has its downsides, its throws to the ground, whatever the itemStack you have in your hand this code has some issues, sometimes the armor gets stuck and the gui/container don't change, i think is becoze it take some tics to the server to recive the packages or whatever and apply changes to inventory, so its end whith something null Video here i can open the inventory of any entityLiving mob set armours change weapons, thats what i wanna control, i create 3 sets of custome container/gui the first for entities whitout armour or armour whitout pockets just five slots for armour and main weapon the second for the armours whith sevent pockets six for munition and one for SubWeapon the third for armours whith 23 pockets , one subWeapon plus 6 slots plus backpack 16 slots the gui now change in base to what its inside the entity chest slot ### Questions - ¿is posible to send a package whith an NBTTag compound whith all the items ffrom local to server ?? i need to fix sync - ¿how do you do the canTakeStack ting i found the code public boolean canTakeStack(EntityPlayer playerIn) { return true; } @SideOnly(Side.CLIENT) public boolean canBeHovered() { return true; } but no idea of how actually use them well thanks Quote
perromercenary00 Posted October 25, 2015 Author Posted October 25, 2015 (hiding them, by setting e.g. xCoord to -999) thats good thats solve most of the troubles but was not so easy i have to make seters a getters to properly control gui and container from iinventory and add some methods to delete the arrayList in the container and recreate it as i whish at demand, for some reason i could not override the other method in the original container class whitout end whit weird behaveours if i override slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) whiout changes it works until player try to drag someting then crash. or left all the slots unaccesibles close/open to fix , whith this method i could avoid the player to make click and get the contens for individual slots ñaa i gonna end written some rules to avoid open the gui over some mobs and creatures ### the nest question is how do you prevent to put items that are not armour in the armmour slots, so you can only put helmet items in the helmet slots and boot in boots slot im pretty sure i read something about it in a guide from jabellar but now idont find it anywhere Quote
perromercenary00 Posted October 26, 2015 Author Posted October 26, 2015 well is becoze i been alredy tryng that and don't works this is in the IInventory class, but this is just for when player pickup somethig or drop something in the inventory i think must do same but in the slot class and thats trouble if i extend the Slot.class whit mi mercenarySlot.class for some reason the forge Container.class don't accep mi slot's and i end whith a bunch of empty slots in the gui, is like all slots that reach to Container.class is null or becomes null and it sends its like that // ################################################################################################### /** * Returns true if automation is allowed to insert the given stack (ignoring * stack size) into the given slot. */ @Override public boolean isItemValidForSlot(int index, ItemStack stack) { if (index > 0 & index < 5 ) { /** Stores the armor type: 0 is helmet, 1 is plate, 2 is legs and 3 is boots */ int armadura = armasDisparables.esArmadura(stack); if (armadura < 0) { return false; } //botas if (index == 1 & armadura != 3) { return false; } //pantalones if (index == 2 & armadura != 2) { return false; } //chest if (index == 3 & armadura != 1) { return false; } //casco if (index == 4 & armadura != 0) { return false; } } return true; } // ################################################################################################### package mercenarymod.gui.containers; //package net.minecraft.inventory; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class mercenarySlot extends Slot { /** The index of the slot in the inventory. */ private final int slotIndex; /** The inventory we want to extract a slot from. */ public final IInventory inventory; /** the id of the slot(also the index in the inventory arraylist) */ public int slotNumber; /** display position of the inventory slot on the screen x axis */ public int xDisplayPosition; /** display position of the inventory slot on the screen y axis */ public int yDisplayPosition; private static final String __OBFID = "CL_00001762"; private boolean habilitado = true; // ##########################################################################################3 public mercenarySlot(IInventory inventoryIn, int index, int xPosition, int yPosition) { super(inventoryIn, index, xPosition, yPosition); this.inventory = inventoryIn; this.slotIndex = index; this.xDisplayPosition = xPosition; this.yDisplayPosition = yPosition; } // ##########################################################################################3 @Override /** * if par2 has more items than par1, onCrafting(item,countIncrease) is * called */ public void onSlotChange(ItemStack p_75220_1_, ItemStack p_75220_2_) { if (p_75220_1_ != null && p_75220_2_ != null) { if (p_75220_1_.getItem() == p_75220_2_.getItem()) { int i = p_75220_2_.stackSize - p_75220_1_.stackSize; if (i > 0) { this.onCrafting(p_75220_1_, i); } } } } // ##########################################################################################3 @Override /** * the itemStack passed in is the output - ie, iron ingots, and pickaxes, * not ore and wood. Typically increases an internal count then calls * onCrafting(item). */ protected void onCrafting(ItemStack stack, int amount) { } // ##########################################################################################3 @Override /** * the itemStack passed in is the output - ie, iron ingots, and pickaxes, * not ore and wood. */ protected void onCrafting(ItemStack stack) { } // ##########################################################################################3 @Override public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack) { this.onSlotChanged(); } // ##########################################################################################3 @Override /** * Check if the stack is a valid item for this slot. Always true beside for * the armor slots. */ public boolean isItemValid(ItemStack stack) { return true; } // ##########################################################################################3 @Override /** * Helper fnct to get the stack in the slot. */ public ItemStack getStack() { return this.inventory.getStackInSlot(this.slotIndex); } // ##########################################################################################3 @Override /** * Returns if this slot contains a stack. */ public boolean getHasStack() { return this.getStack() != null; } // ##########################################################################################3 @Override /** * Helper method to put a stack in the slot. */ public void putStack(ItemStack stack) { this.inventory.setInventorySlotContents(this.slotIndex, stack); this.onSlotChanged(); } // ##########################################################################################3 @Override /** * Called when the stack in a Slot changes */ public void onSlotChanged() { this.inventory.markDirty(); } // ##########################################################################################3 @Override /** * Returns the maximum stack size for a given slot (usually the same as * getInventoryStackLimit(), but 1 in the case of armor slots) */ public int getSlotStackLimit() { return this.inventory.getInventoryStackLimit(); } // ##########################################################################################3 @Override public int getItemStackLimit(ItemStack stack) { return this.getSlotStackLimit(); } // ##########################################################################################3 @Override @SideOnly(Side.CLIENT) public String getSlotTexture() { return backgroundName; } // ##########################################################################################3 @Override /** * Decrease the size of the stack in slot (first int arg) by the amount of * the second int arg. Returns the new stack. */ public ItemStack decrStackSize(int amount) { return this.inventory.decrStackSize(this.slotIndex, amount); } // ##########################################################################################3 @Override /** * returns true if the slot exists in the given inventory and location */ public boolean isSlotInInventory(IInventory inv, int slotIn) { return inv == this.inventory && slotIn == this.slotIndex; } // ##########################################################################################3 @Override /** * Return whether this slot's stack can be taken from this slot. */ public boolean canTakeStack(EntityPlayer playerIn) { return habilitado; } // ##########################################################################################3 @Override /** * Actualy only call when we want to render the white square effect over the * slots. Return always True, except for the armor slot of the Donkey/Mule * (we can't interact with the Undead and Skeleton horses) */ @SideOnly(Side.CLIENT) public boolean canBeHovered() { return habilitado; } // ##########################################################################################3 public void setHabilitado(boolean b) { habilitado = b; } // ##########################################################################################3 public boolean getHabilitado() { return habilitado; } } package mercenarymod.gui.containers; import net.minecraft.entity.Entity; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import mercenarymod.entidades.armasDisparables; import mercenarymod.items.armasdefuego.inventario.inventarioArmas; import mercenarymod.items.armasdefuego.inventario.inventarioArmasyEntidades; import mercenarymod.tileentity.ModTileEntity; import mercenarymod.utilidades.util; public class ContainerMenuMercenario02 extends Container { private int bolsillos = 0; private inventarioArmasyEntidades inventarioenlaArmadura; private IInventory playerInv = null; private EntityLivingBase entidad = null; /** * The current drag mode (0 : evenly split, 1 : one item by slot, 2 : not * used ?) */ //private int dragMode = -1; /** The current drag event (0 : start, 1 : add slot : 2 : end) */ //private int dragEvent; /** The list of slots where the itemstack holds will be distributed */ //private final Set dragSlots = Sets.newHashSet(); // ############################################################################################################################################## private void cantidaddeBolsillos() { } // ############################################################################################################################################## /* * SLOTS: * * Tile Entity 0-8 ........ 0 - 8 Player Inventory 9-35 .. 9 - 35 Player * Inventory 0-8 ... 36 - 44 */ public ContainerMenuMercenario02(IInventory playerInv, inventarioArmasyEntidades te) { // super(); this.inventarioenlaArmadura = te; this.bolsillos = te.getBolsillos(); this.entidad = te.getEntity(); this.playerInv = playerInv; // System.out.println("################# ContainerMenuMercenario02"); // weapon slot this.addSlotToContainer(new mercenarySlot(te, 0, 26, ); // entity armor slots this.addSlotToContainer(new mercenarySlot(te, 4, 8, ); this.addSlotToContainer(new mercenarySlot(te, 3, 8, 26)); this.addSlotToContainer(new mercenarySlot(te, 2, 8, 44)); this.addSlotToContainer(new mercenarySlot(te, 1, 8, 62)); // Sub weapon slot this.addSlotToContainer(new mercenarySlot(te, 5, -999, 26)); // six pockets tactical vest this.addSlotToContainer(new mercenarySlot(te, 6, -999, ); this.addSlotToContainer(new mercenarySlot(te, 7, -999, ); this.addSlotToContainer(new mercenarySlot(te, 8, -999, 26)); this.addSlotToContainer(new mercenarySlot(te, 9, -999, 26)); this.addSlotToContainer(new mercenarySlot(te, 10, -999, 44)); this.addSlotToContainer(new mercenarySlot(te, 11, -999, 44)); // BackPack for (int x = 0; x < 4; ++x) { this.addSlotToContainer(new mercenarySlot(te, 12 + (x * 4), -999, 8 + (18 * x))); this.addSlotToContainer(new mercenarySlot(te, 13 + (x * 4), -999, 8 + (18 * x))); this.addSlotToContainer(new mercenarySlot(te, 14 + (x * 4), -999, 8 + (18 * x))); this.addSlotToContainer(new mercenarySlot(te, 15 + (x * 4), -999, 8 + (18 * x))); } // 0 - 27 chest slots // 28 - 54 // Player Inventory, Slot 9-35, Slot IDs 9-35 for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new mercenarySlot(playerInv, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); } } // 55 - 64 // Player Inventory, Slot 0-8, Slot IDs 36-44 for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new mercenarySlot(playerInv, x, 8 + x * 18, 142)); } // te.readFromNBT(null); ItemStack chestIS = this.entidad.getEquipmentInSlot(3); if (chestIS != null) { int sn = armasDisparables.tieneBolsillos(chestIS); this.bolsillos = sn; switch (sn) { case 0: this.cambiarA0(); break; case 7: this.cambiarA7(); break; case 23: this.cambiarA23(); break; } } } // ############################################################################################################################################## public void cambiarA0() { inventoryItemStacks = Lists.newArrayList(); /** the list of all slots in the inventory */ inventorySlots = Lists.newArrayList(); crafters = Lists.newArrayList(); // System.out.println("################# ContainerMenu cambiarA0"); // weapon slot this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 0, 26, ); // entity armor slots this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 4, 8, ); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 3, 8, 26)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 2, 8, 44)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 1, 8, 62)); // Sub weapon slot this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 5, -999, 26)); // six pockets tactical vest this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 6, -999, ); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 7, -999, ); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 8, -999, 26)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 9, -999, 26)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 10, -999, 44)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 11, -999, 44)); // BackPack for (int x = 0; x < 4; ++x) { this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 12 + (x * 4), -999, 8 + (18 * x))); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 13 + (x * 4), -999, 8 + (18 * x))); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 14 + (x * 4), -999, 8 + (18 * x))); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 15 + (x * 4), -999, 8 + (18 * x))); } /* * Tile Entity 0-8 ........ 0-27 Player Inventory 9-35 .. 28 - 55 Player * Inventory 0-8 ... 56 - 64 */ // 0 - 27 chest slots // 28 - 54 // Player Inventory, Slot 9-35, Slot IDs 9-35 for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new mercenarySlot(this.playerInv, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); } } // 55 - 64 // Player Inventory, Slot 0-8, Slot IDs 36-44 for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new mercenarySlot(this.playerInv, x, 8 + x * 18, 142)); } // System.out.println("inventorySlots"+inventorySlots); // System.out.println("inventorySlots="+inventorySlots.size()); } // ############################################################################################################################################## public void cambiarA7() { inventoryItemStacks = Lists.newArrayList(); /** the list of all slots in the inventory */ inventorySlots = Lists.newArrayList(); crafters = Lists.newArrayList(); // System.out.println("################# ContainerMenu cambiarA7"); // weapon slot this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 0, 26, ); // entity armor slots this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 4, 8, ); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 3, 8, 26)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 2, 8, 44)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 1, 8, 62)); // Sub weapon slot this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 5, 26, 26)); // six pockets tactical vest this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 6, 53, ); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 7, 71, ); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 8, 53, 26)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 9, 71, 26)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 10, 53, 44)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 11, 71, 44)); // BackPack for (int x = 0; x < 4; ++x) { this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 12 + (x * 4), -999, 8 + (18 * x))); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 13 + (x * 4), -999, 8 + (18 * x))); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 14 + (x * 4), -999, 8 + (18 * x))); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 15 + (x * 4), -999, 8 + (18 * x))); } /* * Tile Entity 0-8 ........ 0-27 Player Inventory 9-35 .. 28 - 55 Player * Inventory 0-8 ... 56 - 64 */ // 0 - 27 chest slots // 28 - 54 // Player Inventory, Slot 9-35, Slot IDs 9-35 for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new mercenarySlot(this.playerInv, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); } } // 55 - 64 // Player Inventory, Slot 0-8, Slot IDs 36-44 for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new mercenarySlot(this.playerInv, x, 8 + x * 18, 142)); } // System.out.println("inventorySlots"+inventorySlots); // System.out.println("inventorySlots="+inventorySlots.size()); } // ############################################################################################################################################## public void cambiarA23() { inventoryItemStacks = Lists.newArrayList(); /** the list of all slots in the inventory */ inventorySlots = Lists.newArrayList(); crafters = Lists.newArrayList(); // System.out.println("################# ContainerMenu cambiarA7"); // weapon slot this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 0, 26, ); // entity armor slots this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 4, 8, ); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 3, 8, 26)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 2, 8, 44)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 1, 8, 62)); // Sub weapon slot this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 5, 26, 26)); // six pockets tactical vest this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 6, 53, ); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 7, 71, ); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 8, 53, 26)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 9, 71, 26)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 10, 53, 44)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 11, 71, 44)); // BackPack for (int x = 0; x < 4; ++x) { this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 12 + (x * 4), 98, 8 + (18 * x))); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 13 + (x * 4), 116, 8 + (18 * x))); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 14 + (x * 4), 134, 8 + (18 * x))); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 15 + (x * 4), 152, 8 + (18 * x))); } /* * Tile Entity 0-8 ........ 0-27 Player Inventory 9-35 .. 28 - 55 Player * Inventory 0-8 ... 56 - 64 */ // 0 - 27 chest slots // 28 - 54 // Player Inventory, Slot 9-35, Slot IDs 9-35 for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new mercenarySlot(this.playerInv, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); } } // 55 - 64 // Player Inventory, Slot 0-8, Slot IDs 36-44 for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new mercenarySlot(this.playerInv, x, 8 + x * 18, 142)); } // System.out.println("inventorySlots"+inventorySlots); // System.out.println("inventorySlots="+inventorySlots.size()); } // ############################################################################################################################################## @Override public boolean canInteractWith(EntityPlayer playerIn) { return this.inventarioenlaArmadura.isUseableByPlayer(playerIn); } // ############################################################################################################################################## @Override public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) { ItemStack previous = null; Slot slot = (Slot) this.inventorySlots.get(fromSlot); if (slot != null && slot.getHasStack()) { ItemStack current = slot.getStack(); previous = current.copy(); if (fromSlot < 28) { // From TE Inventory to Player Inventory if (!this.mergeItemStack(current, 28, 63, true)) return null; } else { // From Player Inventory to TE Inventory if (!this.mergeItemStack(current, 0, 28, false)) return null; } if (current.stackSize == 0) slot.putStack((ItemStack) null); else slot.onSlotChanged(); if (current.stackSize == previous.stackSize) return null; slot.onPickupFromSlot(playerIn, current); } return previous; } // ############################################################################################################################################## package mercenarymod.items.armasdefuego.inventario; import java.util.ArrayList; import java.util.Random; import mercenarymod.Mercenary; import mercenarymod.entidades.armasDisparables; import mercenarymod.gui.guiHandlers; import mercenarymod.gui.containers.ContainerMenuMercenario00; import mercenarymod.gui.containers.ContainerMenuMercenario01; import mercenarymod.gui.containers.ContainerMenuMercenario02; import mercenarymod.gui.guis.guiMenuMercenario02; import mercenarymod.items.MercenaryModItems; import mercenarymod.tileentity.ModTileEntity; import mercenarymod.utilidades.util; import net.minecraft.block.BlockChest; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.monster.EntitySkeleton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.Container; import net.minecraft.inventory.ContainerDispenser; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntityDispenser; import net.minecraft.tileentity.TileEntityLockable; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; import net.minecraft.world.IWorldNameable; import net.minecraft.world.World; //################################################################################################### public class inventarioArmasyEntidades implements IInventory // extends TileEntityDispenser implements IInventory { { // private ItemStack pistola = null; private int SizeInventory = 28; private ItemStack[] Items = new ItemStack[sizeInventory]; private boolean[] slotHabilitado = new boolean[sizeInventory]; private World worldIn = null; private static final Random RNG = new Random(); private String customName = "algo"; private EntityLivingBase entidad = null; private EntityLivingBase playerIn = null; private double posEX = 0; private double posEY = 0; private double posEZ = 0; private ItemStack chestItem = null; private int numerodeserie = 0; private int bolsillos = 0; private ContainerMenuMercenario02 containerMercenario = null; private guiMenuMercenario02 gui02 = null; // ################################################################################################### public inventarioArmasyEntidades(World worldIn, EntityLivingBase entidad, EntityLivingBase playerIn) { super(); // this.pistola = entidad.getHeldItem() ; this.worldIn = worldIn; this.entidad = entidad; this.playerIn = playerIn; // System.out.println("\n###\n###\n###\ninventarioArmasyEntidades=" + // worldIn.isRemote + "\n###"); NBTTagCompound tagCompund = null; if (this.entidad != null) { this.readFromNBT(null); } } // ################################################################################################### /** * Returns the number of slots in the inventory. */ @Override public int getSizeInventory() // ItemStack pistola { return SizeInventory;// SizeInventory; } // ################################################################################################### /** * inicializa cuales slots son validos y cuales estaran deshabilitados */ // a try to disable the armour slots whiout hide them // @Override public void habilitarSlots() // ItemStack pistola { for (int n = 0; n < SizeInventory; n++) { slotHabilitado[n] = true; if (n <= this.bolsillos + 4) { // slotHabilitado[n] = true; } else { // Items[n] = new ItemStack(MercenaryModItems.vacio, 1, 1); slotHabilitado[n] = false; } // System.out.println("mundo="+worldIn.isRemote+" // slotHabilitado["+n+"]="+slotHabilitado[n]); } } // ################################################################################################### /** * Add the given ItemStack to this Dispenser. Return the Slot the Item was * placed in or -1 if no free slot is available. */ public int addItemStack(ItemStack stack) { for (int i = 0; i < Items.length; ++i) { if ((Items[i] == null || Items[i].getItem() == null)) { this.setInventorySlotContents(i, stack); return i; } } return -1; } // ################################################################################################### /** * Returns the maximum stack size for a inventory slot. Seems to always be * 64, possibly will be extended. *Isn't this more of a set than a get?* */ @Override public int getInventoryStackLimit() { return 64; } // ################################################################################################### /** * For tile entities, ensures the chunk containing the tile entity is saved * to disk later - the game won't think it hasn't changed and skip it. */ public void markDirty() { if (worldIn != null) { // System.out.println("\n\n Marcado como sucio en el mundo=" + // worldIn.isRemote); writeToNBT(new NBTTagCompound()); } } // ################################################################################################### /** * Do not make give this method the name canInteractWith because it clashes * with Container */ @Override public boolean isUseableByPlayer(EntityPlayer player) { return true; } @Override public void openInventory(EntityPlayer player) { // System.out.println("###### openInventory() "); } @Override public void closeInventory(EntityPlayer player) { // System.out.println("###### closeInventory() "); } // ################################################################################################### /** * Returns true if automation is allowed to insert the given stack (ignoring * stack size) into the given slot. */ @Override public boolean isItemValidForSlot(int index, ItemStack stack) { if (index > 0 & index < 5 ) { /** Stores the armor type: 0 is helmet, 1 is plate, 2 is legs and 3 is boots */ int armadura = armasDisparables.esArmadura(stack); if (armadura < 0) { return false; } //botas if (index == 1 & armadura != 3) { return false; } //pantalones if (index == 2 & armadura != 2) { return false; } //chest if (index == 3 & armadura != 1) { return false; } //casco if (index == 4 & armadura != 0) { return false; } } return true; } // ################################################################################################### @Override public int getField(int id) { return 0; } @Override public void setField(int id, int value) { } @Override public int getFieldCount() { return 0; } @Override public void clear() { for (int i = 0; i < Items.length; ++i) { Items[i] = null; } // System.out.println("$$$ clear()"); } @Override public String getName() { return this.customName; } /** * Returns true if this thing is named */ @Override public boolean hasCustomName() { return true; } // @Override public void setCustomName(String name) { this.customName = name; } @Override public IChatComponent getDisplayName() { IChatComponent displayname = new ChatComponentText(EnumChatFormatting.RED + "" + entidad.getName() + " id:/" + entidad.getEntityId()); return displayname; } // #########################################################################3 // @Override public void readFromNBT(NBTTagCompound compound) { // super.readFromNBT(compound); // System.out.println("\n### read from nbt mundo=" + worldIn.isRemote); // Items = new ItemStack[this.getSizeInventory()]; this.clear(); Items[0] = this.entidad.getEquipmentInSlot(0);// .getHeldItem(); Items[1] = this.entidad.getEquipmentInSlot(1);// getCurrentArmor(0); // boots Items[2] = this.entidad.getEquipmentInSlot(2);// getCurrentArmor(1); // pants Items[3] = this.entidad.getEquipmentInSlot(3);// getCurrentArmor(2); // chest Items[4] = this.entidad.getEquipmentInSlot(4);// getCurrentArmor(3); // helmet ItemStack chestIS = this.entidad.getEquipmentInSlot(3); //Items[3]; // this.bolsillos = 0; this.numerodeserie = 0; if (chestIS != null) { //get the amount of slots in this chest Armour Item int sn = armasDisparables.tieneBolsillos(chestIS); this.bolsillos = sn; //set slots pattern in Container if (containerMercenario != null) { // System.out.println("####################### // containerMercenario="+sn); switch (sn) { case 0: containerMercenario.cambiarA0(); break; case 7: containerMercenario.cambiarA7(); break; case 23: containerMercenario.cambiarA23(); break; } } //set gui background in gui if (gui02 != null) { // System.out.println("####################### gui02="+sn); gui02.guiN = sn; } this.chestItem = chestIS; //serial number from armour to know diferences betwint instance of the same kind of item numerodeserie = getInttag(chestIS, "numerodeserie"); if (numerodeserie < 1) { numerodeserie = util.getSerialAlHazar(); setInttag(chestIS, "numerodeserie", numerodeserie); } if (sn > 0) { NBTTagCompound compound2 = chestIS.getTagCompound(); if (compound2 != null) { NBTTagList nbttaglist2 = compound2.getTagList("Items", 10); for (int i = 0; i < nbttaglist2.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = nbttaglist2.getCompoundTagAt(i); int j = nbttagcompound1.getByte("Slot") & 255; // System.out.println("\n### read from nbt"); if (j >= 0 && j < Items.length) { Items[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); if (Items[j] != null) { // System.out.println("mundo="+worldIn.isRemote+" // slot read" + j + " =" + // Items[j].getUnlocalizedName()); } } } if (compound2.hasKey("CustomName", ) { this.customName = compound2.getString("CustomName"); } } } } else { //change slots order in Container to just basic five if (containerMercenario != null) { containerMercenario.cambiarA0(); } //change Gui BackGroundto basic five background if (gui02 != null) { gui02.guiN = 0; } } // System.out.println("mundo="+worldIn.isRemote+" // bolsillos="+this.bolsillos); // System.out.println("mundo="+worldIn.isRemote+" // numerodeserie="+this.numerodeserie); habilitarSlots(); } // #########################################################################3 // @Override public void writeToNBT(NBTTagCompound compound) { // super.writeToNBT(compound); // System.out.println("\n### write to nbt mundo=" + worldIn.isRemote); ItemStack chestIS = Items[3];// this.entidad.getEquipmentInSlot(3); int numerodeserieIS = 0; if (chestIS != null) { numerodeserieIS = getInttag(chestIS, "numerodeserie"); if (numerodeserieIS < 1) { numerodeserieIS = util.getSerialAlHazar(); setInttag(chestIS, "numerodeserie", numerodeserieIS); } } // System.out.println(worldIn.isRemote + " sn0=" + this.numerodeserie); // System.out.println(worldIn.isRemote + " sn1=" + numerodeserieIS); if (numerodeserieIS != numerodeserie) { this.entidad.setCurrentItemOrArmor(3, Items[3]); readFromNBT(null); // System.out.println("###" + "\n\n\n" + "Chest Item hass change"); if (playerIn instanceof EntityPlayer & worldIn.isRemote) { // ((EntityPlayer) playerIn).openGui(Mercenary.instance, // guiHandlers.GUIMERCENARIA00, worldIn, 0, 0, 0); } } else { if (chestIS != null) { int sn = armasDisparables.tieneBolsillos(chestIS); if (sn > 0) { NBTTagList nbttaglist = new NBTTagList(); for (int i = 5; i < Items.length; ++i) { if (Items[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte) i); Items[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } NBTTagCompound chestcompound = chestIS.getTagCompound(); if (chestcompound == null) { chestcompound = new NBTTagCompound(); } if (this.hasCustomName()) { chestcompound.setString("CustomName", this.customName); } chestcompound.setTag("Items", nbttaglist); chestIS.setTagCompound(chestcompound); this.Items[3] = chestIS; } } this.entidad.setCurrentItemOrArmor(0, Items[0]); this.entidad.setCurrentItemOrArmor(1, Items[1]); this.entidad.setCurrentItemOrArmor(2, Items[2]); this.entidad.setCurrentItemOrArmor(3, Items[3]); this.entidad.setCurrentItemOrArmor(4, Items[4]); } } // #########################################################################3 public int getDispenseSlot() { int i = -1; int j = 1; for (int k = 0; k < Items.length; ++k) { if (Items[k] != null && RNG.nextInt(j++) == 0) { i = k; } } return i; } // #########################################################################3 public String getGuiID() { return "minecraft:chest"; } // #########################################################################3 public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) { return new ContainerMenuMercenario02(playerInventory, this); } // #########################################################################3 @Override public ItemStack getStackInSlot(int index) { /* * if (index == 3){ //System.out.println("\n\n"+worldIn.isRemote); * * if (Items[3] == null){ //System.out.println(" SlotContents"+index+ * " st="+"null" ); } else { //System.out.println(" SlotContents"+index+ * " st="+Items[3].getUnlocalizedName() ); } * * } * */ if (index < 0 || index >= this.getSizeInventory()) return null; // System.out.println("getStackInSlot"+index); return this.Items[index]; } // #########################################################################3 @Override public ItemStack decrStackSize(int index, int count) { if (this.getStackInSlot(index) != null) { ItemStack itemstack; if (this.getStackInSlot(index).stackSize <= count) { itemstack = this.getStackInSlot(index); this.setInventorySlotContents(index, null); this.markDirty(); return itemstack; } else { itemstack = this.getStackInSlot(index).splitStack(count); if (this.getStackInSlot(index).stackSize <= 0) { this.setInventorySlotContents(index, null); } else { // Just to show that changes happened this.setInventorySlotContents(index, this.getStackInSlot(index)); } this.markDirty(); return itemstack; } } else { return null; } } // #########################################################################3 @Override public ItemStack getStackInSlotOnClosing(int index) { ItemStack stack = this.getStackInSlot(index); this.setInventorySlotContents(index, null); return stack; } // #########################################################################3 @Override public void setInventorySlotContents(int index, ItemStack stack) { if (index == 3) { // System.out.println("\n\n" + worldIn.isRemote); if (Items[3] == null) { // System.out.println(" SlotContents" + index + " st=" + // "null"); } else { // System.out.println(" SlotContents" + index + " st=" + // Items[3].getUnlocalizedName()); } if (stack == null) { // System.out.println(" setInventorySlotContents" + index + " // st=" + "null"); } else { // System.out.println(" setInventorySlotContents" + index + " // st=" + stack.getUnlocalizedName()); } if (playerIn instanceof EntityPlayer) { // ((EntityPlayer) playerIn).openGui(Mercenary.instance, // guiHandlers.GUIMERCENARIA00, worldIn, 0, 0, 0); } } if (index < 0 || index >= this.getSizeInventory()) return; if (stack != null && stack.stackSize > this.getInventoryStackLimit()) stack.stackSize = this.getInventoryStackLimit(); if (stack != null && stack.stackSize == 0) stack = null; this.Items[index] = stack; this.markDirty(); } public String getCustomName() { return this.customName; } // #########################################################################3 public static float getFloattag(ItemStack item, String tag) { NBTTagCompound etiquetas = item.getTagCompound(); if (etiquetas == null) { etiquetas = new NBTTagCompound(); item.setTagCompound(etiquetas); return 0.0F; } float ex = etiquetas.getFloat(tag); return ex; } // #########################################################################3 public static void setFloattag(ItemStack item, String tag, float value) { NBTTagCompound etiquetas = item.getTagCompound(); if (etiquetas == null) { etiquetas = new NBTTagCompound(); } etiquetas.setFloat(tag, value); item.setTagCompound(etiquetas); } // #########################################################################3 public static int getInttag(ItemStack item, String tag) { NBTTagCompound etiquetas = item.getTagCompound(); if (etiquetas == null) { etiquetas = new NBTTagCompound(); item.setTagCompound(etiquetas); return 0; } int ex = etiquetas.getInteger(tag); return ex; } // #########################################################################3 public static void setInttag(ItemStack item, String tag, int value) { NBTTagCompound etiquetas = item.getTagCompound(); if (etiquetas == null) { etiquetas = new NBTTagCompound(); } etiquetas.setInteger(tag, value); item.setTagCompound(etiquetas); } // #########################################################################3 public static int[] getIntArraytag(ItemStack item, String tag) { NBTTagCompound etiquetas = item.getTagCompound(); if (etiquetas == null) { etiquetas = new NBTTagCompound(); item.setTagCompound(etiquetas); int[] empty = { 0 }; return empty; } int[] ex = etiquetas.getIntArray(tag); return ex; } // #########################################################################3 public static void setIntArraytag(ItemStack item, String tag, int[] value) { NBTTagCompound etiquetas = item.getTagCompound(); if (etiquetas == null) { etiquetas = new NBTTagCompound(); } etiquetas.setIntArray(tag, value); item.setTagCompound(etiquetas); } // #########################################################################3 public static Boolean getBooleantag(ItemStack item, String tag) { NBTTagCompound etiquetas = item.getTagCompound(); if (etiquetas == null) { etiquetas = new NBTTagCompound(); item.setTagCompound(etiquetas); return false; } boolean ex = etiquetas.getBoolean(tag); return ex; } // #########################################################################3 public static void setBooleantag(ItemStack item, String tag, boolean value) { NBTTagCompound etiquetas = item.getTagCompound(); if (etiquetas == null) { etiquetas = item.getTagCompound(); } etiquetas.setBoolean(tag, value); item.setTagCompound(etiquetas); } // #########################################################################3 public int getBolsillos() { return this.bolsillos; } // #########################################################################3 public EntityLivingBase getEntity() { return this.entidad; } public void setContainer(ContainerMenuMercenario02 containerMercenario) { this.containerMercenario = containerMercenario; } public void setGui(guiMenuMercenario02 gui02) { this.gui02 = gui02; } } i been thinking maiby i fucked up whith basic java i dont see becoze tireness or something this thing whith the inventory is for unification only one inventory that could work in a vainilla cown, in my custom creepers as well in an elf from the lord of rings mod (asuming its gone a be 1.8 or 1.9 version) and the inventory must be simple but awesome in today test the thing goes very well whith littlemaid mod mobs mod and mi mob when the main gun gets empty it automatically switch to watever is in sub weapon slot and have a creeper that can chase the player whith an ak 47, but first fix this gui then fix the exploting thing bugs and the other thing whit the spawn in the world not working Quote
Draco18s Posted October 26, 2015 Posted October 26, 2015 You never call setHabilitado() anywhere. There's also no god damn reason you need to override every single method of the slot or container classes. For example, here's a custom slot class I use: public class SlotIInventory extends Slot { public SlotIInventory(IInventory p_i1824_1_, int p_i1824_2_, int p_i1824_3_, int p_i1824_4_) { super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_); } @Override public boolean isItemValid(ItemStack stack) { if(inventory.isItemValidForSlot(slotNumber, stack)) { ItemStack ss = stack.copy(); ss.stackSize = 1; inventory.setInventorySlotContents(slotNumber, ss); } return false; } @Override public boolean canTakeStack(EntityPlayer par1EntityPlayer) { inventory.setInventorySlotContents(slotNumber, null); return false; } } That's it. No isSlotInInventory , no decrStackSize , just the methods I actually NEED. Second: // Player Inventory, Slot 9-35, Slot IDs 9-35 for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new mercenarySlot(playerInv, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); } } Why the fuck are you making the player's inventory slots your custom slot type? WHY? THIRD when you call cambiarA0, cambiarA7, or cambiarA23, you're adding the player's inventory slots again. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
perromercenary00 Posted October 26, 2015 Author Posted October 26, 2015 and thats solve it all fix the slot.class and whith that i fix the other things now i can display the entity inventorys, whitout hiden slots disabling the player from steal from the entityes. fix the thing whith the armour slots now only allow the rigth armour type package mercenarymod.gui.containers; import mercenarymod.entidades.armasDisparables; //package net.minecraft.inventory; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class mercenarySlot extends Slot { /** The index of the slot in the inventory. */ private final int slotIndex; /** The inventory we want to extract a slot from. */ public final IInventory inventory; /** the id of the slot(also the index in the inventory arraylist) */ public int slotNumber; /** display position of the inventory slot on the screen x axis */ public int xDisplayPosition; /** display position of the inventory slot on the screen y axis */ public int yDisplayPosition; private static final String __OBFID = "CL_00001762"; private boolean habilitado = true; // ##########################################################################################3 public mercenarySlot(IInventory inventoryIn, int index, int xPosition, int yPosition, boolean habilitado) { super(inventoryIn, index, xPosition, yPosition); this.inventory = inventoryIn; this.slotIndex = index; this.xDisplayPosition = xPosition; this.yDisplayPosition = yPosition; this.habilitado = habilitado; } // ##########################################################################################3 @Override /** * Check if the stack is a valid item for this slot. Always true beside for * the armor slots. */ public boolean isItemValid(ItemStack stack) { int index = this.slotIndex; if (index > 0 & index < 5 ) { /** Stores the armor type: 0 is helmet, 1 is plate, 2 is legs and 3 is boots */ int armadura = armasDisparables.esArmadura(stack); if (armadura < 0) { return false; } //botas if (index == 1 & armadura != 3) { return false; } //pantalones if (index == 2 & armadura != 2) { return false; } //chest if (index == 3 & armadura != 1) { return false; } //casco if (index == 4 & armadura != 0) { return false; } } return habilitado; } // ##########################################################################################3 @Override /** * Return whether this slot's stack can be taken from this slot. */ public boolean canTakeStack(EntityPlayer playerIn) { return habilitado; } // ##########################################################################################3 @Override /** * Actualy only call when we want to render the white square effect over the * slots. Return always True, except for the armor slot of the Donkey/Mule * (we can't interact with the Undead and Skeleton horses) */ @SideOnly(Side.CLIENT) public boolean canBeHovered() { return habilitado; } // ##########################################################################################3 public void setHabilitado(boolean b) { habilitado = b; } // ##########################################################################################3 public boolean getHabilitado() { return habilitado; } } package mercenarymod.gui.containers; import net.minecraft.entity.Entity; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import mercenarymod.entidades.armasDisparables; import mercenarymod.items.armasdefuego.inventario.inventarioArmas; import mercenarymod.items.armasdefuego.inventario.inventarioArmasyEntidades; import mercenarymod.tileentity.ModTileEntity; import mercenarymod.utilidades.util; public class ContainerMenuMercenario02 extends Container { private inventarioArmasyEntidades inventarioenlaArmadura; private IInventory playerInv = null; private EntityLivingBase entidad = null; // ############################################################################################################################################## // ############################################################################################################################################## public ContainerMenuMercenario02(IInventory playerInv, inventarioArmasyEntidades te, boolean canbeTaken ) { // super(); this.inventarioenlaArmadura = te; this.entidad = te.getEntity(); this.playerInv = playerInv; // te.readFromNBT(null); ItemStack chestIS = this.entidad.getEquipmentInSlot(3); int sn = 0; if (chestIS != null) { //get the slots number from armour and change to that sn = armasDisparables.tieneBolsillos(chestIS); } switch (sn) { case 0: this.cambiarA0(canbeTaken); break; case 7: this.cambiarA7(canbeTaken); break; case 23: this.cambiarA23(canbeTaken); break; } } // ############################################################################################################################################## public void cambiarA0( boolean canbeTaken ) { //reset all inventory arrays to Zero inventoryItemStacks = Lists.newArrayList(); inventorySlots = Lists.newArrayList(); crafters = Lists.newArrayList(); // 0 - 27 chest slots // weapon slot this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 0, 26, 8, canbeTaken)); // entity armor slots this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 4, 8, 8, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 3, 8, 26, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 2, 8, 44, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 1, 8, 62, canbeTaken)); // Sub weapon slot this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 5, 26, 26, false)); // six pockets tactical vest this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 6, 53, 8, false)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 7, 71, 8, false)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 8, 53, 26, false)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 9, 71, 26, false)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 10, 53, 44, false)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 11, 71, 44, false)); // BackPack for (int x = 0; x < 4; ++x) { this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 12 + (x * 4), 98, 8 + (18 * x), false)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 13 + (x * 4), 116, 8 + (18 * x), false)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 14 + (x * 4), 134, 8 + (18 * x), false)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 15 + (x * 4), 152, 8 + (18 * x), false)); } // 28 - 54 // Player Inventory, Slot 28 - 54, Slot IDs 28 - 54 for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(this.playerInv, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); } } // 55 - 63 // Player Inventory, Slot 55-63, Slot IDs 55-63 for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(this.playerInv, x, 8 + x * 18, 142)); } } // ############################################################################################################################################## public void cambiarA7(boolean canbeTaken) { //reset all inventory arrays to Zero inventoryItemStacks = Lists.newArrayList(); inventorySlots = Lists.newArrayList(); crafters = Lists.newArrayList(); // 0 - 27 chest slots // weapon slot this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 0, 26, 8, canbeTaken)); // entity armor slots this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 4, 8, 8, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 3, 8, 26, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 2, 8, 44, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 1, 8, 62, canbeTaken)); // Sub weapon slot this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 5, 26, 26, canbeTaken)); // six pockets tactical vest this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 6, 53, 8, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 7, 71, 8, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 8, 53, 26, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 9, 71, 26, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 10, 53, 44, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 11, 71, 44, canbeTaken)); // BackPack for (int x = 0; x < 4; ++x) { this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 12 + (x * 4), 98, 8 + (18 * x), false)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 13 + (x * 4), 116, 8 + (18 * x), false)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 14 + (x * 4), 134, 8 + (18 * x), false)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 15 + (x * 4), 152, 8 + (18 * x), false)); } // 28 - 54 // Player Inventory, Slot 28 - 54, Slot IDs 28 - 54 for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(this.playerInv, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); } } // 55 - 63 // Player Inventory, Slot 55-63, Slot IDs 55-63 for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(this.playerInv, x, 8 + x * 18, 142)); } } // ############################################################################################################################################## public void cambiarA23(boolean canbeTaken) { //reset all inventory arrays to Zero inventoryItemStacks = Lists.newArrayList(); inventorySlots = Lists.newArrayList(); crafters = Lists.newArrayList(); // 0 - 27 chest slots // weapon slot this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 0, 26, 8, canbeTaken)); // entity armor slots this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 4, 8, 8, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 3, 8, 26, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 2, 8, 44, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 1, 8, 62, canbeTaken)); // Sub weapon slot this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 5, 26, 26, canbeTaken)); // six pockets tactical vest this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 6, 53, 8, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 7, 71, 8, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 8, 53, 26, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 9, 71, 26, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 10, 53, 44, canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 11, 71, 44, canbeTaken)); // BackPack for (int x = 0; x < 4; ++x) { this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 12 + (x * 4), 98, 8 + (18 * x), canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 13 + (x * 4), 116, 8 + (18 * x), canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 14 + (x * 4), 134, 8 + (18 * x), canbeTaken)); this.addSlotToContainer(new mercenarySlot(inventarioenlaArmadura, 15 + (x * 4), 152, 8 + (18 * x), canbeTaken)); } // 28 - 54 // Player Inventory, Slot 28 - 54, Slot IDs 28 - 54 for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(this.playerInv, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); } } // 55 - 63 // Player Inventory, Slot 55-63, Slot IDs 55-63 for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(this.playerInv, x, 8 + x * 18, 142)); } } // ############################################################################################################################################## @Override public boolean canInteractWith(EntityPlayer playerIn) { return this.inventarioenlaArmadura.isUseableByPlayer(playerIn); } // ############################################################################################################################################## @Override public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) { ItemStack previous = null; Slot slot = (Slot) this.inventorySlots.get(fromSlot); if (slot != null && slot.getHasStack()) { ItemStack current = slot.getStack(); previous = current.copy(); if (fromSlot < 28) { // From TE Inventory to Player Inventory if (!this.mergeItemStack(current, 28, 63, true)) return null; } else { // From Player Inventory to TE Inventory if (!this.mergeItemStack(current, 0, 28, false)) return null; } if (current.stackSize == 0) slot.putStack((ItemStack) null); else slot.onSlotChanged(); if (current.stackSize == previous.stackSize) return null; slot.onPickupFromSlot(playerIn, current); } return previous; } // ############################################################################################################################################## // 0 -4 armadura y arma // 5 arma secundaria // 6-11 pockets // 12 -27 backpack // 28 -54 inventory // 55 -63 hotbar // ################################################################################################################################################################################# } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.