From 8d62de7055a8c901240412ac41f3cb5091ea41a9 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Tue, 6 Mar 2012 22:42:58 -0500 Subject: [PATCH] Added for diff visibility: - BlockBed - BlockDeadBush - BlockLongGrass - BlockVine --- .../java/net/minecraft/server/BlockBed.java | 201 ++++++++++++ .../net/minecraft/server/BlockDeadBush.java | 34 ++ .../net/minecraft/server/BlockLongGrass.java | 34 ++ .../java/net/minecraft/server/BlockVine.java | 294 ++++++++++++++++++ 4 files changed, 563 insertions(+) create mode 100644 src/main/java/net/minecraft/server/BlockBed.java create mode 100644 src/main/java/net/minecraft/server/BlockDeadBush.java create mode 100644 src/main/java/net/minecraft/server/BlockLongGrass.java create mode 100644 src/main/java/net/minecraft/server/BlockVine.java diff --git a/src/main/java/net/minecraft/server/BlockBed.java b/src/main/java/net/minecraft/server/BlockBed.java new file mode 100644 index 0000000000..68232ad830 --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockBed.java @@ -0,0 +1,201 @@ +package net.minecraft.server; + +import java.util.Iterator; +import java.util.Random; + +public class BlockBed extends BlockDirectional { + + public static final int[][] a = new int[][] { { 0, 1}, { -1, 0}, { 0, -1}, { 1, 0}}; + + public BlockBed(int i) { + super(i, 134, Material.CLOTH); + this.s(); + } + + public boolean interact(World world, int i, int j, int k, EntityHuman entityhuman) { + if (world.isStatic) { + return true; + } else { + int l = world.getData(i, j, k); + + if (!d(l)) { + int i1 = b(l); + + i += a[i1][0]; + k += a[i1][1]; + if (world.getTypeId(i, j, k) != this.id) { + return true; + } + + l = world.getData(i, j, k); + } + + if (!world.worldProvider.c()) { + double d0 = (double) i + 0.5D; + double d1 = (double) j + 0.5D; + double d2 = (double) k + 0.5D; + + world.setTypeId(i, j, k, 0); + int j1 = b(l); + + i += a[j1][0]; + k += a[j1][1]; + if (world.getTypeId(i, j, k) == this.id) { + world.setTypeId(i, j, k, 0); + d0 = (d0 + (double) i + 0.5D) / 2.0D; + d1 = (d1 + (double) j + 0.5D) / 2.0D; + d2 = (d2 + (double) k + 0.5D) / 2.0D; + } + + world.createExplosion((Entity) null, (double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), 5.0F, true); + return true; + } else { + if (e(l)) { + EntityHuman entityhuman1 = null; + Iterator iterator = world.players.iterator(); + + while (iterator.hasNext()) { + EntityHuman entityhuman2 = (EntityHuman) iterator.next(); + + if (entityhuman2.isSleeping()) { + ChunkCoordinates chunkcoordinates = entityhuman2.F; + + if (chunkcoordinates.x == i && chunkcoordinates.y == j && chunkcoordinates.z == k) { + entityhuman1 = entityhuman2; + } + } + } + + if (entityhuman1 != null) { + entityhuman.a("tile.bed.occupied"); + return true; + } + + a(world, i, j, k, false); + } + + EnumBedResult enumbedresult = entityhuman.a(i, j, k); + + if (enumbedresult == EnumBedResult.OK) { + a(world, i, j, k, true); + return true; + } else { + if (enumbedresult == EnumBedResult.NOT_POSSIBLE_NOW) { + entityhuman.a("tile.bed.noSleep"); + } else if (enumbedresult == EnumBedResult.NOT_SAFE) { + entityhuman.a("tile.bed.notSafe"); + } + + return true; + } + } + } + } + + public int a(int i, int j) { + if (i == 0) { + return Block.WOOD.textureId; + } else { + int k = b(j); + int l = Direction.h[k][i]; + + return d(j) ? (l == 2 ? this.textureId + 2 + 16 : (l != 5 && l != 4 ? this.textureId + 1 : this.textureId + 1 + 16)) : (l == 3 ? this.textureId - 1 + 16 : (l != 5 && l != 4 ? this.textureId : this.textureId + 16)); + } + } + + public int c() { + return 14; + } + + public boolean b() { + return false; + } + + public boolean a() { + return false; + } + + public void updateShape(IBlockAccess iblockaccess, int i, int j, int k) { + this.s(); + } + + public void doPhysics(World world, int i, int j, int k, int l) { + int i1 = world.getData(i, j, k); + int j1 = b(i1); + + if (d(i1)) { + if (world.getTypeId(i - a[j1][0], j, k - a[j1][1]) != this.id) { + world.setTypeId(i, j, k, 0); + } + } else if (world.getTypeId(i + a[j1][0], j, k + a[j1][1]) != this.id) { + world.setTypeId(i, j, k, 0); + if (!world.isStatic) { + this.b(world, i, j, k, i1, 0); + } + } + } + + public int getDropType(int i, Random random, int j) { + return d(i) ? 0 : Item.BED.id; + } + + private void s() { + this.a(0.0F, 0.0F, 0.0F, 1.0F, 0.5625F, 1.0F); + } + + public static boolean d(int i) { + return (i & 8) != 0; + } + + public static boolean e(int i) { + return (i & 4) != 0; + } + + public static void a(World world, int i, int j, int k, boolean flag) { + int l = world.getData(i, j, k); + + if (flag) { + l |= 4; + } else { + l &= -5; + } + + world.setData(i, j, k, l); + } + + public static ChunkCoordinates f(World world, int i, int j, int k, int l) { + int i1 = world.getData(i, j, k); + int j1 = BlockDirectional.b(i1); + + for (int k1 = 0; k1 <= 1; ++k1) { + int l1 = i - a[j1][0] * k1 - 1; + int i2 = k - a[j1][1] * k1 - 1; + int j2 = l1 + 2; + int k2 = i2 + 2; + + for (int l2 = l1; l2 <= j2; ++l2) { + for (int i3 = i2; i3 <= k2; ++i3) { + if (world.e(l2, j - 1, i3) && world.isEmpty(l2, j, i3) && world.isEmpty(l2, j + 1, i3)) { + if (l <= 0) { + return new ChunkCoordinates(l2, j, i3); + } + + --l; + } + } + } + } + + return null; + } + + public void dropNaturally(World world, int i, int j, int k, int l, float f, int i1) { + if (!d(l)) { + super.dropNaturally(world, i, j, k, l, f, 0); + } + } + + public int g() { + return 1; + } +} diff --git a/src/main/java/net/minecraft/server/BlockDeadBush.java b/src/main/java/net/minecraft/server/BlockDeadBush.java new file mode 100644 index 0000000000..d6e4597a55 --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockDeadBush.java @@ -0,0 +1,34 @@ +package net.minecraft.server; + +import java.util.Random; + +public class BlockDeadBush extends BlockFlower { + + protected BlockDeadBush(int i, int j) { + super(i, j, Material.REPLACEABLE_PLANT); + float f = 0.4F; + + this.a(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.8F, 0.5F + f); + } + + protected boolean d(int i) { + return i == Block.SAND.id; + } + + public int a(int i, int j) { + return this.textureId; + } + + public int getDropType(int i, Random random, int j) { + return -1; + } + + public void a(World world, EntityHuman entityhuman, int i, int j, int k, int l) { + if (!world.isStatic && entityhuman.T() != null && entityhuman.T().id == Item.SHEARS.id) { + entityhuman.a(StatisticList.C[this.id], 1); + this.a(world, i, j, k, new ItemStack(Block.DEAD_BUSH, 1, l)); + } else { + super.a(world, entityhuman, i, j, k, l); + } + } +} diff --git a/src/main/java/net/minecraft/server/BlockLongGrass.java b/src/main/java/net/minecraft/server/BlockLongGrass.java new file mode 100644 index 0000000000..2f192f54da --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockLongGrass.java @@ -0,0 +1,34 @@ +package net.minecraft.server; + +import java.util.Random; + +public class BlockLongGrass extends BlockFlower { + + protected BlockLongGrass(int i, int j) { + super(i, j, Material.REPLACEABLE_PLANT); + float f = 0.4F; + + this.a(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.8F, 0.5F + f); + } + + public int a(int i, int j) { + return j == 1 ? this.textureId : (j == 2 ? this.textureId + 16 + 1 : (j == 0 ? this.textureId + 16 : this.textureId)); + } + + public int getDropType(int i, Random random, int j) { + return random.nextInt(8) == 0 ? Item.SEEDS.id : -1; + } + + public int getDropCount(int i, Random random) { + return 1 + random.nextInt(i * 2 + 1); + } + + public void a(World world, EntityHuman entityhuman, int i, int j, int k, int l) { + if (!world.isStatic && entityhuman.T() != null && entityhuman.T().id == Item.SHEARS.id) { + entityhuman.a(StatisticList.C[this.id], 1); + this.a(world, i, j, k, new ItemStack(Block.LONG_GRASS, 1, l)); + } else { + super.a(world, entityhuman, i, j, k, l); + } + } +} diff --git a/src/main/java/net/minecraft/server/BlockVine.java b/src/main/java/net/minecraft/server/BlockVine.java new file mode 100644 index 0000000000..d6bda347c4 --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockVine.java @@ -0,0 +1,294 @@ +package net.minecraft.server; + +import java.util.Random; + +public class BlockVine extends Block { + + public BlockVine(int i) { + super(i, 143, Material.REPLACEABLE_PLANT); + this.a(true); + } + + public void f() { + this.a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + } + + public int c() { + return 20; + } + + public boolean a() { + return false; + } + + public boolean b() { + return false; + } + + public void updateShape(IBlockAccess iblockaccess, int i, int j, int k) { + int l = iblockaccess.getData(i, j, k); + float f = 1.0F; + float f1 = 1.0F; + float f2 = 1.0F; + float f3 = 0.0F; + float f4 = 0.0F; + float f5 = 0.0F; + boolean flag = l > 0; + + if ((l & 2) != 0) { + f3 = Math.max(f3, 0.0625F); + f = 0.0F; + f1 = 0.0F; + f4 = 1.0F; + f2 = 0.0F; + f5 = 1.0F; + flag = true; + } + + if ((l & 8) != 0) { + f = Math.min(f, 0.9375F); + f3 = 1.0F; + f1 = 0.0F; + f4 = 1.0F; + f2 = 0.0F; + f5 = 1.0F; + flag = true; + } + + if ((l & 4) != 0) { + f5 = Math.max(f5, 0.0625F); + f2 = 0.0F; + f = 0.0F; + f3 = 1.0F; + f1 = 0.0F; + f4 = 1.0F; + flag = true; + } + + if ((l & 1) != 0) { + f2 = Math.min(f2, 0.9375F); + f5 = 1.0F; + f = 0.0F; + f3 = 1.0F; + f1 = 0.0F; + f4 = 1.0F; + flag = true; + } + + if (!flag && this.d(iblockaccess.getTypeId(i, j + 1, k))) { + f1 = Math.min(f1, 0.9375F); + f4 = 1.0F; + f = 0.0F; + f3 = 1.0F; + f2 = 0.0F; + f5 = 1.0F; + } + + this.a(f, f1, f2, f3, f4, f5); + } + + public AxisAlignedBB e(World world, int i, int j, int k) { + return null; + } + + public boolean canPlace(World world, int i, int j, int k, int l) { + switch (l) { + case 1: + return this.d(world.getTypeId(i, j + 1, k)); + + case 2: + return this.d(world.getTypeId(i, j, k + 1)); + + case 3: + return this.d(world.getTypeId(i, j, k - 1)); + + case 4: + return this.d(world.getTypeId(i + 1, j, k)); + + case 5: + return this.d(world.getTypeId(i - 1, j, k)); + + default: + return false; + } + } + + private boolean d(int i) { + if (i == 0) { + return false; + } else { + Block block = Block.byId[i]; + + return block.b() && block.material.isSolid(); + } + } + + private boolean g(World world, int i, int j, int k) { + int l = world.getData(i, j, k); + int i1 = l; + + if (l > 0) { + for (int j1 = 0; j1 <= 3; ++j1) { + int k1 = 1 << j1; + + if ((l & k1) != 0 && !this.d(world.getTypeId(i + Direction.a[j1], j, k + Direction.b[j1])) && (world.getTypeId(i, j + 1, k) != this.id || (world.getData(i, j + 1, k) & k1) == 0)) { + i1 &= ~k1; + } + } + } + + if (i1 == 0 && !this.d(world.getTypeId(i, j + 1, k))) { + return false; + } else { + if (i1 != l) { + world.setData(i, j, k, i1); + } + + return true; + } + } + + public void doPhysics(World world, int i, int j, int k, int l) { + if (!world.isStatic && !this.g(world, i, j, k)) { + this.b(world, i, j, k, world.getData(i, j, k), 0); + world.setTypeId(i, j, k, 0); + } + } + + public void a(World world, int i, int j, int k, Random random) { + if (!world.isStatic && world.random.nextInt(4) == 0) { + byte b0 = 4; + int l = 5; + boolean flag = false; + + int i1; + int j1; + int k1; + + label138: + for (i1 = i - b0; i1 <= i + b0; ++i1) { + for (j1 = k - b0; j1 <= k + b0; ++j1) { + for (k1 = j - 1; k1 <= j + 1; ++k1) { + if (world.getTypeId(i1, k1, j1) == this.id) { + --l; + if (l <= 0) { + flag = true; + break label138; + } + } + } + } + } + + i1 = world.getData(i, j, k); + j1 = world.random.nextInt(6); + k1 = Direction.d[j1]; + int l1; + int i2; + + if (j1 == 1 && j < 255 && world.isEmpty(i, j + 1, k)) { + if (flag) { + return; + } + + l1 = world.random.nextInt(16) & i1; + if (l1 > 0) { + for (i2 = 0; i2 <= 3; ++i2) { + if (!this.d(world.getTypeId(i + Direction.a[i2], j + 1, k + Direction.b[i2]))) { + l1 &= ~(1 << i2); + } + } + + if (l1 > 0) { + world.setTypeIdAndData(i, j + 1, k, this.id, l1); + } + } + } else { + int j2; + + if (j1 >= 2 && j1 <= 5 && (i1 & 1 << k1) == 0) { + if (flag) { + return; + } + + l1 = world.getTypeId(i + Direction.a[k1], j, k + Direction.b[k1]); + if (l1 != 0 && Block.byId[l1] != null) { + if (Block.byId[l1].material.j() && Block.byId[l1].b()) { + world.setData(i, j, k, i1 | 1 << k1); + } + } else { + i2 = k1 + 1 & 3; + j2 = k1 + 3 & 3; + if ((i1 & 1 << i2) != 0 && this.d(world.getTypeId(i + Direction.a[k1] + Direction.a[i2], j, k + Direction.b[k1] + Direction.b[i2]))) { + world.setTypeIdAndData(i + Direction.a[k1], j, k + Direction.b[k1], this.id, 1 << i2); + } else if ((i1 & 1 << j2) != 0 && this.d(world.getTypeId(i + Direction.a[k1] + Direction.a[j2], j, k + Direction.b[k1] + Direction.b[j2]))) { + world.setTypeIdAndData(i + Direction.a[k1], j, k + Direction.b[k1], this.id, 1 << j2); + } else if ((i1 & 1 << i2) != 0 && world.isEmpty(i + Direction.a[k1] + Direction.a[i2], j, k + Direction.b[k1] + Direction.b[i2]) && this.d(world.getTypeId(i + Direction.a[i2], j, k + Direction.b[i2]))) { + world.setTypeIdAndData(i + Direction.a[k1] + Direction.a[i2], j, k + Direction.b[k1] + Direction.b[i2], this.id, 1 << (k1 + 2 & 3)); + } else if ((i1 & 1 << j2) != 0 && world.isEmpty(i + Direction.a[k1] + Direction.a[j2], j, k + Direction.b[k1] + Direction.b[j2]) && this.d(world.getTypeId(i + Direction.a[j2], j, k + Direction.b[j2]))) { + world.setTypeIdAndData(i + Direction.a[k1] + Direction.a[j2], j, k + Direction.b[k1] + Direction.b[j2], this.id, 1 << (k1 + 2 & 3)); + } else if (this.d(world.getTypeId(i + Direction.a[k1], j + 1, k + Direction.b[k1]))) { + world.setTypeIdAndData(i + Direction.a[k1], j, k + Direction.b[k1], this.id, 0); + } + } + } else if (j > 1) { + l1 = world.getTypeId(i, j - 1, k); + if (l1 == 0) { + i2 = world.random.nextInt(16) & i1; + if (i2 > 0) { + world.setTypeIdAndData(i, j - 1, k, this.id, i2); + } + } else if (l1 == this.id) { + i2 = world.random.nextInt(16) & i1; + j2 = world.getData(i, j - 1, k); + if (j2 != (j2 | i2)) { + world.setData(i, j - 1, k, j2 | i2); + } + } + } + } + } + } + + public void postPlace(World world, int i, int j, int k, int l) { + byte b0 = 0; + + switch (l) { + case 2: + b0 = 1; + break; + + case 3: + b0 = 4; + break; + + case 4: + b0 = 8; + break; + + case 5: + b0 = 2; + } + + if (b0 != 0) { + world.setData(i, j, k, b0); + } + } + + public int getDropType(int i, Random random, int j) { + return 0; + } + + public int a(Random random) { + return 0; + } + + public void a(World world, EntityHuman entityhuman, int i, int j, int k, int l) { + if (!world.isStatic && entityhuman.T() != null && entityhuman.T().id == Item.SHEARS.id) { + entityhuman.a(StatisticList.C[this.id], 1); + this.a(world, i, j, k, new ItemStack(Block.VINE, 1, 0)); + } else { + super.a(world, entityhuman, i, j, k, l); + } + } +}