From 802a46a7097354fe40a6502edc5357e105e84fc3 Mon Sep 17 00:00:00 2001 From: speakeasy Date: Tue, 11 Jan 2011 05:07:56 +0800 Subject: [PATCH] Added hooks for BlockIgniteEvent Signed-off-by: speakeasy --- .../java/net/minecraft/server/BlockFire.java | 212 ++++++++++++++++++ .../net/minecraft/server/BlockStationary.java | 72 ++++++ .../minecraft/server/ItemFlintAndSteel_1.java | 70 ++++++ 3 files changed, 354 insertions(+) create mode 100644 src/main/java/net/minecraft/server/BlockFire.java create mode 100644 src/main/java/net/minecraft/server/BlockStationary.java create mode 100644 src/main/java/net/minecraft/server/ItemFlintAndSteel_1.java diff --git a/src/main/java/net/minecraft/server/BlockFire.java b/src/main/java/net/minecraft/server/BlockFire.java new file mode 100644 index 0000000000..a0871334d9 --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockFire.java @@ -0,0 +1,212 @@ +package net.minecraft.server; + +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.CraftWorld; +import java.util.Random; + + +public class BlockFire extends Block { + + private int a[]; + private int b[]; + + protected BlockFire(int i, int j) { + super(i, j, Material.l); + a = new int[256]; + b = new int[256]; + a(Block.x.bh, 5, 20); + a(Block.J.bh, 5, 5); + a(Block.K.bh, 30, 60); + a(Block.an.bh, 30, 20); + a(Block.am.bh, 15, 100); + a(Block.ab.bh, 30, 60); + a(true); + } + + private void a(int i, int j, int k) { + a[i] = j; + b[i] = k; + } + + public AxisAlignedBB d(World world, int i, int j, int k) { + return null; + } + + public boolean a() { + return false; + } + + public int a(Random random) { + return 0; + } + + public int b() { + return 10; + } + + @Override + public void a(World world, int i, int j, int k, Random random) { + boolean flag = world.a(i, j - 1, k) == Block.bb.bh; + int ll = world.b(i, j, k); + + if (ll < 15) { + world.b(i, j, k, ll + 1); + world.h(i, j, k, bh); + } + if (!flag && !g(world, i, j, k)) { + if (!world.d(i, j - 1, k) || ll > 3) { + world.d(i, j, k, 0); + } + return; + } + // CraftBukkit: Cast to fix compile errors. + if ((i == 0) && (!b((IBlockAccess)world, i, j - 1, k)) && ll == 15 && (random.nextInt(4) == 0)) { + world.d(i, j, k, 0); + return; + } + if (ll % 2 == 0 && ll > 2) { + a(world, i + 1, j, k, 300, random); + a(world, i - 1, j, k, 300, random); + a(world, i, j - 1, k, 250, random); + a(world, i, j + 1, k, 250, random); + a(world, i, j, k - 1, 300, random); + a(world, i, j, k + 1, 300, random); + for (int i1 = i - 1; i1 <= i + 1; i1++) { + for (int j1 = k - 1; j1 <= k + 1; j1++) { + for (int k1 = j - 1; k1 <= j + 4; k1++) { + if (i1 == i && k1 == j && j1 == k) { + continue; + } + int l1 = 100; + + if (k1 > j + 1) { + l1 += (k1 - (j + 1)) * 100; + } + int i2 = h(world, i1, k1, j1); + + // CraftBukkit: Call to stop spead of fire. + CraftServer server = ((WorldServer)world).getServer(); + CraftWorld cworld = ((WorldServer) world).getWorld(); + org.bukkit.Block bblock = (cworld.getBlockAt(i1, k1, j1)); + BlockIgniteEvent event = new BlockIgniteEvent((org.bukkit.Block) bblock, BlockIgniteEvent.IgniteCause.SPREAD, null); + server.getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + if (i2 > 0 && random.nextInt(l1) <= i2) { + world.d(i1, k1, j1, bh); + } + } + } + } + } + } + + private void a(World world, int i, int j, int k, int l, Random random) { + int i1 = b[world.a(i, j, k)]; + + if (random.nextInt(l) < i1) { + boolean flag = world.a(i, j, k) == Block.am.bh ? true : false; + + if (random.nextInt(2) == 0) { + // CraftBukkit: Call to stop very slow spread of fire. + CraftServer server = ((WorldServer)world).getServer(); + CraftWorld cworld = ((WorldServer)world).getWorld(); + org.bukkit.Block sbblock = (cworld.getBlockAt(i, j, k)); + BlockIgniteEvent event = new BlockIgniteEvent((org.bukkit.Block) sbblock, BlockIgniteEvent.IgniteCause.SLOW_SPREAD, null); + server.getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + world.d(i, j, k, bh); + } else { + world.d(i, j, k, 0); + } + if (flag) { + Block.am.a(world, i, j, k, 0); + } + } + } + + private boolean g(World world, int i, int j, int k) { + // CraftBukkit: Cast to correct compile errors 6 times. + if (b((IBlockAccess)world, i + 1, j, k)) { + return true; + } + if (b((IBlockAccess)world, i - 1, j, k)) { + return true; + } + if (b((IBlockAccess)world, i, j - 1, k)) { + return true; + } + if (b((IBlockAccess)world, i, j + 1, k)) { + return true; + } + if (b((IBlockAccess)world, i, j, k - 1)) { + return true; + } + return b((IBlockAccess)world, i, j, k + 1); + } + + private int h(World world, int i, int j, int k) { + int l = 0; + + if (!world.e(i, j, k)) { + return 0; + } else { + l = f(world, i + 1, j, k, l); + l = f(world, i - 1, j, k, l); + l = f(world, i, j - 1, k, l); + l = f(world, i, j + 1, k, l); + l = f(world, i, j, k - 1, l); + l = f(world, i, j, k + 1, l); + return l; + } + } + + public boolean d() { + return false; + } + + public boolean b(IBlockAccess iblockaccess, int i, int j, int k) { + return a[iblockaccess.a(i, j, k)] > 0; + } + + public int f(World world, int i, int j, int k, int l) { + int i1 = a[world.a(i, j, k)]; + + if (i1 > l) { + return i1; + } else { + return l; + } + } + + public boolean a(World world, int i, int j, int k) { + return world.d(i, j - 1, k) || g(world, i, j, k); + } + + public void b(World world, int i, int j, int k, int l) { + if (!world.d(i, j - 1, k) && !g(world, i, j, k)) { + world.d(i, j, k, 0); + return; + } else { + return; + } + } + + public void e(World world, int i, int j, int k) { + if (world.a(i, j - 1, k) == Block.ap.bh && Block.be.a_(world, i, j, k)) { + return; + } + if (!world.d(i, j - 1, k) && !g(world, i, j, k)) { + world.d(i, j, k, 0); + return; + } else { + world.h(i, j, k, bh); + return; + } + } +} + diff --git a/src/main/java/net/minecraft/server/BlockStationary.java b/src/main/java/net/minecraft/server/BlockStationary.java new file mode 100644 index 0000000000..452449aac0 --- /dev/null +++ b/src/main/java/net/minecraft/server/BlockStationary.java @@ -0,0 +1,72 @@ +package net.minecraft.server; + +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.CraftWorld; +import java.util.Random; + +public class BlockStationary extends BlockFluids { + + protected BlockStationary(int k, Material material) { + super(k, material); + a(false); + if (material == Material.g) { + a(true); + } + } + + public void b(World world, int k, int l, int i1, int j1) { + super.b(world, k, l, i1, j1); + if (world.a(k, l, i1) == bh) { + i(world, k, l, i1); + } + } + + private void i(World world, int k, int l, int i1) { + int j1 = world.b(k, l, i1); + + world.i = true; + world.a(k, l, i1, bh - 1, j1); + world.b(k, l, i1, k, l, i1); + world.h(k, l, i1, bh - 1); + world.i = false; + } + + @Override + public void a(World world, int k, int l, int i1, Random random) { + if (bs == Material.g) { + int j1 = random.nextInt(3); + // CraftBukkit: prevent lava putting something on fire. + CraftServer server = ((WorldServer)world).getServer(); + CraftWorld cworld = ((WorldServer)world).getWorld(); + org.bukkit.Block bblock = (cworld.getBlockAt(k, l, i1)); + BlockIgniteEvent event = new BlockIgniteEvent((org.bukkit.Block) bblock, BlockIgniteEvent.IgniteCause.LAVA, null); + server.getPluginManager().callEvent(event); + if (event.isCancelled()) { + ; + } else { + for (int k1 = 0; k1 < j1; k1++) { + k += random.nextInt(3) - 1; + l++; + i1 += random.nextInt(3) - 1; + int l1 = world.a(k, l, i1); + + if (l1 == 0) { + if (j(world, k - 1, l, i1) || j(world, k + 1, l, i1) || j(world, k, l, i1 - 1) || j(world, k, l, i1 + 1) || j(world, k, l - 1, i1) || j(world, k, l + 1, i1)) { + world.d(k, l, i1, Block.ar.bh); + return; + } + continue; + } + if (Block.m[l1].bs.c()) { + return; + } + } + } + } + } + + private boolean j(World world, int k, int l, int i1) { + return world.c(k, l, i1).e(); + } +} diff --git a/src/main/java/net/minecraft/server/ItemFlintAndSteel_1.java b/src/main/java/net/minecraft/server/ItemFlintAndSteel_1.java new file mode 100644 index 0000000000..ab017d6851 --- /dev/null +++ b/src/main/java/net/minecraft/server/ItemFlintAndSteel_1.java @@ -0,0 +1,70 @@ +package net.minecraft.server; + +import org.bukkit.craftbukkit.CraftBlock; +import org.bukkit.craftbukkit.CraftItemStack; +import org.bukkit.craftbukkit.CraftPlayer; +import org.bukkit.event.Event.Type; +import org.bukkit.event.player.PlayerItemEvent; +import org.bukkit.event.block.BlockIgniteEvent; + + +public class ItemFlintAndSteel_1 extends Item { + + public ItemFlintAndSteel_1(int i) { + super(i); + aX = 1; + aY = 64; + } + + public boolean a(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) { + // Craftbukkit start - get the clicked block + CraftBlock blockClicked = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k); + + if (l == 0) { + j--; + } + if (l == 1) { + j++; + } + if (l == 2) { + k--; + } + if (l == 3) { + k++; + } + if (l == 4) { + i--; + } + if (l == 5) { + i++; + } + int i1 = world.a(i, j, k); + + if (i1 == 0) { + // Craftbukkit start + // Flint and steel + + CraftItemStack itemInHand = new CraftItemStack(itemstack); + CraftPlayer thePlayer = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, thePlayer, itemInHand, blockClicked, CraftBlock.notchToBlockFace(l)); + ((WorldServer) world).getServer().getPluginManager().callEvent(pie); + + org.bukkit.Block pblock = (((WorldServer) world).getWorld().getBlockAt(i, j, k)); + BlockIgniteEvent bie = new BlockIgniteEvent((org.bukkit.Block) pblock, BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL, thePlayer); + ((WorldServer) world).getServer().getPluginManager().callEvent(bie); + + boolean preventLighter = pie.isCancelled(); + boolean preventFire = bie.isCancelled(); + + if (preventLighter || preventFire) { + return false; + } else { + world.a((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D, "fire.ignite", 1.0F, b.nextFloat() * 0.4F + 0.8F); + world.d(i, j, k, Block.ar.bh); + } + } + itemstack.b(1); + return true; + } +} +