Convert to a multi-module Maven setup

This is much more user-friendly - users can either compile a specific module or create a profile to compile for the specific Minecraft versions they're looking to support. It means that it's much easier for people to continue assisting with the development of OpenInv in the future without access to every version of CB since 1.4.5.

This commit restores and updates most of the old system.
This commit is contained in:
Jikoo
2016-11-25 08:01:44 -05:00
parent b76440ab9a
commit 3bf7225712
40 changed files with 1088 additions and 196 deletions

28
v1_11_R1/pom.xml Normal file
View File

@@ -0,0 +1,28 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinv</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>openinvadapter1_11_R1</artifactId>
<name>OpenInvAdapter1_11_R1</name>
<dependencies>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,174 @@
/*
* Copyright (C) 2011-2016 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
import java.util.Iterator;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.IAnySilentChest;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.BlockChest;
import net.minecraft.server.v1_11_R1.BlockChest.Type;
import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.Entity;
import net.minecraft.server.v1_11_R1.EntityOcelot;
import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.EnumDirection;
import net.minecraft.server.v1_11_R1.ITileInventory;
import net.minecraft.server.v1_11_R1.InventoryLargeChest;
import net.minecraft.server.v1_11_R1.TileEntity;
import net.minecraft.server.v1_11_R1.TileEntityChest;
import net.minecraft.server.v1_11_R1.World;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
public class AnySilentChest implements IAnySilentChest {
private final OpenInv plugin;
public AnySilentChest(OpenInv plugin) {
this.plugin = plugin;
}
@Override
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
BlockPosition position = new BlockPosition(x, y, z);
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
BlockChest chest = (BlockChest) (((BlockChest) world.getType(position).getBlock()).g == Type.TRAP ?
Block.getByName("trapped_chest") : Block.getByName("chest"));
// If a block is on top
if (topBlocking(world, position)) {
return true;
}
// If the block next to the chest is chest and has a block on top
for (EnumDirection direction : EnumDirectionList.HORIZONTAL) {
BlockPosition sidePosition = position.shift(direction);
Block block = world.getType(sidePosition).getBlock();
if (block == chest) {
if (this.topBlocking(world, sidePosition)) {
return true;
}
}
}
return false;
}
private boolean topBlocking(World world, BlockPosition position) {
return this.blockOnTop(world, position) || this.ocelotOnTop(world, position);
}
@SuppressWarnings("deprecation")
private boolean blockOnTop(World world, BlockPosition position) {
Block block = world.getType(position.up()).getBlock();
return block.isOccluding(block.getBlockData());
}
private boolean ocelotOnTop(World world, BlockPosition position) {
Iterator iterator = world.a(EntityOcelot.class,
new AxisAlignedBB(position.getX(), position.getY() + 1,
position.getZ(), position.getX() + 1,
position.getY() + 2, position.getZ() + 1)).iterator();
EntityOcelot entityOcelot;
do {
if (!iterator.hasNext()) {
return false;
}
Entity entity = (Entity) iterator.next();
entityOcelot = (EntityOcelot) entity;
} while (!entityOcelot.isSitting());
return true;
}
@Override
public boolean activateChest(Player p, boolean anyChest, boolean silentChest, int x, int y, int z) {
BlockPosition position = new BlockPosition(x, y, z);
EntityPlayer player = ((CraftPlayer) p).getHandle();
World world = player.world;
if (world.isClientSide) {
return true;
}
BlockChest chest = (BlockChest) (((BlockChest) world.getType(position).getBlock()).g == Type.TRAP ?
Block.getByName("trapped_chest") : Block.getByName("chest"));
TileEntity tileEntity = world.getTileEntity(position);
if (!(tileEntity instanceof TileEntityChest)) {
return true;
}
ITileInventory tileInventory = (ITileInventory) tileEntity;
if (!anyChest && this.topBlocking(world, position)) {
return true;
}
for (EnumDirection direction : EnumDirectionList.HORIZONTAL) {
BlockPosition side = position.shift(direction);
Block block = world.getType(side).getBlock();
if (block == chest) {
if (!anyChest && this.topBlocking(world, side)) {
return true;
}
TileEntity sideTileEntity = world.getTileEntity(side);
if (sideTileEntity instanceof TileEntityChest) {
if (direction != EnumDirection.WEST && direction != EnumDirection.NORTH) {
tileInventory = new InventoryLargeChest("container.chestDouble", tileInventory, (TileEntityChest) sideTileEntity);
} else {
tileInventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) sideTileEntity, tileInventory);
}
}
}
}
boolean returnValue = true;
if (silentChest) {
tileInventory = new SilentInventory(tileInventory);
if (plugin.getConfiguration().notifySilentChest()) {
OpenInv.sendMessage(p, "You are opening a chest silently.");
}
returnValue = false;
}
player.openContainer(tileInventory);
if (anyChest && plugin.getConfiguration().notifyAnyChest()) {
OpenInv.sendMessage(p, "You are opening a blocked chest.");
}
return returnValue;
}
}

View File

@@ -0,0 +1,25 @@
package com.lishid.openinv.internal.v1_11_R1;
import java.util.Iterator;
import com.google.common.collect.Iterators;
import net.minecraft.server.v1_11_R1.EnumDirection;
import net.minecraft.server.v1_11_R1.EnumDirection.EnumDirectionLimit;
public enum EnumDirectionList implements Iterable<EnumDirection> {
HORIZONTAL(EnumDirectionLimit.HORIZONTAL),
VERTICAL(EnumDirectionLimit.VERTICAL);
private final EnumDirectionLimit list;
EnumDirectionList(EnumDirectionLimit list) {
this.list = list;
}
@Override
public Iterator<EnumDirection> iterator() {
return Iterators.forArray(list.a());
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (C) 2011-2016 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
import java.lang.reflect.Field;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
import net.minecraft.server.v1_11_R1.IInventory;
public class InventoryAccess {
private final OpenInv plugin;
public InventoryAccess(OpenInv plugin) {
this.plugin = plugin;
}
public boolean check(Inventory inventory, HumanEntity player) {
IInventory inv = grabInventory(inventory);
if (inv instanceof SpecialPlayerInventory) {
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
return false;
}
} else if (inv instanceof SpecialEnderChest) {
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
return false;
}
}
return true;
}
private IInventory grabInventory(Inventory inventory) {
if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory();
}
// Use reflection to find the inventory
Class<? extends Inventory> clazz = inventory.getClass();
IInventory result = null;
for (Field f : clazz.getDeclaredFields()) {
f.setAccessible(true);
if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
try {
result = (IInventory) f.get(inventory);
} catch (Exception e) {
plugin.log(e);
}
}
}
return result;
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) 2011-2016 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
import org.bukkit.entity.Player;
import com.lishid.openinv.OpenInv;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.MinecraftServer;
import net.minecraft.server.v1_11_R1.PlayerInteractManager;
public class PlayerDataManager {
private final OpenInv plugin;
public PlayerDataManager(OpenInv plugin) {
this.plugin = plugin;
}
public Player loadPlayer(UUID uuid) {
try {
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
if (player == null || !player.hasPlayedBefore()) {
return null;
}
GameProfile profile = new GameProfile(uuid, player.getName());
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
// Create an entity to load the player data
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity
Player target = entity.getBukkitEntity();
if (target != null) {
// Load data
target.loadData();
// Return the entity
return target;
}
} catch (Exception e) {
plugin.log(e);
}
return null;
}
}

View File

@@ -0,0 +1,183 @@
package com.lishid.openinv.internal.v1_11_R1;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftHumanEntity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.InventoryHolder;
import net.minecraft.server.v1_11_R1.ChestLock;
import net.minecraft.server.v1_11_R1.Container;
import net.minecraft.server.v1_11_R1.ContainerChest;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.IChatBaseComponent;
import net.minecraft.server.v1_11_R1.ITileInventory;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.PlayerInventory;
public class SilentInventory implements ITileInventory {
public ITileInventory inv;
public SilentInventory(ITileInventory inv) {
this.inv = inv;
}
@Override
public boolean isLocked()
{
return inv.isLocked();
}
@Override
public void a(ChestLock chestLock) {
inv.a(chestLock);
}
@Override
public ChestLock getLock() {
return inv.getLock();
}
@Override
public int getSize() {
return inv.getSize();
}
@Override
public boolean w_() {
return inv.w_();
}
@Override
public ItemStack getItem(int i) {
return inv.getItem(i);
}
@Override
public ItemStack splitStack(int i, int i1) {
return inv.splitStack(i, i1);
}
@Override
public ItemStack splitWithoutUpdate(int i) {
return inv.splitWithoutUpdate(i);
}
@Override
public void setItem(int i, ItemStack itemStack) {
inv.setItem(i, itemStack);
}
@Override
public int getMaxStackSize() {
return inv.getMaxStackSize();
}
@Override
public void update() {
inv.update();
}
@Override
public boolean a(EntityHuman entityHuman) {
return inv.a(entityHuman);
}
@Override
public void startOpen(EntityHuman entityHuman) {
// Don't do anything
}
@Override
public void closeContainer(EntityHuman entityHuman) {
// Don't do anything
}
@Override
public boolean b(int i, ItemStack itemStack) {
return inv.b(i, itemStack);
}
@Override
public int getProperty(int i) {
return inv.getProperty(i);
}
@Override
public void setProperty(int i, int i1) {
inv.setProperty(i, i1);
}
@Override
public int h() {
return inv.h();
}
@Override
public void clear() {
inv.clear();
}
@Override
public List<ItemStack> getContents() {
return inv.getContents();
}
@Override
public void onOpen(CraftHumanEntity craftHumanEntity) {
inv.onOpen(craftHumanEntity);
}
@Override
public void onClose(CraftHumanEntity craftHumanEntity) {
inv.onClose(craftHumanEntity);
}
@Override
public List<HumanEntity> getViewers() {
return inv.getViewers();
}
@Override
public InventoryHolder getOwner() {
return inv.getOwner();
}
@Override
public void setMaxStackSize(int i) {
inv.setMaxStackSize(i);
}
@Override
public Location getLocation() {
return inv.getLocation();
}
@Override
public String getName() {
return inv.getName();
}
@Override
public boolean hasCustomName() {
return inv.hasCustomName();
}
@Override
public IChatBaseComponent getScoreboardDisplayName() {
return inv.getScoreboardDisplayName();
}
@Override
public Container createContainer(PlayerInventory playerInventory, EntityHuman entityHuman) {
// Don't let the chest itself create the container.
return new ContainerChest(playerInventory, this, entityHuman);
}
@Override
public String getContainerName() {
return inv.getContainerName();
}
}

View File

@@ -0,0 +1,122 @@
/*
* Copyright (C) 2011-2016 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
import java.lang.reflect.Field;
import java.util.List;
import net.minecraft.server.v1_11_R1.NonNullList;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import net.minecraft.server.v1_11_R1.InventoryEnderChest;
import net.minecraft.server.v1_11_R1.InventorySubcontainer;
import net.minecraft.server.v1_11_R1.ItemStack;
public class SpecialEnderChest extends InventorySubcontainer {
private final CraftInventory inventory = new CraftInventory(this);
private final InventoryEnderChest enderChest;
private CraftPlayer owner;
private boolean playerOnline;
public SpecialEnderChest(Player p, boolean online) {
this(p, ((CraftPlayer) p).getHandle().getEnderChest(), online);
}
public SpecialEnderChest(Player p, InventoryEnderChest enderChest, boolean online) {
super(enderChest.getName(), enderChest.hasCustomName(), enderChest.getSize());
this.owner = (CraftPlayer) p;
this.enderChest = enderChest;
this.playerOnline = online;
reflectContents(getClass().getSuperclass(), this, this.enderChest.getContents());
}
private void saveOnExit() {
if (transaction.isEmpty() && !playerOnline) {
owner.saveData();
}
}
private void reflectContents(Class clazz, InventorySubcontainer enderChest, List<ItemStack> items) {
try {
Field itemsField = clazz.getDeclaredField("items");
itemsField.setAccessible(true);
itemsField.set(enderChest, items);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
private void linkInventory(InventoryEnderChest inventory) {
reflectContents(inventory.getClass(), inventory, this.items);
}
public Inventory getBukkitInventory() {
return inventory;
}
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save) {
owner.saveData();
}
return offline;
}
public void playerOnline(Player p) {
if (!playerOnline) {
owner = (CraftPlayer) p;
linkInventory(((CraftPlayer) p).getHandle().getEnderChest());
playerOnline = true;
}
}
public boolean playerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
inventoryRemovalCheck(true);
}
@Override
public InventoryHolder getOwner() {
return this.owner;
}
@Override
public void update() {
super.update();
enderChest.update();
}
}

View File

@@ -0,0 +1,284 @@
/*
* Copyright (C) 2011-2016 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
import java.lang.reflect.Field;
import net.minecraft.server.v1_11_R1.*;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public class SpecialPlayerInventory extends PlayerInventory {
private final CraftInventory inventory = new CraftInventory(this);
private final NonNullList<ItemStack> extra = NonNullList.a();
private CraftPlayer owner;
private NonNullList<ItemStack>[] arrays;
private boolean playerOnline;
public SpecialPlayerInventory(Player p, boolean online) {
super(((CraftPlayer) p).getHandle());
this.owner = (CraftPlayer) p;
this.playerOnline = online;
reflectContents(getClass().getSuperclass(), player.inventory, this);
}
private void reflectContents(Class clazz, PlayerInventory src, PlayerInventory dest) {
try {
Field itemsField = clazz.getDeclaredField("items");
itemsField.setAccessible(true);
itemsField.set(dest, src.items);
Field armorField = clazz.getDeclaredField("armor");
armorField.setAccessible(true);
armorField.set(dest, src.armor);
Field extraSlotsField = clazz.getDeclaredField("extraSlots");
extraSlotsField.setAccessible(true);
extraSlotsField.set(dest, src.extraSlots);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
//noinspection unchecked
arrays = new NonNullList[] { this.items, this.armor, this.extraSlots, this.extra };
}
private void linkInventory(PlayerInventory inventory) {
reflectContents(inventory.getClass(), inventory, this);
}
public Inventory getBukkitInventory() {
return inventory;
}
public boolean inventoryRemovalCheck(boolean save) {
boolean offline = transaction.isEmpty() && !playerOnline;
if (offline && save) {
owner.saveData();
}
return offline;
}
public void playerOnline(Player player) {
if (!playerOnline) {
owner = (CraftPlayer) player;
this.player = owner.getHandle();
linkInventory(owner.getHandle().inventory);
playerOnline = true;
}
}
public boolean playerOffline() {
playerOnline = false;
return inventoryRemovalCheck(false);
}
@Override
public void onClose(CraftHumanEntity who) {
super.onClose(who);
inventoryRemovalCheck(true);
}
@Override
public NonNullList<ItemStack> getContents() {
NonNullList<ItemStack> contents = NonNullList.a();
contents.addAll(this.items);
contents.addAll(this.armor);
contents.addAll(this.extraSlots);
return contents;
}
@Override
public int getSize() {
return super.getSize() + 4;
}
@Override
public ItemStack getItem(int i) {
NonNullList<ItemStack> is = null;
NonNullList<ItemStack>[] contents = this.arrays;
int j = contents.length;
for (int k = 0; k < j; ++k) {
NonNullList<ItemStack> is2 = contents[k];
if (i < is2.size()) {
is = is2;
break;
}
i -= is2.size();
}
if (is == this.items) {
i = getReversedItemSlotNum(i);
} else if (is == this.armor) {
i = getReversedArmorSlotNum(i);
} else if (is == this.extraSlots) {
// Do nothing
} else if (is == this.extra) {
// Do nothing
}
return is == null ? ItemStack.a : is.get(i);
}
@Override
public ItemStack splitStack(int i, int j) {
NonNullList<ItemStack> is = null;
NonNullList<ItemStack>[] contents = this.arrays;
int k = contents.length;
for (int l = 0; l < k; ++l) {
NonNullList<ItemStack> is2 = contents[l];
if (i < is2.size()) {
is = is2;
break;
}
i -= is2.size();
}
if (is == this.items) {
i = getReversedItemSlotNum(i);
} else if (is == this.armor) {
i = getReversedArmorSlotNum(i);
} else if (is == this.extraSlots) {
// Do nothing
} else if (is == this.extra) {
// Do nothing
}
return is != null && !is.get(i).isEmpty() ? ContainerUtil.a(is, i, j) : ItemStack.a;
}
@Override
public ItemStack splitWithoutUpdate(int i) {
NonNullList<ItemStack> is = null;
NonNullList<ItemStack>[] contents = this.arrays;
int j = contents.length;
for (int object = 0; object < j; ++object) {
NonNullList<ItemStack> is2 = contents[object];
if (i < is2.size()) {
is = is2;
break;
}
i -= is2.size();
}
if (is != null && !is.get(i).isEmpty()) {
if (is == this.items) {
i = getReversedItemSlotNum(i);
} else if (is == this.armor) {
i = getReversedArmorSlotNum(i);
} else if (is == this.extraSlots) {
// Do nothing
} else if (is == this.extra) {
// Do nothing
}
Object object = is.get(i);
is.set(i, ItemStack.a);
return (ItemStack) object;
} else {
return ItemStack.a;
}
}
@Override
public void setItem(int i, ItemStack itemStack) {
NonNullList<ItemStack> is = null;
NonNullList<ItemStack>[] contents = this.arrays;
int j = contents.length;
for (int k = 0; k < j; ++k) {
NonNullList<ItemStack> is2 = contents[k];
if (i < is2.size()) {
is = is2;
break;
}
i -= is2.size();
}
if (is != null) {
if (is == this.items) {
i = getReversedItemSlotNum(i);
} else if (is == this.armor) {
i = getReversedArmorSlotNum(i);
} else if (is == this.extraSlots) {
// Do nothing
} else if (is == this.extra) {
owner.getHandle().drop(itemStack, true);
itemStack = ItemStack.a;
}
is.set(i, itemStack);
owner.getHandle().defaultContainer.b();
}
}
private int getReversedItemSlotNum(int i) {
return (i >= 27) ? (i - 27) : (i + 9);
}
private int getReversedArmorSlotNum(int i) {
if (i == 0) return 3;
if (i == 1) return 2;
if (i == 2) return 1;
return (i == 3) ? 0 : i;
}
@Override
public boolean hasCustomName() {
return true;
}
@Override
public String getName() {
return player.getName();
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void update() {
super.update();
player.inventory.update();
}
}