Archiviert
13
0

data improvements

Dieser Commit ist enthalten in:
Tahg 2011-09-26 03:07:06 -04:00
Ursprung b7c43fbff1
Commit d226e551ae
13 geänderte Dateien mit 399 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -538,6 +538,9 @@ public class Block {
Item.byId[LONG_GRASS.id] = new ItemColoredBlock(LONG_GRASS.id - 256, true); Item.byId[LONG_GRASS.id] = new ItemColoredBlock(LONG_GRASS.id - 256, true);
Item.byId[PISTON.id] = new ItemPiston(PISTON.id - 256); Item.byId[PISTON.id] = new ItemPiston(PISTON.id - 256);
Item.byId[PISTON_STICKY.id] = new ItemPiston(PISTON_STICKY.id - 256); Item.byId[PISTON_STICKY.id] = new ItemPiston(PISTON_STICKY.id - 256);
Item.byId[BIG_MUSHROOM_1.id] = new ItemLog(BIG_MUSHROOM_1.id - 256, BIG_MUSHROOM_1); // CraftBukkit
Item.byId[BIG_MUSHROOM_2.id] = new ItemLog(BIG_MUSHROOM_2.id - 256, BIG_MUSHROOM_2); // CraftBukkit
Item.byId[MOB_SPAWNER.id] = new ItemMobSpawner(MOB_SPAWNER.id - 256); // CraftBukkit
for (int i = 0; i < 256; ++i) { for (int i = 0; i < 256; ++i) {
if (byId[i] != null && Item.byId[i] == null) { if (byId[i] != null && Item.byId[i] == null) {

Datei anzeigen

@ -0,0 +1,44 @@
package net.minecraft.server;
import java.util.Random;
public class BlockMobSpawner extends BlockContainer {
protected BlockMobSpawner(int i, int j) {
super(i, j, Material.STONE);
}
public TileEntity a_() {
return new TileEntityMobSpawner();
}
public int a(int i, Random random) {
return Block.MOB_SPAWNER.id; // CraftBukkit
}
public int a(Random random) {
return 1; // CraftBukkit
}
// CraftBukkit start
public void dropNaturally(World world, int i, int j, int k, int l, float f) {
TileEntity entity = world.getTileEntity(i, j, k);
if (entity instanceof TileEntityMobSpawner) {
super.dropNaturally(world, i, j, k, ((TileEntityMobSpawner) entity).getId(), f);
}
}
public void remove(World world, int i, int j, int k) {
dropNaturally(world, i, j, k, 0, 1.0f);
super.remove(world, i, j, k);
}
protected int a_(int i) {
return i;
}
// CraftBukkit end
public boolean a() {
return false;
}
}

Datei anzeigen

@ -0,0 +1,64 @@
package net.minecraft.server;
import java.util.Random;
public class BlockSand extends Block {
public static boolean instaFall = false;
public BlockSand(int i, int j) {
super(i, j, Material.SAND);
}
public void a(World world, int i, int j, int k) {
world.c(i, j, k, this.id, this.c());
}
public void doPhysics(World world, int i, int j, int k, int l) {
world.c(i, j, k, this.id, this.c());
}
public void a(World world, int i, int j, int k, Random random) {
this.g(world, i, j, k);
}
private void g(World world, int i, int j, int k) {
if (d_(world, i, j - 1, k) && j >= 0) {
byte b0 = 32;
if (!instaFall && world.a(i - b0, j - b0, k - b0, i + b0, j + b0, k + b0)) {
EntityFallingSand entityfallingsand = new EntityFallingSand(world, (double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), this.id, world.getData(i, j, k));
world.addEntity(entityfallingsand);
} else {
world.setTypeId(i, j, k, 0);
while (d_(world, i, j - 1, k) && j > 0) {
--j;
}
if (j > 0) {
world.setTypeId(i, j, k, this.id);
}
}
}
}
public int c() {
return 3;
}
public static boolean d_(World world, int i, int j, int k) {
int l = world.getTypeId(i, j, k);
if (l == 0) {
return true;
} else if (l == Block.FIRE.id) {
return true;
} else {
Material material = Block.byId[l].material;
return material == Material.WATER ? true : material == Material.LAVA;
}
}
}

Datei anzeigen

@ -0,0 +1,86 @@
package net.minecraft.server;
public class EntityFallingSand extends Entity {
public int a;
public int data; // CraftBukkit
public int b = 0;
public EntityFallingSand(World world) {
super(world);
}
// CraftBukkit -- changed method signature
public EntityFallingSand(World world, double d0, double d1, double d2, int i, int data) {
super(world);
this.a = i;
this.data = data;
this.aY = true;
this.b(0.98F, 0.98F);
this.height = this.width / 2.0F;
this.setPosition(d0, d1, d2);
this.motX = 0.0D;
this.motY = 0.0D;
this.motZ = 0.0D;
this.lastX = d0;
this.lastY = d1;
this.lastZ = d2;
}
protected boolean e_() {
return false;
}
protected void b() {}
public boolean r_() {
return !this.dead;
}
public void s_() {
if (this.a == 0) {
this.die();
} else {
this.lastX = this.locX;
this.lastY = this.locY;
this.lastZ = this.locZ;
++this.b;
this.motY -= 0.03999999910593033D;
this.move(this.motX, this.motY, this.motZ);
this.motX *= 0.9800000190734863D;
this.motY *= 0.9800000190734863D;
this.motZ *= 0.9800000190734863D;
int i = MathHelper.floor(this.locX);
int j = MathHelper.floor(this.locY);
int k = MathHelper.floor(this.locZ);
if (this.world.getTypeId(i, j, k) == this.a) {
this.world.setTypeId(i, j, k, 0);
}
if (this.onGround) {
this.motX *= 0.699999988079071D;
this.motZ *= 0.699999988079071D;
this.motY *= -0.5D;
this.die();
// CraftBukkit -- setTypeId => setTypeIdAndData
if ((!this.world.a(this.a, i, j, k, true, 1) || BlockSand.d_(this.world, i, j - 1, k) || !this.world.setTypeIdAndData(i, j, k, this.a, this.data)) && !this.world.isStatic) {
this.b(this.a, 1);
}
} else if (this.b > 100 && !this.world.isStatic) {
this.b(this.a, 1);
this.die();
}
}
}
protected void b(NBTTagCompound nbttagcompound) {
nbttagcompound.a("Tile", (byte) this.a);
nbttagcompound.a("Data", (byte) this.data); // CraftBukkit
}
protected void a(NBTTagCompound nbttagcompound) {
this.a = nbttagcompound.c("Tile") & 255;
this.data = nbttagcompound.c("Data") & 15; // CraftBukkit
}
}

Datei anzeigen

@ -23,6 +23,7 @@ public class EntityPainting extends Entity {
this.a = 0; this.a = 0;
this.height = 0.0F; this.height = 0.0F;
this.b(0.5F, 0.5F); this.b(0.5F, 0.5F);
this.e = EnumArt.values()[this.random.nextInt(EnumArt.values().length)]; // CraftBukkit - generate a non-null painting
} }
public EntityPainting(World world, int i, int j, int k, int l) { public EntityPainting(World world, int i, int j, int k, int l) {

Datei anzeigen

@ -0,0 +1,116 @@
package net.minecraft.server;
import java.util.HashMap;
import java.util.Map;
public class EntityTypes {
private static Map a = new HashMap();
private static Map b = new HashMap();
private static Map c = new HashMap();
private static Map d = new HashMap();
public EntityTypes() {}
private static void a(Class oclass, String s, int i) {
a.put(s, oclass);
b.put(oclass, s);
c.put(Integer.valueOf(i), oclass);
d.put(oclass, Integer.valueOf(i));
}
public static Entity a(String s, World world) {
Entity entity = null;
try {
Class oclass = (Class) a.get(s);
if (oclass != null) {
entity = (Entity) oclass.getConstructor(new Class[] { World.class}).newInstance(new Object[] { world});
}
} catch (Exception exception) {
exception.printStackTrace();
}
return entity;
}
public static Entity a(NBTTagCompound nbttagcompound, World world) {
Entity entity = null;
try {
Class oclass = (Class) a.get(nbttagcompound.getString("id"));
if (oclass != null) {
entity = (Entity) oclass.getConstructor(new Class[] { World.class}).newInstance(new Object[] { world});
}
} catch (Exception exception) {
exception.printStackTrace();
}
if (entity != null) {
entity.e(nbttagcompound);
} else {
System.out.println("Skipping Entity with id " + nbttagcompound.getString("id"));
}
return entity;
}
public static int a(Entity entity) {
return ((Integer) d.get(entity.getClass())).intValue();
}
public static String b(Entity entity) {
return (String) b.get(entity.getClass());
}
// CraftBukkit start
public static Class<? extends Entity> getClassFromId(int id) {
return (Class<? extends Entity>) c.get(id);
}
public static int getIdFromClass(Class<? extends Entity> oClass) {
return (Integer) d.get(oClass);
}
public static Class<? extends Entity> getClassFromName(String name) {
return (Class<? extends Entity>) a.get(name);
}
public static String getNameFromClass(Class<? extends Entity> oClass) {
return (String) b.get(oClass);
}
// CraftBukkit end
static {
a(EntityItem.class, "Item", 1);
a(EntityExperienceOrb.class, "XPOrb", 2);
a(EntityArrow.class, "Arrow", 10);
a(EntitySnowball.class, "Snowball", 11);
a(EntityPainting.class, "Painting", 9);
a(EntityLiving.class, "Mob", 48);
a(EntityMonster.class, "Monster", 49);
a(EntityCreeper.class, "Creeper", 50);
a(EntitySkeleton.class, "Skeleton", 51);
a(EntitySpider.class, "Spider", 52);
a(EntityGiantZombie.class, "Giant", 53);
a(EntityZombie.class, "Zombie", 54);
a(EntitySlime.class, "Slime", 55);
a(EntityGhast.class, "Ghast", 56);
a(EntityPigZombie.class, "PigZombie", 57);
a(EntityEnderman.class, "Enderman", 58);
a(EntityCaveSpider.class, "CaveSpider", 59);
a(EntitySilverfish.class, "Silverfish", 60);
a(EntityPig.class, "Pig", 90);
a(EntitySheep.class, "Sheep", 91);
a(EntityCow.class, "Cow", 92);
a(EntityChicken.class, "Chicken", 93);
a(EntitySquid.class, "Squid", 94);
a(EntityWolf.class, "Wolf", 95);
a(EntityTNTPrimed.class, "PrimedTnt", 20);
a(EntityFallingSand.class, "FallingSand", 21);
a(EntityMinecart.class, "Minecart", 40);
a(EntityBoat.class, "Boat", 41);
}
}

Datei anzeigen

@ -30,6 +30,12 @@ public class ItemInWorldManager {
this.world = world; this.world = world;
} }
// CraftBukkit start - keep this for backwards compatibility
public ItemInWorldManager(WorldServer world) {
this.world = world;
}
// CraftBukkit end
public void a(int i) { public void a(int i) {
this.c = i; this.c = i;
if (i == 0) { if (i == 0) {

Datei anzeigen

@ -0,0 +1,44 @@
package net.minecraft.server;
public class ItemMobSpawner extends ItemLog {
public ItemMobSpawner(int i) {
super(i, Block.MOB_SPAWNER);
}
public boolean a(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l) {
if(!super.a(itemstack, entityhuman, world, i, j, k, l)) return false;
System.out.println("Placed the spawner, checking it's entity");
if (l == 0) {
--j;
}
if (l == 1) {
++j;
}
if (l == 2) {
--k;
}
if (l == 3) {
++k;
}
if (l == 4) {
--i;
}
if (l == 5) {
++i;
}
TileEntity entity = world.getTileEntity(i, j, k);
System.out.println(entity);
if (entity instanceof TileEntityMobSpawner) {
System.out.println("Got a valid spawner, attempt to set its type");
((TileEntityMobSpawner)entity).setId(itemstack.getData());
return true;
}
else return false;
}
}

Datei anzeigen

@ -5,7 +5,7 @@ public final class ItemStack {
public int count; public int count;
public int b; public int b;
public int id; public int id;
public int damage; // CraftBukkit - private -> public private int damage;
public ItemStack(Block block) { public ItemStack(Block block) {
this(block, 1); this(block, 1);
@ -35,7 +35,7 @@ public final class ItemStack {
this.count = 0; this.count = 0;
this.id = i; this.id = i;
this.count = j; this.count = j;
this.damage = k; b(k); // CraftBukkit
} }
public static ItemStack a(NBTTagCompound nbttagcompound) { public static ItemStack a(NBTTagCompound nbttagcompound) {
@ -122,7 +122,7 @@ public final class ItemStack {
} }
public void b(int i) { public void b(int i) {
this.damage = i; this.damage = (id > 0) && (id < 256) ? Item.byId[id].filterData(i) : i; // CraftBukkit
} }
public int i() { public int i() {

Datei anzeigen

@ -21,6 +21,17 @@ public class TileEntityMobSpawner extends TileEntity {
return this.world.a((double) this.x + 0.5D, (double) this.y + 0.5D, (double) this.z + 0.5D, 16.0D) != null; return this.world.a((double) this.x + 0.5D, (double) this.y + 0.5D, (double) this.z + 0.5D, 16.0D) != null;
} }
// CraftBukkit start
public int getId() {
return EntityTypes.getIdFromClass(EntityTypes.getClassFromName(mobName));
}
public void setId(int id) {
mobName = EntityTypes.getNameFromClass(EntityTypes.getClassFromId(id));
System.out.println("Setting mob type to: " + mobName);
}
// CraftBukkit end
public void h_() { public void h_() {
this.c = this.b; this.c = this.b;
if (this.a()) { if (this.a()) {
@ -48,28 +59,30 @@ public class TileEntityMobSpawner extends TileEntity {
byte b0 = 4; byte b0 = 4;
for (int i = 0; i < b0; ++i) { for (int i = 0; i < b0; ++i) {
EntityLiving entityliving = (EntityLiving) ((EntityLiving) EntityTypes.a(this.mobName, this.world)); // CraftBukkit start
Entity entity = EntityTypes.a(this.mobName, this.world);
if (entityliving == null) { if (entity == null) {
return; return;
} }
int j = this.world.a(entityliving.getClass(), AxisAlignedBB.b((double) this.x, (double) this.y, (double) this.z, (double) (this.x + 1), (double) (this.y + 1), (double) (this.z + 1)).b(8.0D, 4.0D, 8.0D)).size(); int j = this.world.a(entity.getClass(), AxisAlignedBB.b((double) this.x, (double) this.y, (double) this.z, (double) (this.x + 1), (double) (this.y + 1), (double) (this.z + 1)).b(8.0D, 4.0D, 8.0D)).size();
if (j >= 6) { if (j >= 6) {
this.c(); this.c();
return; return;
} }
if (entityliving != null) { if (entity != null) {
double d3 = (double) this.x + (this.world.random.nextDouble() - this.world.random.nextDouble()) * 4.0D; double d3 = (double) this.x + (this.world.random.nextDouble() - this.world.random.nextDouble()) * 4.0D;
double d4 = (double) (this.y + this.world.random.nextInt(3) - 1); double d4 = (double) (this.y + this.world.random.nextInt(3) - 1);
double d5 = (double) this.z + (this.world.random.nextDouble() - this.world.random.nextDouble()) * 4.0D; double d5 = (double) this.z + (this.world.random.nextDouble() - this.world.random.nextDouble()) * 4.0D;
entityliving.setPositionRotation(d3, d4, d5, this.world.random.nextFloat() * 360.0F, 0.0F); entity.setPositionRotation(d3, d4, d5, this.world.random.nextFloat() * 360.0F, 0.0F);
if (entityliving.d()) { if (entity.world.containsEntity(entity.boundingBox) && entity.world.getEntities(entity, entity.boundingBox).size() == 0 && !entity.world.c(entity.boundingBox)) {
// CraftBukkit end
// CraftBukkit - added a reason for spawning this creature // CraftBukkit - added a reason for spawning this creature
this.world.addEntity(entityliving, SpawnReason.SPAWNER); this.world.addEntity(entity, SpawnReason.SPAWNER);
for (int k = 0; k < 20; ++k) { for (int k = 0; k < 20; ++k) {
d0 = (double) this.x + 0.5D + ((double) this.world.random.nextFloat() - 0.5D) * 2.0D; d0 = (double) this.x + 0.5D + ((double) this.world.random.nextFloat() - 0.5D) * 2.0D;
@ -79,7 +92,7 @@ public class TileEntityMobSpawner extends TileEntity {
this.world.a("flame", d0, d1, d2, 0.0D, 0.0D, 0.0D); this.world.a("flame", d0, d1, d2, 0.0D, 0.0D, 0.0D);
} }
entityliving.ab(); // entity.ab(); // CraftBukkit - client side code, and not available in entity
this.c(); this.c();
} }
} }

Datei anzeigen

@ -687,7 +687,7 @@ public class CraftWorld implements World {
} else if (Egg.class.isAssignableFrom(clazz)) { } else if (Egg.class.isAssignableFrom(clazz)) {
entity = new EntityEgg(world, x, y, z); entity = new EntityEgg(world, x, y, z);
} else if (FallingSand.class.isAssignableFrom(clazz)) { } else if (FallingSand.class.isAssignableFrom(clazz)) {
entity = new EntityFallingSand(world, x, y, z, 0); entity = new EntityFallingSand(world, x, y, z, 0, 0);
} else if (Fireball.class.isAssignableFrom(clazz)) { } else if (Fireball.class.isAssignableFrom(clazz)) {
entity = new EntityFireball(world); entity = new EntityFireball(world);
((EntityFireball) entity).setPositionRotation(x, y, z, yaw, pitch); ((EntityFireball) entity).setPositionRotation(x, y, z, yaw, pitch);

Datei anzeigen

@ -199,12 +199,13 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
public int firstPartial(ItemStack item) { public int firstPartial(ItemStack item) {
ItemStack[] inventory = getContents(); ItemStack[] inventory = getContents();
ItemStack filteredItem = new CraftItemStack(item);
if (item == null) { if (item == null) {
return -1; return -1;
} }
for (int i = 0; i < inventory.length; i++) { for (int i = 0; i < inventory.length; i++) {
ItemStack cItem = inventory[i]; ItemStack cItem = inventory[i];
if (cItem != null && cItem.getTypeId() == item.getTypeId() && cItem.getAmount() < cItem.getMaxStackSize() && cItem.getDurability() == item.getDurability()) { if (cItem != null && cItem.getTypeId() == filteredItem.getTypeId() && cItem.getAmount() < cItem.getMaxStackSize() && cItem.getDurability() == filteredItem.getDurability()) {
return i; return i;
} }
} }

Datei anzeigen

@ -10,11 +10,15 @@ public class CraftItemStack extends ItemStack {
super( super(
item != null ? item.id: 0, item != null ? item.id: 0,
item != null ? item.count : 0, item != null ? item.count : 0,
(short)(item != null ? item.damage : 0) (short)(item != null ? item.getData() : 0)
); );
this.item = item; this.item = item;
} }
public CraftItemStack(ItemStack item) {
this(item.getTypeId(), item.getAmount(), item.getDurability());
}
/* 'Overwritten' constructors from ItemStack, yay for Java sucking */ /* 'Overwritten' constructors from ItemStack, yay for Java sucking */
public CraftItemStack(final int type) { public CraftItemStack(final int type) {
this(type, 0); this(type, 0);
@ -105,15 +109,15 @@ public class CraftItemStack extends ItemStack {
// Ignore damage if item is null // Ignore damage if item is null
if (item != null) { if (item != null) {
super.setDurability(durability); super.setDurability(durability);
item.damage = durability; item.b(durability);
} }
} }
@Override @Override
public short getDurability() { public short getDurability() {
if (item != null) { if (item != null) {
super.setDurability((short) item.damage); // sync, needed? super.setDurability((short) item.getData()); // sync, needed?
return (short) item.damage; return (short) item.getData();
} else { } else {
return -1; return -1;
} }