bonenaut7
Попрошайка
- 1,426
- 31
- 261
Не могу взаимодействовать с предметами в слотах, только таскать цифрами в хотбаре.


Container:
package union.cubeground.mod.common.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import union.cubeground.mod.common.player.ExtendedPlayer;
import union.cubeground.mod.common.slot.ESlot;
import union.cubeground.mod.common.slot.ISlot;
import union.cubeground.mod.common.slot.SlotInv;
public class ContainerCharInventory extends Container {
public EntityPlayer thePlayer;
public ExtendedPlayer exp;
public ContainerCharInventory(EntityPlayer p) {
ExtendedPlayer ex = ExtendedPlayer.get(p);
this.exp = ex;
for (int i = 1; i != 4; i++) for (int j = 0; j != 9; j++) this.addSlotToContainer(new ISlot(ESlot.Access.IO, p.inventory, (i * 9) + j, 6 + (j * 18), 101 + ((i - 1) * 18)));
for (int i = 0; i != 9; i++) this.addSlotToContainer(new ISlot(ESlot.Access.IO, p.inventory, i, 6 + (i * 18), 159));
for (int i = 0; i < 4; ++i) {
final int k = i;
this.addSlotToContainer(new Slot(p.inventory, p.inventory.getSizeInventory() - 1 - i, 8, 8 + i * 18) {
public int getSlotStackLimit() {
return 1;
}
public boolean isItemValid(ItemStack p_75214_1_) {
if (p_75214_1_ == null) return false;
return p_75214_1_.getItem().isValidArmor(p_75214_1_, k, thePlayer);
}
});
}
for (int i = 0; i != 5; i++) this.addSlotToContainer(new SlotInv(ex.invChar, 0, i, 8 + (i * 18), 80));
for (int i = 5; i != 9; i++) this.addSlotToContainer(new SlotInv(ex.invChar, i - 4, i, 80, 8 + ((i - 5) * 18)));
for (int i = 0; i != 5; i++) this.addSlotToContainer(new SlotInv(ex.invAccs, i, i, 98, 8 + (i * 18)));
}
public boolean canInteractWith(EntityPlayer p) {
return true;
}
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) {
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(p_82846_2_);
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (p_82846_2_ == 0) {
if (!this.mergeItemStack(itemstack1, 9, 45, true)) return null;
slot.onSlotChange(itemstack1, itemstack);
}
else if (p_82846_2_ >= 1 && p_82846_2_ < 5)
if (!this.mergeItemStack(itemstack1, 9, 45, false)) return null;
else if (p_82846_2_ >= 5 && p_82846_2_ < 9)
if (!this.mergeItemStack(itemstack1, 9, 45, false)) return null;
else if (itemstack.getItem() instanceof ItemArmor && !((Slot)this.inventorySlots.get(5 + ((ItemArmor)itemstack.getItem()).armorType)).getHasStack()) {
int j = 5 + ((ItemArmor)itemstack.getItem()).armorType;
if (!this.mergeItemStack(itemstack1, j, j + 1, false)) return null;
}
else if (p_82846_2_ >= 9 && p_82846_2_ < 36)
if (!this.mergeItemStack(itemstack1, 36, 45, false)) return null;
else if (p_82846_2_ >= 36 && p_82846_2_ < 45)
if (!this.mergeItemStack(itemstack1, 9, 36, false)) return null;
else if (!this.mergeItemStack(itemstack1, 9, 45, false)) return null;
if (itemstack1.stackSize == 0) slot.putStack((ItemStack)null);
else slot.onSlotChanged();
if (itemstack1.stackSize == itemstack.stackSize) return null;
slot.onPickupFromSlot(p_82846_1_, itemstack1);
}
return itemstack;
}
}
SlotInv:
package union.cubeground.mod.common.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import union.cubeground.mod.common.utils.ICharItem;
public class SlotInv extends ESlot {
public int type;
public SlotInv(IInventory inv, int type, int id, int x, int y) {
super(Access.IO, inv, id, x, y);
this.type = type;
}
public boolean accept(ItemStack var1) {
return var1.getItem() instanceof ICharItem && ((ICharItem)var1.getItem()).getSlot(var1) == this.type;
}
}
ESlot:
package union.cubeground.mod.common.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public abstract class ESlot extends Slot {
public Access accessType;
public ESlot(Access access, IInventory inv, int id, int x, int y) {
super(inv, id, x, y);
this.accessType = access;
}
public abstract boolean accept(ItemStack var1);
public boolean isItemValid(ItemStack stack) {
return this.canInput() && this.accept(stack);
}
public boolean canTakeStack(EntityPlayer player) {
return this.canOutput();
}
public boolean canInput() {
return this.accessType == Access.I || this.accessType == Access.IO;
}
public static boolean canInput(Access access) {
return access == Access.I || access == Access.IO;
}
public boolean canOutput() {
return this.accessType == Access.O || this.accessType == Access.IO;
}
public static enum Access {
NONE, I, IO, O;
}
}
