Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 130 lines 3.5 kB view raw
1package net.minecraft.server; 2 3import java.util.Random; 4 5public class TileEntityDispenser extends TileEntity implements IInventory { 6 7 private ItemStack[] items = new ItemStack[9]; 8 private Random b = new Random(); 9 10 // CraftBukkit start 11 public ItemStack[] getContents() { 12 return this.items; 13 } 14 // CraftBukkit end 15 16 public TileEntityDispenser() { 17 } 18 19 public int getSize() { 20 return 9; 21 } 22 23 public ItemStack getItem(int i) { 24 return this.items[i]; 25 } 26 27 public ItemStack splitStack(int i, int j) { 28 if (this.items[i] != null) { 29 ItemStack itemstack; 30 31 if (this.items[i].count <= j) { 32 itemstack = this.items[i]; 33 this.items[i] = null; 34 this.update(); 35 return itemstack; 36 } else { 37 itemstack = this.items[i].a(j); 38 if (this.items[i].count == 0) { 39 this.items[i] = null; 40 } 41 42 this.update(); 43 return itemstack; 44 } 45 } else { 46 return null; 47 } 48 } 49 50 // CraftBukkit - change signature 51 public int findDispenseSlot() { 52 int i = -1; 53 int j = 1; 54 55 for (int k = 0; k < this.items.length; ++k) { 56 if (this.items[k] != null && this.b.nextInt(j++) == 0) { 57 if (this.items[k].count == 0) continue; // CraftBukkit 58 i = k; 59 } 60 } 61 62 // CraftBukkit start 63 return i; 64 } 65 66 public ItemStack b() { 67 int i = this.findDispenseSlot(); 68 // CraftBukkit end 69 70 if (i >= 0) { 71 return this.splitStack(i, 1); 72 } else { 73 return null; 74 } 75 } 76 77 public void setItem(int i, ItemStack itemstack) { 78 this.items[i] = itemstack; 79 if (itemstack != null && itemstack.count > this.getMaxStackSize()) { 80 itemstack.count = this.getMaxStackSize(); 81 } 82 83 this.update(); 84 } 85 86 public String getName() { 87 return "Trap"; 88 } 89 90 public void a(NBTTagCompound nbttagcompound) { 91 super.a(nbttagcompound); 92 NBTTagList nbttaglist = nbttagcompound.l("Items"); 93 94 this.items = new ItemStack[this.getSize()]; 95 96 for (int i = 0; i < nbttaglist.c(); ++i) { 97 NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(i); 98 int j = nbttagcompound1.c("Slot") & 255; 99 100 if (j >= 0 && j < this.items.length) { 101 this.items[j] = new ItemStack(nbttagcompound1); 102 } 103 } 104 } 105 106 public void b(NBTTagCompound nbttagcompound) { 107 super.b(nbttagcompound); 108 NBTTagList nbttaglist = new NBTTagList(); 109 110 for (int i = 0; i < this.items.length; ++i) { 111 if (this.items[i] != null) { 112 NBTTagCompound nbttagcompound1 = new NBTTagCompound(); 113 114 nbttagcompound1.a("Slot", (byte) i); 115 this.items[i].a(nbttagcompound1); 116 nbttaglist.a((NBTBase) nbttagcompound1); 117 } 118 } 119 120 nbttagcompound.a("Items", (NBTBase) nbttaglist); 121 } 122 123 public int getMaxStackSize() { 124 return 64; 125 } 126 127 public boolean a_(EntityHuman entityhuman) { 128 return this.world.getTileEntity(this.x, this.y, this.z) != this ? false : entityhuman.e((double) this.x + 0.5D, (double) this.y + 0.5D, (double) this.z + 0.5D) <= 64.0D; 129 } 130}