mirror of
https://github.com/barkeser2002/CatServer.git
synced 2026-09-25 10:06:11 +03:00
179 lines
7.8 KiB
Diff
179 lines
7.8 KiB
Diff
--- ../src-base/minecraft/net/minecraft/inventory/Container.java
|
|
+++ ../src-work/minecraft/net/minecraft/inventory/Container.java
|
|
@@ -2,10 +2,8 @@
|
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Sets;
|
|
-import java.util.List;
|
|
-import java.util.Set;
|
|
-import javax.annotation.Nullable;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
+import net.minecraft.entity.player.EntityPlayerMP;
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
@@ -13,7 +11,21 @@
|
|
import net.minecraft.util.math.MathHelper;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
+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;
|
|
|
|
+import javax.annotation.Nullable;
|
|
+import java.util.HashMap;
|
|
+import java.util.List;
|
|
+import java.util.Map;
|
|
+import java.util.Set;
|
|
+
|
|
+//CraftBukkit start
|
|
+// CraftBukkit end
|
|
+
|
|
public abstract class Container
|
|
{
|
|
public List<ItemStack> inventoryItemStacks = Lists.<ItemStack>newArrayList();
|
|
@@ -26,12 +38,47 @@
|
|
private final Set<Slot> dragSlots = Sets.<Slot>newHashSet();
|
|
protected List<IContainerListener> listeners = Lists.<IContainerListener>newArrayList();
|
|
private final Set<EntityPlayer> playerList = Sets.<EntityPlayer>newHashSet();
|
|
+ public InventoryView bukkitView = null;
|
|
+ private int tickCount = 0; // Spigot
|
|
+ public boolean checkReachable = true;
|
|
|
|
+ public InventoryView getBukkitView(){ return this.bukkitView;}
|
|
+
|
|
+ public void transferTo(Container other, org.bukkit.craftbukkit.entity.CraftHumanEntity player) {
|
|
+ InventoryView source = this.getBukkitView(), destination = other.getBukkitView();
|
|
+ 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
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
protected Slot addSlotToContainer(Slot slotIn)
|
|
{
|
|
slotIn.slotNumber = this.inventorySlots.size();
|
|
this.inventorySlots.add(slotIn);
|
|
- this.inventoryItemStacks.add((ItemStack)null);
|
|
+ this.inventoryItemStacks.add(null);
|
|
return slotIn;
|
|
}
|
|
|
|
@@ -74,7 +121,7 @@
|
|
ItemStack itemstack = ((Slot)this.inventorySlots.get(i)).getStack();
|
|
ItemStack itemstack1 = (ItemStack)this.inventoryItemStacks.get(i);
|
|
|
|
- if (!ItemStack.areItemStacksEqual(itemstack1, itemstack))
|
|
+ if (!ItemStack.fastMatches(itemstack1, itemstack) || (tickCount % org.spigotmc.SpigotConfig.itemDirtyTicks == 0 && !ItemStack.fastMatches(itemstack1, itemstack))) // Spigot
|
|
{
|
|
itemstack1 = itemstack == null ? null : itemstack.copy();
|
|
this.inventoryItemStacks.set(i, itemstack1);
|
|
@@ -85,6 +132,7 @@
|
|
}
|
|
}
|
|
}
|
|
+ tickCount++; // Spigot
|
|
}
|
|
|
|
public boolean enchantItem(EntityPlayer playerIn, int id)
|
|
@@ -110,6 +158,7 @@
|
|
|
|
public Slot getSlot(int slotId)
|
|
{
|
|
+ if(slotId < 0 || slotId > this.inventorySlots.size()) return null;
|
|
return (Slot)this.inventorySlots.get(slotId);
|
|
}
|
|
|
|
@@ -168,6 +217,7 @@
|
|
{
|
|
ItemStack itemstack3 = inventoryplayer.getItemStack().copy();
|
|
int j = inventoryplayer.getItemStack().stackSize;
|
|
+ Map<Integer, ItemStack> draggedSlots = new HashMap<Integer, ItemStack>(); // CraftBukkit - Store slots from drag in map (raw slot id -> new stack)
|
|
|
|
for (Slot slot1 : this.dragSlots)
|
|
{
|
|
@@ -188,18 +238,54 @@
|
|
}
|
|
|
|
j -= itemstack1.stackSize - k;
|
|
- slot1.putStack(itemstack1);
|
|
+ //slot1.putStack(itemstack1);
|
|
+ draggedSlots.put(slot1.slotNumber, itemstack1); // CraftBukkit - Put in map instead of setting
|
|
}
|
|
}
|
|
|
|
- itemstack3.stackSize = j;
|
|
+ //itemstack3.stackSize = j;
|
|
+ // CraftBukkit start - InventoryDragEvent
|
|
+ InventoryView view = getBukkitView();
|
|
+ org.bukkit.inventory.ItemStack newcursor = CraftItemStack.asCraftMirror(itemstack3);
|
|
+ newcursor.setAmount(j);
|
|
+ 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()){
|
|
+ eventmap.put(ditem.getKey(), CraftItemStack.asBukkitCopy(ditem.getValue()));
|
|
+ }
|
|
+
|
|
+ // 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.dragMode == j, eventmap); // Should be dragButton
|
|
+ player.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)
|
|
{
|
|
- itemstack3 = null;
|
|
+ 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);
|
|
+ }
|
|
|
|
- inventoryplayer.setItemStack(itemstack3);
|
|
+ if (needsUpdate && player instanceof EntityPlayerMP)
|
|
+ {
|
|
+ ((EntityPlayerMP) player).sendContainerToPlayer(this);
|
|
+ }
|
|
}
|
|
|
|
this.resetDrag();
|