Skip to content

Instantly share code, notes, and snippets.

@TheDiamondYT1
Created May 9, 2017 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheDiamondYT1/e998a5cc7413e7ac315f5f73e9459783 to your computer and use it in GitHub Desktop.
Save TheDiamondYT1/e998a5cc7413e7ac315f5f73e9459783 to your computer and use it in GitHub Desktop.
Minecraft BlockFire.java
/*******************************************************
* From bukkit/mc-dev.
*
* THIS CODE IS COPYRIGHT MOJANG AB.
*
* I have changed some function and method names to
* make it more readable.
*/
package net.minecraft.server;
import java.util.Random;
public class BlockFire extends Block {
private int[] a = new int[256];
private int[] b = new int[256];
protected BlockFire() {
super(Material.FIRE);
this.setTickRandomly(true);
}
/**
* Registers all blocks which can be caught on fire.
*/
public static void e() {
Blocks.FIRE.a(getId(Blocks.WOOD), 5, 20);
Blocks.FIRE.a(getId(Blocks.WOOD_DOUBLE_STEP), 5, 20);
Blocks.FIRE.a(getId(Blocks.WOOD_STEP), 5, 20);
Blocks.FIRE.a(getId(Blocks.FENCE), 5, 20);
Blocks.FIRE.a(getId(Blocks.WOOD_STAIRS), 5, 20);
Blocks.FIRE.a(getId(Blocks.BIRCH_WOOD_STAIRS), 5, 20);
Blocks.FIRE.a(getId(Blocks.SPRUCE_WOOD_STAIRS), 5, 20);
Blocks.FIRE.a(getId(Blocks.JUNGLE_WOOD_STAIRS), 5, 20);
Blocks.FIRE.a(getId(Blocks.LOG), 5, 5);
Blocks.FIRE.a(getId(Blocks.LOG2), 5, 5);
Blocks.FIRE.a(getId(Blocks.LEAVES), 30, 60);
Blocks.FIRE.a(getId(Blocks.LEAVES2), 30, 60);
Blocks.FIRE.a(getId(Blocks.BOOKSHELF), 30, 20);
Blocks.FIRE.a(getId(Blocks.TNT), 15, 100);
Blocks.FIRE.a(getId(Blocks.LONG_GRASS), 60, 100);
Blocks.FIRE.a(getId(Blocks.DOUBLE_PLANT), 60, 100);
Blocks.FIRE.a(getId(Blocks.YELLOW_FLOWER), 60, 100);
Blocks.FIRE.a(getId(Blocks.RED_ROSE), 60, 100);
Blocks.FIRE.a(getId(Blocks.WOOL), 30, 60);
Blocks.FIRE.a(getId(Blocks.VINE), 15, 100);
Blocks.FIRE.a(getId(Blocks.COAL_BLOCK), 5, 5);
Blocks.FIRE.a(getId(Blocks.HAY_BLOCK), 60, 20);
Blocks.FIRE.a(getId(Blocks.WOOL_CARPET), 60, 20);
}
/**
* @param int blockId
* @param int j
* @param int k
*/
public void a(int blockId, int j, int k) {
this.a[blockId] = j;
this.b[blockId] = k;
}
/**
* Returns the bounding box of the block.
*
* @param World world
* @param int x
* @param int y
* @param int z
*
* @return null
*/
public AxisAlignedBB getCollisionBoundingBox(World world, int x, int y, int z) {
return null;
}
/**
* Returns if the block is an opaque cube.
*
* @return false
*/
public boolean isOpaqueCube() {
return false;
}
/**
* Returns if the block is a full cube.
*
* @return false
*/
public boolean isFullCube() {
return false;
}
public int b() {
return 3;
}
/**
* Returns the amount of items to drop on destroy.
*
* @param Random random
*
* @return int
*/
public int quantityDropped(Random random) {
return 0;
}
/**
* How many world ticks before ticking.
*
* @return int
*/
public int tickRate(World world) {
return 30;
}
/**
* @param World world
* @param int x
* @param int y
* @param int z
* @param Random random
*/
public void updateTick(World world, int x, int y, int z, Random random) {
if (world.getGameRules().getBoolean("doFireTick")) {
boolean flag = world.getType(x, y - 1, z) == Blocks.NETHERRACK;
if (world.worldProvider instanceof WorldProviderTheEnd && world.getType(x, y - 1, z) == Blocks.BEDROCK) {
flag = true;
}
if (!this.canPlace(world, x, y, z)) {
world.setAir(x, y, z);
}
if (!flag && world.isRaining() && (world.isRainingAt(x, y, z) || world.isRainingAt(x - 1, y, z) || world.isRainingAt(x + 1, y, z) || world.isRainingAt(x, y, z - 1) || world.isRainingAt(x, y, z + 1))) {
world.setAir(x, y, z);
} else {
int data = world.getData(x, y, z);
if (data < 15) {
world.setData(x, y, z, data + random.nextInt(3) / 2, 4);
}
world.a(x, y, z, this, this.a(world) + random.nextInt(10));
if (!flag && !this.e(world, x, y, z)) {
if (!World.doesBlockHaveSolidTopSurface(world, x, y - 1, z) || data > 3) {
world.setAir(x, y, z);
}
} else if (!flag && !this.e(world, x, y - 1, z) && data == 15 && random.nextInt(4) == 0) {
world.setAir(x, y, z);
} else {
boolean flag1 = world.z(x, y, z);
byte b0 = 0;
if (flag1) {
b0 = -50;
}
this.a(world, x + 1, y, z, 300 + b0, random, data);
this.a(world, x - 1, y, z, 300 + b0, random, data);
this.a(world, x, y - 1, z, 250 + b0, random, data);
this.a(world, x, y + 1, z, 250 + b0, random, data);
this.a(world, x, y, z - 1, 300 + b0, random, data);
this.a(world, x, y, z + 1, 300 + b0, random, data);
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) {
int l1 = 100;
if (k1 > j + 1) {
l1 += (k1 - (j + 1)) * 100;
}
int i2 = this.m(world, i1, k1, j1);
if (i2 > 0) {
int j2 = (i2 + 40 + world.getDifficulty().getDifficultyId() * 7) / (data + 30);
if (flag1) {
j2 /= 2;
}
if (j2 > 0 && random.nextInt(l1) <= j2 && (!world.isRaining() || !world.isRainingAt(i1, k1, j1)) && !world.isRainingAt(i1 - 1, k1, z) && !world.isRainingAt(i1 + 1, k1, j1) && !world.isRainingAt(i1, k1, j1 - 1) && !world.isRainingAt(i1, k1, j1 + 1)) {
int k2 = l + random.nextInt(5) / 4;
if (k2 > 15) {
k2 = 15;
}
world.setTypeAndData(i1, k1, j1, this, k2, 3);
}
}
}
}
}
}
}
}
}
}
/**
* @return boolean
*/
public boolean requiresUpdates() {
return false;
}
/**
* @param World world
* @param int x
* @param int y
* @param int z
* @param Random random
* @param int i1
*/
private void a(World world, int x, int y, int z, int l, Random random, int i1) {
int j1 = this.b[Block.getId(world.getType(x, y, z))];
if (random.nextInt(l) < j1) {
boolean flag = world.getType(x, y, z) == Blocks.TNT;
if (random.nextInt(i1 + 10) < 5 && !world.isRainingAt(x, y, z)) {
int k1 = i1 + random.nextInt(5) / 4;
if (k1 > 15) {
k1 = 15;
}
world.setTypeAndData(x, y, z, this, k1, 3);
} else {
world.setAir(x, y, z);
}
if (flag) {
Blocks.TNT.onBlockDestroyedByPlayer(world, x, y, z, 1);
}
}
}
private boolean e(World world, int x, int y, int z) {
return this.e(world, x + 1, y, z) ? true : (this.e(world, x - 1, y, z) ? true : (this.e(world, x, y - 1, z) ? true : (this.e(world, x, y + 1, z) ? true : (this.e(world, x, y, z - 1) ? true : this.e(world, x, y, z + 1)))));
}
private int m(World world, int x, int y, int z) {
byte b0 = 0;
if (!world.isAirBlock(x, y, z)) {
return 0;
} else {
int l = this.a(world, x + 1, y, z, b0);
l = this.a(world, x - 1, y, z, l);
l = this.a(world, x, y - 1, z, l);
l = this.a(world, x, y + 1, z, l);
l = this.a(world, x, y, z - 1, l);
l = this.a(world, x, y, z + 1, l);
return l;
}
}
/**
* Returns if we can walk through the block.
*
* @return boolean
*/
public boolean isCollidable() {
return false;
}
public boolean e(IBlockAccess access, int x, int y, int z) {
return this.a[Block.getId(access.getType(x, y, z))] > 0;
}
public int a(World world, int x, int y, int z, int l) {
int i1 = this.a[Block.getId(world.getType(x, y, z))];
return i1 > l ? i1 : l;
}
/**
* Returns if we can place this block at a specific location.
*
* @param World world
* @param int x
* @param int y
* @param int z
*
* @return boolean
*/
public boolean canPlace(World world, int x, int y, int z) {
return World.doesBlockHaveTopSurface(world, x, y - 1, z) || this.e(world, x, y, z);
}
/**
* Called when physics is applied to the block (e.g. it falls).
*
* @param World world
* @param int x
* @param int y
* @param int z
* @param Block block
*/
public void doPhysics(World world, int x, int y, int z, Block block) {
if (!World.doesBlockHaveTopSurface(world, x, y - 1, z) && !this.e(world, x, y, z)) {
world.setAir(x, y, z);
}
}
/**
* Called when the block is placed.
*
* @param World world
* @param int x
* @param int y
* @param int z
*/
public void onPlace(World world, int x, int y, int z) {
if (world.worldProvider.getDimensionId() > 0 || !Blocks.PORTAL.e(world, x, y, z)) {
if (!World.doesBlockHaveTopSurface(world, x, y - 1, z) && !this.e(world, x, y, z)) {
world.setAir(x, y, z);
} else {
world.scheduleUpdate(x, y, z, this, this.a(world) + world.random.nextInt(10));
}
}
}
public MaterialMapColor f(int i) {
return MaterialMapColor.f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment