Hacky workaround for Java 9 reflection changes (#93)

This commit is contained in:
Jikoo 2019-04-12 20:56:05 -04:00
parent dc59356f76
commit c5c1f47167
2 changed files with 708 additions and 85 deletions

View file

@ -17,32 +17,31 @@
package com.lishid.openinv.internal.v1_13_R2; package com.lishid.openinv.internal.v1_13_R2;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import net.minecraft.server.v1_13_R2.EntityPlayer; import net.minecraft.server.v1_13_R2.*;
import net.minecraft.server.v1_13_R2.IInventory; import org.bukkit.Location;
import net.minecraft.server.v1_13_R2.InventoryEnderChest; import org.bukkit.craftbukkit.v1_13_R2.entity.CraftHumanEntity;
import net.minecraft.server.v1_13_R2.InventorySubcontainer;
import net.minecraft.server.v1_13_R2.ItemStack;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import java.lang.reflect.Field; import javax.annotation.Nullable;
import java.lang.reflect.Modifier;
import java.util.List; import java.util.List;
public class SpecialEnderChest extends InventorySubcontainer public class SpecialEnderChest implements IInventory, ISpecialEnderChest, AutoRecipeOutput {
implements IInventory, ISpecialEnderChest {
private final InventoryEnderChest enderChest; private EntityPlayer owner;
private final IChatBaseComponent displayName;
private NonNullList<ItemStack> items;
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline; private boolean playerOnline;
public SpecialEnderChest(final Player player, final Boolean online) { public SpecialEnderChest(final Player player, final Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getDisplayName(), this.owner = PlayerDataManager.getHandle(player);
PlayerDataManager.getHandle(player).getEnderChest().getSize(), player); this.displayName = this.owner.getEnderChest().getDisplayName();
this.playerOnline = online; this.playerOnline = online;
this.enderChest = PlayerDataManager.getHandle(player).getEnderChest(); this.items = this.owner.getEnderChest().items;
this.setItemLists(this, this.enderChest.getContents());
} }
@Override @Override
@ -55,21 +54,6 @@ public class SpecialEnderChest extends InventorySubcontainer
return !this.getViewers().isEmpty(); return !this.getViewers().isEmpty();
} }
private void setItemLists(final InventorySubcontainer subcontainer, final List<ItemStack> list) {
try {
// Prepare to remove final modifier
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
// Access and replace main inventory array
Field field = InventorySubcontainer.class.getField("items");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(subcontainer, list);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException
| IllegalAccessException e) {
e.printStackTrace();
}
}
@Override @Override
public void setPlayerOffline() { public void setPlayerOffline() {
this.playerOnline = false; this.playerOnline = false;
@ -79,18 +63,193 @@ public class SpecialEnderChest extends InventorySubcontainer
public void setPlayerOnline(final Player player) { public void setPlayerOnline(final Player player) {
if (!this.playerOnline) { if (!this.playerOnline) {
try { try {
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); this.owner = PlayerDataManager.getHandle(player);
this.bukkitOwner = nmsPlayer.getBukkitEntity(); InventoryEnderChest enderChest = owner.getEnderChest();
this.setItemLists(nmsPlayer.getEnderChest(), this.items); for (int i = 0; i < enderChest.getSize(); ++i) {
} catch (Exception e) {} enderChest.setItem(i, this.items.get(i));
}
this.items = enderChest.items;
} catch (Exception ignored) {}
this.playerOnline = true; this.playerOnline = true;
} }
} }
@Override @Override
public void update() { public void update() {
super.update(); this.owner.getEnderChest().update();
this.enderChest.update(); }
public List<ItemStack> getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
this.owner.getEnderChest().onOpen(who);
}
public void onClose(CraftHumanEntity who) {
this.owner.getEnderChest().onClose(who);
}
public List<HumanEntity> getViewers() {
return this.owner.getEnderChest().getViewers();
}
public void setMaxStackSize(int i) {
this.owner.getEnderChest().setMaxStackSize(i);
}
public InventoryHolder getOwner() {
return this.owner.getEnderChest().getOwner();
}
public Location getLocation() {
return null;
}
public void a(IInventoryListener iinventorylistener) {
this.owner.getEnderChest().a(iinventorylistener);
}
public void b(IInventoryListener iinventorylistener) {
this.owner.getEnderChest().b(iinventorylistener);
}
public ItemStack getItem(int i) {
return i >= 0 && i < this.items.size() ? this.items.get(i) : ItemStack.a;
}
public ItemStack splitStack(int i, int j) {
ItemStack itemstack = ContainerUtil.a(this.items, i, j);
if (!itemstack.isEmpty()) {
this.update();
}
return itemstack;
}
public ItemStack a(ItemStack itemstack) {
ItemStack itemstack1 = itemstack.cloneItemStack();
for (int i = 0; i < this.getSize(); ++i) {
ItemStack itemstack2 = this.getItem(i);
if (itemstack2.isEmpty()) {
this.setItem(i, itemstack1);
this.update();
return ItemStack.a;
}
if (ItemStack.c(itemstack2, itemstack1)) {
int j = Math.min(this.getMaxStackSize(), itemstack2.getMaxStackSize());
int k = Math.min(itemstack1.getCount(), j - itemstack2.getCount());
if (k > 0) {
itemstack2.add(k);
itemstack1.subtract(k);
if (itemstack1.isEmpty()) {
this.update();
return ItemStack.a;
}
}
}
}
if (itemstack1.getCount() != itemstack.getCount()) {
this.update();
}
return itemstack1;
}
public ItemStack splitWithoutUpdate(int i) {
ItemStack itemstack = this.items.get(i);
if (itemstack.isEmpty()) {
return ItemStack.a;
} else {
this.items.set(i, ItemStack.a);
return itemstack;
}
}
public void setItem(int i, ItemStack itemstack) {
this.items.set(i, itemstack);
if (!itemstack.isEmpty() && itemstack.getCount() > this.getMaxStackSize()) {
itemstack.setCount(this.getMaxStackSize());
}
this.update();
}
public int getSize() {
return this.owner.getEnderChest().getSize();
}
public boolean P_() {
for (ItemStack itemstack : this.items) {
if (!itemstack.isEmpty()) {
return false;
}
}
return true;
}
public IChatBaseComponent getDisplayName() {
return this.displayName;
}
@Nullable
public IChatBaseComponent getCustomName() {
return this.displayName;
}
public boolean hasCustomName() {
return false;
}
public void a(@Nullable IChatBaseComponent ichatbasecomponent) {
// Ignored - name is always player's name.
}
public int getMaxStackSize() {
return 64;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen(EntityHuman entityhuman) {
}
public void closeContainer(EntityHuman entityhuman) {
}
public boolean b(int i, ItemStack itemstack) {
return true;
}
public int getProperty(int i) {
return 0;
}
public void setProperty(int i, int j) {
}
public int h() {
return 0;
}
public void clear() {
this.items.clear();
}
public void a(AutoRecipeStackManager autorecipestackmanager) {
for (ItemStack itemstack : this.items) {
autorecipestackmanager.b(itemstack);
}
} }
} }

View file

@ -16,32 +16,69 @@
package com.lishid.openinv.internal.v1_13_R2; package com.lishid.openinv.internal.v1_13_R2;
import com.google.common.collect.ImmutableList;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import net.minecraft.server.v1_13_R2.AutoRecipeStackManager;
import net.minecraft.server.v1_13_R2.ChatMessage; import net.minecraft.server.v1_13_R2.ChatMessage;
import net.minecraft.server.v1_13_R2.ContainerUtil; import net.minecraft.server.v1_13_R2.ContainerUtil;
import net.minecraft.server.v1_13_R2.CrashReport;
import net.minecraft.server.v1_13_R2.CrashReportSystemDetails;
import net.minecraft.server.v1_13_R2.EntityHuman; import net.minecraft.server.v1_13_R2.EntityHuman;
import net.minecraft.server.v1_13_R2.EntityPlayer;
import net.minecraft.server.v1_13_R2.IBlockData;
import net.minecraft.server.v1_13_R2.IChatBaseComponent; import net.minecraft.server.v1_13_R2.IChatBaseComponent;
import net.minecraft.server.v1_13_R2.Item;
import net.minecraft.server.v1_13_R2.ItemArmor;
import net.minecraft.server.v1_13_R2.ItemStack; import net.minecraft.server.v1_13_R2.ItemStack;
import net.minecraft.server.v1_13_R2.NBTTagCompound;
import net.minecraft.server.v1_13_R2.NBTTagList;
import net.minecraft.server.v1_13_R2.NonNullList; import net.minecraft.server.v1_13_R2.NonNullList;
import net.minecraft.server.v1_13_R2.PacketPlayOutSetSlot;
import net.minecraft.server.v1_13_R2.PlayerInventory; import net.minecraft.server.v1_13_R2.PlayerInventory;
import net.minecraft.server.v1_13_R2.ReportedException;
import net.minecraft.server.v1_13_R2.World;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import java.lang.reflect.Field; import javax.annotation.Nullable;
import java.lang.reflect.Modifier; import java.util.ArrayList;
import java.util.Arrays; import java.util.Iterator;
import java.util.List;
import java.util.function.Predicate;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline; private boolean playerOnline;
private NonNullList<ItemStack> items, armor, extraSlots;
private final List<NonNullList<ItemStack>> f;
public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) { public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) {
super(PlayerDataManager.getHandle(bukkitPlayer)); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.setItemArrays(this, this.player.inventory.items, this.player.inventory.armor, this.items = this.player.inventory.items;
this.player.inventory.extraSlots); this.armor = this.player.inventory.armor;
this.extraSlots = this.player.inventory.extraSlots;
this.f = ImmutableList.of(this.items, this.armor, this.extraSlots);
}
@Override
public void setPlayerOnline(final Player player) {
if (!this.playerOnline) {
EntityPlayer entityPlayer = PlayerDataManager.getHandle(player);
entityPlayer.inventory.transaction.addAll(this.transaction);
this.player = entityPlayer;
this.player.inventory.a(this);
this.items = this.player.inventory.items;
this.armor = this.player.inventory.armor;
this.extraSlots = this.player.inventory.extraSlots;
this.playerOnline = true;
}
} }
@Override @Override
@ -56,7 +93,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public ItemStack getItem(int i) { public ItemStack getItem(int i) {
NonNullList<ItemStack> list = this.items; List<ItemStack> list = this.items;
if (i >= list.size()) { if (i >= list.size()) {
i -= list.size(); i -= list.size();
@ -86,7 +123,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public boolean hasCustomName() { public boolean hasCustomName() {
return true; return false;
} }
private int getReversedArmorSlotNum(final int i) { private int getReversedArmorSlotNum(final int i) {
@ -124,7 +161,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setItem(int i, final ItemStack itemstack) { public void setItem(int i, final ItemStack itemstack) {
NonNullList<ItemStack> list = this.items; List<ItemStack> list = this.items;
if (i >= list.size()) { if (i >= list.size()) {
i -= list.size(); i -= list.size();
@ -148,53 +185,11 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
list.set(i, itemstack); list.set(i, itemstack);
} }
private void setItemArrays(final PlayerInventory inventory, final NonNullList<ItemStack> items,
final NonNullList<ItemStack> armor, final NonNullList<ItemStack> extraSlots) {
try {
// Prepare to remove final modifier
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
// Access and replace main inventory list
Field field = PlayerInventory.class.getField("items");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, items);
// Access and replace armor inventory list
field = PlayerInventory.class.getField("armor");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, armor);
// Access and replace offhand inventory list
field = PlayerInventory.class.getField("extraSlots");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, extraSlots);
// Access and replace list containing all inventory lists
field = PlayerInventory.class.getDeclaredField("f");
field.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, Arrays.asList(items, armor, extraSlots));
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
// Unable to set final fields to item lists, we're screwed. Noisily fail.
e.printStackTrace();
}
}
@Override @Override
public void setPlayerOffline() { public void setPlayerOffline() {
this.playerOnline = false; this.playerOnline = false;
} }
@Override
public void setPlayerOnline(final Player player) {
if (!this.playerOnline) {
this.player = PlayerDataManager.getHandle(player);
this.setItemArrays(this.player.inventory, this.items, this.armor, this.extraSlots);
this.playerOnline = true;
}
}
@Override @Override
public ItemStack splitStack(int i, final int j) { public ItemStack splitStack(int i, final int j) {
NonNullList<ItemStack> list = this.items; NonNullList<ItemStack> list = this.items;
@ -252,4 +247,473 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return ItemStack.a; return ItemStack.a;
} }
public List<ItemStack> getContents() {
List<ItemStack> combined = new ArrayList<>(this.items.size() + this.armor.size() + this.extraSlots.size());
for (List<ItemStack> sub : this.f) {
combined.addAll(sub);
}
return combined;
}
public List<ItemStack> getArmorContents() {
return this.armor;
}
public void onOpen(CraftHumanEntity who) {
this.transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
this.transaction.remove(who);
}
public List<HumanEntity> getViewers() {
return this.transaction;
}
public InventoryHolder getOwner() {
return this.player.getBukkitEntity();
}
public Location getLocation() {
return this.player.getBukkitEntity().getLocation();
}
public ItemStack getItemInHand() {
return e(this.itemInHandIndex) ? this.items.get(this.itemInHandIndex) : ItemStack.a;
}
public static int getHotbarSize() {
return 9;
}
private boolean a(ItemStack itemstack, ItemStack itemstack1) {
return !itemstack.isEmpty() && this.b(itemstack, itemstack1) && itemstack.isStackable() && itemstack.getCount() < itemstack.getMaxStackSize() && itemstack.getCount() < this.getMaxStackSize();
}
private boolean b(ItemStack itemstack, ItemStack itemstack1) {
return itemstack.getItem() == itemstack1.getItem() && ItemStack.equals(itemstack, itemstack1);
}
public int canHold(ItemStack itemstack) {
int remains = itemstack.getCount();
for(int i = 0; i < this.items.size(); ++i) {
ItemStack itemstack1 = this.getItem(i);
if (itemstack1.isEmpty()) {
return itemstack.getCount();
}
if (!this.a(itemstack, itemstack1)) {
remains -= (itemstack1.getMaxStackSize() < this.getMaxStackSize() ? itemstack1.getMaxStackSize() : this.getMaxStackSize()) - itemstack1.getCount();
}
if (remains <= 0) {
return itemstack.getCount();
}
}
return itemstack.getCount() - remains;
}
public int getFirstEmptySlotIndex() {
for(int i = 0; i < this.items.size(); ++i) {
if (this.items.get(i).isEmpty()) {
return i;
}
}
return -1;
}
public void d(int i) {
this.itemInHandIndex = this.l();
ItemStack itemstack = this.items.get(this.itemInHandIndex);
this.items.set(this.itemInHandIndex, this.items.get(i));
this.items.set(i, itemstack);
}
public static boolean e(int i) {
return i >= 0 && i < 9;
}
public int c(ItemStack itemstack) {
for(int i = 0; i < this.items.size(); ++i) {
ItemStack itemstack1 = this.items.get(i);
if (!this.items.get(i).isEmpty() && this.b(itemstack, this.items.get(i)) && !this.items.get(i).f() && !itemstack1.hasEnchantments() && !itemstack1.hasName()) {
return i;
}
}
return -1;
}
public int l() {
int i;
int j;
for(j = 0; j < 9; ++j) {
i = (this.itemInHandIndex + j) % 9;
if (this.items.get(i).isEmpty()) {
return i;
}
}
for(j = 0; j < 9; ++j) {
i = (this.itemInHandIndex + j) % 9;
if (!this.items.get(i).hasEnchantments()) {
return i;
}
}
return this.itemInHandIndex;
}
public int a(Predicate<ItemStack> predicate, int i) {
int j = 0;
int k;
for(k = 0; k < this.getSize(); ++k) {
ItemStack itemstack = this.getItem(k);
if (!itemstack.isEmpty() && predicate.test(itemstack)) {
int l = i <= 0 ? itemstack.getCount() : Math.min(i - j, itemstack.getCount());
j += l;
if (i != 0) {
itemstack.subtract(l);
if (itemstack.isEmpty()) {
this.setItem(k, ItemStack.a);
}
if (i > 0 && j >= i) {
return j;
}
}
}
}
if (!this.getCarried().isEmpty() && predicate.test(this.getCarried())) {
k = i <= 0 ? this.getCarried().getCount() : Math.min(i - j, this.getCarried().getCount());
j += k;
if (i != 0) {
this.getCarried().subtract(k);
if (this.getCarried().isEmpty()) {
this.setCarried(ItemStack.a);
}
if (i > 0 && j >= i) {
return j;
}
}
}
return j;
}
private int i(ItemStack itemstack) {
int i = this.firstPartial(itemstack);
if (i == -1) {
i = this.getFirstEmptySlotIndex();
}
return i == -1 ? itemstack.getCount() : this.d(i, itemstack);
}
private int d(int i, ItemStack itemstack) {
Item item = itemstack.getItem();
int j = itemstack.getCount();
ItemStack itemstack1 = this.getItem(i);
if (itemstack1.isEmpty()) {
itemstack1 = new ItemStack(item, 0);
if (itemstack.hasTag()) {
itemstack1.setTag(itemstack.getTag().clone());
}
this.setItem(i, itemstack1);
}
int k = j;
if (j > itemstack1.getMaxStackSize() - itemstack1.getCount()) {
k = itemstack1.getMaxStackSize() - itemstack1.getCount();
}
if (k > this.getMaxStackSize() - itemstack1.getCount()) {
k = this.getMaxStackSize() - itemstack1.getCount();
}
if (k == 0) {
return j;
} else {
j -= k;
itemstack1.add(k);
itemstack1.d(5);
return j;
}
}
public int firstPartial(ItemStack itemstack) {
if (this.a(this.getItem(this.itemInHandIndex), itemstack)) {
return this.itemInHandIndex;
} else if (this.a(this.getItem(40), itemstack)) {
return 40;
} else {
for(int i = 0; i < this.items.size(); ++i) {
if (this.a(this.items.get(i), itemstack)) {
return i;
}
}
return -1;
}
}
public void p() {
for (NonNullList<ItemStack> itemStacks : this.f) {
for (int i = 0; i < itemStacks.size(); ++i) {
if (!itemStacks.get(i).isEmpty()) {
itemStacks.get(i).a(this.player.world, this.player, i, this.itemInHandIndex == i);
}
}
}
}
public boolean pickup(ItemStack itemstack) {
return this.c(-1, itemstack);
}
public boolean c(int i, ItemStack itemstack) {
if (itemstack.isEmpty()) {
return false;
} else {
try {
if (itemstack.f()) {
if (i == -1) {
i = this.getFirstEmptySlotIndex();
}
if (i >= 0) {
this.items.set(i, itemstack.cloneItemStack());
this.items.get(i).d(5);
itemstack.setCount(0);
return true;
} else if (this.player.abilities.canInstantlyBuild) {
itemstack.setCount(0);
return true;
} else {
return false;
}
} else {
int j;
do {
j = itemstack.getCount();
if (i == -1) {
itemstack.setCount(this.i(itemstack));
} else {
itemstack.setCount(this.d(i, itemstack));
}
} while(!itemstack.isEmpty() && itemstack.getCount() < j);
if (itemstack.getCount() == j && this.player.abilities.canInstantlyBuild) {
itemstack.setCount(0);
return true;
} else {
return itemstack.getCount() < j;
}
}
} catch (Throwable var6) {
CrashReport crashreport = CrashReport.a(var6, "Adding item to inventory");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Item being added");
crashreportsystemdetails.a("Item ID", Item.getId(itemstack.getItem()));
crashreportsystemdetails.a("Item data", itemstack.getDamage());
crashreportsystemdetails.a("Item name", () -> itemstack.getName().getString());
throw new ReportedException(crashreport);
}
}
}
public void a(World world, ItemStack itemstack) {
if (!world.isClientSide) {
while(!itemstack.isEmpty()) {
int i = this.firstPartial(itemstack);
if (i == -1) {
i = this.getFirstEmptySlotIndex();
}
if (i == -1) {
this.player.drop(itemstack, false);
break;
}
int j = itemstack.getMaxStackSize() - this.getItem(i).getCount();
if (this.c(i, itemstack.cloneAndSubtract(j))) {
((EntityPlayer)this.player).playerConnection.sendPacket(new PacketPlayOutSetSlot(-2, i, this.getItem(i)));
}
}
}
}
public void f(ItemStack itemstack) {
for (NonNullList<ItemStack> nonnulllist : this.f) {
for (int i = 0; i < nonnulllist.size(); ++i) {
if (nonnulllist.get(i) == itemstack) {
nonnulllist.set(i, ItemStack.a);
break;
}
}
}
}
public float a(IBlockData iblockdata) {
return this.items.get(this.itemInHandIndex).a(iblockdata);
}
public NBTTagList a(NBTTagList nbttaglist) {
NBTTagCompound nbttagcompound;
int i;
for(i = 0; i < this.items.size(); ++i) {
if (!this.items.get(i).isEmpty()) {
nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte) i);
this.items.get(i).save(nbttagcompound);
nbttaglist.add(nbttagcompound);
}
}
for(i = 0; i < this.armor.size(); ++i) {
if (!this.armor.get(i).isEmpty()) {
nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte) (i + 100));
this.armor.get(i).save(nbttagcompound);
nbttaglist.add(nbttagcompound);
}
}
for(i = 0; i < this.extraSlots.size(); ++i) {
if (!this.extraSlots.get(i).isEmpty()) {
nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte) (i + 150));
this.extraSlots.get(i).save(nbttagcompound);
nbttaglist.add(nbttagcompound);
}
}
return nbttaglist;
}
public void b(NBTTagList nbttaglist) {
this.items.clear();
this.armor.clear();
this.extraSlots.clear();
for(int i = 0; i < nbttaglist.size(); ++i) {
NBTTagCompound nbttagcompound = nbttaglist.getCompound(i);
int j = nbttagcompound.getByte("Slot") & 255;
ItemStack itemstack = ItemStack.a(nbttagcompound);
if (!itemstack.isEmpty()) {
if (j >= 0 && j < this.items.size()) {
this.items.set(j, itemstack);
} else if (j >= 100 && j < this.armor.size() + 100) {
this.armor.set(j - 100, itemstack);
} else if (j >= 150 && j < this.extraSlots.size() + 150) {
this.extraSlots.set(j - 150, itemstack);
}
}
}
}
public boolean P_() {
Iterator iterator = this.items.iterator();
ItemStack itemstack;
while(iterator.hasNext()) {
itemstack = (ItemStack)iterator.next();
if (!itemstack.isEmpty()) {
return false;
}
}
iterator = this.armor.iterator();
while(iterator.hasNext()) {
itemstack = (ItemStack)iterator.next();
if (!itemstack.isEmpty()) {
return false;
}
}
iterator = this.extraSlots.iterator();
while(iterator.hasNext()) {
itemstack = (ItemStack)iterator.next();
if (!itemstack.isEmpty()) {
return false;
}
}
return true;
}
@Nullable
public IChatBaseComponent getCustomName() {
return null;
}
public boolean b(IBlockData iblockdata) {
return this.getItem(this.itemInHandIndex).b(iblockdata);
}
public void a(float f) {
if (f > 0.0F) {
f /= 4.0F;
if (f < 1.0F) {
f = 1.0F;
}
for (ItemStack itemstack : this.armor) {
if (itemstack.getItem() instanceof ItemArmor) {
itemstack.damage((int) f, this.player);
}
}
}
}
public void dropContents() {
for (NonNullList<ItemStack> itemStacks : this.f) {
for (int i = 0; i < itemStacks.size(); ++i) {
ItemStack itemstack = itemStacks.get(i);
if (!itemstack.isEmpty()) {
itemStacks.set(i, ItemStack.a);
this.player.a(itemstack, true, false);
}
}
}
}
public boolean h(ItemStack itemstack) {
return this.f.stream().flatMap(NonNullList::stream).anyMatch(itemStack1 -> !itemStack1.isEmpty() && itemStack1.doMaterialsMatch(itemstack));
}
public void a(PlayerInventory playerinventory) {
for (int i = 0; i < playerinventory.getSize(); ++i) {
this.setItem(i, playerinventory.getItem(i));
}
this.itemInHandIndex = playerinventory.itemInHandIndex;
}
public void clear() {
this.f.forEach(NonNullList::clear);
}
public void a(AutoRecipeStackManager autorecipestackmanager) {
for (ItemStack itemstack : this.items) {
autorecipestackmanager.a(itemstack);
}
}
} }