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

By: Erik Broes <erikbroes@ripe.net>
This commit is contained in:
CraftBukkit/Spigot 2011-01-05 01:00:57 +01:00
parent 37bc03b43a
commit d62c61e91b
2 changed files with 91 additions and 2 deletions

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;
}
}