以下是改其构造器全部代码:
public InventoryMenu(Inventory pPlayerInventory, boolean pActive, final Player pOwner) {
super((MenuType<?>)null, 0);
this.active = pActive;
this.owner = pOwner;
this.addSlot(new ResultSlot(pPlayerInventory.player, this.craftSlots, this.resultSlots, 0, 154, 28));
for(int i = 0; i < 2; ++i) {
for(int j = 0; j < 2; ++j) {
this.addSlot(new Slot(this.craftSlots, j + i * 2, 98 + j * 18, 18 + i * 18));
}
}
for(int k = 0; k < 4; ++k) {
final EquipmentSlot equipmentslot = SLOT_IDS[k];
this.addSlot(new Slot(pPlayerInventory, 39 - k, 8, 8 + k * 18) {
public void setByPlayer(ItemStack p_270969_) {
InventoryMenu.onEquipItem(pOwner, equipmentslot, p_270969_, this.getItem());
super.setByPlayer(p_270969_);
}
/**
* Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in
* the case of armor slots)
*/
public int getMaxStackSize() {
return 1;
}
/**
* Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
*/
public boolean mayPlace(ItemStack p_39746_) {
return p_39746_.canEquip(equipmentslot, owner);
}
/**
* Return whether this slot's stack can be taken from this slot.
*/
public boolean mayPickup(Player p_39744_) {
ItemStack itemstack = this.getItem();
return !itemstack.isEmpty() && !p_39744_.isCreative() && EnchantmentHelper.hasBindingCurse(itemstack) ? false : super.mayPickup(p_39744_);
}
public Pair<ResourceLocation, ResourceLocation> getNoItemIcon() {
return Pair.of(InventoryMenu.BLOCK_ATLAS, InventoryMenu.TEXTURE_EMPTY_SLOTS[equipmentslot.getIndex()]);
}
});
}
for(int l = 0; l < 3; ++l) {
for(int j1 = 0; j1 < 9; ++j1) {
this.addSlot(new Slot(pPlayerInventory, j1 + (l + 1) * 9, 8 + j1 * 18, 84 + l * 18));
}
}
for(int i1 = 0; i1 < 9; ++i1) {
this.addSlot(new Slot(pPlayerInventory, i1, 8 + i1 * 18, 142));
}
this.addSlot(new Slot(pPlayerInventory, 40, 77, 62) {
public void setByPlayer(ItemStack p_270479_) {
InventoryMenu.onEquipItem(pOwner, EquipmentSlot.OFFHAND, p_270479_, this.getItem());
super.setByPlayer(p_270479_);
}
public Pair<ResourceLocation, ResourceLocation> getNoItemIcon() {
return Pair.of(InventoryMenu.BLOCK_ATLAS, InventoryMenu.EMPTY_ARMOR_SLOT_SHIELD);
}
});
}
可以看出原版添加Item槽位id可以分为 - ResultCraftSlot(Slotid【下略】:0)
- 2X2CraftSlot(0 ~ 3)
- PlayerInventory(9 ~ 35)
- PlayerHotBar (0 ~ 8)
- Equipment (36 ~ 39)
- OffHand (40)
显然SlotID出现重复,如PlayerHotBar和2X2CraftSlot与ResultCraftSlot明显出现了0,1,2,3重复的Slotid
public static final int CONTAINER_ID = 0;
public static final int RESULT_SLOT = 0;
public static final int CRAFT_SLOT_START = 1;
public static final int CRAFT_SLOT_END = 5;
public static final int ARMOR_SLOT_START = 5;
public static final int ARMOR_SLOT_END = 9;
public static final int INV_SLOT_START = 9;
public static final int INV_SLOT_END = 36;
public static final int USE_ROW_SLOT_START = 36;
public static final int USE_ROW_SLOT_END = 45;
public static final int SHIELD_SLOT = 45;
这是为什么
|