Initial implementation of inventory stuff, (read-)only for StorageMinecart sofar

This commit is contained in:
Erik Broes 2011-01-05 01:00:57 +01:00
parent 3dbacbc2c3
commit 25d519aaf2
3 changed files with 97 additions and 2 deletions

View File

@ -113,6 +113,12 @@ public class EntityMinecart extends Entity
// CraftBukkit end
}
// CraftBukkit start
public ItemStack[] getContents() {
return this.ak;
}
// CraftBukkit end
public AxisAlignedBB d(Entity entity) {
return entity.z;
}

View File

@ -0,0 +1,61 @@
package org.bukkit.craftbukkit;
import org.bukkit.ItemStack;
import org.bukkit.Material;
public class CraftItemStack extends ItemStack {
protected net.minecraft.server.ItemStack item;
public CraftItemStack(net.minecraft.server.ItemStack item) {
super(item.c, item.a);
this.item = item;
}
/*
* Unsure if we have to syn before each of these calls the values in 'item'
* are all public.
*/
@Override
public Material getType() {
super.setTypeID(item.c); // sync, needed?
return super.getType();
}
@Override
public int getTypeID() {
super.setTypeID(item.c); // sync, needed?
return item.c;
}
@Override
public void setTypeID(int type) {
super.setTypeID(item.c);
item.c = type;
}
@Override
public int getAmount() {
super.setAmount(item.a); // sync, needed?
return item.a;
}
@Override
public void setAmount(int amount) {
super.setAmount(amount);
item.a = amount;
}
@Override
public void setDamage(final byte damage) {
super.setDamage(damage);
item.d = damage;
}
@Override
public byte getDamage() {
super.setDamage((byte) item.d); // sync, needed?
return (byte) item.d;
}
}

View File

@ -1,6 +1,11 @@
package org.bukkit.craftbukkit;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.server.EntityMinecart;
import org.bukkit.ItemStack;
import org.bukkit.StorageMinecart;
/**
@ -8,10 +13,33 @@ import org.bukkit.StorageMinecart;
*
* @author sk89q
*/
public class CraftStorageMinecart extends CraftMinecart
implements StorageMinecart {
public class CraftStorageMinecart extends CraftMinecart implements StorageMinecart {
public CraftStorageMinecart(CraftServer server, EntityMinecart entity) {
super(server, 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;
}
}