Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-19 13:00:06 +01:00
Fixed some bugs with inventory
Dieser Commit ist enthalten in:
Ursprung
d3b87965c3
Commit
4eeceacde7
@ -26,12 +26,12 @@ public class CraftInventory implements org.bukkit.Inventory {
|
|||||||
return getInventory().b();
|
return getInventory().b();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getItem(int index) {
|
public CraftItemStack getItem(int index) {
|
||||||
return new CraftItemStack(getInventory().a(index));
|
return new CraftItemStack(getInventory().a(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack[] getContents() {
|
public CraftItemStack[] getContents() {
|
||||||
ItemStack[] items = new ItemStack[getSize()];
|
CraftItemStack[] items = new CraftItemStack[getSize()];
|
||||||
net.minecraft.server.ItemStack[] mcItems = getInventory().getContents();
|
net.minecraft.server.ItemStack[] mcItems = getInventory().getContents();
|
||||||
|
|
||||||
for (int i = 0; i < mcItems.length; i++ ) {
|
for (int i = 0; i < mcItems.length; i++ ) {
|
||||||
@ -127,7 +127,8 @@ public class CraftInventory implements org.bukkit.Inventory {
|
|||||||
public int firstPartial(int materialId) {
|
public int firstPartial(int materialId) {
|
||||||
ItemStack[] inventory = getContents();
|
ItemStack[] inventory = getContents();
|
||||||
for (int i = 0; i < inventory.length; i++) {
|
for (int i = 0; i < inventory.length; i++) {
|
||||||
if (inventory[i].getAmount() <= inventory[i].getMaxStackSize()) {
|
ItemStack item = inventory[i];
|
||||||
|
if (item != null && item.getTypeID() == materialId && item.getAmount() < item.getMaxStackSize()) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,13 +166,19 @@ public class CraftInventory implements org.bukkit.Inventory {
|
|||||||
if (firstFree == -1) {
|
if (firstFree == -1) {
|
||||||
// No space at all!
|
// No space at all!
|
||||||
leftover.put(i, item);
|
leftover.put(i, item);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// More than a single stack!
|
||||||
|
if (item.getAmount() > getMaxItemStack()) {
|
||||||
|
setItem( firstFree, new ItemStack(item.getTypeID(), getMaxItemStack()));
|
||||||
|
item.setAmount(item.getAmount() - getMaxItemStack());
|
||||||
} else {
|
} else {
|
||||||
// Just store it
|
// Just store it
|
||||||
setItem( firstFree, item );
|
setItem( firstFree, item );
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// So, apparently it might only partially fit, well lets do just that
|
// So, apparently it might only partially fit, well lets do just that
|
||||||
ItemStack partialItem = getItem(firstPartial);
|
ItemStack partialItem = getItem(firstPartial);
|
||||||
|
|
||||||
@ -190,6 +197,12 @@ public class CraftInventory implements org.bukkit.Inventory {
|
|||||||
item.setAmount( amount + partialAmount - maxAmount );
|
item.setAmount( amount + partialAmount - maxAmount );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return leftover;
|
return leftover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getMaxItemStack() {
|
||||||
|
return getInventory().c();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package org.bukkit.craftbukkit;
|
package org.bukkit.craftbukkit;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import net.minecraft.server.InventoryPlayer;
|
import net.minecraft.server.InventoryPlayer;
|
||||||
|
|
||||||
import org.bukkit.ItemStack;
|
import org.bukkit.ItemStack;
|
||||||
@ -16,36 +14,34 @@ public class CraftInventoryPlayer extends CraftInventory implements PlayerInvent
|
|||||||
return (InventoryPlayer) inventory;
|
return (InventoryPlayer) inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<ItemStack> getArmorContents() {
|
public CraftItemStack[] getArmorContents() {
|
||||||
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
|
net.minecraft.server.ItemStack[] mcItems = getInventory().getArmorContents();
|
||||||
for (net.minecraft.server.ItemStack item : getInventory().getArmorContents()) {
|
CraftItemStack[] items = new CraftItemStack[mcItems.length];
|
||||||
ItemStack i = null;
|
|
||||||
if (item != null) {
|
for (int i = 0; i < mcItems.length; i++ ) {
|
||||||
i = new CraftItemStack(item);
|
items[i] = new CraftItemStack(mcItems[i]);
|
||||||
}
|
|
||||||
items.add(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getItemInHand() {
|
public CraftItemStack getItemInHand() {
|
||||||
return new CraftItemStack( getInventory().e() );
|
return new CraftItemStack( getInventory().e() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getHelmet() {
|
public CraftItemStack getHelmet() {
|
||||||
return getItem( getSize() - 4 );
|
return getItem( getSize() - 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getChestplate() {
|
public CraftItemStack getChestplate() {
|
||||||
return getItem( getSize() - 3 );
|
return getItem( getSize() - 3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getLeggings() {
|
public CraftItemStack getLeggings() {
|
||||||
return getItem( getSize() - 2 );
|
return getItem( getSize() - 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getBoots() {
|
public CraftItemStack getBoots() {
|
||||||
return getItem( getSize() - 1 );
|
return getItem( getSize() - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public class CraftItemStack extends ItemStack {
|
|||||||
@Override
|
@Override
|
||||||
public int getAmount() {
|
public int getAmount() {
|
||||||
super.setAmount(item != null ? item.a : 0); // sync, needed?
|
super.setAmount(item != null ? item.a : 0); // sync, needed?
|
||||||
return item.a;
|
return (item != null ? item.a : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren