2011-01-12 18:40:42 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
import java.util.ArrayList;
|
2012-07-29 09:33:13 +02:00
|
|
|
import java.util.HashMap;
|
2011-01-29 22:50:29 +01:00
|
|
|
import java.util.List;
|
2012-07-29 09:33:13 +02:00
|
|
|
import java.util.Map;
|
2011-01-29 22:50:29 +01:00
|
|
|
import java.util.Random;
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit
|
2011-01-12 18:40:42 +01:00
|
|
|
|
|
|
|
public class BlockRedstoneTorch extends BlockTorch {
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
private boolean isOn;
|
2012-07-29 09:33:13 +02:00
|
|
|
private static Map b = new HashMap();
|
2011-01-12 18:40:42 +01:00
|
|
|
|
|
|
|
private boolean a(World world, int i, int j, int k, boolean flag) {
|
2012-07-29 09:33:13 +02:00
|
|
|
if (!b.containsKey(world)) {
|
|
|
|
b.put(world, new ArrayList());
|
|
|
|
}
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
List list = (List) b.get(world);
|
|
|
|
|
2011-01-12 18:40:42 +01:00
|
|
|
if (flag) {
|
2012-11-06 13:05:28 +01:00
|
|
|
list.add(new RedstoneUpdateInfo(i, j, k, world.getTime()));
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-01-12 18:40:42 +01:00
|
|
|
int l = 0;
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
for (int i1 = 0; i1 < list.size(); ++i1) {
|
|
|
|
RedstoneUpdateInfo redstoneupdateinfo = (RedstoneUpdateInfo) list.get(i1);
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (redstoneupdateinfo.a == i && redstoneupdateinfo.b == j && redstoneupdateinfo.c == k) {
|
|
|
|
++l;
|
|
|
|
if (l >= 8) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected BlockRedstoneTorch(boolean flag) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.isOn = flag;
|
2013-11-04 14:07:38 +01:00
|
|
|
this.a(true);
|
2012-07-29 09:33:13 +02:00
|
|
|
this.a((CreativeModeTab) null);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public int a(World world) {
|
2011-01-12 18:40:42 +01:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
public void onPlace(World world, int i, int j, int k) {
|
2011-01-29 22:50:29 +01:00
|
|
|
if (world.getData(i, j, k) == 0) {
|
2011-11-30 00:17:43 +01:00
|
|
|
super.onPlace(world, i, j, k);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2012-01-25 05:09:01 +01:00
|
|
|
|
2012-01-28 07:59:59 +01:00
|
|
|
if (this.isOn) {
|
2013-11-04 14:07:38 +01:00
|
|
|
world.applyPhysics(i, j - 1, k, this);
|
|
|
|
world.applyPhysics(i, j + 1, k, this);
|
|
|
|
world.applyPhysics(i - 1, j, k, this);
|
|
|
|
world.applyPhysics(i + 1, j, k, this);
|
|
|
|
world.applyPhysics(i, j, k - 1, this);
|
|
|
|
world.applyPhysics(i, j, k + 1, this);
|
2012-01-28 07:59:59 +01:00
|
|
|
}
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void remove(World world, int i, int j, int k, Block block, int l) {
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.isOn) {
|
2013-11-04 14:07:38 +01:00
|
|
|
world.applyPhysics(i, j - 1, k, this);
|
|
|
|
world.applyPhysics(i, j + 1, k, this);
|
|
|
|
world.applyPhysics(i - 1, j, k, this);
|
|
|
|
world.applyPhysics(i + 1, j, k, this);
|
|
|
|
world.applyPhysics(i, j, k - 1, this);
|
|
|
|
world.applyPhysics(i, j, k + 1, this);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public int b(IBlockAccess iblockaccess, int i, int j, int k, int l) {
|
2011-04-20 19:05:14 +02:00
|
|
|
if (!this.isOn) {
|
2013-03-13 23:33:27 +01:00
|
|
|
return 0;
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
|
|
|
int i1 = iblockaccess.getData(i, j, k);
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
return i1 == 5 && l == 1 ? 0 : (i1 == 3 && l == 3 ? 0 : (i1 == 4 && l == 2 ? 0 : (i1 == 1 && l == 5 ? 0 : (i1 == 2 && l == 4 ? 0 : 15))));
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
private boolean m(World world, int i, int j, int k) {
|
2011-01-29 22:50:29 +01:00
|
|
|
int l = world.getData(i, j, k);
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
return l == 5 && world.isBlockFacePowered(i, j - 1, k, 0) ? true : (l == 3 && world.isBlockFacePowered(i, j, k - 1, 2) ? true : (l == 4 && world.isBlockFacePowered(i, j, k + 1, 3) ? true : (l == 1 && world.isBlockFacePowered(i - 1, j, k, 4) ? true : l == 2 && world.isBlockFacePowered(i + 1, j, k, 5))));
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void a(World world, int i, int j, int k, Random random) {
|
|
|
|
boolean flag = this.m(world, i, j, k);
|
2012-07-29 09:33:13 +02:00
|
|
|
List list = (List) b.get(world);
|
2011-01-12 18:40:42 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
while (list != null && !list.isEmpty() && world.getTime() - ((RedstoneUpdateInfo) list.get(0)).d > 60L) {
|
|
|
|
list.remove(0);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-02-23 13:56:36 +01:00
|
|
|
// CraftBukkit start
|
2011-06-27 00:25:01 +02:00
|
|
|
org.bukkit.plugin.PluginManager manager = world.getServer().getPluginManager();
|
|
|
|
org.bukkit.block.Block block = world.getWorld().getBlockAt(i, j, k);
|
2011-04-20 19:05:14 +02:00
|
|
|
int oldCurrent = this.isOn ? 15 : 0;
|
2011-06-27 00:25:01 +02:00
|
|
|
|
2011-03-16 21:02:02 +01:00
|
|
|
BlockRedstoneEvent event = new BlockRedstoneEvent(block, oldCurrent, oldCurrent);
|
2011-02-23 13:56:36 +01:00
|
|
|
// CraftBukkit end
|
2011-01-14 14:31:10 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.isOn) {
|
2011-01-12 18:40:42 +01:00
|
|
|
if (flag) {
|
2011-03-16 21:02:02 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
if (oldCurrent != 0) {
|
|
|
|
event.setNewCurrent(0);
|
2011-06-27 00:25:01 +02:00
|
|
|
manager.callEvent(event);
|
2011-03-16 21:02:02 +01:00
|
|
|
if (event.getNewCurrent() != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-05-14 16:29:42 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
world.setTypeAndData(i, j, k, Blocks.REDSTONE_TORCH_OFF, world.getData(i, j, k), 3);
|
2011-01-29 22:50:29 +01:00
|
|
|
if (this.a(world, i, j, k, true)) {
|
2011-04-20 19:05:14 +02:00
|
|
|
world.makeSound((double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), "random.fizz", 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
for (int l = 0; l < 5; ++l) {
|
|
|
|
double d0 = (double) i + random.nextDouble() * 0.6D + 0.2D;
|
|
|
|
double d1 = (double) j + random.nextDouble() * 0.6D + 0.2D;
|
|
|
|
double d2 = (double) k + random.nextDouble() * 0.6D + 0.2D;
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
world.addParticle("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
} else if (!flag && !this.a(world, i, j, k, false)) {
|
2011-03-16 21:02:02 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
if (oldCurrent != 15) {
|
|
|
|
event.setNewCurrent(15);
|
2011-06-27 00:25:01 +02:00
|
|
|
manager.callEvent(event);
|
2011-03-16 21:02:02 +01:00
|
|
|
if (event.getNewCurrent() != 15) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-05-14 16:29:42 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
world.setTypeAndData(i, j, k, Blocks.REDSTONE_TORCH_ON, world.getData(i, j, k), 3);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void doPhysics(World world, int i, int j, int k, Block block) {
|
|
|
|
if (!this.b(world, i, j, k, block)) {
|
2013-03-13 23:33:27 +01:00
|
|
|
boolean flag = this.m(world, i, j, k);
|
|
|
|
|
|
|
|
if (this.isOn && flag || !this.isOn && !flag) {
|
2013-11-04 14:07:38 +01:00
|
|
|
world.a(i, j, k, this, this.a(world));
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public int c(IBlockAccess iblockaccess, int i, int j, int k, int l) {
|
|
|
|
return l == 0 ? this.b(iblockaccess, i, j, k, l) : 0;
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public Item getDropType(int i, Random random, int j) {
|
|
|
|
return Item.getItemOf(Blocks.REDSTONE_TORCH_ON);
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public boolean isPowerSource() {
|
2011-01-12 18:40:42 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public boolean c(Block block) {
|
|
|
|
return block == Blocks.REDSTONE_TORCH_OFF || block == Blocks.REDSTONE_TORCH_ON;
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
2011-01-12 18:40:42 +01:00
|
|
|
}
|