Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 303 lines 10 kB view raw
1package net.minecraft.server; 2 3import me.devcody.uberbukkit.math.Vec3i; 4import org.jetbrains.annotations.Nullable; 5 6import java.util.ArrayList; 7import java.util.HashSet; 8import java.util.List; 9import java.util.Set; 10 11public abstract class Container { 12 13 public List d = new ArrayList(); 14 public List e = new ArrayList(); 15 public int windowId = 0; 16 private short a = 0; 17 protected List listeners = new ArrayList(); 18 private Set b = new HashSet(); 19 private Vec3i position = null; 20 21 public Container() { 22 } 23 24 protected void a(Slot slot) { 25 slot.a = this.e.size(); 26 this.e.add(slot); 27 this.d.add(null); 28 } 29 30 public void a(ICrafting icrafting) { 31 if (this.listeners.contains(icrafting)) { 32 throw new IllegalArgumentException("Listener already listening"); 33 } else { 34 this.listeners.add(icrafting); 35 icrafting.a(this, this.b()); 36 this.a(); 37 } 38 } 39 40 public List b() { 41 ArrayList arraylist = new ArrayList(); 42 43 for (int i = 0; i < this.e.size(); ++i) { 44 arraylist.add(((Slot) this.e.get(i)).getItem()); 45 } 46 47 return arraylist; 48 } 49 50 public void a() { 51 for (int i = 0; i < this.e.size(); ++i) { 52 ItemStack itemstack = ((Slot) this.e.get(i)).getItem(); 53 ItemStack itemstack1 = (ItemStack) this.d.get(i); 54 55 if (!ItemStack.equals(itemstack1, itemstack)) { 56 itemstack1 = itemstack == null ? null : itemstack.cloneItemStack(); 57 this.d.set(i, itemstack1); 58 59 for (int j = 0; j < this.listeners.size(); ++j) { 60 ((ICrafting) this.listeners.get(j)).a(this, i, itemstack1); 61 } 62 } 63 } 64 } 65 66 public Slot a(IInventory iinventory, int i) { 67 for (int j = 0; j < this.e.size(); ++j) { 68 Slot slot = (Slot) this.e.get(j); 69 70 if (slot.a(iinventory, i)) { 71 return slot; 72 } 73 } 74 75 return null; 76 } 77 78 public Slot b(int i) { 79 return (Slot) this.e.get(i); 80 } 81 82 public ItemStack a(int i) { 83 Slot slot = (Slot) this.e.get(i); 84 85 return slot != null ? slot.getItem() : null; 86 } 87 88 public ItemStack a(int i, int j, boolean flag, EntityHuman entityhuman) { 89 ItemStack itemstack = null; 90 91 if (j == 0 || j == 1) { 92 InventoryPlayer inventoryplayer = entityhuman.inventory; 93 94 if (i == -999) { 95 if (inventoryplayer.j() != null && i == -999) { 96 if (j == 0) { 97 entityhuman.b(inventoryplayer.j()); 98 inventoryplayer.b((ItemStack) null); 99 } 100 101 if (j == 1) { 102 entityhuman.b(inventoryplayer.j().a(1)); 103 if (inventoryplayer.j().count == 0) { 104 inventoryplayer.b((ItemStack) null); 105 } 106 } 107 } 108 } else { 109 int k; 110 111 if (flag) { 112 ItemStack itemstack1 = this.a(i); 113 114 if (itemstack1 != null) { 115 int l = itemstack1.count; 116 117 itemstack = itemstack1.cloneItemStack(); 118 Slot slot = (Slot) this.e.get(i); 119 120 if (slot != null && slot.getItem() != null) { 121 k = slot.getItem().count; 122 if (k < l) { 123 this.a(i, j, flag, entityhuman); 124 } 125 } 126 } 127 } else { 128 Slot slot1 = (Slot) this.e.get(i); 129 130 if (slot1 != null) { 131 slot1.c(); 132 ItemStack itemstack2 = slot1.getItem(); 133 ItemStack itemstack3 = inventoryplayer.j(); 134 135 if (itemstack2 != null) { 136 itemstack = itemstack2.cloneItemStack(); 137 } 138 139 if (itemstack2 == null) { 140 if (itemstack3 != null && slot1.isAllowed(itemstack3)) { 141 k = j == 0 ? itemstack3.count : 1; 142 if (k > slot1.d()) { 143 k = slot1.d(); 144 } 145 146 slot1.c(itemstack3.a(k)); 147 if (itemstack3.count == 0) { 148 inventoryplayer.b((ItemStack) null); 149 } 150 } 151 } else if (itemstack3 == null) { 152 k = j == 0 ? itemstack2.count : (itemstack2.count + 1) / 2; 153 ItemStack itemstack4 = slot1.a(k); 154 155 inventoryplayer.b(itemstack4); 156 if (itemstack2.count == 0) { 157 slot1.c((ItemStack) null); 158 } 159 160 slot1.a(inventoryplayer.j()); 161 } else if (slot1.isAllowed(itemstack3)) { 162 if (itemstack2.id == itemstack3.id && (!itemstack2.usesData() || itemstack2.getData() == itemstack3.getData())) { 163 k = j == 0 ? itemstack3.count : 1; 164 if (k > slot1.d() - itemstack2.count) { 165 k = slot1.d() - itemstack2.count; 166 } 167 168 if (k > itemstack3.getMaxStackSize() - itemstack2.count) { 169 k = itemstack3.getMaxStackSize() - itemstack2.count; 170 } 171 172 itemstack3.a(k); 173 if (itemstack3.count == 0) { 174 inventoryplayer.b((ItemStack) null); 175 } 176 177 itemstack2.count += k; 178 } else if (itemstack3.count <= slot1.d()) { 179 slot1.c(itemstack3); 180 inventoryplayer.b(itemstack2); 181 } 182 } else if (itemstack2.id == itemstack3.id && itemstack3.getMaxStackSize() > 1 && (!itemstack2.usesData() || itemstack2.getData() == itemstack3.getData())) { 183 k = itemstack2.count; 184 if (k > 0 && k + itemstack3.count <= itemstack3.getMaxStackSize()) { 185 itemstack3.count += k; 186 itemstack2.a(k); 187 if (itemstack2.count == 0) { 188 slot1.c((ItemStack) null); 189 } 190 191 slot1.a(inventoryplayer.j()); 192 } 193 } 194 } 195 } 196 } 197 } 198 199 return itemstack; 200 } 201 202 public void a(EntityHuman entityhuman) { 203 InventoryPlayer inventoryplayer = entityhuman.inventory; 204 205 if (inventoryplayer.j() != null) { 206 entityhuman.b(inventoryplayer.j()); 207 inventoryplayer.b((ItemStack) null); 208 } 209 } 210 211 public void a(IInventory iinventory) { 212 this.a(); 213 } 214 215 public boolean c(EntityHuman entityhuman) { 216 return !this.b.contains(entityhuman); 217 } 218 219 public void a(EntityHuman entityhuman, boolean flag) { 220 if (flag) { 221 this.b.remove(entityhuman); 222 } else { 223 this.b.add(entityhuman); 224 } 225 } 226 227 public abstract boolean b(EntityHuman entityhuman); 228 229 protected void a(ItemStack itemstack, int i, int j, boolean flag) { 230 int k = i; 231 232 if (flag) { 233 k = j - 1; 234 } 235 236 Slot slot; 237 ItemStack itemstack1; 238 239 if (itemstack.isStackable()) { 240 while (itemstack.count > 0 && (!flag && k < j || flag && k >= i)) { 241 slot = (Slot) this.e.get(k); 242 itemstack1 = slot.getItem(); 243 if (itemstack1 != null && itemstack1.id == itemstack.id && (!itemstack.usesData() || itemstack.getData() == itemstack1.getData())) { 244 int l = itemstack1.count + itemstack.count; 245 246 if (l <= itemstack.getMaxStackSize()) { 247 itemstack.count = 0; 248 itemstack1.count = l; 249 slot.c(); 250 } else if (itemstack1.count < itemstack.getMaxStackSize()) { 251 itemstack.count -= itemstack.getMaxStackSize() - itemstack1.count; 252 itemstack1.count = itemstack.getMaxStackSize(); 253 slot.c(); 254 } 255 } 256 257 if (flag) { 258 --k; 259 } else { 260 ++k; 261 } 262 } 263 } 264 265 if (itemstack.count > 0) { 266 if (flag) { 267 k = j - 1; 268 } else { 269 k = i; 270 } 271 272 while (!flag && k < j || flag && k >= i) { 273 slot = (Slot) this.e.get(k); 274 itemstack1 = slot.getItem(); 275 if (itemstack1 == null) { 276 slot.c(itemstack.cloneItemStack()); 277 slot.c(); 278 itemstack.count = 0; 279 break; 280 } 281 282 if (flag) { 283 --k; 284 } else { 285 ++k; 286 } 287 } 288 } 289 } 290 291 public boolean isPositioned() { 292 return (this.position != null); 293 } 294 295 public void setPosition(Vec3i position) { 296 this.position = position; 297 } 298 299 @Nullable 300 public Vec3i getPosition() { 301 return position; 302 } 303}