misc fixes
This commit is contained in:
parent
cfcb590574
commit
00ac4146bc
8 changed files with 119 additions and 116 deletions
|
@ -2484,7 +2484,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
}
|
||||
}
|
||||
|
||||
public int getHotbarSize() {
|
||||
public final int getHotbarSize() {
|
||||
return Equipment.INVENTORY_SLOTS;
|
||||
}
|
||||
|
||||
|
@ -2760,6 +2760,16 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
public int getInventoryCapacity() {
|
||||
return 36;
|
||||
}
|
||||
|
||||
public int getInventoryWeight() {
|
||||
int total = 0;
|
||||
for(int z = 0; z < Equipment.INVENTORY_SLOTS; z++) {
|
||||
ItemStack stack = this.getInventory()[z];
|
||||
if(stack != null)
|
||||
total += stack.getSize() * stack.getItem().getWeight();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public boolean hasArmorSlot(Equipment slot) {
|
||||
return true;
|
||||
|
|
|
@ -8,11 +8,14 @@ import common.collect.Sets;
|
|||
import common.entity.npc.EntityNPC;
|
||||
import common.item.Item;
|
||||
import common.item.ItemStack;
|
||||
import common.item.material.ItemArmor;
|
||||
import common.network.IPlayer;
|
||||
import common.util.Equipment;
|
||||
|
||||
public abstract class Container
|
||||
{
|
||||
public static final int INVENTORY_WIDTH = 16;
|
||||
|
||||
public List<ItemStack> inventoryItemStacks = Lists.<ItemStack>newArrayList();
|
||||
public List<Slot> inventorySlots = Lists.<Slot>newArrayList();
|
||||
public int windowId;
|
||||
|
@ -33,13 +36,33 @@ public abstract class Container
|
|||
return this.offset;
|
||||
}
|
||||
|
||||
protected void addPlayerSlots(EntityNPC player) {
|
||||
this.offset = this.inventorySlots.size();
|
||||
protected void addPlayerSlots(final EntityNPC player) {
|
||||
int x = this.getInventoryOffsetX();
|
||||
int y = this.getInventoryOffsetY();
|
||||
for(Equipment slot : Equipment.ARMOR) {
|
||||
final Equipment type = slot;
|
||||
this.addSlotToContainer(new Slot(player, Equipment.INVENTORY_SLOTS + slot.getIndex(), x + slot.getIndex() * 18, y) {
|
||||
public boolean canStackItems() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return stack != null && stack.getItem() instanceof ItemArmor armor && armor.getArmorType().canUseInSlot(player, type);
|
||||
}
|
||||
|
||||
public String getTexture() {
|
||||
return type.isRing() ? "ring" : type.getName();
|
||||
}
|
||||
|
||||
public boolean canDraw() {
|
||||
return player.hasArmorSlot(type);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.offset = this.inventorySlots.size();
|
||||
List<SlotCommon> list = Lists.newArrayList();
|
||||
for(int z = 0; z < Equipment.INVENTORY_SLOTS; ++z) {
|
||||
this.addSlotToContainer(new SlotCommon(list, player, z, x + (z % 12) * 18, y + (z / 12) * 18));
|
||||
this.addSlotToContainer(new SlotCommon(list, player, z, x + (z % INVENTORY_WIDTH) * 18, y + 20 + (z / INVENTORY_WIDTH) * 18));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ public class ContainerChest extends Container
|
|||
}
|
||||
|
||||
public int getInventoryOffsetX() {
|
||||
return 8 + (this.width < 12 ? 0 : (this.width - 12) * 18 / 2);
|
||||
return 8 + (this.width < INVENTORY_WIDTH ? 0 : (this.width - INVENTORY_WIDTH) * 18 / 2);
|
||||
}
|
||||
|
||||
public int getInventoryOffsetY() {
|
||||
|
|
|
@ -1,129 +1,87 @@
|
|||
package common.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import common.collect.Lists;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.item.ItemStack;
|
||||
import common.item.material.ItemArmor;
|
||||
import common.util.Equipment;
|
||||
|
||||
public class ContainerPlayer extends Container {
|
||||
private final EntityNPC thePlayer;
|
||||
|
||||
public ContainerPlayer(EntityNPC player)
|
||||
{
|
||||
this.thePlayer = player;
|
||||
|
||||
for (Equipment slot : Equipment.ARMOR)
|
||||
{
|
||||
final Equipment type = slot;
|
||||
this.addSlotToContainer(new Slot(player, Equipment.INVENTORY_SLOTS + slot.getIndex(), 8 + (slot.getIndex() / 4) * 18, 8 + (slot.getIndex() % 4) * 18)
|
||||
{
|
||||
public boolean canStackItems()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return stack != null && stack.getItem() instanceof ItemArmor armor && armor.getArmorType().canUseInSlot(ContainerPlayer.this.thePlayer, type);
|
||||
}
|
||||
public String getTexture() {
|
||||
return type.isRing() ? "ring" : type.getName();
|
||||
}
|
||||
public boolean canDraw() {
|
||||
return ContainerPlayer.this.thePlayer.hasArmorSlot(type);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.addPlayerSlots(player);
|
||||
}
|
||||
|
||||
public int getInventoryOffsetY() {
|
||||
return 92;
|
||||
public ContainerPlayer(EntityNPC player) {
|
||||
this.addPlayerSlots(player);
|
||||
}
|
||||
|
||||
public ItemStack getSingleRecipe(ItemStack stack) {
|
||||
return null;
|
||||
public int getInventoryOffsetY() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
public ItemStack getSingleRecipe(ItemStack stack) {
|
||||
return null;
|
||||
// this.baseCrafting.setInventorySlotContents(0, stack);
|
||||
// stack = CraftingRegistry.getMatching(this.baseCrafting);
|
||||
// this.baseCrafting.setInventorySlotContents(0, null);
|
||||
// return stack;
|
||||
}
|
||||
|
||||
public ItemStack craftSingleRecipe(ItemStack stack) {
|
||||
}
|
||||
|
||||
public ItemStack craftSingleRecipe(ItemStack stack) {
|
||||
// this.baseCrafting.setInventorySlotContents(0, stack);
|
||||
// SlotCrafting.handleRemaining(this.baseCrafting, this.thePlayer);
|
||||
// stack = this.baseCrafting.getStackInSlot(0);
|
||||
// this.baseCrafting.setInventorySlotContents(0, null);
|
||||
return stack;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getFreeSlotFor(Equipment type) {
|
||||
for(Equipment slot : type.getPossibleSlots(this.thePlayer)) {
|
||||
if(!this.inventorySlots.get(slot.getIndex()).getHasStack())
|
||||
return slot.getIndex();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public boolean canInteractWith(EntityNPC playerIn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot)this.inventorySlots.get(index);
|
||||
int idx;
|
||||
private int getFreeSlotFor(EntityNPC player, Equipment type) {
|
||||
for(Equipment slot : type.getPossibleSlots(player)) {
|
||||
if(!this.inventorySlots.get(slot.getIndex()).getHasStack())
|
||||
return slot.getIndex();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index) {
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = this.inventorySlots.get(index);
|
||||
int idx;
|
||||
|
||||
if (index >= 0 && index < Equipment.ARMOR_SLOTS)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (itemstack.getItem() instanceof ItemArmor armor && (idx = this.getFreeSlotFor(armor.getArmorType())) >= 0)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, idx, idx + 1))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (index >= Equipment.ARMOR_SLOTS && index < Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if(slot != null && slot.getHasStack()) {
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if (itemstack1.isEmpty())
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
if(index >= 0 && index < Equipment.ARMOR_SLOTS) {
|
||||
if(!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(itemstack.getItem() instanceof ItemArmor armor && (idx = this.getFreeSlotFor(playerIn, armor.getArmorType())) >= 0) {
|
||||
if(!this.mergeItemStack(itemstack1, idx, idx + 1)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(index >= Equipment.ARMOR_SLOTS && index < Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS) {
|
||||
return null;
|
||||
}
|
||||
else if(!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.getSize() == itemstack.getSize())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if(itemstack1.isEmpty()) {
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(playerIn, itemstack1);
|
||||
}
|
||||
if(itemstack1.getSize() == itemstack.getSize()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
slot.onPickupFromSlot(playerIn, itemstack1);
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public enum Equipment implements Identifyable, Displayable {
|
|||
|
||||
HORSE_ARMOR("horse_armor", "Pferderüstung", EntityHorse.class, 8, 0);
|
||||
|
||||
public static final int INVENTORY_SLOTS = 64;
|
||||
public static final int INVENTORY_SLOTS = 256;
|
||||
public static final int ARMOR_SLOTS;
|
||||
public static final Equipment[] ARMOR;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue