13
0
geforkt von Mirrors/Paper

Fixed blocks not keeping data on placement

Dieser Commit ist enthalten in:
Dinnerbone 2011-01-14 19:44:11 +00:00
Ursprung fe4d5db0e0
Commit 202e44ab1a
5 geänderte Dateien mit 568 neuen und 568 gelöschten Zeilen

Datei anzeigen

@ -87,8 +87,8 @@ public class ItemBlock extends Item {
if (this.a == 79) { if (this.a == 79) {
world.a(i, j, k, 20); world.a(i, j, k, 20);
} }
world.a(i, j, k, oldMaterial); world.b(i, j, k, oldMaterial);
world.c(i, j, k, oldData); world.d(i, j, k, oldData);
} else { } else {
world.g(i, j, k); world.g(i, j, k);
world.h(i, j, k, this.a); world.h(i, j, k, this.a);

Datei anzeigen

@ -1,50 +1,50 @@
package net.minecraft.server; package net.minecraft.server;
public class Slot { public class Slot {
public final int a; // CraftBukkit: private -> public public final int a; // CraftBukkit: private -> public
public final IInventory b; // CraftBukkit: private -> public public final IInventory b; // CraftBukkit: private -> public
public int c; public int c;
public int d; public int d;
public int e; public int e;
public Slot(IInventory iinventory, int i, int j, int k) { public Slot(IInventory iinventory, int i, int j, int k) {
b = iinventory; b = iinventory;
a = i; a = i;
d = j; d = j;
e = k; e = k;
} }
public void b() { public void b() {
d(); d();
} }
public boolean a(ItemStack itemstack) { public boolean a(ItemStack itemstack) {
return true; return true;
} }
public ItemStack c() { public ItemStack c() {
return b.a(a); return b.a(a);
} }
public void b(ItemStack itemstack) { public void b(ItemStack itemstack) {
b.a(a, itemstack); b.a(a, itemstack);
d(); d();
} }
public void d() { public void d() {
b.d(); b.d();
} }
public int a() { public int a() {
return b.c(); return b.c();
} }
public ItemStack a(int i) { public ItemStack a(int i) {
return b.b(a, i); return b.b(a, i);
} }
public boolean a(IInventory iinventory, int i) { public boolean a(IInventory iinventory, int i) {
return iinventory == b && i == a; return iinventory == b && i == a;
} }
} }

Datei anzeigen

@ -1,100 +1,100 @@
package net.minecraft.server; package net.minecraft.server;
public class TileEntityChest extends TileEntity implements IInventory { public class TileEntityChest extends TileEntity implements IInventory {
private ItemStack e[]; private ItemStack e[];
// CraftBukkit start // CraftBukkit start
public ItemStack[] getContents() { public ItemStack[] getContents() {
return e; return e;
} }
// CraftBukkit end // CraftBukkit end
public TileEntityChest() { public TileEntityChest() {
e = new ItemStack[36]; e = new ItemStack[36];
} }
public int h_() { public int h_() {
return 27; return 27;
} }
public ItemStack a(int i) { public ItemStack a(int i) {
return e[i]; return e[i];
} }
public ItemStack b(int i, int j) { public ItemStack b(int i, int j) {
if (e[i] != null) { if (e[i] != null) {
if (e[i].a <= j) { if (e[i].a <= j) {
ItemStack itemstack = e[i]; ItemStack itemstack = e[i];
e[i] = null; e[i] = null;
d(); d();
return itemstack; return itemstack;
} }
ItemStack itemstack1 = e[i].a(j); ItemStack itemstack1 = e[i].a(j);
if (e[i].a == 0) { if (e[i].a == 0) {
e[i] = null; e[i] = null;
} }
d(); d();
return itemstack1; return itemstack1;
} else { } else {
return null; return null;
} }
} }
public void a(int i, ItemStack itemstack) { public void a(int i, ItemStack itemstack) {
e[i] = itemstack; e[i] = itemstack;
if (itemstack != null && itemstack.a > c()) { if (itemstack != null && itemstack.a > c()) {
itemstack.a = c(); itemstack.a = c();
} }
d(); d();
} }
public String b() { public String b() {
return "Chest"; return "Chest";
} }
public void a(NBTTagCompound nbttagcompound) { public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound); super.a(nbttagcompound);
NBTTagList nbttaglist = nbttagcompound.k("Items"); NBTTagList nbttaglist = nbttagcompound.k("Items");
e = new ItemStack[h_()]; e = new ItemStack[h_()];
for (int i = 0; i < nbttaglist.b(); i++) { for (int i = 0; i < nbttaglist.b(); i++) {
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(i); NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(i);
int j = nbttagcompound1.b("Slot") & 0xff; int j = nbttagcompound1.b("Slot") & 0xff;
if (j >= 0 && j < e.length) { if (j >= 0 && j < e.length) {
e[j] = new ItemStack(nbttagcompound1); e[j] = new ItemStack(nbttagcompound1);
} }
} }
} }
public void b(NBTTagCompound nbttagcompound) { public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound); super.b(nbttagcompound);
NBTTagList nbttaglist = new NBTTagList(); NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < e.length; i++) { for (int i = 0; i < e.length; i++) {
if (e[i] != null) { if (e[i] != null) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound(); NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.a("Slot", (byte) i); nbttagcompound1.a("Slot", (byte) i);
e[i].a(nbttagcompound1); e[i].a(nbttagcompound1);
nbttaglist.a(((NBTBase) (nbttagcompound1))); nbttaglist.a(((NBTBase) (nbttagcompound1)));
} }
} }
nbttagcompound.a("Items", ((NBTBase) (nbttaglist))); nbttagcompound.a("Items", ((NBTBase) (nbttaglist)));
} }
public int c() { public int c() {
return 64; return 64;
} }
public boolean a_(EntityPlayer entityplayer) { public boolean a_(EntityPlayer entityplayer) {
if (a.m(b, c, d) != this) { if (a.m(b, c, d) != this) {
return false; return false;
} }
return entityplayer.d((double) b + 0.5D, (double) c + 0.5D, (double) d + 0.5D) <= 64D; return entityplayer.d((double) b + 0.5D, (double) c + 0.5D, (double) d + 0.5D) <= 64D;
} }
} }

Datei anzeigen

@ -1,209 +1,209 @@
package net.minecraft.server; package net.minecraft.server;
public class TileEntityFurnace extends TileEntity implements IInventory { public class TileEntityFurnace extends TileEntity implements IInventory {
private ItemStack h[]; private ItemStack h[];
public int e; public int e;
public int f; public int f;
public int g; public int g;
// CraftBukkit start // CraftBukkit start
public ItemStack[] getContents() { public ItemStack[] getContents() {
return h; return h;
} }
// CraftBukkit end // CraftBukkit end
public TileEntityFurnace() { public TileEntityFurnace() {
h = new ItemStack[3]; h = new ItemStack[3];
e = 0; e = 0;
f = 0; f = 0;
g = 0; g = 0;
} }
public int h_() { public int h_() {
return h.length; return h.length;
} }
public ItemStack a(int j) { public ItemStack a(int j) {
return h[j]; return h[j];
} }
public ItemStack b(int j, int k) { public ItemStack b(int j, int k) {
if (h[j] != null) { if (h[j] != null) {
if (h[j].a <= k) { if (h[j].a <= k) {
ItemStack itemstack = h[j]; ItemStack itemstack = h[j];
h[j] = null; h[j] = null;
return itemstack; return itemstack;
} }
ItemStack itemstack1 = h[j].a(k); ItemStack itemstack1 = h[j].a(k);
if (h[j].a == 0) { if (h[j].a == 0) {
h[j] = null; h[j] = null;
} }
return itemstack1; return itemstack1;
} else { } else {
return null; return null;
} }
} }
public void a(int j, ItemStack itemstack) { public void a(int j, ItemStack itemstack) {
h[j] = itemstack; h[j] = itemstack;
if (itemstack != null && itemstack.a > c()) { if (itemstack != null && itemstack.a > c()) {
itemstack.a = c(); itemstack.a = c();
} }
} }
public String b() { public String b() {
return "Furnace"; return "Furnace";
} }
public void a(NBTTagCompound nbttagcompound) { public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound); super.a(nbttagcompound);
NBTTagList nbttaglist = nbttagcompound.k("Items"); NBTTagList nbttaglist = nbttagcompound.k("Items");
h = new ItemStack[h_()]; h = new ItemStack[h_()];
for (int j = 0; j < nbttaglist.b(); j++) { for (int j = 0; j < nbttaglist.b(); j++) {
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(j); NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(j);
byte byte0 = nbttagcompound1.b("Slot"); byte byte0 = nbttagcompound1.b("Slot");
if (byte0 >= 0 && byte0 < h.length) { if (byte0 >= 0 && byte0 < h.length) {
h[byte0] = new ItemStack(nbttagcompound1); h[byte0] = new ItemStack(nbttagcompound1);
} }
} }
e = ((int) (nbttagcompound.c("BurnTime"))); e = ((int) (nbttagcompound.c("BurnTime")));
g = ((int) (nbttagcompound.c("CookTime"))); g = ((int) (nbttagcompound.c("CookTime")));
f = a(h[1]); f = a(h[1]);
} }
public void b(NBTTagCompound nbttagcompound) { public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound); super.b(nbttagcompound);
nbttagcompound.a("BurnTime", (short) e); nbttagcompound.a("BurnTime", (short) e);
nbttagcompound.a("CookTime", (short) g); nbttagcompound.a("CookTime", (short) g);
NBTTagList nbttaglist = new NBTTagList(); NBTTagList nbttaglist = new NBTTagList();
for (int j = 0; j < h.length; j++) { for (int j = 0; j < h.length; j++) {
if (h[j] != null) { if (h[j] != null) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound(); NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.a("Slot", (byte) j); nbttagcompound1.a("Slot", (byte) j);
h[j].a(nbttagcompound1); h[j].a(nbttagcompound1);
nbttaglist.a(((NBTBase) (nbttagcompound1))); nbttaglist.a(((NBTBase) (nbttagcompound1)));
} }
} }
nbttagcompound.a("Items", ((NBTBase) (nbttaglist))); nbttagcompound.a("Items", ((NBTBase) (nbttaglist)));
} }
public int c() { public int c() {
return 64; return 64;
} }
public boolean e() { public boolean e() {
return e > 0; return e > 0;
} }
public void f() { public void f() {
boolean flag = e > 0; boolean flag = e > 0;
boolean flag1 = false; boolean flag1 = false;
if (e > 0) { if (e > 0) {
e--; e--;
} }
if (!a.z) { if (!a.z) {
if (e == 0 && i()) { if (e == 0 && i()) {
f = e = a(h[1]); f = e = a(h[1]);
if (e > 0) { if (e > 0) {
flag1 = true; flag1 = true;
if (h[1] != null) { if (h[1] != null) {
h[1].a--; h[1].a--;
if (h[1].a == 0) { if (h[1].a == 0) {
h[1] = null; h[1] = null;
} }
} }
} }
} }
if (e() && i()) { if (e() && i()) {
g++; g++;
if (g == 200) { if (g == 200) {
g = 0; g = 0;
h(); h();
flag1 = true; flag1 = true;
} }
} else { } else {
g = 0; g = 0;
} }
if (flag != (e > 0)) { if (flag != (e > 0)) {
flag1 = true; flag1 = true;
BlockFurnace.a(e > 0, a, b, c, d); BlockFurnace.a(e > 0, a, b, c, d);
} }
} }
if (flag1) { if (flag1) {
d(); d();
} }
} }
private boolean i() { private boolean i() {
if (h[0] == null) { if (h[0] == null) {
return false; return false;
} }
ItemStack itemstack = FurnaceRecipes.a().a(h[0].a().ba); ItemStack itemstack = FurnaceRecipes.a().a(h[0].a().ba);
if (itemstack == null) { if (itemstack == null) {
return false; return false;
} }
if (h[2] == null) { if (h[2] == null) {
return true; return true;
} }
if (!h[2].a(itemstack)) { if (!h[2].a(itemstack)) {
return false; return false;
} }
if (h[2].a < c() && h[2].a < h[2].b()) { if (h[2].a < c() && h[2].a < h[2].b()) {
return true; return true;
} }
return h[2].a < itemstack.b(); return h[2].a < itemstack.b();
} }
public void h() { public void h() {
if (!i()) { if (!i()) {
return; return;
} }
ItemStack itemstack = FurnaceRecipes.a().a(h[0].a().ba); ItemStack itemstack = FurnaceRecipes.a().a(h[0].a().ba);
if (h[2] == null) { if (h[2] == null) {
h[2] = itemstack.j(); h[2] = itemstack.j();
} else if (h[2].c == itemstack.c) { } else if (h[2].c == itemstack.c) {
h[2].a++; h[2].a++;
} }
h[0].a--; h[0].a--;
if (h[0].a <= 0) { if (h[0].a <= 0) {
h[0] = null; h[0] = null;
} }
} }
private int a(ItemStack itemstack) { private int a(ItemStack itemstack) {
if (itemstack == null) { if (itemstack == null) {
return 0; return 0;
} }
int j = itemstack.a().ba; int j = itemstack.a().ba;
if (j < 256 && Block.m[j].bt == Material.c) { if (j < 256 && Block.m[j].bt == Material.c) {
return 300; return 300;
} }
if (j == Item.B.ba) { if (j == Item.B.ba) {
return 100; return 100;
} }
if (j == Item.k.ba) { if (j == Item.k.ba) {
return 1600; return 1600;
} }
return j != Item.aw.ba ? 0 : 20000; return j != Item.aw.ba ? 0 : 20000;
} }
public boolean a_(EntityPlayer entityplayer) { public boolean a_(EntityPlayer entityplayer) {
if (a.m(b, c, d) != this) { if (a.m(b, c, d) != this) {
return false; return false;
} }
return entityplayer.d((double) b + 0.5D, (double) c + 0.5D, (double) d + 0.5D) <= 64D; return entityplayer.d((double) b + 0.5D, (double) c + 0.5D, (double) d + 0.5D) <= 64D;
} }
} }

Datei anzeigen

@ -1,208 +1,208 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import java.util.HashMap; import java.util.HashMap;
import net.minecraft.server.IInventory; import net.minecraft.server.IInventory;
import org.bukkit.ItemStack; import org.bukkit.ItemStack;
import org.bukkit.Material; import org.bukkit.Material;
public class CraftInventory implements org.bukkit.Inventory { public class CraftInventory implements org.bukkit.Inventory {
protected IInventory inventory; protected IInventory inventory;
public CraftInventory(IInventory inventory) { public CraftInventory(IInventory inventory) {
this.inventory = inventory; this.inventory = inventory;
} }
public IInventory getInventory() { public IInventory getInventory() {
return inventory; return inventory;
} }
public int getSize() { public int getSize() {
return getInventory().h_(); return getInventory().h_();
} }
public String getName() { public String getName() {
return getInventory().b(); return getInventory().b();
} }
public CraftItemStack getItem(int index) { public CraftItemStack getItem(int index) {
return new CraftItemStack(getInventory().a(index)); return new CraftItemStack(getInventory().a(index));
} }
public CraftItemStack[] getContents() { public CraftItemStack[] getContents() {
CraftItemStack[] items = new CraftItemStack[getSize()]; CraftItemStack[] items = new CraftItemStack[getSize()];
net.minecraft.server.ItemStack[] mcItems = getInventory().getContents(); net.minecraft.server.ItemStack[] mcItems = getInventory().getContents();
for (int i = 0; i < mcItems.length; i++ ) { for (int i = 0; i < mcItems.length; i++ ) {
items[i] = new CraftItemStack(mcItems[i]); items[i] = new CraftItemStack(mcItems[i]);
} }
return items; return items;
} }
public void setItem(int index, ItemStack item) { public void setItem(int index, ItemStack item) {
getInventory().a( index, new net.minecraft.server.ItemStack( item.getTypeID(), item.getAmount(), 0)); getInventory().a( index, new net.minecraft.server.ItemStack( item.getTypeID(), item.getAmount(), 0));
} }
public boolean contains(int materialId) { public boolean contains(int materialId) {
for (ItemStack item: getContents()) { for (ItemStack item: getContents()) {
if (item.getTypeID() == materialId) { if (item.getTypeID() == materialId) {
return true; return true;
} }
} }
return false; return false;
} }
public boolean contains(Material material) { public boolean contains(Material material) {
return contains(material.getID()); return contains(material.getID());
} }
public boolean contains(ItemStack item) { public boolean contains(ItemStack item) {
for (ItemStack i: getContents()) { for (ItemStack i: getContents()) {
if (item.equals(i)) { if (item.equals(i)) {
return true; return true;
} }
} }
return false; return false;
} }
public HashMap<Integer, ItemStack> all(int materialId) { public HashMap<Integer, ItemStack> all(int materialId) {
HashMap<Integer, ItemStack> slots = new HashMap<Integer, ItemStack>(); HashMap<Integer, ItemStack> slots = new HashMap<Integer, ItemStack>();
ItemStack[] inventory = getContents(); ItemStack[] inventory = getContents();
for (int i = 0; i < inventory.length; i++) { for (int i = 0; i < inventory.length; i++) {
ItemStack item = inventory[i]; ItemStack item = inventory[i];
if (item.getTypeID() == materialId) { if (item.getTypeID() == materialId) {
slots.put( i, item ); slots.put( i, item );
} }
} }
return slots; return slots;
} }
public HashMap<Integer, ItemStack> all(Material material) { public HashMap<Integer, ItemStack> all(Material material) {
return all(material.getID()); return all(material.getID());
} }
public HashMap<Integer, ItemStack> all(ItemStack item) { public HashMap<Integer, ItemStack> all(ItemStack item) {
HashMap<Integer, ItemStack> slots = new HashMap<Integer, ItemStack>(); HashMap<Integer, ItemStack> slots = new HashMap<Integer, ItemStack>();
ItemStack[] inventory = getContents(); ItemStack[] inventory = getContents();
for (int i = 0; i < inventory.length; i++) { for (int i = 0; i < inventory.length; i++) {
if (item.equals(inventory[i])) { if (item.equals(inventory[i])) {
slots.put( i, item ); slots.put( i, item );
} }
} }
return slots; return slots;
} }
public int first(int materialId) { public int first(int materialId) {
ItemStack[] inventory = getContents(); ItemStack[] inventory = getContents();
for (int i = 0; i < inventory.length; i++) { for (int i = 0; i < inventory.length; i++) {
if (inventory[i].getTypeID() == materialId) { if (inventory[i].getTypeID() == materialId) {
return i; return i;
} }
} }
return -1; return -1;
} }
public int first(Material material) { public int first(Material material) {
return first(material.getID()); return first(material.getID());
} }
public int first(ItemStack item) { public int first(ItemStack item) {
ItemStack[] inventory = getContents(); ItemStack[] inventory = getContents();
for (int i = 0; i < inventory.length; i++) { for (int i = 0; i < inventory.length; i++) {
if (item.equals(inventory[i])) { if (item.equals(inventory[i])) {
return i; return i;
} }
} }
return -1; return -1;
} }
public int firstEmpty() { public int firstEmpty() {
return first(Material.AIR); return first(Material.AIR);
} }
public int firstPartial(int materialId) { public int firstPartial(int materialId) {
ItemStack[] inventory = getContents(); ItemStack[] inventory = getContents();
for (int i = 0; i < inventory.length; i++) { for (int i = 0; i < inventory.length; i++) {
ItemStack item = inventory[i]; ItemStack item = inventory[i];
if (item != null && item.getTypeID() == materialId && item.getAmount() < item.getMaxStackSize()) { if (item != null && item.getTypeID() == materialId && item.getAmount() < item.getMaxStackSize()) {
return i; return i;
} }
} }
return -1; return -1;
} }
public int firstPartial(Material material) { public int firstPartial(Material material) {
return firstPartial(material.getID()); return firstPartial(material.getID());
} }
public int firstPartial(ItemStack item) { public int firstPartial(ItemStack item) {
return firstPartial(item.getTypeID()); return firstPartial(item.getTypeID());
} }
public HashMap<Integer, ItemStack> addItem(ItemStack... items) { public HashMap<Integer, ItemStack> addItem(ItemStack... items) {
HashMap<Integer,ItemStack> leftover = new HashMap<Integer,ItemStack>(); HashMap<Integer,ItemStack> leftover = new HashMap<Integer,ItemStack>();
/* TODO: some optimization /* TODO: some optimization
* - Create a 'firstPartial' with a 'fromIndex' * - Create a 'firstPartial' with a 'fromIndex'
* - Record the lastPartial per Material * - Record the lastPartial per Material
* - Cache firstEmpty result * - Cache firstEmpty result
*/ */
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
ItemStack item = items[i]; ItemStack item = items[i];
while (true) { while (true) {
// Do we already have a stack of it? // Do we already have a stack of it?
int firstPartial = firstPartial( item.getTypeID() ); int firstPartial = firstPartial( item.getTypeID() );
// Drat! no partial stack // Drat! no partial stack
if (firstPartial == -1) { if (firstPartial == -1) {
// Find a free spot! // Find a free spot!
int firstFree = firstEmpty(); int firstFree = firstEmpty();
if (firstFree == -1) { if (firstFree == -1) {
// No space at all! // No space at all!
leftover.put(i, item); leftover.put(i, item);
break; break;
} else { } else {
// More than a single stack! // More than a single stack!
if (item.getAmount() > getMaxItemStack()) { if (item.getAmount() > getMaxItemStack()) {
setItem( firstFree, new ItemStack(item.getTypeID(), getMaxItemStack())); setItem( firstFree, new ItemStack(item.getTypeID(), getMaxItemStack()));
item.setAmount(item.getAmount() - getMaxItemStack()); item.setAmount(item.getAmount() - getMaxItemStack());
} else { } else {
// Just store it // Just store it
setItem( firstFree, item ); setItem( firstFree, item );
break; break;
} }
} }
} else { } else {
// So, apparently it might only partially fit, well lets do just that // So, apparently it might only partially fit, well lets do just that
ItemStack partialItem = getItem(firstPartial); ItemStack partialItem = getItem(firstPartial);
int amount = item.getAmount(); int amount = item.getAmount();
int partialAmount = partialItem.getAmount(); int partialAmount = partialItem.getAmount();
int maxAmount = partialItem.getMaxStackSize(); int maxAmount = partialItem.getMaxStackSize();
// Check if it fully fits // Check if it fully fits
if (amount + partialAmount <= maxAmount) { if (amount + partialAmount <= maxAmount) {
partialItem.setAmount( amount + partialAmount ); partialItem.setAmount( amount + partialAmount );
break; break;
} }
// It fits partially // It fits partially
partialItem.setAmount( maxAmount ); partialItem.setAmount( maxAmount );
item.setAmount( amount + partialAmount - maxAmount ); item.setAmount( amount + partialAmount - maxAmount );
} }
} }
} }
return leftover; return leftover;
} }
private int getMaxItemStack() { private int getMaxItemStack() {
return getInventory().c(); return getInventory().c();
} }
} }