1
0
forked from xjboss/KCauldronX

Initial commit (Forge 1291).

This commit is contained in:
gamerforEA
2015-03-22 20:38:04 +03:00
commit 16773ead6a
611 changed files with 64826 additions and 0 deletions

View File

@ -0,0 +1,83 @@
--- ../src-base/minecraft/net/minecraft/inventory/AnimalChest.java
+++ ../src-work/minecraft/net/minecraft/inventory/AnimalChest.java
@@ -3,6 +3,14 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+// CraftBukkit start
+import java.util.List;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import net.minecraft.entity.passive.EntityHorse;
+import net.minecraft.item.ItemStack;
+// CraftBukkit end
+
public class AnimalChest extends InventoryBasic
{
private static final String __OBFID = "CL_00001731";
@@ -12,6 +20,65 @@
super(p_i1796_1_, false, p_i1796_2_);
}
+ // CraftBukkit start
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private EntityHorse horse;
+ private int maxStack = MAX_STACK;
+
+ public AnimalChest(String s, int i, EntityHorse horse)
+ {
+ this(s, i);
+ this.horse = horse;
+ }
+
+ @Override
+ public ItemStack[] getContents()
+ {
+ return this.inventoryContents;
+ }
+
+ @Override
+ public void onOpen(CraftHumanEntity who)
+ {
+ transaction.add(who);
+ }
+
+ @Override
+ public void onClose(CraftHumanEntity who)
+ {
+ transaction.remove(who);
+ }
+
+ @Override
+ public List<HumanEntity> getViewers()
+ {
+ return transaction;
+ }
+
+ @Override
+ public org.bukkit.inventory.InventoryHolder getOwner()
+ {
+ return (org.bukkit.entity.Horse) this.horse.getBukkitEntity();
+ }
+
+ @Override
+ public void setMaxStackSize(int size)
+ {
+ maxStack = size;
+ }
+
+ @Override
+
+ /**
+ * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
+ * this more of a set than a get?*
+ */
+ public int getInventoryStackLimit()
+ {
+ return maxStack;
+ }
+ // CraftBukkit end
+
@SideOnly(Side.CLIENT)
public AnimalChest(String p_i1797_1_, boolean p_i1797_2_, int p_i1797_3_)
{

View File

@ -0,0 +1,186 @@
--- ../src-base/minecraft/net/minecraft/inventory/Container.java
+++ ../src-work/minecraft/net/minecraft/inventory/Container.java
@@ -13,6 +13,17 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
+// CraftBukkit start
+import java.util.HashMap;
+import java.util.Map;
+import net.minecraft.entity.player.EntityPlayerMP;
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.Event.Result;
+import org.bukkit.event.inventory.InventoryDragEvent;
+import org.bukkit.inventory.InventoryView;
+// CraftBukkit end
+
public abstract class Container
{
public List inventoryItemStacks = new ArrayList();
@@ -21,12 +32,52 @@
@SideOnly(Side.CLIENT)
private short transactionID;
private int field_94535_f = -1;
- private int field_94536_g;
+ public int field_94536_g; // CraftBukkit - private -> public
private final Set field_94537_h = new HashSet();
+ public InventoryView bukkitView = null; // Cauldron
+
protected List crafters = new ArrayList();
private Set playerList = new HashSet();
private static final String __OBFID = "CL_00001730";
+ // CraftBukkit start
+ public boolean checkReachable = true;
+ public InventoryView getBukkitView() { return bukkitView; } // Cauldron
+ public void transferTo(Container other, org.bukkit.craftbukkit.entity.CraftHumanEntity player)
+ {
+ InventoryView source = this.getBukkitView(), destination = other.getBukkitView();
+ // Cauldron start - add null checks to skip modded inventories with no Bukkit wrappers, and
+ // catch AbstractMethodErrors for modded IInventory's with no onClose()
+ if (source != null) {
+ try {
+ ((CraftInventory) source.getTopInventory()).getInventory().onClose(player);
+ } catch (AbstractMethodError ex) {
+ // modded
+ }
+
+ try {
+ ((CraftInventory) source.getBottomInventory()).getInventory().onClose(player);
+ } catch (AbstractMethodError ex) {
+ // modded
+ }
+ }
+ if (destination != null) {
+ try {
+ ((CraftInventory) destination.getTopInventory()).getInventory().onOpen(player);
+ } catch (AbstractMethodError ex) {
+ // modded
+ }
+
+ try {
+ ((CraftInventory) destination.getBottomInventory()).getInventory().onOpen(player);
+ } catch (AbstractMethodError ex) {
+ // modded
+ }
+ }
+ // Cauldron end
+ }
+ // CraftBukkit end
+
protected Slot addSlotToContainer(Slot p_75146_1_)
{
p_75146_1_.slotNumber = this.inventorySlots.size();
@@ -39,7 +90,11 @@
{
if (this.crafters.contains(p_75132_1_))
{
- throw new IllegalArgumentException("Listener already listening");
+ // Cauldron start - As we do not create a new player object on respawn, we need to update the client with changes if listener already exists
+ //throw new IllegalArgumentException("Listener already listening");
+ p_75132_1_.sendContainerAndContentsToPlayer(this, this.getInventory());
+ this.detectAndSendChanges();
+ // Cauldron end
}
else
{
@@ -109,6 +164,10 @@
public Slot getSlot(int p_75139_1_)
{
+ // Cauldron start - vanilla compatibility. fixes NPE with ProjectRed's Item Stock Keeper
+ if (p_75139_1_ < 0 || p_75139_1_ >= this.inventorySlots.size())
+ return null;
+ // Cauldron end
return (Slot)this.inventorySlots.get(p_75139_1_);
}
@@ -168,6 +227,7 @@
itemstack3 = inventoryplayer.getItemStack().copy();
i1 = inventoryplayer.getItemStack().stackSize;
Iterator iterator = this.field_94537_h.iterator();
+ Map<Integer, ItemStack> draggedSlots = new HashMap<Integer, ItemStack>(); // CraftBukkit - Store slots from drag in map (raw slot id -> new stack)
while (iterator.hasNext())
{
@@ -190,18 +250,55 @@
}
i1 -= itemstack1.stackSize - j1;
- slot1.putStack(itemstack1);
+ draggedSlots.put(slot1.slotNumber, itemstack1); // CraftBukkit - Put in map instead of setting
}
}
- itemstack3.stackSize = i1;
+ // CraftBukkit start - InventoryDragEvent
+ InventoryView view = getBukkitView();
+ org.bukkit.inventory.ItemStack newcursor = CraftItemStack.asCraftMirror(itemstack3);
+ newcursor.setAmount(i1);
+ Map<Integer, org.bukkit.inventory.ItemStack> eventmap = new HashMap<Integer, org.bukkit.inventory.ItemStack>();
- if (itemstack3.stackSize <= 0)
+ for (Map.Entry<Integer, ItemStack> ditem : draggedSlots.entrySet())
{
- itemstack3 = null;
+ eventmap.put(ditem.getKey(), CraftItemStack.asBukkitCopy(ditem.getValue()));
}
- inventoryplayer.setItemStack(itemstack3);
+ // It's essential that we set the cursor to the new value here to prevent item duplication if a plugin closes the inventory.
+ ItemStack oldCursor = inventoryplayer.getItemStack();
+ inventoryplayer.setItemStack(CraftItemStack.asNMSCopy(newcursor));
+ InventoryDragEvent event = new InventoryDragEvent(view, (newcursor.getType() != org.bukkit.Material.AIR ? newcursor : null), CraftItemStack.asBukkitCopy(oldCursor), this.field_94535_f == i1, eventmap); // Should be dragButton
+ p_75144_4_.worldObj.getServer().getPluginManager().callEvent(event);
+ // Whether or not a change was made to the inventory that requires an update.
+ boolean needsUpdate = event.getResult() != Result.DEFAULT;
+
+ if (event.getResult() != Result.DENY)
+ {
+ for (Map.Entry<Integer, ItemStack> dslot : draggedSlots.entrySet())
+ {
+ view.setItem(dslot.getKey(), CraftItemStack.asBukkitCopy(dslot.getValue()));
+ }
+
+ // The only time the carried item will be set to null is if the inventory is closed by the server.
+ // If the inventory is closed by the server, then the cursor items are dropped. This is why we change the cursor early.
+ if (inventoryplayer.getItemStack() != null)
+ {
+ inventoryplayer.setItemStack(CraftItemStack.asNMSCopy(event.getCursor()));
+ needsUpdate = true;
+ }
+ }
+ else
+ {
+ inventoryplayer.setItemStack(oldCursor);
+ }
+
+ if (needsUpdate && p_75144_4_ instanceof EntityPlayerMP)
+ {
+ ((EntityPlayerMP) p_75144_4_).sendContainerToPlayer(this);
+ }
+
+ // CraftBukkit end
}
this.func_94533_d();
@@ -235,10 +332,17 @@
if (p_75144_2_ == 1)
{
- p_75144_4_.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack().splitStack(1), true);
+ // CraftBukkit start - Store a reference
+ ItemStack itemstack4 = inventoryplayer.getItemStack();
if (inventoryplayer.getItemStack().stackSize == 0)
{
+ p_75144_4_.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack().splitStack(1), true);
+ }
+
+ if (itemstack4.stackSize == 0)
+ {
+ // CraftBukkit end
inventoryplayer.setItemStack((ItemStack)null);
}
}

View File

@ -0,0 +1,62 @@
--- ../src-base/minecraft/net/minecraft/inventory/ContainerBeacon.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerBeacon.java
@@ -8,6 +8,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityBeacon;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView; // CraftBukkit
+
public class ContainerBeacon extends Container
{
private TileEntityBeacon tileBeacon;
@@ -15,10 +17,15 @@
private int field_82865_g;
private int field_82867_h;
private int field_82868_i;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private InventoryPlayer player;
+ // CraftBukkit end
private static final String __OBFID = "CL_00001735";
public ContainerBeacon(InventoryPlayer p_i1802_1_, TileEntityBeacon p_i1802_2_)
{
+ player = p_i1802_1_; // CraftBukkit
this.tileBeacon = p_i1802_2_;
this.addSlotToContainer(this.beaconSlot = new ContainerBeacon.BeaconSlot(p_i1802_2_, 0, 136, 110));
byte b0 = 36;
@@ -77,6 +84,13 @@
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
+ // CraftBukkit start
+ if (!this.checkReachable)
+ {
+ return true;
+ }
+ // CraftBukkit end
+
return this.tileBeacon.isUseableByPlayer(p_75145_1_);
}
@@ -145,6 +159,20 @@
return itemstack;
}
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView()
+ {
+ if (bukkitEntity != null)
+ {
+ return bukkitEntity;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryBeacon(this.tileBeacon);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
+
class BeaconSlot extends Slot
{
private static final String __OBFID = "CL_00001736";

View File

@ -0,0 +1,63 @@
--- ../src-base/minecraft/net/minecraft/inventory/ContainerBrewingStand.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerBrewingStand.java
@@ -10,15 +10,25 @@
import net.minecraft.stats.AchievementList;
import net.minecraft.tileentity.TileEntityBrewingStand;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventoryBrewer;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerBrewingStand extends Container
{
private TileEntityBrewingStand tileBrewingStand;
private final Slot theSlot;
private int brewTime;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private InventoryPlayer player;
+ // CraftBukkit end
private static final String __OBFID = "CL_00001737";
public ContainerBrewingStand(InventoryPlayer p_i1805_1_, TileEntityBrewingStand p_i1805_2_)
{
+ this.player = p_i1805_1_; // CraftBukkit
this.tileBrewingStand = p_i1805_2_;
this.addSlotToContainer(new ContainerBrewingStand.Potion(p_i1805_1_.player, p_i1805_2_, 0, 56, 46));
this.addSlotToContainer(new ContainerBrewingStand.Potion(p_i1805_1_.player, p_i1805_2_, 1, 79, 53));
@@ -74,6 +84,13 @@
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
+ // CraftBukkit start
+ if (!this.checkReachable)
+ {
+ return true;
+ }
+ // CraftBukkit end
+
return this.tileBrewingStand.isUseableByPlayer(p_75145_1_);
}
@@ -152,6 +169,20 @@
return itemstack;
}
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView()
+ {
+ if (bukkitEntity != null)
+ {
+ return bukkitEntity;
+ }
+
+ CraftInventoryBrewer inventory = new CraftInventoryBrewer(this.tileBrewingStand);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
+
class Ingredient extends Slot
{
private static final String __OBFID = "CL_00001738";

View File

@ -0,0 +1,77 @@
--- ../src-base/minecraft/net/minecraft/inventory/ContainerChest.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerChest.java
@@ -3,10 +3,46 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
+// CraftBukkit start
+import net.minecraft.entity.player.InventoryPlayer;
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerChest extends Container
{
- private IInventory lowerChestInventory;
+ public IInventory lowerChestInventory; // CraftBukkit - private->public
private int numRows;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private InventoryPlayer player;
+
+ public CraftInventoryView getBukkitView()
+ {
+ if (bukkitEntity != null || player == null) // Cauldron
+ {
+ return bukkitEntity;
+ }
+
+ CraftInventory inventory;
+
+ if (this.lowerChestInventory instanceof InventoryPlayer)
+ {
+ inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryPlayer((InventoryPlayer) this.lowerChestInventory);
+ }
+ else if (this.lowerChestInventory instanceof InventoryLargeChest)
+ {
+ inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) this.lowerChestInventory);
+ }
+ else
+ {
+ inventory = new CraftInventory(this.lowerChestInventory);
+ }
+
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
private static final String __OBFID = "CL_00001742";
public ContainerChest(IInventory p_i1806_1_, IInventory p_i1806_2_)
@@ -15,6 +51,12 @@
this.numRows = p_i1806_2_.getSizeInventory() / 9;
p_i1806_2_.openInventory();
int i = (this.numRows - 4) * 18;
+ // CraftBukkit start - Save player
+ if (p_i1806_1_ instanceof InventoryPlayer) // Cauldron - make sure it is an InventoryPlayer before casting
+ {
+ this.player = (InventoryPlayer) p_i1806_1_;
+ }
+ // CraftBukkit end
int j;
int k;
@@ -42,6 +84,13 @@
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
+ // CraftBukkit start
+ if (!this.checkReachable)
+ {
+ return true;
+ }
+ // CraftBukkit end
+
return this.lowerChestInventory.isUseableByPlayer(p_75145_1_);
}

View File

@ -0,0 +1,65 @@
--- ../src-base/minecraft/net/minecraft/inventory/ContainerDispenser.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerDispenser.java
@@ -4,14 +4,28 @@
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityDispenser;
+// CraftBukkit start
+import net.minecraft.entity.player.InventoryPlayer;
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerDispenser extends Container
{
- private TileEntityDispenser tileDispenser;
+ public TileEntityDispenser tileDispenser; // CraftBukkit - private -> public
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private InventoryPlayer player;
+ // CraftBukkit end
private static final String __OBFID = "CL_00001763";
public ContainerDispenser(IInventory p_i1825_1_, TileEntityDispenser p_i1825_2_)
{
this.tileDispenser = p_i1825_2_;
+ // CraftBukkit start - Save player
+ // TODO: Should we check to make sure it really is an InventoryPlayer?
+ this.player = (InventoryPlayer)p_i1825_1_;
+ // CraftBukkit end
int i;
int j;
@@ -39,6 +53,13 @@
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
+ // CraftBukkit start
+ if (!this.checkReachable)
+ {
+ return true;
+ }
+ // CraftBukkit end
+
return this.tileDispenser.isUseableByPlayer(p_75145_1_);
}
@@ -83,4 +104,18 @@
return itemstack;
}
+
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView()
+ {
+ if (bukkitEntity != null)
+ {
+ return bukkitEntity;
+ }
+
+ CraftInventory inventory = new CraftInventory(this.tileDispenser);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}

View File

@ -0,0 +1,208 @@
--- ../src-base/minecraft/net/minecraft/inventory/ContainerEnchantment.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerEnchantment.java
@@ -4,6 +4,8 @@
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.Random;
+
+import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
@@ -14,21 +16,22 @@
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
+// CraftBukkit start
+import java.util.Map;
+
+import org.bukkit.craftbukkit.inventory.CraftInventoryEnchanting;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.enchantment.EnchantItemEvent;
+import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
+import org.bukkit.entity.Player;
+// CraftBukkit end
+
public class ContainerEnchantment extends Container
{
- public IInventory tableInventory = new InventoryBasic("Enchant", true, 1)
- {
- private static final String __OBFID = "CL_00001746";
- public int getInventoryStackLimit()
- {
- return 1;
- }
- public void markDirty()
- {
- super.markDirty();
- ContainerEnchantment.this.onCraftMatrixChanged(this);
- }
- };
+ // CraftBukkit - make type specific (changed from IInventory)
+ public ContainerEnchantTableInventory tableInventory_CB = new ContainerEnchantTableInventory(this, "Enchant", true, 1); // CraftBukkit
+ public IInventory tableInventory = tableInventory_CB;
private World worldPointer;
private int posX;
private int posY;
@@ -36,6 +39,10 @@
private Random rand = new Random();
public long nameSeed;
public int[] enchantLevels = new int[3];
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private Player player;
+ // CraftBukkit end
private static final String __OBFID = "CL_00001745";
public ContainerEnchantment(InventoryPlayer p_i1811_1_, World p_i1811_2_, int p_i1811_3_, int p_i1811_4_, int p_i1811_5_)
@@ -66,6 +73,11 @@
{
this.addSlotToContainer(new Slot(p_i1811_1_, l, 8 + l * 18, 142));
}
+
+ // CraftBukkit start
+ player = (Player) p_i1811_1_.player.getBukkitEntity();
+ tableInventory_CB.player = player; // Cauldron
+ // CraftBukkit end
}
public void addCraftingToCrafters(ICrafting p_75132_1_)
@@ -109,7 +121,7 @@
ItemStack itemstack = p_75130_1_.getStackInSlot(0);
int i;
- if (itemstack != null && itemstack.isItemEnchantable())
+ if (itemstack != null) // CraftBukkit - relax condition
{
this.nameSeed = this.rand.nextLong();
@@ -144,6 +156,23 @@
this.enchantLevels[j] = EnchantmentHelper.calcItemStackEnchantability(this.rand, j, (int)power, itemstack);
}
+ // CraftBukkit start
+ CraftItemStack item = CraftItemStack.asCraftMirror(itemstack);
+ PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(player, this.getBukkitView(), this.worldPointer.getWorld().getBlockAt(this.posX, this.posY, this.posZ), item, this.enchantLevels, i);
+ event.setCancelled(!itemstack.isItemEnchantable());
+ if (this.getBukkitView() != null) this.worldPointer.getServer().getPluginManager().callEvent(event); // Cauldron - allow vanilla mods to byp
+
+ if (event.isCancelled())
+ {
+ for (i = 0; i < 3; ++i)
+ {
+ this.enchantLevels[i] = 0;
+ }
+
+ return;
+ }
+
+ // CraftBukkit end
this.detectAndSendChanges();
}
}
@@ -170,32 +199,64 @@
if (list != null)
{
- p_75140_1_.addExperienceLevel(-this.enchantLevels[p_75140_2_]);
+ // CraftBukkit start
+ Map<org.bukkit.enchantments.Enchantment, Integer> enchants = new java.util.HashMap<org.bukkit.enchantments.Enchantment, Integer>();
- if (flag)
+ for (Object obj : list)
{
- itemstack.func_150996_a(Items.enchanted_book);
+ EnchantmentData instance = (EnchantmentData) obj;
+ enchants.put(org.bukkit.enchantments.Enchantment.getById(instance.enchantmentobj.effectId), instance.enchantmentLevel);
}
- int j = flag && list.size() > 1 ? this.rand.nextInt(list.size()) : -1;
+ CraftItemStack item = CraftItemStack.asCraftMirror(itemstack);
+ EnchantItemEvent event = new EnchantItemEvent((Player) p_75140_1_.getBukkitEntity(), this.getBukkitView(), this.worldPointer.getWorld().getBlockAt(this.posX, this.posY, this.posZ), item, this.enchantLevels[p_75140_2_], enchants, p_75140_2_);
+ if (this.getBukkitView() != null) this.worldPointer.getServer().getPluginManager().callEvent(event); // Cauldron - allow vanilla mods to bypass
+ int level = event.getExpLevelCost();
- for (int k = 0; k < list.size(); ++k)
+ if (event.isCancelled() || (level > p_75140_1_.experienceLevel && !p_75140_1_.capabilities.isCreativeMode) || enchants.isEmpty())
{
- EnchantmentData enchantmentdata = (EnchantmentData)list.get(k);
+ return false;
+ }
- if (!flag || k != j)
+ boolean applied = !flag;
+
+ for (Map.Entry<org.bukkit.enchantments.Enchantment, Integer> entry : event.getEnchantsToAdd().entrySet())
+ {
+ try
{
if (flag)
{
- Items.enchanted_book.addEnchantment(itemstack, enchantmentdata);
+ int enchantId = entry.getKey().getId();
+
+ if (Enchantment.enchantmentsList[enchantId] == null)
+ {
+ continue;
+ }
+
+ EnchantmentData enchantment = new EnchantmentData(enchantId, entry.getValue());
+ Items.enchanted_book.addEnchantment(itemstack, enchantment);
+ applied = true;
+ itemstack.func_150996_a(Items.enchanted_book);
+ break;
}
else
{
- itemstack.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
+ item.addEnchantment(entry.getKey(), entry.getValue());
}
}
+ catch (IllegalArgumentException e)
+ {
+ /* Just swallow invalid enchantments */
+ }
}
+ // Only down level if we've applied the enchantments
+ if (applied)
+ {
+ p_75140_1_.addExperienceLevel(-level);
+ }
+
+ // CraftBukkit end
this.onCraftMatrixChanged(this.tableInventory);
}
}
@@ -225,6 +286,11 @@
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
+ if (!this.checkReachable)
+ {
+ return true; // CraftBukkit
+ }
+
return this.worldPointer.getBlock(this.posX, this.posY, this.posZ) != Blocks.enchanting_table ? false : p_75145_1_.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
}
@@ -283,4 +349,18 @@
return itemstack;
}
+
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView()
+ {
+ if (bukkitEntity != null)
+ {
+ return bukkitEntity;
+ }
+
+ CraftInventoryEnchanting inventory = new CraftInventoryEnchanting(this.tableInventory_CB);
+ bukkitEntity = new CraftInventoryView(this.player, inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}

View File

@ -0,0 +1,57 @@
--- ../src-base/minecraft/net/minecraft/inventory/ContainerFurnace.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerFurnace.java
@@ -8,12 +8,34 @@
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventoryFurnace;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerFurnace extends Container
{
private TileEntityFurnace tileFurnace;
private int lastCookTime;
private int lastBurnTime;
private int lastItemBurnTime;
+
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private InventoryPlayer player;
+
+ public CraftInventoryView getBukkitView()
+ {
+ if (bukkitEntity != null)
+ {
+ return bukkitEntity;
+ }
+
+ CraftInventoryFurnace inventory = new CraftInventoryFurnace(this.tileFurnace);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
private static final String __OBFID = "CL_00001748";
public ContainerFurnace(InventoryPlayer p_i1812_1_, TileEntityFurnace p_i1812_2_)
@@ -22,6 +44,7 @@
this.addSlotToContainer(new Slot(p_i1812_2_, 0, 56, 17));
this.addSlotToContainer(new Slot(p_i1812_2_, 1, 56, 53));
this.addSlotToContainer(new SlotFurnace(p_i1812_1_.player, p_i1812_2_, 2, 116, 35));
+ this.player = p_i1812_1_; // CraftBukkit - save player
int i;
for (i = 0; i < 3; ++i)
@@ -96,6 +119,11 @@
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
+ if (!this.checkReachable)
+ {
+ return true; // CraftBukkit
+ }
+
return this.tileFurnace.isUseableByPlayer(p_75145_1_);
}

View File

@ -0,0 +1,51 @@
--- ../src-base/minecraft/net/minecraft/inventory/ContainerHopper.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerHopper.java
@@ -4,13 +4,36 @@
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerHopper extends Container
{
private final IInventory field_94538_a;
private static final String __OBFID = "CL_00001750";
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private InventoryPlayer player;
+
+ public CraftInventoryView getBukkitView()
+ {
+ if (bukkitEntity != null)
+ {
+ return bukkitEntity;
+ }
+
+ CraftInventory inventory = new CraftInventory(this.field_94538_a);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
+
public ContainerHopper(InventoryPlayer p_i1814_1_, IInventory p_i1814_2_)
{
+ this.player = p_i1814_1_; // CraftBukkit - save player
this.field_94538_a = p_i1814_2_;
p_i1814_2_.openInventory();
byte b0 = 51;
@@ -37,6 +60,11 @@
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
+ if (!this.checkReachable)
+ {
+ return true; // CraftBukkit
+ }
+
return this.field_94538_a.isUseableByPlayer(p_75145_1_);
}

View File

@ -0,0 +1,11 @@
--- ../src-base/minecraft/net/minecraft/inventory/ContainerMerchant.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerMerchant.java
@@ -8,6 +8,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView; // CraftBukkit
+
public class ContainerMerchant extends Container
{
private IMerchant theMerchant;

View File

@ -0,0 +1,82 @@
--- ../src-base/minecraft/net/minecraft/inventory/ContainerPlayer.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerPlayer.java
@@ -12,18 +12,33 @@
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.util.IIcon;
+// CraftBukkit start
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.network.play.server.S2FPacketSetSlot;
+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerPlayer extends Container
{
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2);
public IInventory craftResult = new InventoryCraftResult();
public boolean isLocalWorld;
private final EntityPlayer thePlayer;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private InventoryPlayer player;
+ // CraftBukkit end
private static final String __OBFID = "CL_00001754";
public ContainerPlayer(final InventoryPlayer p_i1819_1_, boolean p_i1819_2_, EntityPlayer p_i1819_3_)
{
this.isLocalWorld = p_i1819_2_;
this.thePlayer = p_i1819_3_;
+ this.craftResult = new InventoryCraftResult(); // CraftBukkit - moved to before InventoryCrafting construction
+ this.craftMatrix = new InventoryCrafting(this, 2, 2, p_i1819_1_.player); // CraftBukkit - pass player
+ this.craftMatrix.resultInventory = this.craftResult; // CraftBukkit - let InventoryCrafting know about its result slot
+ this.player = p_i1819_1_; // CraftBukkit - save player
this.addSlotToContainer(new SlotCrafting(p_i1819_1_.player, this.craftMatrix, this.craftResult, 0, 144, 36));
int i;
int j;
@@ -72,12 +87,24 @@
this.addSlotToContainer(new Slot(p_i1819_1_, i, 8 + i * 18, 142));
}
- this.onCraftMatrixChanged(this.craftMatrix);
+ // this.onCraftMatrixChanged(this.craftMatrix); // CraftBukkit - unneeded since it just sets result slot to empty
}
public void onCraftMatrixChanged(IInventory p_75130_1_)
{
- this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.thePlayer.worldObj));
+ // CraftBukkit start (Note: the following line would cause an error if called during construction)
+ CraftingManager.getInstance().lastCraftView = getBukkitView();
+ ItemStack craftResult = CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.thePlayer.worldObj);
+ this.craftResult.setInventorySlotContents(0, craftResult);
+
+ if (super.crafters.size() < 1)
+ {
+ return;
+ }
+
+ EntityPlayerMP player = (EntityPlayerMP) super.crafters.get(0); // TODO: Is this _always_ correct? Seems like it.
+ player.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(player.openContainer.windowId, 0, craftResult));
+ // CraftBukkit end
}
public void onContainerClosed(EntityPlayer p_75134_1_)
@@ -187,4 +214,18 @@
{
return p_94530_2_.inventory != this.craftResult && super.func_94530_a(p_94530_1_, p_94530_2_);
}
+
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView()
+ {
+ if (bukkitEntity != null)
+ {
+ return bukkitEntity;
+ }
+
+ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftMatrix, this.craftResult);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}

View File

@ -0,0 +1,71 @@
--- ../src-base/minecraft/net/minecraft/inventory/ContainerRepair.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerRepair.java
@@ -17,19 +17,13 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView; // CraftBukkit
+
public class ContainerRepair extends Container
{
private static final Logger logger = LogManager.getLogger();
private IInventory outputSlot = new InventoryCraftResult();
- private IInventory inputSlots = new InventoryBasic("Repair", true, 2)
- {
- private static final String __OBFID = "CL_00001733";
- public void markDirty()
- {
- super.markDirty();
- ContainerRepair.this.onCraftMatrixChanged(this);
- }
- };
+ private IInventory inputSlots = new ContainerRepairInventory(this, "Repair", true, 2);
private World theWorld;
private int field_82861_i;
private int field_82858_j;
@@ -39,9 +33,14 @@
private String repairedItemName;
private final EntityPlayer thePlayer;
private static final String __OBFID = "CL_00001732";
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private InventoryPlayer player;
public ContainerRepair(InventoryPlayer p_i1800_1_, final World p_i1800_2_, final int p_i1800_3_, final int p_i1800_4_, final int p_i1800_5_, EntityPlayer p_i1800_6_)
{
+ this.player = p_i1800_1_;
+ // CraftBukkit end
this.theWorld = p_i1800_2_;
this.field_82861_i = p_i1800_3_;
this.field_82858_j = p_i1800_4_;
@@ -461,6 +460,11 @@
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
+ if (!this.checkReachable)
+ {
+ return true; // CraftBukkit
+ }
+
return this.theWorld.getBlock(this.field_82861_i, this.field_82858_j, this.field_82859_k) != Blocks.anvil ? false : p_75145_1_.getDistanceSq((double)this.field_82861_i + 0.5D, (double)this.field_82858_j + 0.5D, (double)this.field_82859_k + 0.5D) <= 64.0D;
}
@@ -535,4 +539,18 @@
this.updateRepairOutput();
}
+
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView()
+ {
+ if (bukkitEntity != null)
+ {
+ return bukkitEntity;
+ }
+
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryAnvil(this.inputSlots, this.outputSlot);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}

View File

@ -0,0 +1,92 @@
--- ../src-base/minecraft/net/minecraft/inventory/ContainerWorkbench.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerWorkbench.java
@@ -7,18 +7,35 @@
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.world.World;
+// CraftBukkit start
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.network.play.server.S2FPacketSetSlot;
+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerWorkbench extends Container
{
- public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
- public IInventory craftResult = new InventoryCraftResult();
+ public InventoryCrafting craftMatrix; // CraftBukkit - move initialization into constructor
+ public IInventory craftResult; // CraftBukkit - move initialization into constructor
private World worldObj;
private int posX;
private int posY;
private int posZ;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private InventoryPlayer player;
+ // CraftBukkit end
private static final String __OBFID = "CL_00001744";
public ContainerWorkbench(InventoryPlayer p_i1808_1_, World p_i1808_2_, int p_i1808_3_, int p_i1808_4_, int p_i1808_5_)
{
+ // CraftBukkit start - Switched order of IInventory construction and stored player
+ this.craftResult = new InventoryCraftResult();
+ this.craftMatrix = new InventoryCrafting(this, 3, 3, p_i1808_1_.player); // CraftBukkit - pass player
+ this.craftMatrix.resultInventory = this.craftResult;
+ this.player = p_i1808_1_;
+ // CraftBukkit end
this.worldObj = p_i1808_2_;
this.posX = p_i1808_3_;
this.posY = p_i1808_4_;
@@ -53,7 +70,19 @@
public void onCraftMatrixChanged(IInventory p_75130_1_)
{
- this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
+ // CraftBukkit start
+ CraftingManager.getInstance().lastCraftView = getBukkitView();
+ ItemStack craftResult = CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj);
+ this.craftResult.setInventorySlotContents(0, craftResult);
+
+ if (super.crafters.size() < 1)
+ {
+ return;
+ }
+
+ EntityPlayerMP player = (EntityPlayerMP) super.crafters.get(0); // TODO: Is this _always_ correct? Seems like it.
+ player.playerNetServerHandler.sendPacket(new S2FPacketSetSlot(player.openContainer.windowId, 0, craftResult));
+ // CraftBukkit end
}
public void onContainerClosed(EntityPlayer p_75134_1_)
@@ -76,6 +105,11 @@
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
+ if (!this.checkReachable)
+ {
+ return true; // CraftBukkit
+ }
+
return this.worldObj.getBlock(this.posX, this.posY, this.posZ) != Blocks.crafting_table ? false : p_75145_1_.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
}
@@ -141,4 +175,18 @@
{
return p_94530_2_.inventory != this.craftResult && super.func_94530_a(p_94530_1_, p_94530_2_);
}
+
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView()
+ {
+ if (bukkitEntity != null)
+ {
+ return bukkitEntity;
+ }
+
+ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftMatrix, this.craftResult);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}

View File

@ -0,0 +1,32 @@
--- ../src-base/minecraft/net/minecraft/inventory/IInventory.java
+++ ../src-work/minecraft/net/minecraft/inventory/IInventory.java
@@ -3,6 +3,8 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity; // CraftBukkit
+
public interface IInventory
{
int getSizeInventory();
@@ -30,4 +32,20 @@
void closeInventory();
boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_);
+
+ // CraftBukkit start
+ ItemStack[] getContents();
+
+ void onOpen(CraftHumanEntity who);
+
+ void onClose(CraftHumanEntity who);
+
+ java.util.List<org.bukkit.entity.HumanEntity> getViewers();
+
+ org.bukkit.inventory.InventoryHolder getOwner();
+
+ void setMaxStackSize(int size);
+
+ int MAX_STACK = 64;
+ // CraftBukkit end
}

View File

@ -0,0 +1,57 @@
--- ../src-base/minecraft/net/minecraft/inventory/InventoryBasic.java
+++ ../src-work/minecraft/net/minecraft/inventory/InventoryBasic.java
@@ -2,6 +2,11 @@
import java.util.ArrayList;
import java.util.List;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.inventory.InventoryHolder;
+
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -9,7 +14,7 @@
{
private String inventoryTitle;
private int slotsCount;
- private ItemStack[] inventoryContents;
+ protected ItemStack[] inventoryContents; // CraftBukkit - protected
private List field_70480_d;
private boolean field_94051_e;
private static final String __OBFID = "CL_00001514";
@@ -150,4 +155,33 @@
{
return true;
}
+
+ // Cauldron start
+ @Override
+ public ItemStack[] getContents()
+ {
+ return null;
+ }
+
+ @Override
+ public void onOpen(CraftHumanEntity who) {}
+
+ @Override
+ public void onClose(CraftHumanEntity who) {}
+
+ @Override
+ public List<HumanEntity> getViewers()
+ {
+ return null;
+ }
+
+ @Override
+ public InventoryHolder getOwner()
+ {
+ return null;
+ }
+
+ @Override
+ public void setMaxStackSize(int size) {}
+ // Cauldron end
}

View File

@ -0,0 +1,53 @@
--- ../src-base/minecraft/net/minecraft/inventory/InventoryCraftResult.java
+++ ../src-work/minecraft/net/minecraft/inventory/InventoryCraftResult.java
@@ -2,10 +2,41 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
public class InventoryCraftResult implements IInventory
{
private ItemStack[] stackResult = new ItemStack[1];
+
+ // CraftBukkit start
+ private int maxStack = MAX_STACK;
+
+ public ItemStack[] getContents()
+ {
+ return this.stackResult;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner()
+ {
+ return null; // Result slots don't get an owner
+ }
+
+ // Don't need a transaction; the InventoryCrafting keeps track of it for us
+ public void onOpen(CraftHumanEntity who) {}
+ public void onClose(CraftHumanEntity who) {}
+ public java.util.List<HumanEntity> getViewers()
+ {
+ return new java.util.ArrayList<HumanEntity>();
+ }
+
+ public void setMaxStackSize(int size)
+ {
+ maxStack = size;
+ }
+ // CraftBukkit end
private static final String __OBFID = "CL_00001760";
public int getSizeInventory()
@@ -63,7 +94,7 @@
public int getInventoryStackLimit()
{
- return 64;
+ return maxStack; // CraftBukkit
}
public void markDirty() {}

View File

@ -0,0 +1,81 @@
--- ../src-base/minecraft/net/minecraft/inventory/InventoryCrafting.java
+++ ../src-work/minecraft/net/minecraft/inventory/InventoryCrafting.java
@@ -3,11 +3,69 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
+// CraftBukkit start
+import java.util.List;
+import net.minecraft.item.crafting.IRecipe;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.event.inventory.InventoryType;
+// CraftBukkit end
+
public class InventoryCrafting implements IInventory
{
private ItemStack[] stackList;
private int inventoryWidth;
private Container eventHandler;
+ // CraftBukkit start
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ public IRecipe currentRecipe;
+ public IInventory resultInventory;
+ private EntityPlayer owner;
+ private int maxStack = MAX_STACK;
+
+ public ItemStack[] getContents()
+ {
+ return this.stackList;
+ }
+
+ public void onOpen(CraftHumanEntity who)
+ {
+ transaction.add(who);
+ }
+
+ public InventoryType getInvType()
+ {
+ return stackList.length == 4 ? InventoryType.CRAFTING : InventoryType.WORKBENCH;
+ }
+
+ public void onClose(CraftHumanEntity who)
+ {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers()
+ {
+ return transaction;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner()
+ {
+ if (owner == null) return null; // Cauldron
+ return owner.getBukkitEntity();
+ }
+
+ public void setMaxStackSize(int size)
+ {
+ maxStack = size;
+ resultInventory.setMaxStackSize(size);
+ }
+
+ public InventoryCrafting(Container container, int i, int j, EntityPlayer player)
+ {
+ this(container, i, j);
+ this.owner = player;
+ }
+ // CraftBukkit end
private static final String __OBFID = "CL_00001743";
public InventoryCrafting(Container p_i1807_1_, int p_i1807_2_, int p_i1807_3_)
@@ -105,7 +163,7 @@
public int getInventoryStackLimit()
{
- return 64;
+ return maxStack; // CraftBukkit
}
public void markDirty() {}

View File

@ -0,0 +1,64 @@
--- ../src-base/minecraft/net/minecraft/inventory/InventoryEnderChest.java
+++ ../src-work/minecraft/net/minecraft/inventory/InventoryEnderChest.java
@@ -6,9 +6,61 @@
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntityEnderChest;
+// CraftBukkit start
+import java.util.List;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
+
public class InventoryEnderChest extends InventoryBasic
{
private TileEntityEnderChest associatedChest;
+
+ // CraftBukkit start
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ public org.bukkit.entity.Player player;
+ private int maxStack = MAX_STACK;
+
+ public ItemStack[] getContents()
+ {
+ return this.inventoryContents;
+ }
+
+ public void onOpen(CraftHumanEntity who)
+ {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who)
+ {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers()
+ {
+ return transaction;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner()
+ {
+ return this.player;
+ }
+
+ public void setMaxStackSize(int size)
+ {
+ maxStack = size;
+ }
+
+ /**
+ * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
+ * this more of a set than a get?*
+ */
+ public int getInventoryStackLimit()
+ {
+ return maxStack;
+ }
+ // CraftBukkit end
private static final String __OBFID = "CL_00001759";
public InventoryEnderChest()

View File

@ -0,0 +1,76 @@
--- ../src-base/minecraft/net/minecraft/inventory/InventoryLargeChest.java
+++ ../src-work/minecraft/net/minecraft/inventory/InventoryLargeChest.java
@@ -3,11 +3,62 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
+// CraftBukkit start
+import java.util.List;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class InventoryLargeChest implements IInventory
{
private String name;
- private IInventory upperChest;
- private IInventory lowerChest;
+ public IInventory upperChest; // CraftBukkit - private -> public
+ public IInventory lowerChest; // CraftBukkit - private -> public
+ // CraftBukkit start
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+
+ public ItemStack[] getContents()
+ {
+ ItemStack[] result = new ItemStack[this.getSizeInventory()];
+
+ for (int i = 0; i < result.length; i++)
+ {
+ result[i] = this.getStackInSlot(i);
+ }
+
+ return result;
+ }
+
+ public void onOpen(CraftHumanEntity who)
+ {
+ this.upperChest.onOpen(who);
+ this.lowerChest.onOpen(who);
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who)
+ {
+ this.upperChest.onClose(who);
+ this.lowerChest.onClose(who);
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers()
+ {
+ return transaction;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner()
+ {
+ return null; // This method won't be called since CraftInventoryDoubleChest doesn't defer to here
+ }
+
+ public void setMaxStackSize(int size)
+ {
+ this.upperChest.setMaxStackSize(size);
+ this.lowerChest.setMaxStackSize(size);
+ }
+ // CraftBukkit end
private static final String __OBFID = "CL_00001507";
public InventoryLargeChest(String p_i1559_1_, IInventory p_i1559_2_, IInventory p_i1559_3_)
@@ -77,7 +128,7 @@
public int getInventoryStackLimit()
{
- return this.upperChest.getInventoryStackLimit();
+ return Math.min(this.upperChest.getInventoryStackLimit(), this.lowerChest.getInventoryStackLimit()); // CraftBukkit - check both sides
}
public void markDirty()

View File

@ -0,0 +1,65 @@
--- ../src-base/minecraft/net/minecraft/inventory/InventoryMerchant.java
+++ ../src-work/minecraft/net/minecraft/inventory/InventoryMerchant.java
@@ -6,6 +6,12 @@
import net.minecraft.village.MerchantRecipe;
import net.minecraft.village.MerchantRecipeList;
+// CraftBukkit start
+import java.util.List;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class InventoryMerchant implements IInventory
{
private final IMerchant theMerchant;
@@ -13,6 +19,40 @@
private final EntityPlayer thePlayer;
private MerchantRecipe currentRecipe;
private int currentRecipeIndex;
+ // CraftBukkit start
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = MAX_STACK;
+
+ public ItemStack[] getContents()
+ {
+ return this.theInventory;
+ }
+
+ public void onOpen(CraftHumanEntity who)
+ {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who)
+ {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers()
+ {
+ return transaction;
+ }
+
+ public void setMaxStackSize(int i)
+ {
+ maxStack = i;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner()
+ {
+ return thePlayer.getBukkitEntity();
+ }
+ // CraftBukkit end
private static final String __OBFID = "CL_00001756";
public InventoryMerchant(EntityPlayer p_i1820_1_, IMerchant p_i1820_2_)
@@ -124,7 +164,7 @@
public int getInventoryStackLimit()
{
- return 64;
+ return maxStack; // CraftBukkit
}
public boolean isUseableByPlayer(EntityPlayer p_70300_1_)

View File

@ -0,0 +1,11 @@
--- ../src-base/minecraft/net/minecraft/inventory/Slot.java
+++ ../src-work/minecraft/net/minecraft/inventory/Slot.java
@@ -10,7 +10,7 @@
public class Slot
{
- private final int slotIndex;
+ public final int slotIndex; // CraftBukkit - private -> public
public final IInventory inventory;
public int slotNumber;
public int xDisplayPosition;

View File

@ -0,0 +1,36 @@
--- ../src-base/minecraft/net/minecraft/inventory/SlotFurnace.java
+++ ../src-work/minecraft/net/minecraft/inventory/SlotFurnace.java
@@ -9,6 +9,12 @@
import net.minecraft.stats.AchievementList;
import net.minecraft.util.MathHelper;
+// CraftBukkit start
+import net.minecraft.tileentity.TileEntityFurnace;
+import org.bukkit.entity.Player;
+import org.bukkit.event.inventory.FurnaceExtractEvent;
+// CraftBukkit end
+
public class SlotFurnace extends Slot
{
private EntityPlayer thePlayer;
@@ -74,6 +80,20 @@
i = j;
}
+ // Cauldron start - validate inventory before attempting to cast it
+ if (this.inventory instanceof TileEntityFurnace)
+ {
+ // CraftBukkit start
+ Player player = (Player) thePlayer.getBukkitEntity();
+ TileEntityFurnace furnace = ((TileEntityFurnace) this.inventory);
+ org.bukkit.block.Block block = thePlayer.worldObj.getWorld().getBlockAt(furnace.xCoord, furnace.yCoord, furnace.zCoord);
+ FurnaceExtractEvent event = new FurnaceExtractEvent(player, block, org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(p_75208_1_.getItem()), p_75208_1_.stackSize, i);
+ thePlayer.worldObj.getServer().getPluginManager().callEvent(event);
+ i = event.getExpToDrop();
+ // CraftBukkit end
+ }
+ // Cauldron end
+
while (i > 0)
{
j = EntityXPOrb.getXPSplit(i);