mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-22 13:09:59 +00:00
1367 lines
55 KiB
Diff
1367 lines
55 KiB
Diff
--- ../src-base/minecraft/net/minecraft/block/Block.java
|
|
+++ ../src-work/minecraft/net/minecraft/block/Block.java
|
|
@@ -46,8 +46,9 @@
|
|
public class Block
|
|
{
|
|
private static final ResourceLocation AIR_ID = new ResourceLocation("air");
|
|
- public static final RegistryNamespacedDefaultedByKey<ResourceLocation, Block> blockRegistry = new RegistryNamespacedDefaultedByKey(AIR_ID);
|
|
- public static final ObjectIntIdentityMap<IBlockState> BLOCK_STATE_IDS = new ObjectIntIdentityMap();
|
|
+ public static final RegistryNamespacedDefaultedByKey<ResourceLocation, Block> blockRegistry = net.minecraftforge.fml.common.registry.GameData.getBlockRegistry();
|
|
+ @Deprecated //Modders: DO NOT use this! Use GameRegistry
|
|
+ public static final ObjectIntIdentityMap<IBlockState> BLOCK_STATE_IDS = net.minecraftforge.fml.common.registry.GameData.getBlockStateIDMap();
|
|
public static final AxisAlignedBB field_185505_j = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
|
|
public static final AxisAlignedBB field_185506_k = null;
|
|
private CreativeTabs displayOnCreativeTab;
|
|
@@ -70,6 +71,9 @@
|
|
private IBlockState defaultBlockState;
|
|
private String unlocalizedName;
|
|
|
|
+ public final net.minecraftforge.fml.common.registry.RegistryDelegate<Block> delegate =
|
|
+ ((net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry)blockRegistry).getDelegate(this, Block.class);
|
|
+
|
|
public static int getIdFromBlock(Block blockIn)
|
|
{
|
|
return blockRegistry.getIDForObject(blockIn);
|
|
@@ -83,7 +87,8 @@
|
|
|
|
public static Block getBlockById(int id)
|
|
{
|
|
- return (Block)blockRegistry.getObjectById(id);
|
|
+ Block ret = (Block)blockRegistry.getObjectById(id);
|
|
+ return ret == null ? net.minecraft.init.Blocks.air : ret;
|
|
}
|
|
|
|
public static IBlockState getStateById(int id)
|
|
@@ -268,7 +273,7 @@
|
|
|
|
public boolean isReplaceable(IBlockAccess worldIn, BlockPos pos)
|
|
{
|
|
- return false;
|
|
+ return getMaterial().isReplaceable();
|
|
}
|
|
|
|
public Block setHardness(float hardness)
|
|
@@ -305,9 +310,10 @@
|
|
return this.needsRandomTick;
|
|
}
|
|
|
|
+ @Deprecated //Forge: New State sensitive version.
|
|
public boolean hasTileEntity()
|
|
{
|
|
- return this.isBlockContainer;
|
|
+ return hasTileEntity(getDefaultState());
|
|
}
|
|
|
|
public AxisAlignedBB func_185496_a(IBlockState p_185496_1_, IBlockAccess p_185496_2_, BlockPos p_185496_3_)
|
|
@@ -346,13 +352,13 @@
|
|
@SideOnly(Side.CLIENT)
|
|
public int func_185484_c(IBlockState p_185484_1_, IBlockAccess p_185484_2_, BlockPos p_185484_3_)
|
|
{
|
|
- int i = p_185484_2_.getCombinedLight(p_185484_3_, p_185484_1_.func_185906_d());
|
|
+ int i = p_185484_2_.getCombinedLight(p_185484_3_, p_185484_1_.getLightValue(p_185484_2_, p_185484_3_));
|
|
|
|
if (i == 0 && p_185484_1_.getBlock() instanceof BlockSlab)
|
|
{
|
|
p_185484_3_ = p_185484_3_.down();
|
|
p_185484_1_ = p_185484_2_.getBlockState(p_185484_3_);
|
|
- return p_185484_2_.getCombinedLight(p_185484_3_, p_185484_1_.func_185906_d());
|
|
+ return p_185484_2_.getCombinedLight(p_185484_3_, p_185484_1_.getLightValue(p_185484_2_, p_185484_3_));
|
|
}
|
|
else
|
|
{
|
|
@@ -415,7 +421,7 @@
|
|
}
|
|
}
|
|
|
|
- return !pos.getBlockState(side.offset(p_176225_4_)).func_185914_p();
|
|
+ return !pos.getBlockState(side.offset(p_176225_4_)).doesSideBlockRendering(pos, side, p_176225_4_);
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
@@ -472,6 +478,10 @@
|
|
|
|
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
|
|
{
|
|
+ if (hasTileEntity(state) && !(this instanceof BlockContainer))
|
|
+ {
|
|
+ worldIn.removeTileEntity(pos);
|
|
+ }
|
|
}
|
|
|
|
public int quantityDropped(Random random)
|
|
@@ -486,8 +496,7 @@
|
|
|
|
public float getPlayerRelativeBlockHardness(IBlockState playerIn, EntityPlayer worldIn, World pos, BlockPos p_180647_4_)
|
|
{
|
|
- float f = playerIn.func_185887_b(pos, p_180647_4_);
|
|
- return f < 0.0F ? 0.0F : (!worldIn.func_184823_b(playerIn) ? worldIn.func_184813_a(playerIn) / f / 100.0F : worldIn.func_184813_a(playerIn) / f / 30.0F);
|
|
+ return net.minecraftforge.common.ForgeHooks.blockStrength(playerIn, worldIn, pos, p_180647_4_);
|
|
}
|
|
|
|
public final void dropBlockAsItem(World worldIn, BlockPos pos, IBlockState state, int forture)
|
|
@@ -497,20 +506,16 @@
|
|
|
|
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
|
|
{
|
|
- if (!worldIn.isRemote)
|
|
+ if (!worldIn.isRemote && !worldIn.restoringBlockSnapshots) // do not drop items while restoring blockstates, prevents item dupe
|
|
{
|
|
- int i = this.quantityDroppedWithBonus(fortune, worldIn.rand);
|
|
+ java.util.List<ItemStack> items = getDrops(worldIn, pos, state, fortune);
|
|
+ chance = net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(items, worldIn, pos, state, fortune, chance, false, harvesters.get());
|
|
|
|
- for (int j = 0; j < i; ++j)
|
|
+ for (ItemStack item : items)
|
|
{
|
|
if (worldIn.rand.nextFloat() <= chance)
|
|
{
|
|
- Item item = this.getItemDropped(state, worldIn.rand, fortune);
|
|
-
|
|
- if (item != null)
|
|
- {
|
|
- spawnAsEntity(worldIn, pos, new ItemStack(item, 1, this.damageDropped(state)));
|
|
- }
|
|
+ spawnAsEntity(worldIn, pos, item);
|
|
}
|
|
}
|
|
}
|
|
@@ -518,8 +523,13 @@
|
|
|
|
public static void spawnAsEntity(World worldIn, BlockPos pos, ItemStack stack)
|
|
{
|
|
- if (!worldIn.isRemote && worldIn.getGameRules().getBoolean("doTileDrops"))
|
|
+ if (!worldIn.isRemote && worldIn.getGameRules().getBoolean("doTileDrops") && !worldIn.restoringBlockSnapshots) // do not drop items while restoring blockstates, prevents item dupe
|
|
{
|
|
+ if (captureDrops.get())
|
|
+ {
|
|
+ capturedDrops.get().add(stack);
|
|
+ return;
|
|
+ }
|
|
float f = 0.5F;
|
|
double d0 = (double)(worldIn.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
|
double d1 = (double)(worldIn.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
|
@@ -588,7 +598,7 @@
|
|
|
|
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
|
|
{
|
|
- return worldIn.getBlockState(pos).getBlock().blockMaterial.isReplaceable();
|
|
+ return worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);
|
|
}
|
|
|
|
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand side, ItemStack hitX, EnumFacing hitY, float hitZ, float p_180639_9_, float p_180639_10_)
|
|
@@ -638,25 +648,35 @@
|
|
player.triggerAchievement(StatList.func_188055_a(this));
|
|
player.addExhaustion(0.025F);
|
|
|
|
- if (this.canSilkHarvest() && EnchantmentHelper.getEnchantmentLevel(Enchantments.field_185306_r, p_180657_6_) > 0)
|
|
+ if (this.canSilkHarvest(worldIn, pos, state, player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.field_185306_r, p_180657_6_) > 0)
|
|
{
|
|
+ java.util.List<ItemStack> items = new java.util.ArrayList<ItemStack>();
|
|
ItemStack itemstack = this.createStackedBlock(state);
|
|
|
|
if (itemstack != null)
|
|
{
|
|
- spawnAsEntity(worldIn, pos, itemstack);
|
|
+ items.add(itemstack);
|
|
}
|
|
+
|
|
+ net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(items, worldIn, pos, state, 0, 1.0f, true, player);
|
|
+ for (ItemStack stack : items)
|
|
+ {
|
|
+ spawnAsEntity(worldIn, pos, stack);
|
|
+ }
|
|
}
|
|
else
|
|
{
|
|
+ harvesters.set(player);
|
|
int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.field_185308_t, p_180657_6_);
|
|
this.dropBlockAsItem(worldIn, pos, state, i);
|
|
+ harvesters.set(null);
|
|
}
|
|
}
|
|
|
|
+ @Deprecated //Forge: State sensitive version
|
|
protected boolean canSilkHarvest()
|
|
{
|
|
- return this.getDefaultState().func_185917_h() && !this.isBlockContainer;
|
|
+ return this.getDefaultState().func_185917_h() && !this.hasTileEntity(silk_check_state.get());
|
|
}
|
|
|
|
protected ItemStack createStackedBlock(IBlockState state)
|
|
@@ -844,6 +864,1175 @@
|
|
return "Block{" + blockRegistry.getNameForObject(this) + "}";
|
|
}
|
|
|
|
+ /* ======================================== FORGE START =====================================*/
|
|
+ //For ForgeInternal use Only!
|
|
+ protected ThreadLocal<EntityPlayer> harvesters = new ThreadLocal();
|
|
+ private ThreadLocal<IBlockState> silk_check_state = new ThreadLocal();
|
|
+ protected static java.util.Random RANDOM = new java.util.Random(); // Useful for random things without a seed.
|
|
+ /**
|
|
+ * Get a light value for the block at the specified coordinates, normal ranges are between 0 and 15
|
|
+ *
|
|
+ * @param state Block state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return The light value
|
|
+ */
|
|
+ public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ IBlockState other = world.getBlockState(pos);
|
|
+ if (other.getBlock() != this)
|
|
+ {
|
|
+ return other.getLightValue(world, pos);
|
|
+ }
|
|
+ return state.func_185906_d();
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Checks if a player or entity can use this block to 'climb' like a ladder.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param entity The entity trying to use the ladder, CAN be null.
|
|
+ * @return True if the block should act like a ladder
|
|
+ */
|
|
+ public boolean isLadder(IBlockAccess world, BlockPos pos, EntityLivingBase entity) { return false; }
|
|
+
|
|
+ /**
|
|
+ * Return true if the block is a normal, solid cube. This
|
|
+ * determines indirect power state, entity ejection from blocks, and a few
|
|
+ * others.
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return True if the block is a full cube
|
|
+ */
|
|
+ public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return getMaterial().isOpaque() && isFullCube() && !canProvidePower();
|
|
+ return state.func_185904_a().isOpaque() && state.func_185917_h() && !state.func_185897_m();
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Check if the face of a block should block rendering.
|
|
+ *
|
|
+ * Faces which are fully opaque should return true, faces with transparency
|
|
+ * or faces which do not span the full size of the block should return false.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param side The side to check
|
|
+ * @return True if the block is opaque on the specified side.
|
|
+ */
|
|
+ public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face)
|
|
+ {
|
|
+ return state.func_185914_p();
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Checks if the block is a solid face on the given side, used by placement logic.
|
|
+ *
|
|
+ * @param base_state The base state, getActualState should be called first
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param side The side to check
|
|
+ * @return True if the block is solid on the specified side.
|
|
+ */
|
|
+ public boolean isSideSolid(IBlockState base_state, IBlockAccess world, BlockPos pos, EnumFacing side)
|
|
+ {
|
|
+ if (base_state.func_185896_q()) // Short circuit to vanilla function if its true
|
|
+ return true;
|
|
+
|
|
+ IBlockState state = this.getActualState(base_state, world, pos);
|
|
+
|
|
+ if (this instanceof BlockSlab)
|
|
+ {
|
|
+ return isFullBlock()
|
|
+ || (state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP && side == EnumFacing.UP )
|
|
+ || (state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM && side == EnumFacing.DOWN);
|
|
+ }
|
|
+ else if (this instanceof BlockFarmland)
|
|
+ {
|
|
+ return (side != EnumFacing.DOWN && side != EnumFacing.UP);
|
|
+ }
|
|
+ else if (this instanceof BlockStairs)
|
|
+ {
|
|
+ boolean flipped = state.getValue(BlockStairs.HALF) == BlockStairs.EnumHalf.TOP;
|
|
+ BlockStairs.EnumShape shape = (BlockStairs.EnumShape)state.getValue(BlockStairs.SHAPE);
|
|
+ EnumFacing facing = (EnumFacing)state.getValue(BlockStairs.FACING);
|
|
+ if (side == EnumFacing.UP) return flipped;
|
|
+ if (side == EnumFacing.DOWN) return !flipped;
|
|
+ if (facing == side) return true;
|
|
+ if (flipped)
|
|
+ {
|
|
+ if (shape == BlockStairs.EnumShape.INNER_LEFT ) return side == facing.rotateYCCW();
|
|
+ if (shape == BlockStairs.EnumShape.INNER_RIGHT) return side == facing.rotateY();
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ if (shape == BlockStairs.EnumShape.INNER_LEFT ) return side == facing.rotateY();
|
|
+ if (shape == BlockStairs.EnumShape.INNER_RIGHT) return side == facing.rotateYCCW();
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+ else if (this instanceof BlockSnow)
|
|
+ {
|
|
+ return ((Integer)state.getValue(BlockSnow.LAYERS)) >= 8;
|
|
+ }
|
|
+ else if (this instanceof BlockHopper && side == EnumFacing.UP)
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+ else if (this instanceof BlockCompressedPowered)
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+ return isNormalCube(state, world, pos);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines if this block should set fire and deal fire damage
|
|
+ * to entities coming into contact with it.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return True if the block should deal damage
|
|
+ */
|
|
+ public boolean isBurning(IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines this block should be treated as an air block
|
|
+ * by the rest of the code. This method is primarily
|
|
+ * useful for creating pure logic-blocks that will be invisible
|
|
+ * to the player and otherwise interact as air would.
|
|
+ *
|
|
+ * @param sata The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return True if the block considered air
|
|
+ */
|
|
+ public boolean isAir(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return state.func_185904_a() == Material.air;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines if the player can harvest this block, obtaining it's drops when the block is destroyed.
|
|
+ *
|
|
+ * @param player The player damaging the block, may be null
|
|
+ * @param meta The block's current metadata
|
|
+ * @return True to spawn the drops
|
|
+ */
|
|
+ public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player)
|
|
+ {
|
|
+ return net.minecraftforge.common.ForgeHooks.canHarvestBlock(this, player, world, pos);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Called when a player removes a block. This is responsible for
|
|
+ * actually destroying the block, and the block is intact at time of call.
|
|
+ * This is called regardless of whether the player can harvest the block or
|
|
+ * not.
|
|
+ *
|
|
+ * Return true if the block is actually destroyed.
|
|
+ *
|
|
+ * Note: When used in multiplayer, this is called on both client and
|
|
+ * server sides!
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param player The player damaging the block, may be null
|
|
+ * @param pos Block position in world
|
|
+ * @param willHarvest True if Block.harvestBlock will be called after this, if the return in true.
|
|
+ * Can be useful to delay the destruction of tile entities till after harvestBlock
|
|
+ * @return True if the block is actually destroyed.
|
|
+ */
|
|
+ public boolean removedByPlayer(World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
|
|
+ {
|
|
+ return world.setBlockToAir(pos);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Chance that fire will spread and consume this block.
|
|
+ * 300 being a 100% chance, 0, being a 0% chance.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param face The face that the fire is coming from
|
|
+ * @return A number ranging from 0 to 300 relating used to determine if the block will be consumed by fire
|
|
+ */
|
|
+ public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face)
|
|
+ {
|
|
+ return net.minecraft.init.Blocks.fire.getFlammability(this);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Called when fire is updating, checks if a block face can catch fire.
|
|
+ *
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param face The face that the fire is coming from
|
|
+ * @return True if the face can be on fire, false otherwise.
|
|
+ */
|
|
+ public boolean isFlammable(IBlockAccess world, BlockPos pos, EnumFacing face)
|
|
+ {
|
|
+ return getFlammability(world, pos, face) > 0;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Called when fire is updating on a neighbor block.
|
|
+ * The higher the number returned, the faster fire will spread around this block.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param face The face that the fire is coming from
|
|
+ * @return A number that is used to determine the speed of fire growth around the block
|
|
+ */
|
|
+ public int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face)
|
|
+ {
|
|
+ return net.minecraft.init.Blocks.fire.getEncouragement(this);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Currently only called by fire when it is on top of this block.
|
|
+ * Returning true will prevent the fire from naturally dying during updating.
|
|
+ * Also prevents firing from dying from rain.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param metadata The blocks current metadata
|
|
+ * @param side The face that the fire is coming from
|
|
+ * @return True if this block sustains fire, meaning it will never go out.
|
|
+ */
|
|
+ public boolean isFireSource(World world, BlockPos pos, EnumFacing side)
|
|
+ {
|
|
+ if (this == net.minecraft.init.Blocks.netherrack && side == EnumFacing.UP)
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+ if ((world.provider instanceof net.minecraft.world.WorldProviderEnd) && this == net.minecraft.init.Blocks.bedrock && side == EnumFacing.UP)
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ private boolean isTileProvider = this instanceof ITileEntityProvider;
|
|
+ /**
|
|
+ * Called throughout the code as a replacement for block instanceof BlockContainer
|
|
+ * Moving this to the Block base class allows for mods that wish to extend vanilla
|
|
+ * blocks, and also want to have a tile entity on that block, may.
|
|
+ *
|
|
+ * Return true from this function to specify this block has a tile entity.
|
|
+ *
|
|
+ * @param state State of the current block
|
|
+ * @return True if block has a tile entity, false otherwise
|
|
+ */
|
|
+ public boolean hasTileEntity(IBlockState state)
|
|
+ {
|
|
+ return isTileProvider;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Called throughout the code as a replacement for ITileEntityProvider.createNewTileEntity
|
|
+ * Return the same thing you would from that function.
|
|
+ * This will fall back to ITileEntityProvider.createNewTileEntity(World) if this block is a ITileEntityProvider
|
|
+ *
|
|
+ * @param metadata The Metadata of the current block
|
|
+ * @return A instance of a class extending TileEntity
|
|
+ */
|
|
+ public TileEntity createTileEntity(World world, IBlockState state)
|
|
+ {
|
|
+ if (isTileProvider)
|
|
+ {
|
|
+ return ((ITileEntityProvider)this).createNewTileEntity(world, getMetaFromState(state));
|
|
+ }
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * State and fortune sensitive version, this replaces the old (int meta, Random rand)
|
|
+ * version in 1.1.
|
|
+ *
|
|
+ * @param state Current state
|
|
+ * @param fortune Current item fortune level
|
|
+ * @param random Random number generator
|
|
+ * @return The number of items to drop
|
|
+ */
|
|
+ public int quantityDropped(IBlockState state, int fortune, Random random)
|
|
+ {
|
|
+ return quantityDroppedWithBonus(fortune, random);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * This returns a complete list of items dropped from this block.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param state Current state
|
|
+ * @param fortune Breakers fortune level
|
|
+ * @return A ArrayList containing all items this block drops
|
|
+ */
|
|
+ public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
|
|
+ {
|
|
+ List<ItemStack> ret = new java.util.ArrayList<ItemStack>();
|
|
+
|
|
+ Random rand = world instanceof World ? ((World)world).rand : RANDOM;
|
|
+
|
|
+ int count = quantityDropped(state, fortune, rand);
|
|
+ for(int i = 0; i < count; i++)
|
|
+ {
|
|
+ Item item = this.getItemDropped(state, rand, fortune);
|
|
+ if (item != null)
|
|
+ {
|
|
+ ret.add(new ItemStack(item, 1, this.damageDropped(state)));
|
|
+ }
|
|
+ }
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Return true from this function if the player with silk touch can harvest this block directly, and not it's normal drops.
|
|
+ *
|
|
+ * @param world The world
|
|
+ * @param pos Block position in world
|
|
+ * @param state current block state
|
|
+ * @param player The player doing the harvesting
|
|
+ * @return True if the block can be directly harvested using silk touch
|
|
+ */
|
|
+ public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player)
|
|
+ {
|
|
+ silk_check_state.set(state);;
|
|
+ boolean ret = this.canSilkHarvest();
|
|
+ silk_check_state.set(null);
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines if a specified mob type can spawn on this block, returning false will
|
|
+ * prevent any mob from spawning on the block.
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param type The Mob Category Type
|
|
+ * @return True to allow a mob of the specified category to spawn, false to prevent it.
|
|
+ */
|
|
+ public boolean canCreatureSpawn(IBlockState state, IBlockAccess world, BlockPos pos, net.minecraft.entity.EntityLiving.SpawnPlacementType type)
|
|
+ {
|
|
+ return isSideSolid(state, world, pos, EnumFacing.UP);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines if this block is classified as a Bed, Allowing
|
|
+ * players to sleep in it, though the block has to specifically
|
|
+ * perform the sleeping functionality in it's activated event.
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param player The player or camera entity, null in some cases.
|
|
+ * @return True to treat this as a bed
|
|
+ */
|
|
+ public boolean isBed(IBlockState state, IBlockAccess world, BlockPos pos, Entity player)
|
|
+ {
|
|
+ return this == net.minecraft.init.Blocks.bed;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Returns the position that the player is moved to upon
|
|
+ * waking up, or respawning at the bed.
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param player The player or camera entity, null in some cases.
|
|
+ * @return The spawn position
|
|
+ */
|
|
+ public BlockPos getBedSpawnPosition(IBlockState state, IBlockAccess world, BlockPos pos, EntityPlayer player)
|
|
+ {
|
|
+ if (world instanceof World)
|
|
+ return BlockBed.getSafeExitLocation((World)world, pos, 0);
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Called when a user either starts or stops sleeping in the bed.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param player The player or camera entity, null in some cases.
|
|
+ * @param occupied True if we are occupying the bed, or false if they are stopping use of the bed
|
|
+ */
|
|
+ public void setBedOccupied(IBlockAccess world, BlockPos pos, EntityPlayer player, boolean occupied)
|
|
+ {
|
|
+ if (world instanceof World)
|
|
+ {
|
|
+ IBlockState state = world.getBlockState(pos);
|
|
+ state = state.getBlock().getActualState(state, world, pos);
|
|
+ state = state.withProperty(BlockBed.OCCUPIED, true);
|
|
+ ((World)world).setBlockState(pos, state, 4);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Returns the direction of the block. Same values that
|
|
+ * are returned by BlockDirectional
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return Bed direction
|
|
+ */
|
|
+ public EnumFacing getBedDirection(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return (EnumFacing)getActualState(state, world, pos).getValue(BlockHorizontal.field_185512_D);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines if the current block is the foot half of the bed.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return True if the current block is the foot side of a bed.
|
|
+ */
|
|
+ public boolean isBedFoot(IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return getActualState(world.getBlockState(pos), world, pos).getValue(BlockBed.PART) == BlockBed.EnumPartType.FOOT;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Called when a leaf should start its decay process.
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ */
|
|
+ public void beginLeavesDecay(IBlockState state, World world, BlockPos pos){}
|
|
+
|
|
+ /**
|
|
+ * Determines if this block can prevent leaves connected to it from decaying.
|
|
+ * @param state The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return true if the presence this block can prevent leaves from decaying.
|
|
+ */
|
|
+ public boolean canSustainLeaves(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines if this block is considered a leaf block, used to apply the leaf decay and generation system.
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return true if this block is considered leaves.
|
|
+ */
|
|
+ public boolean isLeaves(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return state.func_185904_a() == Material.leaves;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Used during tree growth to determine if newly generated leaves can replace this block.
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return true if this block can be replaced by growing leaves.
|
|
+ */
|
|
+ public boolean canBeReplacedByLeaves(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return !state.func_185913_b();
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return true if the block is wood (logs)
|
|
+ */
|
|
+ public boolean isWood(IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines if the current block is replaceable by Ore veins during world generation.
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param target The generic target block the gen is looking for, Standards define stone
|
|
+ * for overworld generation, and neatherack for the nether.
|
|
+ * @return True to allow this block to be replaced by a ore
|
|
+ */
|
|
+ public boolean isReplaceableOreGen(IBlockState state, IBlockAccess world, BlockPos pos, com.google.common.base.Predicate<IBlockState> target)
|
|
+ {
|
|
+ return target.apply(state);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Location sensitive version of getExplosionRestance
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param exploder The entity that caused the explosion, can be null
|
|
+ * @param explosion The explosion
|
|
+ * @return The amount of the explosion absorbed.
|
|
+ */
|
|
+ public float getExplosionResistance(World world, BlockPos pos, Entity exploder, Explosion explosion)
|
|
+ {
|
|
+ return getExplosionResistance(exploder);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Called when the block is destroyed by an explosion.
|
|
+ * Useful for allowing the block to take into account tile entities,
|
|
+ * state, etc. when exploded, before it is removed.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param Explosion The explosion instance affecting the block
|
|
+ */
|
|
+ public void onBlockExploded(World world, BlockPos pos, Explosion explosion)
|
|
+ {
|
|
+ world.setBlockToAir(pos);
|
|
+ onBlockDestroyedByExplosion(world, pos, explosion);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determine if this block can make a redstone connection on the side provided,
|
|
+ * Useful to control which sides are inputs and outputs for redstone wires.
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param side The side that is trying to make the connection, CAN BE NULL
|
|
+ * @return True to make the connection
|
|
+ */
|
|
+ public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side)
|
|
+ {
|
|
+ return state.func_185897_m() && side != null;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines if a torch can be placed on the top surface of this block.
|
|
+ * Useful for creating your own block that torches can be on, such as fences.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return True to allow the torch to be placed
|
|
+ */
|
|
+ public boolean canPlaceTorchOnTop(IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ if (isSideSolid(world, pos, EnumFacing.UP))
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ return this instanceof BlockFence || this == net.minecraft.init.Blocks.glass || this == net.minecraft.init.Blocks.cobblestone_wall || this == net.minecraft.init.Blocks.stained_glass;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /** Dont think this exists in 1.8 anymore
|
|
+ /**
|
|
+ * Determines if this block should render in this pass.
|
|
+ *
|
|
+ * @param pass The pass in question
|
|
+ * @return True to render
|
|
+ * /
|
|
+ public boolean canRenderInPass(int pass)
|
|
+ {
|
|
+ return pass == func_149701_w();
|
|
+ }
|
|
+ */
|
|
+
|
|
+ /**
|
|
+ * Called when a user uses the creative pick block button on this block
|
|
+ *
|
|
+ * @param target The full target the player is looking at
|
|
+ * @return A ItemStack to add to the player's inventory, Null if nothing should be added.
|
|
+ */
|
|
+ public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player)
|
|
+ {
|
|
+ return getPickBlock(target, world, pos);
|
|
+ }
|
|
+ @Deprecated
|
|
+ public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos)
|
|
+ {
|
|
+ Item item = getItem(world, pos);
|
|
+
|
|
+ if (item == null)
|
|
+ {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ Block block = item instanceof ItemBlock && !isFlowerPot() ? Block.getBlockFromItem(item) : this;
|
|
+ return new ItemStack(item, 1, block.getDamageValue(world, pos));
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Used by getTopSolidOrLiquidBlock while placing biome decorations, villages, etc
|
|
+ * Also used to determine if the player can spawn on this block.
|
|
+ *
|
|
+ * @return False to disallow spawning
|
|
+ */
|
|
+ public boolean isFoliage(IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Allows a block to override the standard EntityLivingBase.updateFallState
|
|
+ * particles, this is a server side method that spawns particles with
|
|
+ * WorldServer.spawnParticle
|
|
+ *
|
|
+ * @param world The current Server world
|
|
+ * @param blockPosition of the block that the entity landed on.
|
|
+ * @param iblockstate State at the specific world/pos
|
|
+ * @param entity the entity that hit landed on the block.
|
|
+ * @param numberOfParticles that vanilla would have spawned.
|
|
+ * @return True to prevent vanilla landing particles form spawning.
|
|
+ */
|
|
+ public boolean addLandingEffects(net.minecraft.world.WorldServer worldObj, BlockPos blockPosition, IBlockState iblockstate, EntityLivingBase entity, int numberOfParticles )
|
|
+ {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Spawn a digging particle effect in the world, this is a wrapper
|
|
+ * around EffectRenderer.addBlockHitEffects to allow the block more
|
|
+ * control over the particles. Useful when you have entirely different
|
|
+ * texture sheets for different sides/locations in the world.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param target The target the player is looking at {x/y/z/side/sub}
|
|
+ * @param effectRenderer A reference to the current effect renderer.
|
|
+ * @return True to prevent vanilla digging particles form spawning.
|
|
+ */
|
|
+ @SideOnly(Side.CLIENT)
|
|
+ public boolean addHitEffects(World worldObj, MovingObjectPosition target, net.minecraft.client.particle.EffectRenderer effectRenderer)
|
|
+ {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Spawn particles for when the block is destroyed. Due to the nature
|
|
+ * of how this is invoked, the x/y/z locations are not always guaranteed
|
|
+ * to host your block. So be sure to do proper sanity checks before assuming
|
|
+ * that the location is this block.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Position to spawn the particle
|
|
+ * @param effectRenderer A reference to the current effect renderer.
|
|
+ * @return True to prevent vanilla break particles from spawning.
|
|
+ */
|
|
+ @SideOnly(Side.CLIENT)
|
|
+ public boolean addDestroyEffects(World world, BlockPos pos, net.minecraft.client.particle.EffectRenderer effectRenderer)
|
|
+ {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines if this block can support the passed in plant, allowing it to be planted and grow.
|
|
+ * Some examples:
|
|
+ * Reeds check if its a reed, or if its sand/dirt/grass and adjacent to water
|
|
+ * Cacti checks if its a cacti, or if its sand
|
|
+ * Nether types check for soul sand
|
|
+ * Crops check for tilled soil
|
|
+ * Caves check if it's a solid surface
|
|
+ * Plains check if its grass or dirt
|
|
+ * Water check if its still water
|
|
+ *
|
|
+ * @param state The Current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param direction The direction relative to the given position the plant wants to be, typically its UP
|
|
+ * @param plantable The plant that wants to check
|
|
+ * @return True to allow the plant to be planted/stay.
|
|
+ */
|
|
+ public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, net.minecraftforge.common.IPlantable plantable)
|
|
+ {
|
|
+ IBlockState plant = plantable.getPlant(world, pos.offset(direction));
|
|
+ net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
|
|
+
|
|
+ if (plant.getBlock() == net.minecraft.init.Blocks.cactus && this == net.minecraft.init.Blocks.cactus)
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ if (plant.getBlock() == net.minecraft.init.Blocks.reeds && this == net.minecraft.init.Blocks.reeds)
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ if (plantable instanceof BlockBush && ((BlockBush)plantable).canPlaceBlockOn(this))
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ switch (plantType)
|
|
+ {
|
|
+ case Desert: return this == net.minecraft.init.Blocks.sand || this == net.minecraft.init.Blocks.hardened_clay || this == net.minecraft.init.Blocks.stained_hardened_clay || this == net.minecraft.init.Blocks.dirt;
|
|
+ case Nether: return this == net.minecraft.init.Blocks.soul_sand;
|
|
+ case Crop: return this == net.minecraft.init.Blocks.farmland;
|
|
+ case Cave: return isSideSolid(world, pos, EnumFacing.UP);
|
|
+ case Plains: return this == net.minecraft.init.Blocks.grass || this == net.minecraft.init.Blocks.dirt || this == net.minecraft.init.Blocks.farmland;
|
|
+ case Water: return getMaterial() == Material.water && ((Integer)state.getValue(BlockLiquid.LEVEL)) == 0;
|
|
+ case Beach:
|
|
+ boolean isBeach = this == net.minecraft.init.Blocks.grass || this == net.minecraft.init.Blocks.dirt || this == net.minecraft.init.Blocks.sand;
|
|
+ boolean hasWater = (world.getBlockState(pos.east()).getBlock().getMaterial() == Material.water ||
|
|
+ world.getBlockState(pos.west()).getBlock().getMaterial() == Material.water ||
|
|
+ world.getBlockState(pos.north()).getBlock().getMaterial() == Material.water ||
|
|
+ world.getBlockState(pos.south()).getBlock().getMaterial() == Material.water);
|
|
+ return isBeach && hasWater;
|
|
+ }
|
|
+
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Called when a plant grows on this block, only implemented for saplings using the WorldGen*Trees classes right now.
|
|
+ * Modder may implement this for custom plants.
|
|
+ * This does not use ForgeDirection, because large/huge trees can be located in non-representable direction,
|
|
+ * so the source location is specified.
|
|
+ * Currently this just changes the block to dirt if it was grass.
|
|
+ *
|
|
+ * Note: This happens DURING the generation, the generation may not be complete when this is called.
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world Current world
|
|
+ * @param pos Block position in world
|
|
+ * @param source Source plant's position in world
|
|
+ */
|
|
+ public void onPlantGrow(IBlockState state, World world, BlockPos pos, BlockPos source)
|
|
+ {
|
|
+ if (this == net.minecraft.init.Blocks.grass || this == net.minecraft.init.Blocks.farmland)
|
|
+ {
|
|
+ world.setBlockState(pos, net.minecraft.init.Blocks.dirt.getDefaultState(), 2);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Checks if this soil is fertile, typically this means that growth rates
|
|
+ * of plants on this soil will be slightly sped up.
|
|
+ * Only vanilla case is tilledField when it is within range of water.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return True if the soil should be considered fertile.
|
|
+ */
|
|
+ public boolean isFertile(World world, BlockPos pos)
|
|
+ {
|
|
+ if (this == net.minecraft.init.Blocks.farmland)
|
|
+ {
|
|
+ return ((Integer)world.getBlockState(pos).getValue(BlockFarmland.MOISTURE)) > 0;
|
|
+ }
|
|
+
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Location aware and overrideable version of the lightOpacity array,
|
|
+ * return the number to subtract from the light value when it passes through this block.
|
|
+ *
|
|
+ * This is not guaranteed to have the tile entity in place before this is called, so it is
|
|
+ * Recommended that you have your tile entity call relight after being placed if you
|
|
+ * rely on it for light info.
|
|
+ *
|
|
+ * @param state The Block state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return The amount of light to block, 0 for air, 255 for fully opaque.
|
|
+ */
|
|
+ public int getLightOpacity(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return state.func_185891_c();
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines if this block is can be destroyed by the specified entities normal behavior.
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @return True to allow the ender dragon to destroy this block
|
|
+ */
|
|
+ public boolean canEntityDestroy(IBlockState state, IBlockAccess world, BlockPos pos, Entity entity)
|
|
+ {
|
|
+ if (entity instanceof net.minecraft.entity.boss.EntityDragon)
|
|
+ {
|
|
+ return this != net.minecraft.init.Blocks.barrier &&
|
|
+ this != net.minecraft.init.Blocks.obsidian &&
|
|
+ this != net.minecraft.init.Blocks.end_stone &&
|
|
+ this != net.minecraft.init.Blocks.bedrock &&
|
|
+ this != net.minecraft.init.Blocks.end_portal &&
|
|
+ this != net.minecraft.init.Blocks.end_portal_frame &&
|
|
+ this != net.minecraft.init.Blocks.command_block &&
|
|
+ this != net.minecraft.init.Blocks.field_185776_dc &&
|
|
+ this != net.minecraft.init.Blocks.field_185777_dd &&
|
|
+ this != net.minecraft.init.Blocks.iron_bars &&
|
|
+ this != net.minecraft.init.Blocks.field_185775_db;
|
|
+ }
|
|
+ else if (entity instanceof net.minecraft.entity.boss.EntityWither)
|
|
+ {
|
|
+ return net.minecraft.entity.boss.EntityWither.func_181033_a(this);
|
|
+ }
|
|
+
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines if this block can be used as the base of a beacon.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param beacon Beacon position in world
|
|
+ * @return True, to support the beacon, and make it active with this block.
|
|
+ */
|
|
+ public boolean isBeaconBase(IBlockAccess worldObj, BlockPos pos, BlockPos beacon)
|
|
+ {
|
|
+ return this == net.minecraft.init.Blocks.emerald_block || this == net.minecraft.init.Blocks.gold_block || this == net.minecraft.init.Blocks.diamond_block || this == net.minecraft.init.Blocks.iron_block;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Rotate the block. For vanilla blocks this rotates around the axis passed in (generally, it should be the "face" that was hit).
|
|
+ * Note: for mod blocks, this is up to the block and modder to decide. It is not mandated that it be a rotation around the
|
|
+ * face, but could be a rotation to orient *to* that face, or a visiting of possible rotations.
|
|
+ * The method should return true if the rotation was successful though.
|
|
+ *
|
|
+ * @param world The world
|
|
+ * @param pos Block position in world
|
|
+ * @param axis The axis to rotate around
|
|
+ * @return True if the rotation was successful, False if the rotation failed, or is not possible
|
|
+ */
|
|
+ public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis)
|
|
+ {
|
|
+ IBlockState state = world.getBlockState(pos);
|
|
+ for (IProperty<?> prop : state.getProperties().keySet())
|
|
+ {
|
|
+ if (prop.getName().equals("facing") || prop.getName().equals("rotation"))
|
|
+ {
|
|
+ world.setBlockState(pos, state.cycleProperty(prop));
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Get the rotations that can apply to the block at the specified coordinates. Null means no rotations are possible.
|
|
+ * Note, this is up to the block to decide. It may not be accurate or representative.
|
|
+ * @param world The world
|
|
+ * @param pos Block position in world
|
|
+ * @return An array of valid axes to rotate around, or null for none or unknown
|
|
+ */
|
|
+ public EnumFacing[] getValidRotations(World world, BlockPos pos)
|
|
+ {
|
|
+ IBlockState state = world.getBlockState(pos);
|
|
+ for (IProperty<?> prop : state.getProperties().keySet())
|
|
+ {
|
|
+ if (prop.getName().equals("facing") && prop.getValueClass() == EnumFacing.class)
|
|
+ {
|
|
+ @SuppressWarnings("unchecked")
|
|
+ java.util.Collection<EnumFacing> values = ((java.util.Collection<EnumFacing>)prop.getAllowedValues());
|
|
+ return values.toArray(new EnumFacing[values.size()]);
|
|
+ }
|
|
+ }
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determines the amount of enchanting power this block can provide to an enchanting table.
|
|
+ * @param world The World
|
|
+ * @param pos Block position in world
|
|
+ * @return The amount of enchanting power this block produces.
|
|
+ */
|
|
+ public float getEnchantPowerBonus(World world, BlockPos pos)
|
|
+ {
|
|
+ return this == net.minecraft.init.Blocks.bookshelf ? 1 : 0;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Common way to recolor a block with an external tool
|
|
+ * @param world The world
|
|
+ * @param pos Block position in world
|
|
+ * @param side The side hit with the coloring tool
|
|
+ * @param color The color to change to
|
|
+ * @return If the recoloring was successful
|
|
+ */
|
|
+ @SuppressWarnings({ "unchecked", "rawtypes" })
|
|
+ public boolean recolorBlock(World world, BlockPos pos, EnumFacing side, net.minecraft.item.EnumDyeColor color)
|
|
+ {
|
|
+ IBlockState state = world.getBlockState(pos);
|
|
+ for (IProperty prop : state.getProperties().keySet())
|
|
+ {
|
|
+ if (prop.getName().equals("color") && prop.getValueClass() == net.minecraft.item.EnumDyeColor.class)
|
|
+ {
|
|
+ net.minecraft.item.EnumDyeColor current = (net.minecraft.item.EnumDyeColor)state.getValue(prop);
|
|
+ if (current != color)
|
|
+ {
|
|
+ world.setBlockState(pos, state.withProperty(prop, color));
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Gathers how much experience this block drops when broken.
|
|
+ *
|
|
+ * @param state The current state
|
|
+ * @param world The world
|
|
+ * @param pos Block position
|
|
+ * @param fortune
|
|
+ * @return Amount of XP from breaking this block.
|
|
+ */
|
|
+ public int getExpDrop(IBlockState state, IBlockAccess world, BlockPos pos, int fortune)
|
|
+ {
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Called when a tile entity on a side of this block changes is created or is destroyed.
|
|
+ * @param world The world
|
|
+ * @param pos Block position in world
|
|
+ * @param neighbor Block position of neighbor
|
|
+ */
|
|
+ public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor){}
|
|
+
|
|
+ /**
|
|
+ * Called to determine whether to allow the a block to handle its own indirect power rather than using the default rules.
|
|
+ * @param world The world
|
|
+ * @param pos Block position in world
|
|
+ * @param side The INPUT side of the block to be powered - ie the opposite of this block's output side
|
|
+ * @return Whether Block#isProvidingWeakPower should be called when determining indirect power
|
|
+ */
|
|
+ public boolean shouldCheckWeakPower(IBlockAccess world, BlockPos pos, EnumFacing side)
|
|
+ {
|
|
+ return isNormalCube();
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * If this block should be notified of weak changes.
|
|
+ * Weak changes are changes 1 block away through a solid block.
|
|
+ * Similar to comparators.
|
|
+ *
|
|
+ * @param world The current world
|
|
+ * @param pos Block position in world
|
|
+ * @param side The side to check
|
|
+ * @return true To be notified of changes
|
|
+ */
|
|
+ public boolean getWeakChanges(IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ private String[] harvestTool = new String[16];;
|
|
+ private int[] harvestLevel = new int[]{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
|
|
+ /**
|
|
+ * Sets or removes the tool and level required to harvest this block.
|
|
+ *
|
|
+ * @param toolClass Class
|
|
+ * @param level Harvest level:
|
|
+ * Wood: 0
|
|
+ * Stone: 1
|
|
+ * Iron: 2
|
|
+ * Diamond: 3
|
|
+ * Gold: 0
|
|
+ */
|
|
+ public void setHarvestLevel(String toolClass, int level)
|
|
+ {
|
|
+ java.util.Iterator<IBlockState> itr = getBlockState().getValidStates().iterator();
|
|
+ while (itr.hasNext())
|
|
+ {
|
|
+ setHarvestLevel(toolClass, level, itr.next());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Sets or removes the tool and level required to harvest this block.
|
|
+ *
|
|
+ * @param toolClass Class
|
|
+ * @param level Harvest level:
|
|
+ * Wood: 0
|
|
+ * Stone: 1
|
|
+ * Iron: 2
|
|
+ * Diamond: 3
|
|
+ * Gold: 0
|
|
+ * @param state The specific state.
|
|
+ */
|
|
+ public void setHarvestLevel(String toolClass, int level, IBlockState state)
|
|
+ {
|
|
+ int idx = this.getMetaFromState(state);
|
|
+ this.harvestTool[idx] = toolClass;
|
|
+ this.harvestLevel[idx] = level;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Queries the class of tool required to harvest this block, if null is returned
|
|
+ * we assume that anything can harvest this block.
|
|
+ */
|
|
+ public String getHarvestTool(IBlockState state)
|
|
+ {
|
|
+ return harvestTool[getMetaFromState(state)];
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Queries the harvest level of this item stack for the specified tool class,
|
|
+ * Returns -1 if this tool is not of the specified type
|
|
+ *
|
|
+ * @param stack This item stack instance
|
|
+ * @return Harvest level, or -1 if not the specified tool type.
|
|
+ */
|
|
+ public int getHarvestLevel(IBlockState state)
|
|
+ {
|
|
+ return harvestLevel[getMetaFromState(state)];
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Checks if the specified tool type is efficient on this block,
|
|
+ * meaning that it digs at full speed.
|
|
+ */
|
|
+ public boolean isToolEffective(String type, IBlockState state)
|
|
+ {
|
|
+ if ("pickaxe".equals(type) && (this == net.minecraft.init.Blocks.redstone_ore || this == net.minecraft.init.Blocks.lit_redstone_ore || this == net.minecraft.init.Blocks.obsidian))
|
|
+ return false;
|
|
+ return type != null && type.equals(getHarvestTool(state));
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Can return IExtendedBlockState
|
|
+ */
|
|
+ public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
+ {
|
|
+ return state;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Called when the entity is inside this block, may be used to determined if the entity can breathing,
|
|
+ * display material overlays, or if the entity can swim inside a block.
|
|
+ *
|
|
+ * @param world that is being tested.
|
|
+ * @param blockpos position thats being tested.
|
|
+ * @param iblockstate state at world/blockpos
|
|
+ * @param entity that is being tested.
|
|
+ * @param yToTest, primarily for testingHead, which sends the the eye level of the entity, other wise it sends a y that can be tested vs liquid height.
|
|
+ * @param materialIn to test for.
|
|
+ * @param testingHead when true, its testing the entities head for vision, breathing ect... otherwise its testing the body, for swimming and movement adjustment.
|
|
+ * @return null for default behavior, true if the entity is within the material, false if it was not.
|
|
+ */
|
|
+ public Boolean isEntityInsideMaterial(World world, BlockPos blockpos, IBlockState iblockstate, Entity entity, double yToTest, Material materialIn, boolean testingHead)
|
|
+ {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Called when boats or fishing hooks are inside the block to check if they are inside
|
|
+ * the material requested.
|
|
+ *
|
|
+ * @param world world that is being tested.
|
|
+ * @param pos block thats being tested.
|
|
+ * @param boundingBox box to test, generally the bounds of an entity that are besting tested.
|
|
+ * @param materialIn to check for.
|
|
+ * @return null for default behavior, true if the box is within the material, false if it was not.
|
|
+ */
|
|
+ public Boolean isAABBInsideMaterial(World world, BlockPos pos, AxisAlignedBB boundingBox, Material materialIn)
|
|
+ {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Queries if this block should render in a given layer.
|
|
+ * ISmartBlockModel can use MinecraftForgeClient.getRenderLayer to alter their model based on layer
|
|
+ */
|
|
+ public boolean canRenderInLayer(BlockRenderLayer layer)
|
|
+ {
|
|
+ return getBlockLayer() == layer;
|
|
+ }
|
|
+
|
|
+ // For Internal use only to capture droped items inside getDrops
|
|
+ protected static ThreadLocal<Boolean> captureDrops = new ThreadLocal<Boolean>()
|
|
+ {
|
|
+ @Override protected Boolean initialValue() { return false; }
|
|
+ };
|
|
+ protected static ThreadLocal<List<ItemStack>> capturedDrops = new ThreadLocal<List<ItemStack>>()
|
|
+ {
|
|
+ @Override protected List<ItemStack> initialValue() { return new java.util.ArrayList<ItemStack>(); }
|
|
+ };
|
|
+ protected List<ItemStack> captureDrops(boolean start)
|
|
+ {
|
|
+ if (start)
|
|
+ {
|
|
+ captureDrops.set(true);
|
|
+ capturedDrops.get().clear();
|
|
+ return null;
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ captureDrops.set(false);
|
|
+ return capturedDrops.get();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private ResourceLocation registryName = null;
|
|
+ /**
|
|
+ * Sets a unique name for this Block. This should be used for uniquely identify the instance of the Block.
|
|
+ * This is the valid replacement for the atrocious 'getUnlocalizedName().substring(6)' stuff that everyone does.
|
|
+ * Unlocalized names have NOTHING to do with unique identifiers. As demonstrated by vanilla blocks and items.
|
|
+ *
|
|
+ * The supplied name will be prefixed with the currently active mod's modId.
|
|
+ * If the supplied name already has a prefix that is different, it will be used and a warning will be logged.
|
|
+ *
|
|
+ * If a name already exists, or this Block is already registered in a registry, then an IllegalStateException is thrown.
|
|
+ *
|
|
+ * Returns 'this' to allow for chaining.
|
|
+ *
|
|
+ * @param name Unique registry name
|
|
+ * @return This instance
|
|
+ */
|
|
+ public final Block setRegistryName(String name)
|
|
+ {
|
|
+ if (getRegistryName() != null)
|
|
+ throw new IllegalStateException("Attempted to set registry name on block with exisiting registry name! New: " + name + " Old: " + getRegistryName());
|
|
+ int index = name.lastIndexOf(':');
|
|
+ String oldPrefix = index == -1 ? "" : name.substring(0, index);
|
|
+ name = index == -1 ? name : name.substring(index + 1);
|
|
+ net.minecraftforge.fml.common.ModContainer mc = net.minecraftforge.fml.common.Loader.instance().activeModContainer();
|
|
+ String prefix = mc == null ? "minecraft" : mc.getModId();
|
|
+ if (!oldPrefix.equals(prefix) && oldPrefix.length() > 0)
|
|
+ {
|
|
+ net.minecraftforge.fml.common.FMLLog.bigWarning("Dangerous alternative prefix %s for name %s, invalid registry invocation/invalid name?", oldPrefix, name);
|
|
+ prefix = oldPrefix;
|
|
+ }
|
|
+ this.registryName = new ResourceLocation(prefix, name);
|
|
+ return this;
|
|
+ }
|
|
+ public final Block setRegistryName(ResourceLocation name){ return setRegistryName(name.toString()); }
|
|
+ public final Block setRegistryName(String modID, String name){ return setRegistryName(modID + ":" + name); }
|
|
+
|
|
+ /**
|
|
+ * A unique identifier for this block, if this block is registered in the game registry it will return that name.
|
|
+ * Otherwise it will return the name set in setRegistryName().
|
|
+ * If neither are valid null is returned.
|
|
+ *
|
|
+ * @return Unique identifier or null.
|
|
+ */
|
|
+ public final String getRegistryName()
|
|
+ {
|
|
+ if (delegate.getResourceName() != null) return delegate.getResourceName().toString();
|
|
+ return registryName != null ? registryName.toString() : null;
|
|
+ }
|
|
+ /* ========================================= FORGE END ======================================*/
|
|
+
|
|
public static void registerBlocks()
|
|
{
|
|
registerBlock(0, AIR_ID, (new BlockAir()).setUnlocalizedName("air"));
|