Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package refugeecraft.blocks;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import net.minecraft.block.BlockFire;
- import net.minecraft.client.renderer.texture.IIconRegister;
- import refugeecraft.lib.References;
- /**
- * Created by OUGHT on 21.06.2014.
- */
- public class BlockRMFire extends BlockFire
- {
- public BlockRMFire()
- {
- super();
- }
- @Override
- public String getUnlocalizedName()
- {
- return String.format("tile.%s%s", References.RESOURCESPREFIX,
- getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
- }
- public String getUnwrappedUnlocalizedName(String unlocalizedName)
- {
- return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
- }
- @Override
- @SideOnly (Side.CLIENT)
- public void registerBlockIcons(IIconRegister iconRegister)
- {
- this.blockIcon = iconRegister.registerIcon(References.RESOURCESPREFIX +
- getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
- }
- }
- package refugeecraft.blocks;
- import com.google.common.collect.Maps;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.MapColor;
- import net.minecraft.client.renderer.texture.IIconRegister;
- import net.minecraft.init.Blocks;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.util.IIcon;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraftforge.common.util.ForgeDirection;
- import refugeecraft.RefugeeCraft;
- import refugeecraft.lib.Strings;
- import java.util.IdentityHashMap;
- import java.util.Map;
- import java.util.Random;
- /**
- * Created by OUGHT on 21.06.2014.
- */
- public class BlockRadioactiveFire extends BlockRMFire
- {
- @Deprecated
- private int[] field_149849_a = new int[4096];
- @Deprecated
- private int[] field_149848_b = new int[4096];
- @SideOnly (Side.CLIENT)
- private IIcon[] icons;
- public BlockRadioactiveFire ()
- {
- super();
- this.setBlockName(Strings.RadioactiveFireName);
- this.setCreativeTab(RefugeeCraft.getCreativeTab());
- this.setLightLevel(1F);
- this.setTickRandomly(true);
- this.setHardness(0.0F);
- this.disableStats();
- RModBlocks.register(this);
- }
- @SideOnly (Side.CLIENT)
- @Override
- public void registerBlockIcons (IIconRegister iconRegister)
- {
- super.registerBlockIcons(iconRegister);
- this.icons = new IIcon[]
- {iconRegister.registerIcon(
- getUnwrappedUnlocalizedName(super.getUnlocalizedName()) + "_layer_0"),
- iconRegister.registerIcon(
- getUnwrappedUnlocalizedName(super.getUnlocalizedName()) + "_layer_1")};
- }
- @SideOnly (Side.CLIENT)
- @Override
- public IIcon getFireIcon (int i)
- {
- return this.icons[i];
- }
- /**
- * Gets the block's texture. Args: side, meta
- */
- @SideOnly(Side.CLIENT)
- @Override
- public IIcon getIcon(int p_149691_1_, int p_149691_2_)
- {
- return this.icons[0];
- }
- @Override
- public MapColor getMapColor(int p_149728_1_)
- {
- return MapColor.greenColor;
- }
- /**
- * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
- * cleared to be reused)
- */
- @Override
- public AxisAlignedBB getCollisionBoundingBoxFromPool (World p_149668_1_, int p_149668_2_, int p_149668_3_,
- int p_149668_4_)
- {
- return null;
- }
- /**
- * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
- * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
- */
- @Override
- public boolean isOpaqueCube ()
- {
- return false;
- }
- /**
- * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
- */
- public boolean renderAsNormalBlock ()
- {
- return false;
- }
- /**
- * The type of render function that is called for this block
- * 3 is Fire
- */
- public int getRenderType()
- {
- return 3;
- }
- /**
- * Returns the quantity of items to drop on block destruction.
- */
- public int quantityDropped (Random p_149745_1_)
- {
- return 0;
- }
- /**
- * How many world ticks before ticking
- */
- public int tickRate (World p_149738_1_)
- {
- return 10;
- }
- /**
- * Что-то странное
- * Возвращает у блока 1, а у огня 0
- */
- @Override
- public boolean func_149698_L ()
- {
- return true;
- }
- /**
- * Tries to set block on fire.
- */
- private void tryCatchFire (World world, int x, int y, int z, int flameHumidity,
- Random random, int flameLimitMetadata, ForgeDirection face)
- {
- int j1 = world.getBlock(x, y, z).getFlammability(world, x, y, z, face);
- if (random.nextInt(flameHumidity) < j1)
- {
- boolean isTNT = world.getBlock(x, y, z) == Blocks.tnt;
- if (random.nextInt(flameLimitMetadata + 10) < 5 && !world
- .canLightningStrikeAt(x, y, z)) // не под дождем ли блок
- {
- int metadata = flameLimitMetadata + random.nextInt(5) / 4;
- if (metadata > 15)
- {
- metadata = 15;
- }
- world.setBlock(x, y, z, this, metadata, 3);
- }
- else
- {
- world.setBlockToAir(x, y, z);
- }
- if (isTNT)
- {
- Blocks.tnt.onBlockDestroyedByPlayer(world, x, y, z, 1);
- }
- }
- }
- /**
- * Returns true if at least one block next to this one can burn.
- */
- private boolean canNeighborBurn (World world, int x, int y, int z)
- {
- return this.canCatchFire(world, x + 1, y, z, ForgeDirection.WEST) ||
- this.canCatchFire(world, x - 1, y, z, ForgeDirection.EAST) ||
- this.canCatchFire(world, x, y - 1, z, ForgeDirection.UP) ||
- this.canCatchFire(world, x, y + 1, z, ForgeDirection.DOWN) ||
- this.canCatchFire(world, x, y, z - 1, ForgeDirection.SOUTH) ||
- this.canCatchFire(world, x, y, z + 1, ForgeDirection.NORTH);
- }
- /**
- * Gets the highest chance of a neighbor block encouraging this block to catch fire
- */
- private int getChanceOfNeighborsEncouragingFire (World world, int x, int y, int z)
- {
- byte byte0 = 0;
- if (!world.isAirBlock(x, y, z))
- {
- return 0;
- }
- else
- {
- int chance = byte0;
- chance = this.getChanceToEncourageFire(world, x + 1, y, z, chance, ForgeDirection.WEST);
- chance = this.getChanceToEncourageFire(world, x - 1, y, z, chance, ForgeDirection.EAST);
- chance = this.getChanceToEncourageFire(world, x, y - 1, z, chance, ForgeDirection.UP);
- chance = this.getChanceToEncourageFire(world, x, y + 1, z, chance, ForgeDirection.DOWN);
- chance = this.getChanceToEncourageFire(world, x, y, z - 1, chance, ForgeDirection.SOUTH);
- chance = this.getChanceToEncourageFire(world, x, y, z + 1, chance, ForgeDirection.NORTH);
- return chance;
- }
- }
- /**
- * Ticks the block if it's been scheduled
- */
- public void updateTick (World world, int x, int y, int z, Random random)
- {
- if (world.getGameRules().getGameRuleBooleanValue("doFireTick"))
- {
- doFireTick(world, x, y, z, random);
- }
- }
- public void doFireTick (World world, int x, int y, int z, Random random)
- {
- boolean isInfiniteFire = world.getBlock(x, y - 1, z).isFireSource(world, x, y - 1, z, ForgeDirection.UP);
- if (!this.canPlaceBlockAt(world, x, y, z))
- {
- world.setBlockToAir(x, y, z);
- }
- if (!isInfiniteFire && world.isRaining() &&
- (world.canLightningStrikeAt(x, y, z) ||
- world.canLightningStrikeAt(x - 1, y, z) ||
- world.canLightningStrikeAt(x + 1, y, z) ||
- world.canLightningStrikeAt(x, y, z - 1) ||
- world.canLightningStrikeAt(x, y, z + 1)))
- {
- world.setBlockToAir(x, y, z);
- }
- else
- {
- int fireMetadata = world.getBlockMetadata(x, y, z);
- if (fireMetadata < 15)
- {
- world.setBlockMetadataWithNotify(x, y, z,
- fireMetadata + random.nextInt(3) / 2, 4);
- }
- world.scheduleBlockUpdate(x, y, z, this,
- this.tickRate(world) + random.nextInt(10));
- if (!isInfiniteFire && !this.canNeighborBurn(world, x, y, z))
- {
- if (!World.doesBlockHaveSolidTopSurface(world, x, y - 1,
- z) || fireMetadata > 3)
- {
- world.setBlockToAir(x, y, z);
- }
- }
- else if (!isInfiniteFire && !this.canCatchFire(world, x, y - 1, z, ForgeDirection.UP) &&
- fireMetadata == 15 && random.nextInt(4) == 0)
- {
- world.setBlockToAir(x, y, z);
- }
- else
- {
- boolean isBlockHumid = world.isBlockHighHumidity(x, y, z);
- byte humidFactor = 0;
- if (isBlockHumid)
- {
- humidFactor = -50;
- }
- this.tryCatchFire(world, x + 1, y, z, 300 + humidFactor, random, fireMetadata,
- ForgeDirection.WEST);
- this.tryCatchFire(world, x - 1, y, z, 300 + humidFactor, random, fireMetadata,
- ForgeDirection.EAST);
- this.tryCatchFire(world, x, y - 1, z, 250 + humidFactor, random, fireMetadata,
- ForgeDirection.UP);
- this.tryCatchFire(world, x, y + 1, z, 250 + humidFactor, random, fireMetadata,
- ForgeDirection.DOWN);
- this.tryCatchFire(world, x, y, z - 1, 300 + humidFactor, random, fireMetadata,
- ForgeDirection.SOUTH);
- this.tryCatchFire(world, x, y, z + 1, 300 + humidFactor, random, fireMetadata,
- ForgeDirection.NORTH);
- tryToStopFire(world, x, y, z, random, fireMetadata, isBlockHumid);
- }
- }
- }
- public void tryToStopFire (World world, int x, int y, int z, Random random, int fireMetadata,
- boolean isBlockHumid)
- {
- for (int i1 = x - 1; i1 <= x + 1; ++i1)
- {
- for (int j1 = z - 1; j1 <= z + 1; ++j1)
- {
- for (int k1 = y - 1; k1 <= y + 4; ++k1)
- {
- if (i1 != x || k1 != y || j1 != z)
- {
- int spreadingFactor = 100;
- if (k1 > y + 1)
- {
- spreadingFactor += (k1 - (y + 1)) * 100; // в высоту маловероятнее, чем в ширину
- }
- int chanceOnSupport = this.getChanceOfNeighborsEncouragingFire(world, i1, k1, j1);
- if (chanceOnSupport > 0)
- {
- int spreadStopTheshold = (chanceOnSupport + 40 + world.difficultySetting
- .getDifficultyId() * 7) / (fireMetadata + 30);
- if (isBlockHumid)
- {
- spreadStopTheshold /= 2;
- }
- if (spreadStopTheshold > 0 && random.nextInt(spreadingFactor) <= spreadStopTheshold &&
- (!world.isRaining() ||
- !world.canLightningStrikeAt(i1, k1, j1)) &&
- !world.canLightningStrikeAt(i1 - 1, k1, z) &&
- !world.canLightningStrikeAt(i1 + 1, k1, j1) &&
- !world.canLightningStrikeAt(i1, k1, j1 - 1) &&
- !world.canLightningStrikeAt(i1, k1, j1 + 1))
- {
- int newFireMetadata = fireMetadata + random.nextInt(5) / 4;
- if (newFireMetadata > 15)
- {
- newFireMetadata = 15;
- }
- world.setBlock(i1, k1, j1, this, newFireMetadata, 3);
- }
- }
- }
- }
- }
- }
- }
- /**
- * Returns if this block is collidable (only used by Fire). Args: x, y, z
- */
- public boolean isCollidable()
- {
- return false;
- }
- /**
- * Checks the specified block coordinate to see if it can catch fire. Args: blockAccess, x, y, z
- */
- @Deprecated
- public boolean canBlockCatchFire(IBlockAccess p_149844_1_, int p_149844_2_, int p_149844_3_, int p_149844_4_)
- {
- return canCatchFire(p_149844_1_, p_149844_2_, p_149844_3_, p_149844_4_, ForgeDirection.UP);
- }
- @Deprecated
- public int func_149846_a(World p_149846_1_, int p_149846_2_, int p_149846_3_, int p_149846_4_, int p_149846_5_)
- {
- return getChanceToEncourageFire(p_149846_1_, p_149846_2_, p_149846_3_, p_149846_4_, p_149846_5_, ForgeDirection.UP);
- }
- /**
- * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
- */
- public boolean canPlaceBlockAt(World p_149742_1_, int p_149742_2_, int p_149742_3_, int p_149742_4_)
- {
- return World.doesBlockHaveSolidTopSurface(p_149742_1_, p_149742_2_, p_149742_3_ - 1, p_149742_4_) || this.canNeighborBurn(p_149742_1_, p_149742_2_, p_149742_3_, p_149742_4_);
- }
- /**
- * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
- * their own) Args: x, y, z, neighbor Block
- */
- public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
- {
- if (!World.doesBlockHaveSolidTopSurface(p_149695_1_, p_149695_2_, p_149695_3_ - 1, p_149695_4_) && !this.canNeighborBurn(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_))
- {
- p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_, p_149695_4_);
- }
- }
- /**
- * Called whenever the block is added into the world. Args: world, x, y, z
- */
- public void onBlockAdded(World p_149726_1_, int p_149726_2_, int p_149726_3_, int p_149726_4_)
- {
- if (p_149726_1_.provider.dimensionId > 0 || !Blocks.portal.func_150000_e(p_149726_1_, p_149726_2_, p_149726_3_, p_149726_4_))
- {
- if (!World.doesBlockHaveSolidTopSurface(p_149726_1_, p_149726_2_, p_149726_3_ - 1, p_149726_4_) && !this.canNeighborBurn(p_149726_1_, p_149726_2_, p_149726_3_, p_149726_4_))
- {
- p_149726_1_.setBlockToAir(p_149726_2_, p_149726_3_, p_149726_4_);
- }
- else
- {
- p_149726_1_.scheduleBlockUpdate(p_149726_2_, p_149726_3_, p_149726_4_, this, this.tickRate(p_149726_1_) + p_149726_1_.rand.nextInt(10));
- }
- }
- }
- /**
- * A randomly called display update to be able to add particles or other items for display
- */
- @SideOnly(Side.CLIENT)
- @Override
- public void randomDisplayTick(World p_149734_1_, int p_149734_2_, int p_149734_3_, int p_149734_4_, Random p_149734_5_)
- {
- if (p_149734_5_.nextInt(24) == 0)
- {
- p_149734_1_.playSound((double)((float)p_149734_2_ + 0.5F), (double)((float)p_149734_3_ + 0.5F), (double)((float)p_149734_4_ + 0.5F), "fire.fire", 1.0F + p_149734_5_.nextFloat(), p_149734_5_.nextFloat() * 0.7F + 0.3F, false);
- }
- }
- /*================================= Forge Start ======================================*/
- private static class FireInfo
- {
- private int encouragement = 0;
- private int flammibility = 0;
- }
- private IdentityHashMap<Block, FireInfo> blockInfo = Maps.newIdentityHashMap();
- public void setFireInfo (Block block, int encouragement, int flammibility)
- {
- if (block == Blocks.air) throw new IllegalArgumentException("Tried to set air on fire... This is bad.");
- int id = Block.getIdFromBlock(block);
- this.field_149849_a[id] = encouragement;
- this.field_149848_b[id] = flammibility;
- FireInfo info = getInfo(block, true);
- info.encouragement = encouragement;
- info.flammibility = flammibility;
- }
- private FireInfo getInfo (Block block, boolean garentee)
- {
- FireInfo ret = blockInfo.get(block);
- if (ret == null && garentee)
- {
- ret = new FireInfo();
- blockInfo.put(block, ret);
- }
- return ret;
- }
- public void rebuildFireInfo ()
- {
- for (int x = 0; x < 4096; x++)
- {
- //If we care.. we could detect changes in here and make sure we keep them, however
- //it's my thinking that anyone who hacks into the private variables should DIAF and we don't care about them.
- field_149849_a[x] = 0;
- field_149848_b[x] = 0;
- }
- for (Map.Entry<Block, FireInfo> e : blockInfo.entrySet())
- {
- int id = Block.getIdFromBlock(e.getKey());
- if (id >= 0 && id < 4096)
- {
- field_149849_a[id] = e.getValue().encouragement;
- field_149848_b[id] = e.getValue().flammibility;
- }
- }
- }
- public int getFlammability (Block block)
- {
- int id = Block.getIdFromBlock(block);
- return id >= 0 && id < 4096 ? field_149848_b[id] : 0;
- }
- public int getEncouragement (Block block)
- {
- int id = Block.getIdFromBlock(block);
- return id >= 0 && id < 4096 ? field_149849_a[id] : 0;
- }
- /**
- * Side sensitive version that calls the block function.
- *
- * @param world The current world
- * @param x X Position
- * @param y Y Position
- * @param z Z Position
- * @param face The side the fire is coming from
- * @return True if the face can catch fire.
- */
- public boolean canCatchFire (IBlockAccess world, int x, int y, int z, ForgeDirection face)
- {
- return world.getBlock(x, y, z).isFlammable(world, x, y, z, face);
- }
- /**
- * Side sensitive version that calls the block function.
- *
- * @param world The current world
- * @param x X Position
- * @param y Y Position
- * @param z Z Position
- * @param oldChance The previous maximum chance.
- * @param face The side the fire is coming from
- * @return The chance of the block catching fire& or oldChance if it is higher
- */
- public int getChanceToEncourageFire (IBlockAccess world, int x, int y, int z, int oldChance, ForgeDirection face)
- {
- int newChance = world.getBlock(x, y, z).getFireSpreadSpeed(world, x, y, z, face);
- return (newChance > oldChance ? newChance : oldChance);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement