1
0
forked from xjboss/KCauldronX

Implement Bukkit's inventory for modded inventories, fix #257

This commit is contained in:
Sergey Shatunov 2016-02-01 04:54:40 +07:00
parent e3bc245aa4
commit 6c2be10dc9
4 changed files with 165 additions and 27 deletions

View File

@ -1818,7 +1818,7 @@
finally finally
{ {
@@ -1135,19 +2442,18 @@ @@ -1135,19 +2442,18 @@
{
if (itemstack.getItem() == Items.written_book && itemstack1.getItem() == Items.writable_book) if (itemstack.getItem() == Items.written_book && itemstack1.getItem() == Items.writable_book)
{ {
- itemstack1.setTagInfo("author", new NBTTagString(this.playerEntity.getCommandSenderName())); - itemstack1.setTagInfo("author", new NBTTagString(this.playerEntity.getCommandSenderName()));

View File

@ -1,6 +1,6 @@
--- ../src-base/minecraft/net/minecraft/network/rcon/RConThreadClient.java --- ../src-base/minecraft/net/minecraft/network/rcon/RConThreadClient.java
+++ ../src-work/minecraft/net/minecraft/network/rcon/RConThreadClient.java +++ ../src-work/minecraft/net/minecraft/network/rcon/RConThreadClient.java
@@ -41,20 +41,21 @@ @@ -41,9 +41,9 @@
public void run() public void run()
{ {
@ -10,24 +10,22 @@
- try - try
+ while (true) + while (true)
{ {
- if (!this.running) if (!this.running)
+ if (!this.running || clientSocket == null)
{ {
break; @@ -53,6 +53,12 @@
}
BufferedInputStream bufferedinputstream = new BufferedInputStream(this.clientSocket.getInputStream()); BufferedInputStream bufferedinputstream = new BufferedInputStream(this.clientSocket.getInputStream());
int i = bufferedinputstream.read(this.buffer, 0, 1460); int i = bufferedinputstream.read(this.buffer, 0, 1460);
-
- if (10 > i)
+
+ if (i < 10)
{
+ this.running = false; // Cauldron
return;
}
@@ -110,26 +111,23 @@ + if (i < 10)
+ {
+ this.running = false; // Cauldron
+ return;
+ }
+
if (10 <= i)
{
byte b0 = 0;
@@ -110,26 +116,23 @@
} }
} }
} }
@ -57,7 +55,7 @@
} }
private void sendResponse(int p_72654_1_, int p_72654_2_, String p_72654_3_) throws IOException private void sendResponse(int p_72654_1_, int p_72654_2_, String p_72654_3_) throws IOException
@@ -167,6 +165,7 @@ @@ -167,6 +170,7 @@
private void closeSocket() private void closeSocket()
{ {

View File

@ -149,14 +149,14 @@
return false; return false;
} }
} }
@@ -427,11 +526,70 @@ @@ -427,11 +526,66 @@
if (itemstack != null && func_145890_b(p_145892_1_, itemstack, p_145892_2_, p_145892_3_)) if (itemstack != null && func_145890_b(p_145892_1_, itemstack, p_145892_2_, p_145892_3_))
{ {
ItemStack itemstack1 = itemstack.copy(); ItemStack itemstack1 = itemstack.copy();
- ItemStack itemstack2 = func_145889_a(p_145892_0_, p_145892_1_.decrStackSize(p_145892_2_, 1), -1); - ItemStack itemstack2 = func_145889_a(p_145892_0_, p_145892_1_.decrStackSize(p_145892_2_, 1), -1);
+ // CraftBukkit start - Call event on collection of items from inventories into the hopper + // CraftBukkit start - Call event on collection of items from inventories into the hopper
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(p_145892_1_.decrStackSize(p_145892_2_, 1)); + CraftItemStack oitemstack = CraftItemStack.asCraftMirror(p_145892_1_.decrStackSize(p_145892_2_, 1));
+ Inventory sourceInventory; + Inventory sourceInventory = null;
+ // Have to special case large chests as they work oddly + // Have to special case large chests as they work oddly
+ if (p_145892_1_ instanceof InventoryLargeChest) + if (p_145892_1_ instanceof InventoryLargeChest)
@ -172,15 +172,11 @@
+ { + {
+ sourceInventory = p_145892_1_.getOwner().getInventory(); + sourceInventory = p_145892_1_.getOwner().getInventory();
+ } + }
+ else
+ {
+ // TODO: create a mod inventory for passing to the event, instead of null
+ sourceInventory = null;
+ }
+ } + }
+ catch (AbstractMethodError e) + catch (AbstractMethodError e)
+ { + {} finally {
+ sourceInventory = null; + if (sourceInventory == null)
+ sourceInventory = new kcauldron.CraftInventoryWrapper(p_145892_1_);
+ } + }
+ // Cauldron end + // Cauldron end
+ } + }
@ -222,7 +218,7 @@
return true; return true;
} }
@@ -451,6 +609,20 @@ @@ -451,6 +605,20 @@
} }
else else
{ {

View File

@ -0,0 +1,144 @@
package kcauldron;
import java.util.Collections;
import java.util.List;
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class CraftInventoryWrapper extends CraftInventory {
public CraftInventoryWrapper(IInventory inventory) {
super(new Inv(inventory));
((Inv) super.inventory).wrapper = this;
}
private static final class Inv implements IInventory, InventoryHolder {
CraftInventoryWrapper wrapper;
IInventory inventory;
Inv(IInventory inventory) {
this.inventory = inventory;
}
@Override
public Inventory getInventory() {
return wrapper;
}
@Override
public int getSizeInventory() {
return inventory.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int p_70301_1_) {
return inventory.getStackInSlot(p_70301_1_);
}
@Override
public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) {
return inventory.decrStackSize(p_70298_1_, p_70298_2_);
}
@Override
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
return inventory.getStackInSlotOnClosing(p_70304_1_);
}
@Override
public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) {
inventory.setInventorySlotContents(p_70299_1_, p_70299_2_);
}
@Override
public String getInventoryName() {
return inventory.getInventoryName();
}
@Override
public boolean hasCustomInventoryName() {
return inventory.hasCustomInventoryName();
}
@Override
public int getInventoryStackLimit() {
return inventory.getInventoryStackLimit();
}
@Override
public void markDirty() {
inventory.markDirty();
}
@Override
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
return inventory.isUseableByPlayer(p_70300_1_);
}
@Override
public void openInventory() {
inventory.openInventory();
}
@Override
public void closeInventory() {
inventory.closeInventory();
}
@Override
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
return inventory.isItemValidForSlot(p_94041_1_, p_94041_2_);
}
@Override
public ItemStack[] getContents() {
return inventory.getContents();
}
@Override
public void onOpen(CraftHumanEntity who) {
try {
inventory.onOpen(who);
} catch (AbstractMethodError ignored) {
}
}
@Override
public void onClose(CraftHumanEntity who) {
try {
inventory.onClose(who);
} catch (AbstractMethodError ignored) {
}
}
@Override
public List<HumanEntity> getViewers() {
try {
return inventory.getViewers();
} catch (AbstractMethodError ignored) {
return Collections.emptyList();
}
}
@Override
public InventoryHolder getOwner() {
return this;
}
@Override
public void setMaxStackSize(int size) {
try {
inventory.setMaxStackSize(size);
} catch (AbstractMethodError ignored) {
}
}
}
}