diff options
author | Erik Broes <erikbroes@grum.nl> | 2011-01-09 18:27:46 +0100 |
---|---|---|
committer | Erik Broes <erikbroes@grum.nl> | 2011-01-09 18:28:46 +0100 |
commit | e8a565e6cfd2bc326a1207e17165916f7a830497 (patch) | |
tree | 561bfaf2b3e83ed0c43b632816de64cf5f5415fb /src/main | |
parent | b72dad0a61d11c01c498a7e58b3e4a7389533488 (diff) | |
download | craftbukkit-e8a565e6cfd2bc326a1207e17165916f7a830497.tar craftbukkit-e8a565e6cfd2bc326a1207e17165916f7a830497.tar.gz craftbukkit-e8a565e6cfd2bc326a1207e17165916f7a830497.tar.lz craftbukkit-e8a565e6cfd2bc326a1207e17165916f7a830497.tar.xz craftbukkit-e8a565e6cfd2bc326a1207e17165916f7a830497.zip |
Added getContents() to IInventory and implemented it.
Implemented Inventory and PlayerInventory and updated StorageMinecart and Slot.
Added getMaxStackSize to CraftItemStack.
Diffstat (limited to 'src/main')
15 files changed, 1557 insertions, 35 deletions
diff --git a/src/main/java/net/minecraft/server/EntityPlayerMP.java b/src/main/java/net/minecraft/server/EntityPlayerMP.java new file mode 100644 index 00000000..751081c2 --- /dev/null +++ b/src/main/java/net/minecraft/server/EntityPlayerMP.java @@ -0,0 +1,291 @@ +package net.minecraft.server; + + +import java.util.*; + + +public class EntityPlayerMP extends EntityPlayer + implements ICrafting { + + public NetServerHandler a; + public MinecraftServer b; + public ItemInWorldManager c; + public double d; + public double e; + public List f; + public Set aj; + public double ak; + public boolean al; + private int bE; + private int bF; + private int bG[] = { + -1, -1, -1, -1, -1 + }; + private int bH; + public boolean am; + + public EntityPlayerMP(MinecraftServer minecraftserver, World world, String s1, ItemInWorldManager iteminworldmanager) { + super(world); + f = new LinkedList(); + aj = new HashSet(); + al = false; + bE = 0xfa0a1f01; + bF = 60; + bH = 0; + int i = world.m; + int j = world.o; + int l = world.n; + + if (!world.q.e) { + i += W.nextInt(20) - 10; + l = world.e(i, j); + j += W.nextInt(20) - 10; + } + c((double) i + 0.5D, l, (double) j + 0.5D, 0.0F, 0.0F); + b = minecraftserver; + S = 0.0F; + iteminworldmanager.a = this; + aw = s1; + c = iteminworldmanager; + H = 0.0F; + } + + public void k() { + // CraftBukkit: Downcast to make it work. + ap.a((ICrafting)this); + } + + public int[] E() { + return bG; + } + + public void b_() { + bF--; + ap.a(); + for (int i = 0; i < 5; i++) { + int j = a(i); + + if (j != bG[i]) { + b.k.a(this, new Packet5PlayerInventory(g, i, j)); + bG[i] = j; + } + } + + } + + public int a(int i) { + if (i == 0) { + return c(an.e()); + } else { + return c(an.b[i - 1]); + } + } + + private int c(ItemStack itemstack) { + if (itemstack == null) { + return -1; + } else { + return itemstack.c; + } + } + + public void f(Entity entity) { + an.h(); + } + + public boolean a(Entity entity, int i) { + if (bF > 0) { + return false; + } + if (!b.n) { + if (entity instanceof EntityPlayer) { + return false; + } + if (entity instanceof EntityArrow) { + EntityArrow entityarrow = (EntityArrow) entity; + + if (entityarrow.b instanceof EntityPlayer) { + return false; + } + } + } + return super.a(entity, i); + } + + public void c(int i) { + super.c(i); + } + + public void F() { + super.b_(); + ChunkCoordIntPair chunkcoordintpair = null; + double d1 = 0.0D; + + for (int i = 0; i < f.size(); i++) { + ChunkCoordIntPair chunkcoordintpair1 = (ChunkCoordIntPair) f.get(i); + double d2 = chunkcoordintpair1.a(this); + + if (i == 0 || d2 < d1) { + chunkcoordintpair = chunkcoordintpair1; + d1 = chunkcoordintpair1.a(this); + } + } + + if (chunkcoordintpair != null) { + boolean flag = false; + + if (d1 < 1024D) { + flag = true; + } + if (a.b() < 2) { + flag = true; + } + if (flag) { + f.remove(chunkcoordintpair); + a.b(new Packet51MapChunk(chunkcoordintpair.a * 16, 0, chunkcoordintpair.b * 16, 16, 128, 16, b.e)); + List list = b.e.d(chunkcoordintpair.a * 16, 0, chunkcoordintpair.b * 16, chunkcoordintpair.a * 16 + 16, 128, chunkcoordintpair.b * 16 + 16); + + for (int j = 0; j < list.size(); j++) { + a((TileEntity) list.get(j)); + } + + } + } + if (ba != bE) { + a.b(new Packet8(ba)); + bE = ba; + } + } + + private void a(TileEntity tileentity) { + if (tileentity != null) { + Packet packet = tileentity.f(); + + if (packet != null) { + a.b(packet); + } + } + } + + public void G() { + s = t = u = 0.0D; + bB = false; + super.G(); + } + + public void c(Entity entity, int i) { + if (!entity.G) { + if (entity instanceof EntityItem) { + b.k.a(entity, new Packet22Collect(entity.g, g)); + } + if (entity instanceof EntityArrow) { + b.k.a(entity, new Packet22Collect(entity.g, g)); + } + } + super.c(entity, i); + ap.a(); + } + + public void H() { + if (!au) { + av = -1; + au = true; + b.k.a(this, new Packet18ArmAnimation(this, 1)); + } + } + + public float s() { + return 1.62F; + } + + public void e(Entity entity) { + super.e(entity); + a.b(new Packet39(this, k)); + a.a(p, q, r, v, w); + } + + protected void a(double d1, boolean flag) {} + + public void b(double d1, boolean flag) { + super.a(d1, flag); + } + + public boolean p() { + return al; + } + + private void R() { + bH = bH % 100 + 1; + } + + public void a(int i, int j, int l) { + R(); + a.b(new Packet100(bH, 1, "Crafting", 9)); + ap = new CraftingInventoryWorkbenchCB(an, this.l, i, j, l); + ap.f = bH; + // CraftBukkit: Downcast to make it work. + ap.a((ICrafting)this); + } + + public void a(IInventory iinventory) { + R(); + a.b(new Packet100(bH, 0, iinventory.b(), iinventory.a())); + ap = new CraftingInventoryChestCB(an, iinventory); + ap.f = bH; + // CraftBukkit: Downcast to make it work. + ap.a((ICrafting)this); + } + + public void a(TileEntityFurnace tileentityfurnace) { + R(); + a.b(new Packet100(bH, 2, tileentityfurnace.b(), tileentityfurnace.a())); + ap = new CraftingInventoryFurnaceCB(an, tileentityfurnace); + ap.f = bH; + // CraftBukkit: Downcast to make it work. + ap.a((ICrafting)this); + } + + public void a(CraftingInventoryCB craftinginventorycb, int i, ItemStack itemstack) { + if (craftinginventorycb.a(i) instanceof SlotCrafting) { + return; + } + if (am) { + return; + } else { + a.b(new Packet103(craftinginventorycb.f, i, itemstack)); + return; + } + } + + public void a(CraftingInventoryCB craftinginventorycb, List list) { + a.b(new Packet104(craftinginventorycb.f, list)); + a.b(new Packet103(-1, -1, an.i())); + } + + public void a(CraftingInventoryCB craftinginventorycb, int i, int j) { + a.b(new Packet105(craftinginventorycb.f, i, j)); + } + + public void a(ItemStack itemstack) {} + + public void I() { + a.b(new Packet101(ap.f)); + K(); + } + + public void J() { + if (am) { + return; + } else { + a.b(new Packet103(-1, -1, an.i())); + return; + } + } + + public void K() { + // CraftBukkit: Downcast to make it work. + ap.a((ICrafting)this); + ap = ao; + } +} + diff --git a/src/main/java/net/minecraft/server/IInventory.java b/src/main/java/net/minecraft/server/IInventory.java new file mode 100644 index 00000000..c573e819 --- /dev/null +++ b/src/main/java/net/minecraft/server/IInventory.java @@ -0,0 +1,24 @@ +package net.minecraft.server;
+
+
+public interface IInventory {
+
+ public abstract int a();
+
+ public abstract ItemStack a(int i);
+
+ public abstract ItemStack a(int i, int j);
+
+ public abstract void a(int i, ItemStack itemstack);
+
+ public abstract String b();
+
+ public abstract int c();
+
+ public abstract void d();
+
+ public abstract boolean a_(EntityPlayer entityplayer);
+
+ public abstract ItemStack[] getContents(); // CraftBukkit
+}
+
diff --git a/src/main/java/net/minecraft/server/InventoryCraftResult.java b/src/main/java/net/minecraft/server/InventoryCraftResult.java new file mode 100644 index 00000000..8d7f8d6d --- /dev/null +++ b/src/main/java/net/minecraft/server/InventoryCraftResult.java @@ -0,0 +1,54 @@ +package net.minecraft.server;
+
+
+public class InventoryCraftResult
+ implements IInventory {
+
+ private ItemStack a[];
+
+ // CraftBukkit
+ public ItemStack[] getContents() {
+ return a;
+ }
+
+ public InventoryCraftResult() {
+ a = new ItemStack[1];
+ }
+
+ public int a() {
+ return 1;
+ }
+
+ public ItemStack a(int i) {
+ return a[i];
+ }
+
+ public String b() {
+ return "Result";
+ }
+
+ public ItemStack a(int i, int j) {
+ if (a[i] != null) {
+ ItemStack itemstack = a[i];
+
+ a[i] = null;
+ return itemstack;
+ } else {
+ return null;
+ }
+ }
+
+ public void a(int i, ItemStack itemstack) {
+ a[i] = itemstack;
+ }
+
+ public int c() {
+ return 64;
+ }
+
+ public void d() {}
+
+ public boolean a_(EntityPlayer entityplayer) {
+ return true;
+ }
+}
diff --git a/src/main/java/net/minecraft/server/InventoryCrafting.java b/src/main/java/net/minecraft/server/InventoryCrafting.java new file mode 100644 index 00000000..90502d47 --- /dev/null +++ b/src/main/java/net/minecraft/server/InventoryCrafting.java @@ -0,0 +1,69 @@ +package net.minecraft.server;
+
+
+public class InventoryCrafting
+ implements IInventory {
+
+ private ItemStack a[];
+ private int b;
+ private CraftingInventoryCB c;
+
+ //CraftBukkit
+ public ItemStack[] getContents() {
+ return a;
+ }
+
+ public InventoryCrafting(CraftingInventoryCB craftinginventorycb, int i, int j) {
+ b = i * j;
+ a = new ItemStack[b];
+ c = craftinginventorycb;
+ }
+
+ public int a() {
+ return b;
+ }
+
+ public ItemStack a(int i) {
+ return a[i];
+ }
+
+ public String b() {
+ return "Crafting";
+ }
+
+ public ItemStack a(int i, int j) {
+ if (a[i] != null) {
+ if (a[i].a <= j) {
+ ItemStack itemstack = a[i];
+
+ a[i] = null;
+ c.a(this);
+ return itemstack;
+ }
+ ItemStack itemstack1 = a[i].a(j);
+
+ if (a[i].a == 0) {
+ a[i] = null;
+ }
+ c.a(this);
+ return itemstack1;
+ } else {
+ return null;
+ }
+ }
+
+ public void a(int i, ItemStack itemstack) {
+ a[i] = itemstack;
+ c.a(this);
+ }
+
+ public int c() {
+ return 64;
+ }
+
+ public void d() {}
+
+ public boolean a_(EntityPlayer entityplayer) {
+ return true;
+ }
+}
diff --git a/src/main/java/net/minecraft/server/InventoryLargeChest.java b/src/main/java/net/minecraft/server/InventoryLargeChest.java new file mode 100644 index 00000000..e79d74b5 --- /dev/null +++ b/src/main/java/net/minecraft/server/InventoryLargeChest.java @@ -0,0 +1,71 @@ +package net.minecraft.server;
+
+
+public class InventoryLargeChest
+ implements IInventory {
+
+ private String a;
+ private IInventory b;
+ private IInventory c;
+
+ // CraftBukkit start
+ public ItemStack[] getContents() {
+ ItemStack[] result = new ItemStack[a()];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = a(i);
+ }
+ return result;
+ }
+ // CraftBukkit end
+
+ public InventoryLargeChest(String s, IInventory iinventory, IInventory iinventory1) {
+ a = s;
+ b = iinventory;
+ c = iinventory1;
+ }
+
+ public int a() {
+ return b.a() + c.a();
+ }
+
+ public String b() {
+ return a;
+ }
+
+ public ItemStack a(int i) {
+ if (i >= b.a()) {
+ return c.a(i - b.a());
+ } else {
+ return b.a(i);
+ }
+ }
+
+ public ItemStack a(int i, int j) {
+ if (i >= b.a()) {
+ return c.a(i - b.a(), j);
+ } else {
+ return b.a(i, j);
+ }
+ }
+
+ public void a(int i, ItemStack itemstack) {
+ if (i >= b.a()) {
+ c.a(i - b.a(), itemstack);
+ } else {
+ b.a(i, itemstack);
+ }
+ }
+
+ public int c() {
+ return b.c();
+ }
+
+ public void d() {
+ b.d();
+ c.d();
+ }
+
+ public boolean a_(EntityPlayer entityplayer) {
+ return b.a_(entityplayer) && c.a_(entityplayer);
+ }
+}
diff --git a/src/main/java/net/minecraft/server/InventoryPlayer.java b/src/main/java/net/minecraft/server/InventoryPlayer.java new file mode 100644 index 00000000..186fa6e9 --- /dev/null +++ b/src/main/java/net/minecraft/server/InventoryPlayer.java @@ -0,0 +1,345 @@ +package net.minecraft.server;
+
+
+public class InventoryPlayer
+ implements IInventory {
+
+ public ItemStack a[];
+ public ItemStack b[];
+ public int c;
+ private EntityPlayer e;
+ private ItemStack f;
+ public boolean d;
+
+ // CraftBukket start
+ public ItemStack[] getContents() {
+ return a;
+ }
+
+ public ItemStack[] getArmorContents() {
+ return b;
+ }
+ // CraftBukket end
+
+ public InventoryPlayer(EntityPlayer entityplayer) {
+ a = new ItemStack[36];
+ b = new ItemStack[4];
+ c = 0;
+ d = false;
+ e = entityplayer;
+ }
+
+ public ItemStack e() {
+ return a[c];
+ }
+
+ private int d(int k) {
+ for (int l = 0; l < a.length; l++) {
+ if (a[l] != null && a[l].c == k) {
+ return l;
+ }
+ }
+
+ return -1;
+ }
+
+ private int e(int k) {
+ for (int l = 0; l < a.length; l++) {
+ if (a[l] != null && a[l].c == k && a[l].a < a[l].b() && a[l].a < c()) {
+ return l;
+ }
+ }
+
+ return -1;
+ }
+
+ private int j() {
+ for (int k = 0; k < a.length; k++) {
+ if (a[k] == null) {
+ return k;
+ }
+ }
+
+ return -1;
+ }
+
+ private int b(int k, int l) {
+ int i1 = e(k);
+
+ if (i1 < 0) {
+ i1 = j();
+ }
+ if (i1 < 0) {
+ return l;
+ }
+ if (a[i1] == null) {
+ a[i1] = new ItemStack(k, 0);
+ }
+ int j1 = l;
+
+ if (j1 > a[i1].b() - a[i1].a) {
+ j1 = a[i1].b() - a[i1].a;
+ }
+ if (j1 > c() - a[i1].a) {
+ j1 = c() - a[i1].a;
+ }
+ if (j1 == 0) {
+ return l;
+ } else {
+ l -= j1;
+ a[i1].a += j1;
+ a[i1].b = 5;
+ return l;
+ }
+ }
+
+ public void f() {
+ for (int k = 0; k < a.length; k++) {
+ if (a[k] != null && a[k].b > 0) {
+ a[k].b--;
+ }
+ }
+
+ }
+
+ public boolean b(int k) {
+ int l = d(k);
+
+ if (l < 0) {
+ return false;
+ }
+ if (--a[l].a <= 0) {
+ a[l] = null;
+ }
+ return true;
+ }
+
+ public boolean a(ItemStack itemstack) {
+ if (itemstack.d == 0) {
+ itemstack.a = b(itemstack.c, itemstack.a);
+ if (itemstack.a == 0) {
+ return true;
+ }
+ }
+ int k = j();
+
+ if (k >= 0) {
+ a[k] = itemstack;
+ a[k].b = 5;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public ItemStack a(int k, int l) {
+ ItemStack aitemstack[] = a;
+
+ if (k >= a.length) {
+ aitemstack = b;
+ k -= a.length;
+ }
+ if (aitemstack[k] != null) {
+ if (aitemstack[k].a <= l) {
+ ItemStack itemstack = aitemstack[k];
+
+ aitemstack[k] = null;
+ return itemstack;
+ }
+ ItemStack itemstack1 = aitemstack[k].a(l);
+
+ if (aitemstack[k].a == 0) {
+ aitemstack[k] = null;
+ }
+ return itemstack1;
+ } else {
+ return null;
+ }
+ }
+
+ public void a(int k, ItemStack itemstack) {
+ ItemStack aitemstack[] = a;
+
+ if (k >= aitemstack.length) {
+ k -= aitemstack.length;
+ aitemstack = b;
+ }
+ aitemstack[k] = itemstack;
+ }
+
+ public float a(Block block) {
+ float f1 = 1.0F;
+
+ if (a[c] != null) {
+ f1 *= a[c].a(block);
+ }
+ return f1;
+ }
+
+ public NBTTagList a(NBTTagList nbttaglist) {
+ for (int k = 0; k < a.length; k++) {
+ if (a[k] != null) {
+ NBTTagCompound nbttagcompound = new NBTTagCompound();
+
+ nbttagcompound.a("Slot", (byte) k);
+ a[k].a(nbttagcompound);
+ nbttaglist.a(nbttagcompound);
+ }
+ }
+
+ for (int l = 0; l < b.length; l++) {
+ if (b[l] != null) {
+ NBTTagCompound nbttagcompound1 = new NBTTagCompound();
+
+ nbttagcompound1.a("Slot", (byte) (l + 100));
+ b[l].a(nbttagcompound1);
+ nbttaglist.a(nbttagcompound1);
+ }
+ }
+
+ return nbttaglist;
+ }
+
+ public void b(NBTTagList nbttaglist) {
+ a = new ItemStack[36];
+ b = new ItemStack[4];
+ for (int k = 0; k < nbttaglist.b(); k++) {
+ NBTTagCompound nbttagcompound = (NBTTagCompound) nbttaglist.a(k);
+ int l = nbttagcompound.b("Slot") & 0xff;
+ ItemStack itemstack = new ItemStack(nbttagcompound);
+
+ if (itemstack.a() == null) {
+ continue;
+ }
+ if (l >= 0 && l < a.length) {
+ a[l] = itemstack;
+ }
+ if (l >= 100 && l < b.length + 100) {
+ b[l - 100] = itemstack;
+ }
+ }
+
+ }
+
+ public int a() {
+ return a.length + 4;
+ }
+
+ public ItemStack a(int k) {
+ ItemStack aitemstack[] = a;
+
+ if (k >= aitemstack.length) {
+ k -= aitemstack.length;
+ aitemstack = b;
+ }
+ return aitemstack[k];
+ }
+
+ public String b() {
+ return "Inventory";
+ }
+
+ public int c() {
+ return 64;
+ }
+
+ public int a(Entity entity) {
+ ItemStack itemstack = a(c);
+
+ if (itemstack != null) {
+ return itemstack.a(entity);
+ } else {
+ return 1;
+ }
+ }
+
+ public boolean b(Block block) {
+ if (block.bs != Material.d && block.bs != Material.e && block.bs != Material.t && block.bs != Material.s) {
+ return true;
+ }
+ ItemStack itemstack = a(c);
+
+ if (itemstack != null) {
+ return itemstack.b(block);
+ } else {
+ return false;
+ }
+ }
+
+ public int g() {
+ int k = 0;
+ int l = 0;
+ int i1 = 0;
+
+ for (int j1 = 0; j1 < b.length; j1++) {
+ if (b[j1] != null && (b[j1].a() instanceof ItemArmor)) {
+ int k1 = b[j1].c();
+ int l1 = b[j1].d;
+ int i2 = k1 - l1;
+
+ l += i2;
+ i1 += k1;
+ int j2 = ((ItemArmor) b[j1].a()).bc;
+
+ k += j2;
+ }
+ }
+
+ if (i1 == 0) {
+ return 0;
+ } else {
+ return ((k - 1) * l) / i1 + 1;
+ }
+ }
+
+ public void c(int k) {
+ for (int l = 0; l < b.length; l++) {
+ if (b[l] == null || !(b[l].a() instanceof ItemArmor)) {
+ continue;
+ }
+ b[l].b(k);
+ if (b[l].a == 0) {
+ b[l].a(e);
+ b[l] = null;
+ }
+ }
+
+ }
+
+ public void h() {
+ for (int k = 0; k < a.length; k++) {
+ if (a[k] != null) {
+ e.a(a[k], true);
+ a[k] = null;
+ }
+ }
+
+ for (int l = 0; l < b.length; l++) {
+ if (b[l] != null) {
+ e.a(b[l], true);
+ b[l] = null;
+ }
+ }
+
+ }
+
+ public void d() {
+ d = true;
+ }
+
+ public void b(ItemStack itemstack) {
+ f = itemstack;
+ e.a(itemstack);
+ }
+
+ public ItemStack i() {
+ return f;
+ }
+
+ public boolean a_(EntityPlayer entityplayer) {
+ if (e.G) {
+ return false;
+ }
+ return entityplayer.b((Entity)e) <= 64D; // CraftBukkit: downcast to Entity
+ }
+}
diff --git a/src/main/java/net/minecraft/server/Slot.java b/src/main/java/net/minecraft/server/Slot.java new file mode 100644 index 00000000..63234dd4 --- /dev/null +++ b/src/main/java/net/minecraft/server/Slot.java @@ -0,0 +1,51 @@ +package net.minecraft.server;
+
+
+public class Slot {
+
+ public final int a; // CraftBukkit: private -> public
+ public final IInventory b; // CraftBukkit: private -> public
+ public int c;
+ public int d;
+ public int e;
+
+ public Slot(IInventory iinventory, int i, int j, int k) {
+ b = iinventory;
+ a = i;
+ d = j;
+ e = k;
+ }
+
+ public void b() {
+ d();
+ }
+
+ public boolean a(ItemStack itemstack) {
+ return true;
+ }
+
+ public ItemStack c() {
+ return b.a(a);
+ }
+
+ public void b(ItemStack itemstack) {
+ b.a(a, itemstack);
+ d();
+ }
+
+ public void d() {
+ b.d();
+ }
+
+ public int a() {
+ return b.c();
+ }
+
+ public ItemStack a(int i) {
+ return b.a(a, i);
+ }
+
+ public boolean a(IInventory iinventory, int i) {
+ return iinventory == b && i == a;
+ }
+}
diff --git a/src/main/java/net/minecraft/server/TileEntityChest.java b/src/main/java/net/minecraft/server/TileEntityChest.java new file mode 100644 index 00000000..cc5e7f81 --- /dev/null +++ b/src/main/java/net/minecraft/server/TileEntityChest.java @@ -0,0 +1,103 @@ +package net.minecraft.server;
+
+
+public class TileEntityChest extends TileEntity
+ implements IInventory {
+
+ private ItemStack e[];
+
+ // CraftBukkit start
+ public ItemStack[] getContents() {
+ return e;
+ }
+ // CraftBukkit end
+
+ public TileEntityChest() {
+ e = new ItemStack[36];
+ }
+
+ public int a() {
+ return 27;
+ }
+
+ public ItemStack a(int i) {
+ return e[i];
+ }
+
+ public ItemStack a(int i, int j) {
+ if (e[i] != null) {
+ if (e[i].a <= j) {
+ ItemStack itemstack = e[i];
+
+ e[i] = null;
+ d();
+ return itemstack;
+ }
+ ItemStack itemstack1 = e[i].a(j);
+
+ if (e[i].a == 0) {
+ e[i] = null;
+ }
+ d();
+ return itemstack1;
+ } else {
+ return null;
+ }
+ }
+
+ public void a(int i, ItemStack itemstack) {
+ e[i] = itemstack;
+ if (itemstack != null && itemstack.a > c()) {
+ itemstack.a = c();
+ }
+ d();
+ }
+
+ public String b() {
+ return "Chest";
+ }
+
+ public void a(NBTTagCompound nbttagcompound) {
+ super.a(nbttagcompound);
+ NBTTagList nbttaglist = nbttagcompound.k("Items");
+
+ e = new ItemStack[a()];
+ for (int i = 0; i < nbttaglist.b(); i++) {
+ NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(i);
+ int j = nbttagcompound1.b("Slot") & 0xff;
+
+ if (j >= 0 && j < e.length) {
+ e[j] = new ItemStack(nbttagcompound1);
+ }
+ }
+
+ }
+
+ public void b(NBTTagCompound nbttagcompound) {
+ super.b(nbttagcompound);
+ NBTTagList nbttaglist = new NBTTagList();
+
+ for (int i = 0; i < e.length; i++) {
+ if (e[i] != null) {
+ NBTTagCompound nbttagcompound1 = new NBTTagCompound();
+
+ nbttagcompound1.a("Slot", (byte) i);
+ e[i].a(nbttagcompound1);
+ nbttaglist.a(nbttagcompound1);
+ }
+ }
+
+ nbttagcompound.a("Items", nbttaglist);
+ }
+
+ public int c() {
+ return 64;
+ }
+
+ public boolean a_(EntityPlayer entityplayer) {
+ if (a.l(b, c, d) != this) {
+ return false;
+ }
+ return entityplayer.d((double) b + 0.5D, (double) c + 0.5D, (double) d + 0.5D) <= 64D;
+ }
+}
diff --git a/src/main/java/net/minecraft/server/TileEntityFurnace.java b/src/main/java/net/minecraft/server/TileEntityFurnace.java new file mode 100644 index 00000000..ff266f7c --- /dev/null +++ b/src/main/java/net/minecraft/server/TileEntityFurnace.java @@ -0,0 +1,240 @@ +package net.minecraft.server;
+
+
+public class TileEntityFurnace extends TileEntity
+ implements IInventory {
+
+ private ItemStack h[];
+ public int e;
+ public int f;
+ public int g;
+
+ // CraftBukkit start
+ public ItemStack[] getContents() {
+ return h;
+ }
+ // CraftBukkit end
+
+ public TileEntityFurnace() {
+ h = new ItemStack[3];
+ e = 0;
+ f = 0;
+ g = 0;
+ }
+
+ public int a() {
+ return h.length;
+ }
+
+ public ItemStack a(int j) {
+ return h[j];
+ }
+
+ public ItemStack a(int j, int k) {
+ if (h[j] != null) {
+ if (h[j].a <= k) {
+ ItemStack itemstack = h[j];
+
+ h[j] = null;
+ return itemstack;
+ }
+ ItemStack itemstack1 = h[j].a(k);
+
+ if (h[j].a == 0) {
+ h[j] = null;
+ }
+ return itemstack1;
+ } else {
+ return null;
+ }
+ }
+
+ public void a(int j, ItemStack itemstack) {
+ h[j] = itemstack;
+ if (itemstack != null && itemstack.a > c()) {
+ itemstack.a = c();
+ }
+ }
+
+ public String b() {
+ return "Furnace";
+ }
+
+ public void a(NBTTagCompound nbttagcompound) {
+ super.a(nbttagcompound);
+ NBTTagList nbttaglist = nbttagcompound.k("Items");
+
+ h = new ItemStack[a()];
+ for (int j = 0; j < nbttaglist.b(); j++) {
+ NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(j);
+ byte byte0 = nbttagcompound1.b("Slot");
+
+ if (byte0 >= 0 && byte0 < h.length) {
+ h[byte0] = new ItemStack(nbttagcompound1);
+ }
+ }
+
+ e = nbttagcompound.c("BurnTime");
+ g = nbttagcompound.c("CookTime");
+ f = a(h[1]);
+ }
+
+ public void b(NBTTagCompound nbttagcompound) {
+ super.b(nbttagcompound);
+ nbttagcompound.a("BurnTime", (short) e);
+ nbttagcompound.a("CookTime", (short) g);
+ NBTTagList nbttaglist = new NBTTagList();
+
+ for (int j = 0; j < h.length; j++) {
+ if (h[j] != null) {
+ NBTTagCompound nbttagcompound1 = new NBTTagCompound();
+
+ nbttagcompound1.a("Slot", (byte) j);
+ h[j].a(nbttagcompound1);
+ nbttaglist.a(nbttagcompound1);
+ }
+ }
+
+ nbttagcompound.a("Items", nbttaglist);
+ }
+
+ public int c() {
+ return 64;
+ }
+
+ public boolean g() {
+ return e > 0;
+ }
+
+ public void e() {
+ boolean flag = e > 0;
+ boolean flag1 = false;
+
+ if (e > 0) {
+ e--;
+ }
+ if (!a.z) {
+ if (e == 0 && i()) {
+ f = e = a(h[1]);
+ if (e > 0) {
+ flag1 = true;
+ if (h[1] != null) {
+ h[1].a--;
+ if (h[1].a == 0) {
+ h[1] = null;
+ }
+ }
+ }
+ }
+ if (g() && i()) {
+ g++;
+ if (g == 200) {
+ g = 0;
+ h();
+ flag1 = true;
+ }
+ } else {
+ g = 0;
+ }
+ if (flag != (e > 0)) {
+ flag1 = true;
+ BlockFurnace.a(e > 0, a, b, c, d);
+ }
+ }
+ if (flag1) {
+ d();
+ }
+ }
+
+ private boolean i() {
+ if (h[0] == null) {
+ return false;
+ }
+ int j = b(h[0].a().aW);
+
+ if (j < 0) {
+ return false;
+ }
+ if (h[2] == null) {
+ return true;
+ }
+ if (h[2].c != j) {
+ return false;
+ }
+ if (h[2].a < c() && h[2].a < h[2].b()) {
+ return true;
+ }
+ return h[2].a < Item.c[j].b();
+ }
+
+ public void h() {
+ if (!i()) {
+ return;
+ }
+ int j = b(h[0].a().aW);
+
+ if (h[2] == null) {
+ h[2] = new ItemStack(j, 1);
+ } else if (h[2].c == j) {
+ h[2].a++;
+ }
+ h[0].a--;
+ if (h[0].a <= 0) {
+ h[0] = null;
+ }
+ }
+
+ private int b(int j) {
+ if (j == Block.H.bh) {
+ return Item.m.aW;
+ }
+ if (j == Block.G.bh) {
+ return Item.n.aW;
+ }
+ if (j == Block.aw.bh) {
+ return Item.l.aW;
+ }
+ if (j == Block.E.bh) {
+ return Block.M.bh;
+ }
+ if (j == Item.ao.aW) {
+ return Item.ap.aW;
+ }
+ if (j == Item.aS.aW) {
+ return Item.aT.aW;
+ }
+ if (j == Block.w.bh) {
+ return Block.t.bh;
+ }
+ if (j == Item.aG.aW) {
+ return Item.aF.aW;
+ } else {
+ return -1;
+ }
+ }
+
+ private int a(ItemStack itemstack) {
+ if (itemstack == null) {
+ return 0;
+ }
+ int j = itemstack.a().aW;
+
+ if (j < 256 && Block.m[j].bs == Material.c) {
+ return 300;
+ }
+ if (j == Item.B.aW) {
+ return 100;
+ }
+ if (j == Item.k.aW) {
+ return 1600;
+ }
+ return j != Item.aw.aW ? 0 : 20000;
+ }
+
+ public boolean a_(EntityPlayer entityplayer) {
+ if (a.l(b, c, d) != this) {
+ return false;
+ }
+ return entityplayer.d((double) b + 0.5D, (double) c + 0.5D, (double) d + 0.5D) <= 64D;
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/CraftHumanEntity.java index b03f0967..91437f4f 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftHumanEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftHumanEntity.java @@ -2,22 +2,18 @@ package org.bukkit.craftbukkit; import net.minecraft.server.EntityPlayer; -import net.minecraft.server.InventoryPlayer; import org.bukkit.HumanEntity; import org.bukkit.ItemStack; +import org.bukkit.PlayerInventory; public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { private EntityPlayer entity; + private CraftInventoryPlayer inventory; public CraftHumanEntity(final CraftServer server, final EntityPlayer entity) { super(server, entity); this.entity = entity; - } - - public ItemStack getSelectedItem() { - // TODO: Implement inventories - final InventoryPlayer inventory = entity.an; - return new ItemStack(inventory.e().c, inventory.e().a); + this.inventory = new CraftInventoryPlayer( entity.an ); } public String getName() { @@ -34,6 +30,14 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { this.entity = entity; } + public PlayerInventory getInventory() { + return inventory; + } + + public ItemStack getItemInHand() { + return getInventory().getItemInHand(); + } + @Override public String toString() { return "CraftHumanEntity{" + "id=" + getEntityID() + "name=" + getName() + '}'; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/CraftInventory.java new file mode 100644 index 00000000..c74ecea3 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftInventory.java @@ -0,0 +1,195 @@ +package org.bukkit.craftbukkit;
+
+import java.util.HashMap;
+
+import net.minecraft.server.IInventory;
+
+import org.bukkit.ItemStack;
+import org.bukkit.Material;
+
+public class CraftInventory implements org.bukkit.Inventory {
+ protected IInventory inventory;
+
+ public CraftInventory(IInventory inventory) {
+ this.inventory = inventory;
+ }
+
+ public IInventory getInventory() {
+ return inventory;
+ }
+
+ public int getSize() {
+ return getInventory().a();
+ }
+
+ public String getName() {
+ return getInventory().b();
+ }
+
+ public ItemStack getItem(int index) {
+ return new CraftItemStack(getInventory().a(index));
+ }
+
+ public ItemStack[] getContents() {
+ ItemStack[] items = new ItemStack[getSize()];
+ net.minecraft.server.ItemStack[] mcItems = getInventory().getContents();
+
+ for (int i = 0; i < mcItems.length; i++ ) {
+ items[i] = new CraftItemStack(mcItems[i]);
+ }
+
+ return items;
+ }
+
+ public void setItem(int index, ItemStack item) {
+ getInventory().a( index, new net.minecraft.server.ItemStack( item.getTypeID(), item.getAmount()));
+ }
+
+ public boolean contains(int materialId) {
+ for (ItemStack item: getContents()) {
+ if (item.getTypeID() == materialId) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean contains(Material material) {
+ return contains(material.getID());
+ }
+
+ public boolean contains(ItemStack item) {
+ for (ItemStack i: getContents()) {
+ if (item.equals(i)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public HashMap<Integer, ItemStack> all(int materialId) {
+ HashMap<Integer, ItemStack> slots = new HashMap<Integer, ItemStack>();
+
+ ItemStack[] inventory = getContents();
+ for (int i = 0; i < inventory.length; i++) {
+ ItemStack item = inventory[i];
+ if (item.getTypeID() == materialId) {
+ slots.put( i, item );
+ }
+ }
+ return slots;
+ }
+
+ public HashMap<Integer, ItemStack> all(Material material) {
+ return all(material.getID());
+ }
+
+ public HashMap<Integer, ItemStack> all(ItemStack item) {
+ HashMap<Integer, ItemStack> slots = new HashMap<Integer, ItemStack>();
+
+ ItemStack[] inventory = getContents();
+ for (int i = 0; i < inventory.length; i++) {
+ if (item.equals(inventory[i])) {
+ slots.put( i, item );
+ }
+ }
+ return slots;
+ }
+
+ public int first(int materialId) {
+ ItemStack[] inventory = getContents();
+ for (int i = 0; i < inventory.length; i++) {
+ if (inventory[i].getTypeID() == materialId) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public int first(Material material) {
+ return first(material.getID());
+ }
+
+ public int first(ItemStack item) {
+ ItemStack[] inventory = getContents();
+ for (int i = 0; i < inventory.length; i++) {
+ if (item.equals(inventory[i])) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public int firstEmpty() {
+ return first(Material.Air);
+ }
+
+ public int firstPartial(int materialId) {
+ ItemStack[] inventory = getContents();
+ for (int i = 0; i < inventory.length; i++) {
+ if (inventory[i].getAmount() <= inventory[i].getMaxStackSize()) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public int firstPartial(Material material) {
+ return firstPartial(material.getID());
+ }
+
+ public int firstPartial(ItemStack item) {
+ return firstPartial(item.getTypeID());
+ }
+
+ public HashMap<Integer,ItemStack> addItem(ItemStack... items) {
+ HashMap<Integer,ItemStack> leftover = new HashMap<Integer,ItemStack>();
+
+ /* TODO: some optimization
+ * - Create a 'firstPartial' with a 'fromIndex'
+ * - Record the lastPartial per Material
+ * - Cache firstEmpty result
+ */
+
+ for (int i = 0; i < items.length; i++) {
+ ItemStack item = items[i];
+ while (true) {
+ // Do we already have a stack of it?
+ int firstPartial = firstPartial( item.getTypeID() );
+
+ // Drat! no partial stack
+ if (firstPartial == -1) {
+ // Find a free spot!
+ int firstFree = firstEmpty();
+
+ if (firstFree == -1) {
+ // No space at all!
+ leftover.put(i, item);
+ } else {
+ // Just store it
+ setItem( firstFree, item );
+ }
+ break;
+ }
+
+ // So, apparently it might only partially fit, well lets do just that
+ ItemStack partialItem = getItem(firstPartial);
+
+ int amount = item.getAmount();
+ int partialAmount = partialItem.getAmount();
+ int maxAmount = partialItem.getMaxStackSize();
+
+ // Check if it fully fits
+ if (amount + partialAmount <= maxAmount) {
+ partialItem.setAmount( amount + partialAmount );
+ break;
+ }
+
+ // It fits partially
+ partialItem.setAmount( maxAmount );
+ item.setAmount( amount + partialAmount - maxAmount );
+ }
+ }
+ return leftover;
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftInventoryPlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftInventoryPlayer.java new file mode 100644 index 00000000..3ee882fc --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftInventoryPlayer.java @@ -0,0 +1,67 @@ +package org.bukkit.craftbukkit;
+
+import java.util.ArrayList;
+
+import net.minecraft.server.InventoryPlayer;
+
+import org.bukkit.ItemStack;
+import org.bukkit.PlayerInventory;
+
+public class CraftInventoryPlayer extends CraftInventory implements PlayerInventory {
+ public CraftInventoryPlayer(net.minecraft.server.InventoryPlayer inventory) {
+ super(inventory);
+ }
+
+ public InventoryPlayer getInventory() {
+ return (InventoryPlayer) inventory;
+ }
+
+ public ArrayList<ItemStack> getArmorContents() {
+ ArrayList<ItemStack> items = new ArrayList<ItemStack>();
+ for (net.minecraft.server.ItemStack item : getInventory().getArmorContents()) {
+ ItemStack i = null;
+ if (item != null) {
+ i = new CraftItemStack(item);
+ }
+ items.add(i);
+ }
+
+ return items;
+ }
+
+ public ItemStack getItemInHand() {
+ return new CraftItemStack( getInventory().e() );
+ }
+
+ public ItemStack getHelmet() {
+ return getItem( getSize() - 4 );
+ }
+
+ public ItemStack getChestplate() {
+ return getItem( getSize() - 3 );
+ }
+
+ public ItemStack getLeggings() {
+ return getItem( getSize() - 2 );
+ }
+
+ public ItemStack getBoots() {
+ return getItem( getSize() - 1 );
+ }
+
+ public void setHelmet(ItemStack helmet) {
+ setItem( getSize() - 4, helmet );
+ }
+
+ public void setChestplate(ItemStack chestplate) {
+ setItem( getSize() - 3, chestplate );
+ }
+
+ public void setLeggings(ItemStack leggings) {
+ setItem( getSize() - 2, leggings );
+ }
+
+ public void setBoots(ItemStack boots) {
+ setItem( getSize() - 1, boots );
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java index 3527721b..d1571ac4 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java @@ -12,7 +12,7 @@ public class CraftItemStack extends ItemStack { } /* - * Unsure if we have to syn before each of these calls the values in 'item' + * Unsure if we have to sync before each of these calls the values in 'item' * are all public. */ @@ -82,4 +82,8 @@ public class CraftItemStack extends ItemStack { } } + @Override + public int getMaxStackSize() { + return item.a().b(); + } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftSlot.java b/src/main/java/org/bukkit/craftbukkit/CraftSlot.java new file mode 100644 index 00000000..32b12b7a --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftSlot.java @@ -0,0 +1,25 @@ +package org.bukkit.craftbukkit;
+
+import org.bukkit.Inventory;
+import org.bukkit.ItemStack;
+import net.minecraft.server.Slot;
+
+public class CraftSlot implements org.bukkit.Slot {
+ private final Slot slot;
+
+ public CraftSlot(Slot slot) {
+ this.slot = slot;
+ }
+
+ public Inventory getInventory() {
+ return new CraftInventory( slot.b );
+ }
+
+ public int getIndex() {
+ return slot.a;
+ }
+
+ public ItemStack getItem() {
+ return new CraftItemStack( slot.c() );
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java b/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java index 7567529e..3063482d 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java @@ -1,11 +1,8 @@ package org.bukkit.craftbukkit; -import java.util.ArrayList; -import java.util.List; - import net.minecraft.server.EntityMinecart; -import org.bukkit.ItemStack; +import org.bukkit.Inventory; import org.bukkit.StorageMinecart; /** @@ -14,32 +11,14 @@ import org.bukkit.StorageMinecart; * @author sk89q */ public class CraftStorageMinecart extends CraftMinecart implements StorageMinecart { + private CraftInventory inventory; + public CraftStorageMinecart(CraftServer server, EntityMinecart entity) { super(server, entity); + inventory = new CraftInventory( entity ); } - public int getSize() { - return minecart.c(); - } - - public String getName() { - return minecart.b(); - } - - public ItemStack getItem(int index) { - return new CraftItemStack(minecart.a(index)); - } - - public List<ItemStack> getContents() { - ArrayList<ItemStack> items = new ArrayList<ItemStack>(); - for (net.minecraft.server.ItemStack item: minecart.getContents()) { - ItemStack i = null; - if (item != null) { - i = new CraftItemStack( item ); - } - items.add(i); - } - - return items; + public Inventory getInventory() { + return inventory; } } |