2013-05-23 01:01:19 -04:00
|
|
|
package net.minecraftforge.fluids;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
2014-01-29 18:34:23 -08:00
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
2013-05-23 01:01:19 -04:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.material.Material;
|
2014-11-25 19:56:35 -08:00
|
|
|
import net.minecraft.block.properties.IProperty;
|
|
|
|
|
import net.minecraft.block.properties.PropertyInteger;
|
|
|
|
|
import net.minecraft.block.state.BlockState;
|
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
2013-05-23 01:01:19 -04:00
|
|
|
import net.minecraft.entity.Entity;
|
2014-01-29 18:34:23 -08:00
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
|
import net.minecraft.item.Item;
|
2013-05-23 01:01:19 -04:00
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2014-11-25 19:56:35 -08:00
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
|
import net.minecraft.util.EnumWorldBlockLayer;
|
2013-05-23 01:01:19 -04:00
|
|
|
import net.minecraft.util.Vec3;
|
|
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
|
import net.minecraft.world.World;
|
2014-11-25 19:56:35 -08:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2013-05-23 01:01:19 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is a base implementation for Fluid blocks.
|
2013-07-28 19:15:00 +02:00
|
|
|
*
|
2013-05-23 01:01:19 -04:00
|
|
|
* It is highly recommended that you extend this class or one of the Forge-provided child classes.
|
2013-07-28 19:15:00 +02:00
|
|
|
*
|
2013-05-23 01:01:19 -04:00
|
|
|
* @author King Lemming, OvermindDL1
|
2013-07-28 19:15:00 +02:00
|
|
|
*
|
2013-05-23 01:01:19 -04:00
|
|
|
*/
|
2013-07-16 21:40:49 -07:00
|
|
|
public abstract class BlockFluidBase extends Block implements IFluidBlock
|
|
|
|
|
{
|
2014-01-29 18:34:23 -08:00
|
|
|
protected final static Map<Block, Boolean> defaultDisplacements = Maps.newHashMap();
|
2013-05-23 01:01:19 -04:00
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
static
|
|
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
defaultDisplacements.put(Blocks.oak_door, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.spruce_door, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.birch_door, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.jungle_door, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.acacia_door, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.dark_oak_door, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.trapdoor, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.iron_trapdoor, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.oak_fence, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.spruce_fence, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.birch_fence, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.jungle_fence, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.dark_oak_fence, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.acacia_fence, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.nether_brick_fence, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.oak_fence_gate, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.spruce_fence_gate, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.birch_fence_gate, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.jungle_fence_gate, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.dark_oak_fence_gate, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.acacia_fence_gate, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.wooden_pressure_plate, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.stone_pressure_plate, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.light_weighted_pressure_plate, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.heavy_weighted_pressure_plate, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.ladder, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.iron_bars, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.glass_pane, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.stained_glass_pane, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.portal, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.end_portal, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.cobblestone_wall, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.barrier, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.standing_banner, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.wall_banner, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.cake, false);
|
|
|
|
|
|
2014-01-29 18:34:23 -08:00
|
|
|
defaultDisplacements.put(Blocks.iron_door, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.standing_sign, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.wall_sign, false);
|
|
|
|
|
defaultDisplacements.put(Blocks.reeds, false);
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
2014-01-29 18:34:23 -08:00
|
|
|
protected Map<Block, Boolean> displacements = Maps.newHashMap();
|
2013-05-23 01:01:19 -04:00
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 15);
|
2013-05-23 01:01:19 -04:00
|
|
|
protected int quantaPerBlock = 8;
|
|
|
|
|
protected float quantaPerBlockFloat = 8F;
|
|
|
|
|
protected int density = 1;
|
|
|
|
|
protected int densityDir = -1;
|
2013-07-31 22:15:42 -05:00
|
|
|
protected int temperature = 295;
|
2013-05-23 01:01:19 -04:00
|
|
|
|
|
|
|
|
protected int tickRate = 20;
|
2014-11-25 19:56:35 -08:00
|
|
|
protected EnumWorldBlockLayer renderLayer = EnumWorldBlockLayer.TRANSLUCENT;
|
2013-05-23 01:01:19 -04:00
|
|
|
protected int maxScaledLight = 0;
|
|
|
|
|
|
|
|
|
|
protected final String fluidName;
|
2014-01-29 18:34:23 -08:00
|
|
|
|
|
|
|
|
public BlockFluidBase(Fluid fluid, Material material)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-12-12 23:32:18 -08:00
|
|
|
super(material);
|
2014-02-05 00:05:37 -08:00
|
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
|
this.setTickRandomly(true);
|
|
|
|
|
this.disableStats();
|
2013-05-23 01:01:19 -04:00
|
|
|
|
|
|
|
|
this.fluidName = fluid.getName();
|
|
|
|
|
this.density = fluid.density;
|
2013-07-31 22:15:42 -05:00
|
|
|
this.temperature = fluid.temperature;
|
2013-05-23 01:01:19 -04:00
|
|
|
this.maxScaledLight = fluid.luminosity;
|
|
|
|
|
this.tickRate = fluid.viscosity / 200;
|
2013-09-30 14:02:23 -07:00
|
|
|
this.densityDir = fluid.density > 0 ? -1 : 1;
|
2014-01-29 18:34:23 -08:00
|
|
|
fluid.setBlock(this);
|
2013-05-23 01:01:19 -04:00
|
|
|
|
2014-01-29 18:34:23 -08:00
|
|
|
displacements.putAll(defaultDisplacements);
|
2014-11-25 19:56:35 -08:00
|
|
|
this.setDefaultState(blockState.getBaseState().withProperty(LEVEL, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected BlockState createBlockState()
|
|
|
|
|
{
|
|
|
|
|
return new BlockState(this, LEVEL);
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
2014-01-29 18:34:23 -08:00
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
@Override
|
|
|
|
|
public int getMetaFromState(IBlockState state)
|
|
|
|
|
{
|
|
|
|
|
return ((Integer)state.getValue(LEVEL)).intValue();
|
|
|
|
|
}
|
2013-07-16 21:40:49 -07:00
|
|
|
public BlockFluidBase setQuantaPerBlock(int quantaPerBlock)
|
|
|
|
|
{
|
|
|
|
|
if (quantaPerBlock > 16 || quantaPerBlock < 1) quantaPerBlock = 8;
|
2013-05-23 01:01:19 -04:00
|
|
|
this.quantaPerBlock = quantaPerBlock;
|
|
|
|
|
this.quantaPerBlockFloat = quantaPerBlock;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public BlockFluidBase setDensity(int density)
|
|
|
|
|
{
|
|
|
|
|
if (density == 0) density = 1;
|
2013-05-23 01:01:19 -04:00
|
|
|
this.density = density;
|
|
|
|
|
this.densityDir = density > 0 ? -1 : 1;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-31 22:15:42 -05:00
|
|
|
public BlockFluidBase setTemperature(int temperature)
|
|
|
|
|
{
|
|
|
|
|
this.temperature = temperature;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public BlockFluidBase setTickRate(int tickRate)
|
|
|
|
|
{
|
|
|
|
|
if (tickRate <= 0) tickRate = 20;
|
2013-05-23 01:01:19 -04:00
|
|
|
this.tickRate = tickRate;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
public BlockFluidBase setRenderLayer(EnumWorldBlockLayer renderLayer)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
this.renderLayer = renderLayer;
|
2013-05-23 01:01:19 -04:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
public BlockFluidBase setMaxScaledLight(int maxScaledLight)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
this.maxScaledLight = maxScaledLight;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-11-25 19:56:35 -08:00
|
|
|
* Returns true if the block at (pos) is displaceable. Does not displace the block.
|
2014-01-29 18:34:23 -08:00
|
|
|
*/
|
2014-11-25 19:56:35 -08:00
|
|
|
public boolean canDisplace(IBlockAccess world, BlockPos pos)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
if (world.isAirBlock(pos)) return true;
|
2013-05-23 01:01:19 -04:00
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
Block block = world.getBlockState(pos).getBlock();
|
2013-05-23 01:01:19 -04:00
|
|
|
|
2014-01-29 18:34:23 -08:00
|
|
|
if (block == this)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-07-16 21:40:49 -07:00
|
|
|
|
2014-01-29 18:34:23 -08:00
|
|
|
if (displacements.containsKey(block))
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-01-29 18:34:23 -08:00
|
|
|
return displacements.get(block);
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-05 00:05:37 -08:00
|
|
|
Material material = block.getMaterial();
|
|
|
|
|
if (material.blocksMovement() || material == Material.portal)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-07-28 19:15:00 +02:00
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
int density = getDensity(world, pos);
|
|
|
|
|
if (density == Integer.MAX_VALUE)
|
2013-08-08 18:38:46 -05:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-11-25 19:56:35 -08:00
|
|
|
|
2013-08-08 18:38:46 -05:00
|
|
|
if (this.density > density)
|
2013-07-26 16:25:40 -05:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-11-25 19:56:35 -08:00
|
|
|
* Attempt to displace the block at (pos), return true if it was displaced.
|
2014-01-29 18:34:23 -08:00
|
|
|
*/
|
2014-11-25 19:56:35 -08:00
|
|
|
public boolean displaceIfPossible(World world, BlockPos pos)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
if (world.isAirBlock(pos))
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
2013-07-16 21:40:49 -07:00
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
IBlockState state = world.getBlockState(pos);
|
|
|
|
|
Block block = state.getBlock();
|
2014-01-29 18:34:23 -08:00
|
|
|
if (block == this)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-07-16 21:40:49 -07:00
|
|
|
|
2014-01-29 18:34:23 -08:00
|
|
|
if (displacements.containsKey(block))
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-01-29 18:34:23 -08:00
|
|
|
if (displacements.get(block))
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
block.dropBlockAsItem(world, pos, state, 0);
|
2013-05-23 01:01:19 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 00:05:37 -08:00
|
|
|
Material material = block.getMaterial();
|
|
|
|
|
if (material.blocksMovement() || material == Material.portal)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-07-28 19:15:00 +02:00
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
int density = getDensity(world, pos);
|
|
|
|
|
if (density == Integer.MAX_VALUE)
|
2013-08-08 18:38:46 -05:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
block.dropBlockAsItem(world, pos, state, 0);
|
2013-08-08 18:38:46 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-11-25 19:56:35 -08:00
|
|
|
|
2013-08-08 18:38:46 -05:00
|
|
|
if (this.density > density)
|
2013-07-26 16:25:40 -05:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
public abstract int getQuantaValue(IBlockAccess world, BlockPos pos);
|
2013-05-23 01:01:19 -04:00
|
|
|
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public abstract boolean canCollideCheck(IBlockState state, boolean fullHit);
|
2013-05-23 01:01:19 -04:00
|
|
|
|
|
|
|
|
public abstract int getMaxRenderHeightMeta();
|
|
|
|
|
|
2014-01-29 18:34:23 -08:00
|
|
|
/* BLOCK FUNCTIONS */
|
2013-05-23 01:01:19 -04:00
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public void onBlockAdded(World world, BlockPos pos, IBlockState state)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
world.scheduleUpdate(pos, this, tickRate);
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block neighborBlock)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
world.scheduleUpdate(pos, this, tickRate);
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Used to prevent updates on chunk generation
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public boolean requiresUpdates()
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public boolean isPassable(IBlockAccess world, BlockPos pos)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public AxisAlignedBB getCollisionBoundingBox(World world, BlockPos pos, IBlockState state)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public Item getItemDropped(IBlockState state, Random rand, int fortune)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-01-29 18:34:23 -08:00
|
|
|
return null;
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 00:05:37 -08:00
|
|
|
public int quantityDropped(Random par1Random)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 00:05:37 -08:00
|
|
|
public int tickRate(World world)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return tickRate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public Vec3 modifyAcceleration(World world, BlockPos pos, Entity entity, Vec3 vec)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
if (densityDir > 0) return vec;
|
|
|
|
|
Vec3 vec_flow = this.getFlowVector(world, pos);
|
|
|
|
|
return vec.addVector(
|
|
|
|
|
vec_flow.xCoord * (quantaPerBlock * 4),
|
|
|
|
|
vec_flow.yCoord * (quantaPerBlock * 4),
|
|
|
|
|
vec_flow.zCoord * (quantaPerBlock * 4));
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public int getLightValue(IBlockAccess world, BlockPos pos)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
|
|
|
|
if (maxScaledLight == 0)
|
|
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
return super.getLightValue(world, pos);
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
2014-11-25 19:56:35 -08:00
|
|
|
int data = ((Integer)world.getBlockState(pos).getValue(LEVEL)).intValue();
|
2013-05-23 01:01:19 -04:00
|
|
|
return (int) (data / quantaPerBlockFloat * maxScaledLight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 00:05:37 -08:00
|
|
|
public int getRenderType()
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return FluidRegistry.renderIdFluid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 00:05:37 -08:00
|
|
|
public boolean isOpaqueCube()
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public boolean isFullCube()
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 18:34:23 -08:00
|
|
|
/* Never used...?
|
2013-05-23 01:01:19 -04:00
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public float getBlockBrightness(World world, BlockPos pos)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
float lightThis = world.getLightBrightness(pos);
|
2013-05-23 01:01:19 -04:00
|
|
|
float lightUp = world.getLightBrightness(x, y + 1, z);
|
|
|
|
|
return lightThis > lightUp ? lightThis : lightUp;
|
|
|
|
|
}
|
2014-01-29 18:34:23 -08:00
|
|
|
*/
|
2013-05-23 01:01:19 -04:00
|
|
|
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public int getMixedBrightnessForBlock(IBlockAccess world, BlockPos pos)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
int lightThis = world.getCombinedLight(pos, 0);
|
|
|
|
|
int lightUp = world.getCombinedLight(pos.offsetUp(), 0);
|
2013-05-23 01:01:19 -04:00
|
|
|
int lightThisBase = lightThis & 255;
|
2013-07-16 21:40:49 -07:00
|
|
|
int lightUpBase = lightUp & 255;
|
|
|
|
|
int lightThisExt = lightThis >> 16 & 255;
|
|
|
|
|
int lightUpExt = lightUp >> 16 & 255;
|
2013-07-28 19:15:00 +02:00
|
|
|
return (lightThisBase > lightUpBase ? lightThisBase : lightUpBase) |
|
2013-07-16 21:40:49 -07:00
|
|
|
((lightThisExt > lightUpExt ? lightThisExt : lightUpExt) << 16);
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public EnumWorldBlockLayer getBlockLayer()
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
return this.renderLayer;
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public boolean shouldSideBeRendered(IBlockAccess world, BlockPos pos, EnumFacing side)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
Block block = world.getBlockState(pos).getBlock();
|
2014-01-29 18:34:23 -08:00
|
|
|
if (block != this)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-02-05 00:05:37 -08:00
|
|
|
return !block.isOpaqueCube();
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
2014-11-25 19:56:35 -08:00
|
|
|
return block.getMaterial() == this.getMaterial() ? false : super.shouldSideBeRendered(world, pos, side);
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
|
2014-01-29 18:34:23 -08:00
|
|
|
/* FLUID FUNCTIONS */
|
2014-11-25 19:56:35 -08:00
|
|
|
public static final int getDensity(IBlockAccess world, BlockPos pos)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
Block block = world.getBlockState(pos).getBlock();
|
2013-07-16 21:40:49 -07:00
|
|
|
if (!(block instanceof BlockFluidBase))
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
|
}
|
2013-07-16 21:40:49 -07:00
|
|
|
return ((BlockFluidBase)block).density;
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
2014-11-25 19:56:35 -08:00
|
|
|
|
|
|
|
|
public static final int getTemperature(IBlockAccess world, BlockPos pos)
|
2013-07-31 22:15:42 -05:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
Block block = world.getBlockState(pos).getBlock();
|
2013-07-31 22:15:42 -05:00
|
|
|
if (!(block instanceof BlockFluidBase))
|
|
|
|
|
{
|
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
|
}
|
|
|
|
|
return ((BlockFluidBase)block).temperature;
|
|
|
|
|
}
|
2013-05-23 01:01:19 -04:00
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
public static double getFlowDirection(IBlockAccess world, BlockPos pos)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
Block block = world.getBlockState(pos).getBlock();
|
2014-02-05 00:05:37 -08:00
|
|
|
if (!block.getMaterial().isLiquid())
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return -1000.0;
|
|
|
|
|
}
|
2014-11-25 19:56:35 -08:00
|
|
|
Vec3 vec = ((BlockFluidBase) block).getFlowVector(world, pos);
|
2013-05-23 01:01:19 -04:00
|
|
|
return vec.xCoord == 0.0D && vec.zCoord == 0.0D ? -1000.0D : Math.atan2(vec.zCoord, vec.xCoord) - Math.PI / 2D;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
public final int getQuantaValueBelow(IBlockAccess world, BlockPos pos, int belowThis)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
int quantaRemaining = getQuantaValue(world, pos);
|
2013-07-16 21:40:49 -07:00
|
|
|
if (quantaRemaining >= belowThis)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return quantaRemaining;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
public final int getQuantaValueAbove(IBlockAccess world, BlockPos pos, int aboveThis)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
int quantaRemaining = getQuantaValue(world, pos);
|
2013-07-16 21:40:49 -07:00
|
|
|
if (quantaRemaining <= aboveThis)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return quantaRemaining;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
public final float getQuantaPercentage(IBlockAccess world, BlockPos pos)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
int quantaRemaining = getQuantaValue(world, pos);
|
2013-05-23 01:01:19 -04:00
|
|
|
return quantaRemaining / quantaPerBlockFloat;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
public Vec3 getFlowVector(IBlockAccess world, BlockPos pos)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
Vec3 vec = new Vec3(0.0D, 0.0D, 0.0D);
|
|
|
|
|
int decay = quantaPerBlock - getQuantaValue(world, pos);
|
2013-05-23 01:01:19 -04:00
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
for (int side = 0; side < 4; ++side)
|
|
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
int x2 = pos.getX();
|
|
|
|
|
int z2 = pos.getZ();
|
2013-05-23 01:01:19 -04:00
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
switch (side)
|
|
|
|
|
{
|
|
|
|
|
case 0: --x2; break;
|
|
|
|
|
case 1: --z2; break;
|
|
|
|
|
case 2: ++x2; break;
|
|
|
|
|
case 3: ++z2; break;
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
BlockPos pos2 = new BlockPos(x2, pos.getY(), z2);
|
|
|
|
|
int otherDecay = quantaPerBlock - getQuantaValue(world, pos2);
|
2013-07-16 21:40:49 -07:00
|
|
|
if (otherDecay >= quantaPerBlock)
|
|
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
if (!world.getBlockState(pos2).getBlock().getMaterial().blocksMovement())
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
otherDecay = quantaPerBlock - getQuantaValue(world, pos2.offsetDown());
|
2013-07-16 21:40:49 -07:00
|
|
|
if (otherDecay >= 0)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
int power = otherDecay - (decay - quantaPerBlock);
|
2014-11-25 19:56:35 -08:00
|
|
|
vec = vec.addVector((pos2.getX() - pos.getX()) * power, 0, (pos2.getZ() - pos.getZ()) * power);
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
}
|
2013-07-16 21:40:49 -07:00
|
|
|
}
|
|
|
|
|
else if (otherDecay >= 0)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
int power = otherDecay - decay;
|
2014-11-25 19:56:35 -08:00
|
|
|
vec = vec.addVector((pos2.getX() - pos.getX()) * power, 0, (pos2.getZ() - pos.getZ()) * power);
|
2013-05-23 01:01:19 -04:00
|
|
|
}
|
|
|
|
|
}
|
2013-07-16 21:40:49 -07:00
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
if (world.getBlockState(pos.offsetUp()).getBlock() == this)
|
2013-07-16 21:40:49 -07:00
|
|
|
{
|
2013-07-28 19:15:00 +02:00
|
|
|
boolean flag =
|
2014-11-25 19:56:35 -08:00
|
|
|
isBlockSolid(world, pos.add( 0, 0, -1), EnumFacing.NORTH) ||
|
|
|
|
|
isBlockSolid(world, pos.add( 0, 0, 1), EnumFacing.SOUTH) ||
|
|
|
|
|
isBlockSolid(world, pos.add(-1, 0, 0), EnumFacing.WEST) ||
|
|
|
|
|
isBlockSolid(world, pos.add( 1, 0, 0), EnumFacing.EAST) ||
|
|
|
|
|
isBlockSolid(world, pos.add( 0, 1, -1), EnumFacing.NORTH) ||
|
|
|
|
|
isBlockSolid(world, pos.add( 0, 1, 1), EnumFacing.SOUTH) ||
|
|
|
|
|
isBlockSolid(world, pos.add(-1, 1, 0), EnumFacing.WEST) ||
|
|
|
|
|
isBlockSolid(world, pos.add( 1, 1, 0), EnumFacing.EAST);
|
2013-07-28 19:15:00 +02:00
|
|
|
|
2013-07-16 21:40:49 -07:00
|
|
|
if (flag)
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
vec = vec.normalize().addVector(0.0D, -6.0D, 0.0D);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
vec = vec.normalize();
|
|
|
|
|
return vec;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 18:34:23 -08:00
|
|
|
/* IFluidBlock */
|
2013-05-23 01:01:19 -04:00
|
|
|
@Override
|
2013-07-16 21:40:49 -07:00
|
|
|
public Fluid getFluid()
|
|
|
|
|
{
|
2013-05-23 01:01:19 -04:00
|
|
|
return FluidRegistry.getFluid(fluidName);
|
|
|
|
|
}
|
2013-08-18 23:16:36 -07:00
|
|
|
|
|
|
|
|
@Override
|
2014-11-25 19:56:35 -08:00
|
|
|
public float getFilledPercentage(World world, BlockPos pos)
|
2013-08-18 23:16:36 -07:00
|
|
|
{
|
2014-11-25 19:56:35 -08:00
|
|
|
int quantaRemaining = getQuantaValue(world, pos) + 1;
|
2013-08-18 23:16:36 -07:00
|
|
|
float remaining = quantaRemaining / quantaPerBlockFloat;
|
|
|
|
|
if (remaining > 1) remaining = 1.0f;
|
|
|
|
|
return remaining * (density > 0 ? 1 : -1);
|
|
|
|
|
}
|
2014-11-25 19:56:35 -08:00
|
|
|
}
|