summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft
diff options
context:
space:
mode:
authorTahg <tahgtahv@gmail.com>2011-09-26 03:07:06 -0400
committerTahg <tahgtahv@gmail.com>2011-09-26 03:07:46 -0400
commitd226e551ae7b77bc002e6686a36a6374ed515fbc (patch)
tree1b7e23dc7338b928e29cbd453bf0ef68fd7f125b /src/main/java/net/minecraft
parentb7c43fbff1dffef1b4c9c4e57633d8c16606db58 (diff)
downloadcraftbukkit-d226e551ae7b77bc002e6686a36a6374ed515fbc.tar
craftbukkit-d226e551ae7b77bc002e6686a36a6374ed515fbc.tar.gz
craftbukkit-d226e551ae7b77bc002e6686a36a6374ed515fbc.tar.lz
craftbukkit-d226e551ae7b77bc002e6686a36a6374ed515fbc.tar.xz
craftbukkit-d226e551ae7b77bc002e6686a36a6374ed515fbc.zip
data improvements
Diffstat (limited to 'src/main/java/net/minecraft')
-rw-r--r--src/main/java/net/minecraft/server/Block.java3
-rw-r--r--src/main/java/net/minecraft/server/BlockMobSpawner.java44
-rw-r--r--src/main/java/net/minecraft/server/BlockSand.java64
-rw-r--r--src/main/java/net/minecraft/server/EntityFallingSand.java86
-rw-r--r--src/main/java/net/minecraft/server/EntityPainting.java1
-rw-r--r--src/main/java/net/minecraft/server/EntityTypes.java116
-rw-r--r--src/main/java/net/minecraft/server/ItemInWorldManager.java6
-rw-r--r--src/main/java/net/minecraft/server/ItemMobSpawner.java44
-rw-r--r--src/main/java/net/minecraft/server/ItemStack.java6
-rw-r--r--src/main/java/net/minecraft/server/TileEntityMobSpawner.java29
10 files changed, 388 insertions, 11 deletions
diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java
index 517686d0..4eee4f7d 100644
--- a/src/main/java/net/minecraft/server/Block.java
+++ b/src/main/java/net/minecraft/server/Block.java
@@ -538,6 +538,9 @@ public class Block {
Item.byId[LONG_GRASS.id] = new ItemColoredBlock(LONG_GRASS.id - 256, true);
Item.byId[PISTON.id] = new ItemPiston(PISTON.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) {
if (byId[i] != null && Item.byId[i] == null) {
diff --git a/src/main/java/net/minecraft/server/BlockMobSpawner.java b/src/main/java/net/minecraft/server/BlockMobSpawner.java
new file mode 100644
index 00000000..752fd228
--- /dev/null
+++ b/src/main/java/net/minecraft/server/BlockMobSpawner.java
@@ -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;
+ }
+}
diff --git a/src/main/java/net/minecraft/server/BlockSand.java b/src/main/java/net/minecraft/server/BlockSand.java
new file mode 100644
index 00000000..abee35b0
--- /dev/null
+++ b/src/main/java/net/minecraft/server/BlockSand.java
@@ -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;
+ }
+ }
+}
diff --git a/src/main/java/net/minecraft/server/EntityFallingSand.java b/src/main/java/net/minecraft/server/EntityFallingSand.java
new file mode 100644
index 00000000..0853c895
--- /dev/null
+++ b/src/main/java/net/minecraft/server/EntityFallingSand.java
@@ -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
+ }
+}
diff --git a/src/main/java/net/minecraft/server/EntityPainting.java b/src/main/java/net/minecraft/server/EntityPainting.java
index a98c4d0b..d94fe56c 100644
--- a/src/main/java/net/minecraft/server/EntityPainting.java
+++ b/src/main/java/net/minecraft/server/EntityPainting.java
@@ -23,6 +23,7 @@ public class EntityPainting extends Entity {
this.a = 0;
this.height = 0.0F;
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) {
diff --git a/src/main/java/net/minecraft/server/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java
new file mode 100644
index 00000000..057d30de
--- /dev/null
+++ b/src/main/java/net/minecraft/server/EntityTypes.java
@@ -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);
+ }
+}
diff --git a/src/main/java/net/minecraft/server/ItemInWorldManager.java b/src/main/java/net/minecraft/server/ItemInWorldManager.java
index 674f8ee9..e88f63c3 100644
--- a/src/main/java/net/minecraft/server/ItemInWorldManager.java
+++ b/src/main/java/net/minecraft/server/ItemInWorldManager.java
@@ -30,6 +30,12 @@ public class ItemInWorldManager {
this.world = world;
}
+ // CraftBukkit start - keep this for backwards compatibility
+ public ItemInWorldManager(WorldServer world) {
+ this.world = world;
+ }
+ // CraftBukkit end
+
public void a(int i) {
this.c = i;
if (i == 0) {
diff --git a/src/main/java/net/minecraft/server/ItemMobSpawner.java b/src/main/java/net/minecraft/server/ItemMobSpawner.java
new file mode 100644
index 00000000..e0c0e805
--- /dev/null
+++ b/src/main/java/net/minecraft/server/ItemMobSpawner.java
@@ -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;
+ }
+}
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
index eb4f2b30..65747732 100644
--- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java
@@ -5,7 +5,7 @@ public final class ItemStack {
public int count;
public int b;
public int id;
- public int damage; // CraftBukkit - private -> public
+ private int damage;
public ItemStack(Block block) {
this(block, 1);
@@ -35,7 +35,7 @@ public final class ItemStack {
this.count = 0;
this.id = i;
this.count = j;
- this.damage = k;
+ b(k); // CraftBukkit
}
public static ItemStack a(NBTTagCompound nbttagcompound) {
@@ -122,7 +122,7 @@ public final class ItemStack {
}
public void b(int i) {
- this.damage = i;
+ this.damage = (id > 0) && (id < 256) ? Item.byId[id].filterData(i) : i; // CraftBukkit
}
public int i() {
diff --git a/src/main/java/net/minecraft/server/TileEntityMobSpawner.java b/src/main/java/net/minecraft/server/TileEntityMobSpawner.java
index c40e65bd..acb0b64d 100644
--- a/src/main/java/net/minecraft/server/TileEntityMobSpawner.java
+++ b/src/main/java/net/minecraft/server/TileEntityMobSpawner.java
@@ -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;
}
+ // 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_() {
this.c = this.b;
if (this.a()) {
@@ -48,28 +59,30 @@ public class TileEntityMobSpawner extends TileEntity {
byte b0 = 4;
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;
}
- 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) {
this.c();
return;
}
- if (entityliving != null) {
+ if (entity != null) {
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 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);
- if (entityliving.d()) {
+ entity.setPositionRotation(d3, d4, d5, this.world.random.nextFloat() * 360.0F, 0.0F);
+ 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
- this.world.addEntity(entityliving, SpawnReason.SPAWNER);
+ this.world.addEntity(entity, SpawnReason.SPAWNER);
for (int k = 0; k < 20; ++k) {
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);
}
- entityliving.ab();
+ // entity.ab(); // CraftBukkit - client side code, and not available in entity
this.c();
}
}