base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,82 @@
package net.minecraft.block;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockAir extends Block
{
protected BlockAir()
{
super(Material.AIR);
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.INVISIBLE;
}
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
return NULL_AABB;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean canCollideCheck(IBlockState state, boolean hitIfLiquid)
{
return false;
}
/**
* Spawns this Block's drops into the World as EntityItems.
*/
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
}
/**
* Whether this Block can be replaced directly by other blocks (true for e.g. tall grass)
*/
public boolean isReplaceable(IBlockAccess worldIn, BlockPos pos)
{
return true;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,243 @@
package net.minecraft.block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerRepair;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.IInteractionObject;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class BlockAnvil extends BlockFalling
{
public static final PropertyDirection FACING = BlockHorizontal.FACING;
public static final PropertyInteger DAMAGE = PropertyInteger.create("damage", 0, 2);
protected static final AxisAlignedBB X_AXIS_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.125D, 1.0D, 1.0D, 0.875D);
protected static final AxisAlignedBB Z_AXIS_AABB = new AxisAlignedBB(0.125D, 0.0D, 0.0D, 0.875D, 1.0D, 1.0D);
protected static final Logger LOGGER = LogManager.getLogger();
protected BlockAnvil()
{
super(Material.ANVIL);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(DAMAGE, Integer.valueOf(0)));
this.setLightOpacity(0);
this.setCreativeTab(CreativeTabs.DECORATIONS);
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
EnumFacing enumfacing = placer.getHorizontalFacing().rotateY();
try
{
return super.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(FACING, enumfacing).withProperty(DAMAGE, Integer.valueOf(meta >> 2));
}
catch (IllegalArgumentException var11)
{
if (!worldIn.isRemote)
{
LOGGER.warn(String.format("Invalid damage property for anvil at %s. Found %d, must be in [0, 1, 2]", pos, meta >> 2));
if (placer instanceof EntityPlayer)
{
placer.sendMessage(new TextComponentTranslation("Invalid damage property. Please pick in [0, 1, 2]", new Object[0]));
}
}
return super.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, placer).withProperty(FACING, enumfacing).withProperty(DAMAGE, Integer.valueOf(0));
}
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (!worldIn.isRemote)
{
playerIn.displayGui(new BlockAnvil.Anvil(worldIn, pos));
}
return true;
}
/**
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
* returns the metadata of the dropped item based on the old metadata of the block.
*/
public int damageDropped(IBlockState state)
{
return ((Integer)state.getValue(DAMAGE)).intValue();
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
return enumfacing.getAxis() == EnumFacing.Axis.X ? X_AXIS_AABB : Z_AXIS_AABB;
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
items.add(new ItemStack(this));
items.add(new ItemStack(this, 1, 1));
items.add(new ItemStack(this, 1, 2));
}
protected void onStartFalling(EntityFallingBlock fallingEntity)
{
fallingEntity.setHurtEntities(true);
}
public void onEndFalling(World worldIn, BlockPos pos, IBlockState p_176502_3_, IBlockState p_176502_4_)
{
worldIn.playEvent(1031, pos, 0);
}
public void onBroken(World worldIn, BlockPos pos)
{
worldIn.playEvent(1029, pos, 0);
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return true;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta & 3)).withProperty(DAMAGE, Integer.valueOf((meta & 15) >> 2));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
i = i | ((Integer)state.getValue(DAMAGE)).intValue() << 2;
return i;
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.getBlock() != this ? state : state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING, DAMAGE});
}
public static class Anvil implements IInteractionObject
{
private final World world;
private final BlockPos position;
public Anvil(World worldIn, BlockPos pos)
{
this.world = worldIn;
this.position = pos;
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return "anvil";
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return false;
}
/**
* Get the formatted ChatComponent that will be used for the sender's username in chat
*/
public ITextComponent getDisplayName()
{
return new TextComponentTranslation(Blocks.ANVIL.getUnlocalizedName() + ".name", new Object[0]);
}
public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
{
return new ContainerRepair(playerInventory, this.world, this.position, playerIn);
}
public String getGuiID()
{
return "minecraft:anvil";
}
}
}

View File

@@ -0,0 +1,336 @@
package net.minecraft.block;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityBanner;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockBanner extends BlockContainer
{
public static final PropertyDirection FACING = BlockHorizontal.FACING;
public static final PropertyInteger ROTATION = PropertyInteger.create("rotation", 0, 15);
protected static final AxisAlignedBB STANDING_AABB = new AxisAlignedBB(0.25D, 0.0D, 0.25D, 0.75D, 1.0D, 0.75D);
protected BlockBanner()
{
super(Material.WOOD);
}
/**
* Gets the localized name of this block. Used for the statistics page.
*/
public String getLocalizedName()
{
return I18n.translateToLocal("item.banner.white.name");
}
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
return NULL_AABB;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Determines if an entity can path through this block
*/
public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
{
return true;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* Return true if an entity can be spawned inside the block (used to get the player's bed spawn location)
*/
public boolean canSpawnInBlock()
{
return true;
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityBanner();
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.BANNER;
}
private ItemStack getTileDataItemStack(World worldIn, BlockPos pos)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
return tileentity instanceof TileEntityBanner ? ((TileEntityBanner)tileentity).getItem() : ItemStack.EMPTY;
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
ItemStack itemstack = this.getTileDataItemStack(worldIn, pos);
return itemstack.isEmpty() ? new ItemStack(Items.BANNER) : itemstack;
}
/**
* Spawns this Block's drops into the World as EntityItems.
*/
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
{
super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
}
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return !this.hasInvalidNeighbor(worldIn, pos) && super.canPlaceBlockAt(worldIn, pos);
}
/**
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via
* Block.removedByPlayer
*/
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
if (te instanceof TileEntityBanner)
{
TileEntityBanner tileentitybanner = (TileEntityBanner)te;
ItemStack itemstack = tileentitybanner.getItem();
spawnAsEntity(worldIn, pos, itemstack);
}
else
{
super.harvestBlock(worldIn, player, pos, state, (TileEntity)null, stack);
}
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
@Override
public void getDrops(net.minecraft.util.NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityBanner)
{
TileEntityBanner tileentitybanner = (TileEntityBanner)te;
ItemStack itemstack = tileentitybanner.getItem();
drops.add(itemstack);
}
else
{
drops.add(new ItemStack(Items.BANNER, 1, 0));
}
}
public static class BlockBannerHanging extends BlockBanner
{
protected static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.875D, 1.0D, 0.78125D, 1.0D);
protected static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.78125D, 0.125D);
protected static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.875D, 0.0D, 0.0D, 1.0D, 0.78125D, 1.0D);
protected static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.125D, 0.78125D, 1.0D);
public BlockBannerHanging()
{
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the
* passed blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the
* passed blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
switch ((EnumFacing)state.getValue(FACING))
{
case NORTH:
default:
return NORTH_AABB;
case SOUTH:
return SOUTH_AABB;
case WEST:
return WEST_AABB;
case EAST:
return EAST_AABB;
}
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a
* neighbor change. Cases may include when redstone power is updated, cactus blocks popping off due to a
* neighboring solid block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
if (!worldIn.getBlockState(pos.offset(enumfacing.getOpposite())).getMaterial().isSolid())
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
EnumFacing enumfacing = EnumFacing.getFront(meta);
if (enumfacing.getAxis() == EnumFacing.Axis.Y)
{
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(FACING, enumfacing);
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((EnumFacing)state.getValue(FACING)).getIndex();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING});
}
}
public static class BlockBannerStanding extends BlockBanner
{
public BlockBannerStanding()
{
this.setDefaultState(this.blockState.getBaseState().withProperty(ROTATION, Integer.valueOf(0)));
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return STANDING_AABB;
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the
* passed blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(ROTATION, Integer.valueOf(rot.rotate(((Integer)state.getValue(ROTATION)).intValue(), 16)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the
* passed blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withProperty(ROTATION, Integer.valueOf(mirrorIn.mirrorRotation(((Integer)state.getValue(ROTATION)).intValue(), 16)));
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a
* neighbor change. Cases may include when redstone power is updated, cactus blocks popping off due to a
* neighboring solid block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (!worldIn.getBlockState(pos.down()).getMaterial().isSolid())
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(ROTATION, Integer.valueOf(meta));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(ROTATION)).intValue();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {ROTATION});
}
}
}

View File

@@ -0,0 +1,51 @@
package net.minecraft.block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockBarrier extends Block
{
protected BlockBarrier()
{
super(Material.BARRIER);
this.setBlockUnbreakable();
this.setResistance(6000001.0F);
this.disableStats();
this.translucent = true;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.INVISIBLE;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
@SideOnly(Side.CLIENT)
public float getAmbientOcclusionLightValue(IBlockState state)
{
return 1.0F;
}
/**
* Spawns this Block's drops into the World as EntityItems.
*/
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
}
}

View File

@@ -0,0 +1,250 @@
package net.minecraft.block;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public abstract class BlockBasePressurePlate extends Block
{
/** The bounding box for the pressure plate pressed state */
protected static final AxisAlignedBB PRESSED_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.03125D, 0.9375D);
protected static final AxisAlignedBB UNPRESSED_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.0625D, 0.9375D);
/** This bounding box is used to check for entities in a certain area and then determine the pressed state. */
protected static final AxisAlignedBB PRESSURE_AABB = new AxisAlignedBB(0.125D, 0.0D, 0.125D, 0.875D, 0.25D, 0.875D);
protected BlockBasePressurePlate(Material materialIn)
{
this(materialIn, materialIn.getMaterialMapColor());
}
protected BlockBasePressurePlate(Material materialIn, MapColor mapColorIn)
{
super(materialIn, mapColorIn);
this.setCreativeTab(CreativeTabs.REDSTONE);
this.setTickRandomly(true);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
boolean flag = this.getRedstoneStrength(state) > 0;
return flag ? PRESSED_AABB : UNPRESSED_AABB;
}
/**
* How many world ticks before ticking
*/
public int tickRate(World worldIn)
{
return 20;
}
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
return NULL_AABB;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Determines if an entity can path through this block
*/
public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
{
return true;
}
/**
* Return true if an entity can be spawned inside the block (used to get the player's bed spawn location)
*/
public boolean canSpawnInBlock()
{
return true;
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return this.canBePlacedOn(worldIn, pos.down());
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (!this.canBePlacedOn(worldIn, pos.down()))
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
}
private boolean canBePlacedOn(World worldIn, BlockPos pos)
{
return worldIn.getBlockState(pos).isTopSolid() || worldIn.getBlockState(pos).getBlock() instanceof BlockFence;
}
/**
* Called randomly when setTickRandomly is set to true (used by e.g. crops to grow, etc.)
*/
public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random random)
{
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isRemote)
{
int i = this.getRedstoneStrength(state);
if (i > 0)
{
this.updateState(worldIn, pos, state, i);
}
}
}
/**
* Called When an Entity Collided with the Block
*/
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
if (!worldIn.isRemote)
{
int i = this.getRedstoneStrength(state);
if (i == 0)
{
this.updateState(worldIn, pos, state, i);
}
}
}
/**
* Updates the pressure plate when stepped on
*/
protected void updateState(World worldIn, BlockPos pos, IBlockState state, int oldRedstoneStrength)
{
int i = this.computeRedstoneStrength(worldIn, pos);
boolean flag = oldRedstoneStrength > 0;
boolean flag1 = i > 0;
if (oldRedstoneStrength != i)
{
state = this.setRedstoneStrength(state, i);
worldIn.setBlockState(pos, state, 2);
this.updateNeighbors(worldIn, pos);
worldIn.markBlockRangeForRenderUpdate(pos, pos);
}
if (!flag1 && flag)
{
this.playClickOffSound(worldIn, pos);
}
else if (flag1 && !flag)
{
this.playClickOnSound(worldIn, pos);
}
if (flag1)
{
worldIn.scheduleUpdate(new BlockPos(pos), this, this.tickRate(worldIn));
}
}
protected abstract void playClickOnSound(World worldIn, BlockPos color);
protected abstract void playClickOffSound(World worldIn, BlockPos pos);
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
if (this.getRedstoneStrength(state) > 0)
{
this.updateNeighbors(worldIn, pos);
}
super.breakBlock(worldIn, pos, state);
}
/**
* Notify block and block below of changes
*/
protected void updateNeighbors(World worldIn, BlockPos pos)
{
worldIn.notifyNeighborsOfStateChange(pos, this, false);
worldIn.notifyNeighborsOfStateChange(pos.down(), this, false);
}
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return this.getRedstoneStrength(blockState);
}
public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return side == EnumFacing.UP ? this.getRedstoneStrength(blockState) : 0;
}
/**
* Can this block provide power. Only wire currently seems to have this change based on its state.
*/
public boolean canProvidePower(IBlockState state)
{
return true;
}
public EnumPushReaction getMobilityFlag(IBlockState state)
{
return EnumPushReaction.DESTROY;
}
protected abstract int computeRedstoneStrength(World worldIn, BlockPos pos);
protected abstract int getRedstoneStrength(IBlockState state);
protected abstract IBlockState setRedstoneStrength(IBlockState state, int strength);
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,167 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityBeacon;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.HttpUtil;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockBeacon extends BlockContainer
{
public BlockBeacon()
{
super(Material.GLASS, MapColor.DIAMOND);
this.setHardness(3.0F);
this.setCreativeTab(CreativeTabs.MISC);
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityBeacon();
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
else
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityBeacon)
{
playerIn.displayGUIChest((TileEntityBeacon)tileentity);
playerIn.addStat(StatList.BEACON_INTERACTION);
}
return true;
}
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}
/**
* Called by ItemBlocks after a block is set in the world, to allow post-place logic
*/
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
if (stack.hasDisplayName())
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityBeacon)
{
((TileEntityBeacon)tileentity).setName(stack.getDisplayName());
}
}
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityBeacon)
{
((TileEntityBeacon)tileentity).updateBeacon();
worldIn.addBlockEvent(pos, this, 1, 0);
}
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
public static void updateColorAsync(final World worldIn, final BlockPos glassPos)
{
HttpUtil.DOWNLOADER_EXECUTOR.submit(new Runnable()
{
public void run()
{
Chunk chunk = worldIn.getChunkFromBlockCoords(glassPos);
for (int i = glassPos.getY() - 1; i >= 0; --i)
{
final BlockPos blockpos = new BlockPos(glassPos.getX(), i, glassPos.getZ());
if (!chunk.canSeeSky(blockpos))
{
break;
}
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.getBlock() == Blocks.BEACON)
{
((WorldServer)worldIn).addScheduledTask(new Runnable()
{
public void run()
{
TileEntity tileentity = worldIn.getTileEntity(blockpos);
if (tileentity instanceof TileEntityBeacon)
{
((TileEntityBeacon)tileentity).updateBeacon();
worldIn.addBlockEvent(blockpos, Blocks.BEACON, 1, 0);
}
}
});
}
}
}
});
}
}

View File

@@ -0,0 +1,513 @@
package net.minecraft.block;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Biomes;
import net.minecraft.init.Items;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityBed;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockBed extends BlockHorizontal implements ITileEntityProvider
{
public static final PropertyEnum<BlockBed.EnumPartType> PART = PropertyEnum.<BlockBed.EnumPartType>create("part", BlockBed.EnumPartType.class);
public static final PropertyBool OCCUPIED = PropertyBool.create("occupied");
protected static final AxisAlignedBB BED_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5625D, 1.0D);
public BlockBed()
{
super(Material.CLOTH);
this.setDefaultState(this.blockState.getBaseState().withProperty(PART, BlockBed.EnumPartType.FOOT).withProperty(OCCUPIED, Boolean.valueOf(false)));
this.hasTileEntity = true;
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
if (state.getValue(PART) == BlockBed.EnumPartType.FOOT)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityBed)
{
EnumDyeColor enumdyecolor = ((TileEntityBed)tileentity).getColor();
return MapColor.getBlockColor(enumdyecolor);
}
}
return MapColor.CLOTH;
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
else
{
if (state.getValue(PART) != BlockBed.EnumPartType.HEAD)
{
pos = pos.offset((EnumFacing)state.getValue(FACING));
state = worldIn.getBlockState(pos);
if (state.getBlock() != this)
{
return true;
}
}
net.minecraft.world.WorldProvider.WorldSleepResult sleepResult = worldIn.provider.canSleepAt(playerIn, pos);
if (sleepResult != net.minecraft.world.WorldProvider.WorldSleepResult.BED_EXPLODES)
{
if (sleepResult == net.minecraft.world.WorldProvider.WorldSleepResult.DENY) return true;
if (((Boolean)state.getValue(OCCUPIED)).booleanValue())
{
EntityPlayer entityplayer = this.getPlayerInBed(worldIn, pos);
if (entityplayer != null)
{
playerIn.sendStatusMessage(new TextComponentTranslation("tile.bed.occupied", new Object[0]), true);
return true;
}
state = state.withProperty(OCCUPIED, Boolean.valueOf(false));
worldIn.setBlockState(pos, state, 4);
}
EntityPlayer.SleepResult entityplayer$sleepresult = playerIn.trySleep(pos);
if (entityplayer$sleepresult == EntityPlayer.SleepResult.OK)
{
state = state.withProperty(OCCUPIED, Boolean.valueOf(true));
worldIn.setBlockState(pos, state, 4);
return true;
}
else
{
if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_POSSIBLE_NOW)
{
playerIn.sendStatusMessage(new TextComponentTranslation("tile.bed.noSleep", new Object[0]), true);
}
else if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_SAFE)
{
playerIn.sendStatusMessage(new TextComponentTranslation("tile.bed.notSafe", new Object[0]), true);
}
else if (entityplayer$sleepresult == EntityPlayer.SleepResult.TOO_FAR_AWAY)
{
playerIn.sendStatusMessage(new TextComponentTranslation("tile.bed.tooFarAway", new Object[0]), true);
}
return true;
}
}
else
{
worldIn.setBlockToAir(pos);
BlockPos blockpos = pos.offset(((EnumFacing)state.getValue(FACING)).getOpposite());
if (worldIn.getBlockState(blockpos).getBlock() == this)
{
worldIn.setBlockToAir(blockpos);
}
worldIn.newExplosion((Entity)null, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 5.0F, true, true);
return true;
}
}
}
@Nullable
private EntityPlayer getPlayerInBed(World worldIn, BlockPos pos)
{
for (EntityPlayer entityplayer : worldIn.playerEntities)
{
if (entityplayer.isPlayerSleeping() && entityplayer.bedLocation.equals(pos))
{
return entityplayer;
}
}
return null;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* Block's chance to react to a living entity falling on it.
*/
public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance)
{
super.onFallenUpon(worldIn, pos, entityIn, fallDistance * 0.5F);
}
/**
* Called when an Entity lands on this Block. This method *must* update motionY because the entity will not do that
* on its own
*/
public void onLanded(World worldIn, Entity entityIn)
{
if (entityIn.isSneaking())
{
super.onLanded(worldIn, entityIn);
}
else if (entityIn.motionY < 0.0D)
{
entityIn.motionY = -entityIn.motionY * 0.6600000262260437D;
if (!(entityIn instanceof EntityLivingBase))
{
entityIn.motionY *= 0.8D;
}
}
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
if (state.getValue(PART) == BlockBed.EnumPartType.FOOT)
{
if (worldIn.getBlockState(pos.offset(enumfacing)).getBlock() != this)
{
worldIn.setBlockToAir(pos);
}
}
else if (worldIn.getBlockState(pos.offset(enumfacing.getOpposite())).getBlock() != this)
{
if (!worldIn.isRemote)
{
this.dropBlockAsItem(worldIn, pos, state, 0);
}
worldIn.setBlockToAir(pos);
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return state.getValue(PART) == BlockBed.EnumPartType.FOOT ? Items.AIR : Items.BED;
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return BED_AABB;
}
@SideOnly(Side.CLIENT)
public boolean hasCustomBreakingProgress(IBlockState state)
{
return true;
}
/**
* Returns a safe BlockPos to disembark the bed
*/
@Nullable
public static BlockPos getSafeExitLocation(World worldIn, BlockPos pos, int tries)
{
EnumFacing enumfacing = (EnumFacing)worldIn.getBlockState(pos).getValue(FACING);
int i = pos.getX();
int j = pos.getY();
int k = pos.getZ();
for (int l = 0; l <= 1; ++l)
{
int i1 = i - enumfacing.getFrontOffsetX() * l - 1;
int j1 = k - enumfacing.getFrontOffsetZ() * l - 1;
int k1 = i1 + 2;
int l1 = j1 + 2;
for (int i2 = i1; i2 <= k1; ++i2)
{
for (int j2 = j1; j2 <= l1; ++j2)
{
BlockPos blockpos = new BlockPos(i2, j, j2);
if (hasRoomForPlayer(worldIn, blockpos))
{
if (tries <= 0)
{
return blockpos;
}
--tries;
}
}
}
}
return null;
}
protected static boolean hasRoomForPlayer(World worldIn, BlockPos pos)
{
return worldIn.getBlockState(pos.down()).isTopSolid() && !worldIn.getBlockState(pos).getMaterial().isSolid() && !worldIn.getBlockState(pos.up()).getMaterial().isSolid();
}
/**
* Spawns this Block's drops into the World as EntityItems.
*/
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
if (state.getValue(PART) == BlockBed.EnumPartType.HEAD)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
EnumDyeColor enumdyecolor = tileentity instanceof TileEntityBed ? ((TileEntityBed)tileentity).getColor() : EnumDyeColor.RED;
spawnAsEntity(worldIn, pos, new ItemStack(Items.BED, 1, enumdyecolor.getMetadata()));
}
}
public EnumPushReaction getMobilityFlag(IBlockState state)
{
return EnumPushReaction.DESTROY;
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
BlockPos blockpos = pos;
if (state.getValue(PART) == BlockBed.EnumPartType.FOOT)
{
blockpos = pos.offset((EnumFacing)state.getValue(FACING));
}
TileEntity tileentity = worldIn.getTileEntity(blockpos);
EnumDyeColor enumdyecolor = tileentity instanceof TileEntityBed ? ((TileEntityBed)tileentity).getColor() : EnumDyeColor.RED;
return new ItemStack(Items.BED, 1, enumdyecolor.getMetadata());
}
/**
* Called before the Block is set to air in the world. Called regardless of if the player's tool can actually
* collect this block
*/
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
if (player.capabilities.isCreativeMode && state.getValue(PART) == BlockBed.EnumPartType.FOOT)
{
BlockPos blockpos = pos.offset((EnumFacing)state.getValue(FACING));
if (worldIn.getBlockState(blockpos).getBlock() == this)
{
worldIn.setBlockToAir(blockpos);
}
}
}
/**
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via
* Block.removedByPlayer
*/
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack stack)
{
if (state.getValue(PART) == BlockBed.EnumPartType.HEAD && te instanceof TileEntityBed)
{
TileEntityBed tileentitybed = (TileEntityBed)te;
ItemStack itemstack = tileentitybed.getItemStack();
spawnAsEntity(worldIn, pos, itemstack);
}
else
{
super.harvestBlock(worldIn, player, pos, state, (TileEntity)null, stack);
}
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
super.breakBlock(worldIn, pos, state);
worldIn.removeTileEntity(pos);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
EnumFacing enumfacing = EnumFacing.getHorizontal(meta);
return (meta & 8) > 0 ? this.getDefaultState().withProperty(PART, BlockBed.EnumPartType.HEAD).withProperty(FACING, enumfacing).withProperty(OCCUPIED, Boolean.valueOf((meta & 4) > 0)) : this.getDefaultState().withProperty(PART, BlockBed.EnumPartType.FOOT).withProperty(FACING, enumfacing);
}
/**
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
* metadata, such as fence connections.
*/
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
if (state.getValue(PART) == BlockBed.EnumPartType.FOOT)
{
IBlockState iblockstate = worldIn.getBlockState(pos.offset((EnumFacing)state.getValue(FACING)));
if (iblockstate.getBlock() == this)
{
state = state.withProperty(OCCUPIED, iblockstate.getValue(OCCUPIED));
}
}
return state;
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
if (state.getValue(PART) == BlockBed.EnumPartType.HEAD)
{
i |= 8;
if (((Boolean)state.getValue(OCCUPIED)).booleanValue())
{
i |= 4;
}
}
return i;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING, PART, OCCUPIED});
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityBed();
}
@SideOnly(Side.CLIENT)
public static boolean isHeadPiece(int metadata)
{
return (metadata & 8) != 0;
}
public static enum EnumPartType implements IStringSerializable
{
HEAD("head"),
FOOT("foot");
private final String name;
private EnumPartType(String name)
{
this.name = name;
}
public String toString()
{
return this.name;
}
public String getName()
{
return this.name;
}
}
}

View File

@@ -0,0 +1,66 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockBeetroot extends BlockCrops
{
public static final PropertyInteger BEETROOT_AGE = PropertyInteger.create("age", 0, 3);
private static final AxisAlignedBB[] BEETROOT_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.125D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.25D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.375D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5D, 1.0D)};
protected PropertyInteger getAgeProperty()
{
return BEETROOT_AGE;
}
public int getMaxAge()
{
return 3;
}
protected Item getSeed()
{
return Items.BEETROOT_SEEDS;
}
protected Item getCrop()
{
return Items.BEETROOT;
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (rand.nextInt(3) == 0)
{
this.checkAndDropBlock(worldIn, pos, state);
}
else
{
super.updateTick(worldIn, pos, state, rand);
}
}
protected int getBonemealAgeIncrease(World worldIn)
{
return super.getBonemealAgeIncrease(worldIn) / 3;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {BEETROOT_AGE});
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return BEETROOT_AABB[((Integer)state.getValue(this.getAgeProperty())).intValue()];
}
}

View File

@@ -0,0 +1,16 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
public class BlockBone extends BlockRotatedPillar
{
public BlockBone()
{
super(Material.ROCK, MapColor.SAND);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
this.setHardness(2.0F);
this.setSoundType(SoundType.STONE);
}
}

View File

@@ -0,0 +1,33 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
public class BlockBookshelf extends Block
{
public BlockBookshelf()
{
super(Material.WOOD);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 3;
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.BOOK;
}
}

View File

@@ -0,0 +1,57 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockBreakable extends Block
{
private final boolean ignoreSimilarity;
protected BlockBreakable(Material materialIn, boolean ignoreSimilarityIn)
{
this(materialIn, ignoreSimilarityIn, materialIn.getMaterialMapColor());
}
protected BlockBreakable(Material materialIn, boolean ignoreSimilarityIn, MapColor mapColorIn)
{
super(materialIn, mapColorIn);
this.ignoreSimilarity = ignoreSimilarityIn;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
Block block = iblockstate.getBlock();
if (this == Blocks.GLASS || this == Blocks.STAINED_GLASS)
{
if (blockState != iblockstate)
{
return true;
}
if (block == this)
{
return false;
}
}
return !this.ignoreSimilarity && block == this ? false : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
}

View File

@@ -0,0 +1,240 @@
package net.minecraft.block;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityBrewingStand;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockBrewingStand extends BlockContainer
{
public static final PropertyBool[] HAS_BOTTLE = new PropertyBool[] {PropertyBool.create("has_bottle_0"), PropertyBool.create("has_bottle_1"), PropertyBool.create("has_bottle_2")};
protected static final AxisAlignedBB BASE_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.125D, 1.0D);
protected static final AxisAlignedBB STICK_AABB = new AxisAlignedBB(0.4375D, 0.0D, 0.4375D, 0.5625D, 0.875D, 0.5625D);
public BlockBrewingStand()
{
super(Material.IRON);
this.setDefaultState(this.blockState.getBaseState().withProperty(HAS_BOTTLE[0], Boolean.valueOf(false)).withProperty(HAS_BOTTLE[1], Boolean.valueOf(false)).withProperty(HAS_BOTTLE[2], Boolean.valueOf(false)));
}
/**
* Gets the localized name of this block. Used for the statistics page.
*/
public String getLocalizedName()
{
return I18n.translateToLocal("item.brewingStand.name");
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityBrewingStand();
}
public boolean isFullCube(IBlockState state)
{
return false;
}
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, STICK_AABB);
addCollisionBoxToList(pos, entityBox, collidingBoxes, BASE_AABB);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return BASE_AABB;
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
else
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityBrewingStand)
{
playerIn.displayGUIChest((TileEntityBrewingStand)tileentity);
playerIn.addStat(StatList.BREWINGSTAND_INTERACTION);
}
return true;
}
}
/**
* Called by ItemBlocks after a block is set in the world, to allow post-place logic
*/
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
if (stack.hasDisplayName())
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityBrewingStand)
{
((TileEntityBrewingStand)tileentity).setName(stack.getDisplayName());
}
}
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
double d0 = (double)((float)pos.getX() + 0.4F + rand.nextFloat() * 0.2F);
double d1 = (double)((float)pos.getY() + 0.7F + rand.nextFloat() * 0.3F);
double d2 = (double)((float)pos.getZ() + 0.4F + rand.nextFloat() * 0.2F);
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityBrewingStand)
{
InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityBrewingStand)tileentity);
}
super.breakBlock(worldIn, pos, state);
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.BREWING_STAND;
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(Items.BREWING_STAND);
}
public boolean hasComparatorInputOverride(IBlockState state)
{
return true;
}
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
{
return Container.calcRedstone(worldIn.getTileEntity(pos));
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
IBlockState iblockstate = this.getDefaultState();
for (int i = 0; i < 3; ++i)
{
iblockstate = iblockstate.withProperty(HAS_BOTTLE[i], Boolean.valueOf((meta & 1 << i) > 0));
}
return iblockstate;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
for (int j = 0; j < 3; ++j)
{
if (((Boolean)state.getValue(HAS_BOTTLE[j])).booleanValue())
{
i |= 1 << j;
}
}
return i;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {HAS_BOTTLE[0], HAS_BOTTLE[1], HAS_BOTTLE[2]});
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,166 @@
package net.minecraft.block;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockBush extends Block implements net.minecraftforge.common.IPlantable
{
protected static final AxisAlignedBB BUSH_AABB = new AxisAlignedBB(0.30000001192092896D, 0.0D, 0.30000001192092896D, 0.699999988079071D, 0.6000000238418579D, 0.699999988079071D);
protected BlockBush()
{
this(Material.PLANTS);
}
protected BlockBush(Material materialIn)
{
this(materialIn, materialIn.getMaterialMapColor());
}
protected BlockBush(Material materialIn, MapColor mapColorIn)
{
super(materialIn, mapColorIn);
this.setTickRandomly(true);
this.setCreativeTab(CreativeTabs.DECORATIONS);
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
IBlockState soil = worldIn.getBlockState(pos.down());
return super.canPlaceBlockAt(worldIn, pos) && soil.getBlock().canSustainPlant(soil, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
}
/**
* Return true if the block can sustain a Bush
*/
protected boolean canSustainBush(IBlockState state)
{
return state.getBlock() == Blocks.GRASS || state.getBlock() == Blocks.DIRT || state.getBlock() == Blocks.FARMLAND;
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
this.checkAndDropBlock(worldIn, pos, state);
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
this.checkAndDropBlock(worldIn, pos, state);
}
protected void checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state)
{
if (!this.canBlockStay(worldIn, pos, state))
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
}
}
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
if (state.getBlock() == this) //Forge: This function is called during world gen and placement, before this block is set, so if we are not 'here' then assume it's the pre-check.
{
IBlockState soil = worldIn.getBlockState(pos.down());
return soil.getBlock().canSustainPlant(soil, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
}
return this.canSustainBush(worldIn.getBlockState(pos.down()));
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return BUSH_AABB;
}
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
return NULL_AABB;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
@Override
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos)
{
if (this == Blocks.WHEAT) return net.minecraftforge.common.EnumPlantType.Crop;
if (this == Blocks.CARROTS) return net.minecraftforge.common.EnumPlantType.Crop;
if (this == Blocks.POTATOES) return net.minecraftforge.common.EnumPlantType.Crop;
if (this == Blocks.BEETROOTS) return net.minecraftforge.common.EnumPlantType.Crop;
if (this == Blocks.MELON_STEM) return net.minecraftforge.common.EnumPlantType.Crop;
if (this == Blocks.PUMPKIN_STEM) return net.minecraftforge.common.EnumPlantType.Crop;
if (this == Blocks.DEADBUSH) return net.minecraftforge.common.EnumPlantType.Desert;
if (this == Blocks.WATERLILY) return net.minecraftforge.common.EnumPlantType.Water;
if (this == Blocks.RED_MUSHROOM) return net.minecraftforge.common.EnumPlantType.Cave;
if (this == Blocks.BROWN_MUSHROOM) return net.minecraftforge.common.EnumPlantType.Cave;
if (this == Blocks.NETHER_WART) return net.minecraftforge.common.EnumPlantType.Nether;
if (this == Blocks.SAPLING) return net.minecraftforge.common.EnumPlantType.Plains;
if (this == Blocks.TALLGRASS) return net.minecraftforge.common.EnumPlantType.Plains;
if (this == Blocks.DOUBLE_PLANT) return net.minecraftforge.common.EnumPlantType.Plains;
if (this == Blocks.RED_FLOWER) return net.minecraftforge.common.EnumPlantType.Plains;
if (this == Blocks.YELLOW_FLOWER) return net.minecraftforge.common.EnumPlantType.Plains;
return net.minecraftforge.common.EnumPlantType.Plains;
}
@Override
public IBlockState getPlant(net.minecraft.world.IBlockAccess world, BlockPos pos)
{
IBlockState state = world.getBlockState(pos);
if (state.getBlock() != this) return getDefaultState();
return state;
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,430 @@
package net.minecraft.block;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public abstract class BlockButton extends BlockDirectional
{
public static final PropertyBool POWERED = PropertyBool.create("powered");
protected static final AxisAlignedBB AABB_DOWN_OFF = new AxisAlignedBB(0.3125D, 0.875D, 0.375D, 0.6875D, 1.0D, 0.625D);
protected static final AxisAlignedBB AABB_UP_OFF = new AxisAlignedBB(0.3125D, 0.0D, 0.375D, 0.6875D, 0.125D, 0.625D);
protected static final AxisAlignedBB AABB_NORTH_OFF = new AxisAlignedBB(0.3125D, 0.375D, 0.875D, 0.6875D, 0.625D, 1.0D);
protected static final AxisAlignedBB AABB_SOUTH_OFF = new AxisAlignedBB(0.3125D, 0.375D, 0.0D, 0.6875D, 0.625D, 0.125D);
protected static final AxisAlignedBB AABB_WEST_OFF = new AxisAlignedBB(0.875D, 0.375D, 0.3125D, 1.0D, 0.625D, 0.6875D);
protected static final AxisAlignedBB AABB_EAST_OFF = new AxisAlignedBB(0.0D, 0.375D, 0.3125D, 0.125D, 0.625D, 0.6875D);
protected static final AxisAlignedBB AABB_DOWN_ON = new AxisAlignedBB(0.3125D, 0.9375D, 0.375D, 0.6875D, 1.0D, 0.625D);
protected static final AxisAlignedBB AABB_UP_ON = new AxisAlignedBB(0.3125D, 0.0D, 0.375D, 0.6875D, 0.0625D, 0.625D);
protected static final AxisAlignedBB AABB_NORTH_ON = new AxisAlignedBB(0.3125D, 0.375D, 0.9375D, 0.6875D, 0.625D, 1.0D);
protected static final AxisAlignedBB AABB_SOUTH_ON = new AxisAlignedBB(0.3125D, 0.375D, 0.0D, 0.6875D, 0.625D, 0.0625D);
protected static final AxisAlignedBB AABB_WEST_ON = new AxisAlignedBB(0.9375D, 0.375D, 0.3125D, 1.0D, 0.625D, 0.6875D);
protected static final AxisAlignedBB AABB_EAST_ON = new AxisAlignedBB(0.0D, 0.375D, 0.3125D, 0.0625D, 0.625D, 0.6875D);
private final boolean wooden;
protected BlockButton(boolean wooden)
{
super(Material.CIRCUITS);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(POWERED, Boolean.valueOf(false)));
this.setTickRandomly(true);
this.setCreativeTab(CreativeTabs.REDSTONE);
this.wooden = wooden;
}
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
return NULL_AABB;
}
/**
* How many world ticks before ticking
*/
public int tickRate(World worldIn)
{
return this.wooden ? 30 : 20;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Check whether this Block can be placed at pos, while aiming at the specified side of an adjacent block
*/
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side)
{
return canPlaceBlock(worldIn, pos, side);
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
for (EnumFacing enumfacing : EnumFacing.values())
{
if (canPlaceBlock(worldIn, pos, enumfacing))
{
return true;
}
}
return false;
}
/**
* Check whether this block can be placed on the block in the given direction.
*/
protected static boolean canPlaceBlock(World worldIn, BlockPos pos, EnumFacing direction)
{
BlockPos blockpos = pos.offset(direction.getOpposite());
IBlockState iblockstate = worldIn.getBlockState(blockpos);
boolean flag = iblockstate.getBlockFaceShape(worldIn, blockpos, direction) == BlockFaceShape.SOLID;
Block block = iblockstate.getBlock();
if (direction == EnumFacing.UP)
{
return iblockstate.isTopSolid() || !isExceptionBlockForAttaching(block) && flag;
}
else
{
return !isExceptBlockForAttachWithPiston(block) && flag;
}
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return canPlaceBlock(worldIn, pos, facing) ? this.getDefaultState().withProperty(FACING, facing).withProperty(POWERED, Boolean.valueOf(false)) : this.getDefaultState().withProperty(FACING, EnumFacing.DOWN).withProperty(POWERED, Boolean.valueOf(false));
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (this.checkForDrop(worldIn, pos, state) && !canPlaceBlock(worldIn, pos, (EnumFacing)state.getValue(FACING)))
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
}
private boolean checkForDrop(World worldIn, BlockPos pos, IBlockState state)
{
if (this.canPlaceBlockAt(worldIn, pos))
{
return true;
}
else
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
return false;
}
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
boolean flag = ((Boolean)state.getValue(POWERED)).booleanValue();
switch (enumfacing)
{
case EAST:
return flag ? AABB_EAST_ON : AABB_EAST_OFF;
case WEST:
return flag ? AABB_WEST_ON : AABB_WEST_OFF;
case SOUTH:
return flag ? AABB_SOUTH_ON : AABB_SOUTH_OFF;
case NORTH:
default:
return flag ? AABB_NORTH_ON : AABB_NORTH_OFF;
case UP:
return flag ? AABB_UP_ON : AABB_UP_OFF;
case DOWN:
return flag ? AABB_DOWN_ON : AABB_DOWN_OFF;
}
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (((Boolean)state.getValue(POWERED)).booleanValue())
{
return true;
}
else
{
worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)), 3);
worldIn.markBlockRangeForRenderUpdate(pos, pos);
this.playClickSound(playerIn, worldIn, pos);
this.notifyNeighbors(worldIn, pos, (EnumFacing)state.getValue(FACING));
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
return true;
}
}
protected abstract void playClickSound(@Nullable EntityPlayer player, World worldIn, BlockPos pos);
protected abstract void playReleaseSound(World worldIn, BlockPos pos);
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
if (((Boolean)state.getValue(POWERED)).booleanValue())
{
this.notifyNeighbors(worldIn, pos, (EnumFacing)state.getValue(FACING));
}
super.breakBlock(worldIn, pos, state);
}
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return ((Boolean)blockState.getValue(POWERED)).booleanValue() ? 15 : 0;
}
public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
if (!((Boolean)blockState.getValue(POWERED)).booleanValue())
{
return 0;
}
else
{
return blockState.getValue(FACING) == side ? 15 : 0;
}
}
/**
* Can this block provide power. Only wire currently seems to have this change based on its state.
*/
public boolean canProvidePower(IBlockState state)
{
return true;
}
/**
* Called randomly when setTickRandomly is set to true (used by e.g. crops to grow, etc.)
*/
public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random random)
{
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isRemote)
{
if (((Boolean)state.getValue(POWERED)).booleanValue())
{
if (this.wooden)
{
this.checkPressed(state, worldIn, pos);
}
else
{
worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)));
this.notifyNeighbors(worldIn, pos, (EnumFacing)state.getValue(FACING));
this.playReleaseSound(worldIn, pos);
worldIn.markBlockRangeForRenderUpdate(pos, pos);
}
}
}
}
/**
* Called When an Entity Collided with the Block
*/
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
if (!worldIn.isRemote)
{
if (this.wooden)
{
if (!((Boolean)state.getValue(POWERED)).booleanValue())
{
this.checkPressed(state, worldIn, pos);
}
}
}
}
private void checkPressed(IBlockState state, World worldIn, BlockPos pos)
{
List <? extends Entity > list = worldIn.<Entity>getEntitiesWithinAABB(EntityArrow.class, state.getBoundingBox(worldIn, pos).offset(pos));
boolean flag = !list.isEmpty();
boolean flag1 = ((Boolean)state.getValue(POWERED)).booleanValue();
if (flag && !flag1)
{
worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)));
this.notifyNeighbors(worldIn, pos, (EnumFacing)state.getValue(FACING));
worldIn.markBlockRangeForRenderUpdate(pos, pos);
this.playClickSound((EntityPlayer)null, worldIn, pos);
}
if (!flag && flag1)
{
worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)));
this.notifyNeighbors(worldIn, pos, (EnumFacing)state.getValue(FACING));
worldIn.markBlockRangeForRenderUpdate(pos, pos);
this.playReleaseSound(worldIn, pos);
}
if (flag)
{
worldIn.scheduleUpdate(new BlockPos(pos), this, this.tickRate(worldIn));
}
}
private void notifyNeighbors(World worldIn, BlockPos pos, EnumFacing facing)
{
worldIn.notifyNeighborsOfStateChange(pos, this, false);
worldIn.notifyNeighborsOfStateChange(pos.offset(facing.getOpposite()), this, false);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
EnumFacing enumfacing;
switch (meta & 7)
{
case 0:
enumfacing = EnumFacing.DOWN;
break;
case 1:
enumfacing = EnumFacing.EAST;
break;
case 2:
enumfacing = EnumFacing.WEST;
break;
case 3:
enumfacing = EnumFacing.SOUTH;
break;
case 4:
enumfacing = EnumFacing.NORTH;
break;
case 5:
default:
enumfacing = EnumFacing.UP;
}
return this.getDefaultState().withProperty(FACING, enumfacing).withProperty(POWERED, Boolean.valueOf((meta & 8) > 0));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i;
switch ((EnumFacing)state.getValue(FACING))
{
case EAST:
i = 1;
break;
case WEST:
i = 2;
break;
case SOUTH:
i = 3;
break;
case NORTH:
i = 4;
break;
case UP:
default:
i = 5;
break;
case DOWN:
i = 0;
}
if (((Boolean)state.getValue(POWERED)).booleanValue())
{
i |= 8;
}
return i;
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING, POWERED});
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,26 @@
package net.minecraft.block;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockButtonStone extends BlockButton
{
protected BlockButtonStone()
{
super(false);
}
protected void playClickSound(@Nullable EntityPlayer player, World worldIn, BlockPos pos)
{
worldIn.playSound(player, pos, SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON, SoundCategory.BLOCKS, 0.3F, 0.6F);
}
protected void playReleaseSound(World worldIn, BlockPos pos)
{
worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_STONE_BUTTON_CLICK_OFF, SoundCategory.BLOCKS, 0.3F, 0.5F);
}
}

View File

@@ -0,0 +1,26 @@
package net.minecraft.block;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockButtonWood extends BlockButton
{
protected BlockButtonWood()
{
super(true);
}
protected void playClickSound(@Nullable EntityPlayer player, World worldIn, BlockPos pos)
{
worldIn.playSound(player, pos, SoundEvents.BLOCK_WOOD_BUTTON_CLICK_ON, SoundCategory.BLOCKS, 0.3F, 0.6F);
}
protected void playReleaseSound(World worldIn, BlockPos pos)
{
worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_WOOD_BUTTON_CLICK_OFF, SoundCategory.BLOCKS, 0.3F, 0.5F);
}
}

View File

@@ -0,0 +1,198 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockCactus extends Block implements net.minecraftforge.common.IPlantable
{
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 15);
protected static final AxisAlignedBB CACTUS_COLLISION_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.9375D, 0.9375D);
protected static final AxisAlignedBB CACTUS_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 1.0D, 0.9375D);
protected BlockCactus()
{
super(Material.CACTUS);
this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0)));
this.setTickRandomly(true);
this.setCreativeTab(CreativeTabs.DECORATIONS);
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent growing cactus from loading unloaded chunks with block update
BlockPos blockpos = pos.up();
if (worldIn.isAirBlock(blockpos))
{
int i;
for (i = 1; worldIn.getBlockState(pos.down(i)).getBlock() == this; ++i)
{
;
}
if (i < 3)
{
int j = ((Integer)state.getValue(AGE)).intValue();
if(net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, blockpos, state, true))
{
if (j == 15)
{
worldIn.setBlockState(blockpos, this.getDefaultState());
IBlockState iblockstate = state.withProperty(AGE, Integer.valueOf(0));
worldIn.setBlockState(pos, iblockstate, 4);
iblockstate.neighborChanged(worldIn, blockpos, this, pos);
}
else
{
worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(j + 1)), 4);
}
net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
}
}
}
}
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
return CACTUS_COLLISION_AABB;
}
/**
* Return an AABB (in world coords!) that should be highlighted when the player is targeting this Block
*/
@SideOnly(Side.CLIENT)
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos)
{
return CACTUS_AABB.offset(pos);
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return super.canPlaceBlockAt(worldIn, pos) ? this.canBlockStay(worldIn, pos) : false;
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (!this.canBlockStay(worldIn, pos))
{
worldIn.destroyBlock(pos, true);
}
}
public boolean canBlockStay(World worldIn, BlockPos pos)
{
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
Material material = worldIn.getBlockState(pos.offset(enumfacing)).getMaterial();
if (material.isSolid() || material == Material.LAVA)
{
return false;
}
}
IBlockState state = worldIn.getBlockState(pos.down());
return state.getBlock().canSustainPlant(state, worldIn, pos.down(), EnumFacing.UP, this) && !worldIn.getBlockState(pos.up()).getMaterial().isLiquid();
}
/**
* Called When an Entity Collided with the Block
*/
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
entityIn.attackEntityFrom(DamageSource.CACTUS, 1.0F);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(AGE, Integer.valueOf(meta));
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(AGE)).intValue();
}
@Override
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos)
{
return net.minecraftforge.common.EnumPlantType.Desert;
}
@Override
public IBlockState getPlant(net.minecraft.world.IBlockAccess world, BlockPos pos)
{
return getDefaultState();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {AGE});
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,193 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockCake extends Block
{
public static final PropertyInteger BITES = PropertyInteger.create("bites", 0, 6);
protected static final AxisAlignedBB[] CAKE_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.1875D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.3125D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.4375D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.5625D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.6875D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.8125D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D)};
protected BlockCake()
{
super(Material.CAKE);
this.setDefaultState(this.blockState.getBaseState().withProperty(BITES, Integer.valueOf(0)));
this.setTickRandomly(true);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return CAKE_AABB[((Integer)state.getValue(BITES)).intValue()];
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (!worldIn.isRemote)
{
return this.eatCake(worldIn, pos, state, playerIn);
}
else
{
ItemStack itemstack = playerIn.getHeldItem(hand);
return this.eatCake(worldIn, pos, state, playerIn) || itemstack.isEmpty();
}
}
private boolean eatCake(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
if (!player.canEat(false))
{
return false;
}
else
{
player.addStat(StatList.CAKE_SLICES_EATEN);
player.getFoodStats().addStats(2, 0.1F);
int i = ((Integer)state.getValue(BITES)).intValue();
if (i < 6)
{
worldIn.setBlockState(pos, state.withProperty(BITES, Integer.valueOf(i + 1)), 3);
}
else
{
worldIn.setBlockToAir(pos);
}
return true;
}
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return super.canPlaceBlockAt(worldIn, pos) ? this.canBlockStay(worldIn, pos) : false;
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (!this.canBlockStay(worldIn, pos))
{
worldIn.setBlockToAir(pos);
}
}
private boolean canBlockStay(World worldIn, BlockPos pos)
{
return worldIn.getBlockState(pos.down()).getMaterial().isSolid();
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 0;
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.AIR;
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(Items.CAKE);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(BITES, Integer.valueOf(meta));
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(BITES)).intValue();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {BITES});
}
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
{
return (7 - ((Integer)blockState.getValue(BITES)).intValue()) * 2;
}
public boolean hasComparatorInputOverride(IBlockState state)
{
return true;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,165 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockCarpet extends Block
{
public static final PropertyEnum<EnumDyeColor> COLOR = PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class);
protected static final AxisAlignedBB CARPET_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.0625D, 1.0D);
protected BlockCarpet()
{
super(Material.CARPET);
this.setDefaultState(this.blockState.getBaseState().withProperty(COLOR, EnumDyeColor.WHITE));
this.setTickRandomly(true);
this.setCreativeTab(CreativeTabs.DECORATIONS);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return CARPET_AABB;
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.getBlockColor((EnumDyeColor)state.getValue(COLOR));
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return super.canPlaceBlockAt(worldIn, pos) && this.canBlockStay(worldIn, pos);
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
this.checkForDrop(worldIn, pos, state);
}
private boolean checkForDrop(World worldIn, BlockPos pos, IBlockState state)
{
if (!this.canBlockStay(worldIn, pos))
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
return false;
}
else
{
return true;
}
}
private boolean canBlockStay(World worldIn, BlockPos pos)
{
return !worldIn.isAirBlock(pos.down());
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
if (side == EnumFacing.UP)
{
return true;
}
else
{
return blockAccess.getBlockState(pos.offset(side)).getBlock() == this ? true : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
}
/**
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
* returns the metadata of the dropped item based on the old metadata of the block.
*/
public int damageDropped(IBlockState state)
{
return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
for (int i = 0; i < 16; ++i)
{
items.add(new ItemStack(this, 1, i));
}
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(COLOR, EnumDyeColor.byMetadata(meta));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {COLOR});
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return face == EnumFacing.DOWN ? BlockFaceShape.SOLID : BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,28 @@
package net.minecraft.block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
public class BlockCarrot extends BlockCrops
{
private static final AxisAlignedBB[] CARROT_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.125D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.1875D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.25D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.3125D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.375D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.4375D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5625D, 1.0D)};
protected Item getSeed()
{
return Items.CARROT;
}
protected Item getCrop()
{
return Items.CARROT;
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return CARROT_AABB[((Integer)state.getValue(this.getAgeProperty())).intValue()];
}
}

View File

@@ -0,0 +1,354 @@
package net.minecraft.block;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.init.PotionTypes;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemBanner;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionUtils;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntityBanner;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockCauldron extends Block
{
public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 3);
protected static final AxisAlignedBB AABB_LEGS = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.3125D, 1.0D);
protected static final AxisAlignedBB AABB_WALL_NORTH = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.125D);
protected static final AxisAlignedBB AABB_WALL_SOUTH = new AxisAlignedBB(0.0D, 0.0D, 0.875D, 1.0D, 1.0D, 1.0D);
protected static final AxisAlignedBB AABB_WALL_EAST = new AxisAlignedBB(0.875D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
protected static final AxisAlignedBB AABB_WALL_WEST = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.125D, 1.0D, 1.0D);
public BlockCauldron()
{
super(Material.IRON, MapColor.STONE);
this.setDefaultState(this.blockState.getBaseState().withProperty(LEVEL, Integer.valueOf(0)));
}
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_LEGS);
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_WEST);
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_NORTH);
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_EAST);
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_SOUTH);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return FULL_BLOCK_AABB;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Called When an Entity Collided with the Block
*/
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
int i = ((Integer)state.getValue(LEVEL)).intValue();
float f = (float)pos.getY() + (6.0F + (float)(3 * i)) / 16.0F;
if (!worldIn.isRemote && entityIn.isBurning() && i > 0 && entityIn.getEntityBoundingBox().minY <= (double)f)
{
entityIn.extinguish();
this.setWaterLevel(worldIn, pos, state, i - 1);
}
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
ItemStack itemstack = playerIn.getHeldItem(hand);
if (itemstack.isEmpty())
{
return true;
}
else
{
int i = ((Integer)state.getValue(LEVEL)).intValue();
Item item = itemstack.getItem();
if (item == Items.WATER_BUCKET)
{
if (i < 3 && !worldIn.isRemote)
{
if (!playerIn.capabilities.isCreativeMode)
{
playerIn.setHeldItem(hand, new ItemStack(Items.BUCKET));
}
playerIn.addStat(StatList.CAULDRON_FILLED);
this.setWaterLevel(worldIn, pos, state, 3);
worldIn.playSound((EntityPlayer)null, pos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
return true;
}
else if (item == Items.BUCKET)
{
if (i == 3 && !worldIn.isRemote)
{
if (!playerIn.capabilities.isCreativeMode)
{
itemstack.shrink(1);
if (itemstack.isEmpty())
{
playerIn.setHeldItem(hand, new ItemStack(Items.WATER_BUCKET));
}
else if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET)))
{
playerIn.dropItem(new ItemStack(Items.WATER_BUCKET), false);
}
}
playerIn.addStat(StatList.CAULDRON_USED);
this.setWaterLevel(worldIn, pos, state, 0);
worldIn.playSound((EntityPlayer)null, pos, SoundEvents.ITEM_BUCKET_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
return true;
}
else if (item == Items.GLASS_BOTTLE)
{
if (i > 0 && !worldIn.isRemote)
{
if (!playerIn.capabilities.isCreativeMode)
{
ItemStack itemstack3 = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER);
playerIn.addStat(StatList.CAULDRON_USED);
itemstack.shrink(1);
if (itemstack.isEmpty())
{
playerIn.setHeldItem(hand, itemstack3);
}
else if (!playerIn.inventory.addItemStackToInventory(itemstack3))
{
playerIn.dropItem(itemstack3, false);
}
else if (playerIn instanceof EntityPlayerMP)
{
((EntityPlayerMP)playerIn).sendContainerToPlayer(playerIn.inventoryContainer);
}
}
worldIn.playSound((EntityPlayer)null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
this.setWaterLevel(worldIn, pos, state, i - 1);
}
return true;
}
else if (item == Items.POTIONITEM && PotionUtils.getPotionFromItem(itemstack) == PotionTypes.WATER)
{
if (i < 3 && !worldIn.isRemote)
{
if (!playerIn.capabilities.isCreativeMode)
{
ItemStack itemstack2 = new ItemStack(Items.GLASS_BOTTLE);
playerIn.addStat(StatList.CAULDRON_USED);
playerIn.setHeldItem(hand, itemstack2);
if (playerIn instanceof EntityPlayerMP)
{
((EntityPlayerMP)playerIn).sendContainerToPlayer(playerIn.inventoryContainer);
}
}
worldIn.playSound((EntityPlayer)null, pos, SoundEvents.ITEM_BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
this.setWaterLevel(worldIn, pos, state, i + 1);
}
return true;
}
else
{
if (i > 0 && item instanceof ItemArmor)
{
ItemArmor itemarmor = (ItemArmor)item;
if (itemarmor.getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER && itemarmor.hasColor(itemstack) && !worldIn.isRemote)
{
itemarmor.removeColor(itemstack);
this.setWaterLevel(worldIn, pos, state, i - 1);
playerIn.addStat(StatList.ARMOR_CLEANED);
return true;
}
}
if (i > 0 && item instanceof ItemBanner)
{
if (TileEntityBanner.getPatterns(itemstack) > 0 && !worldIn.isRemote)
{
ItemStack itemstack1 = itemstack.copy();
itemstack1.setCount(1);
TileEntityBanner.removeBannerData(itemstack1);
playerIn.addStat(StatList.BANNER_CLEANED);
if (!playerIn.capabilities.isCreativeMode)
{
itemstack.shrink(1);
this.setWaterLevel(worldIn, pos, state, i - 1);
}
if (itemstack.isEmpty())
{
playerIn.setHeldItem(hand, itemstack1);
}
else if (!playerIn.inventory.addItemStackToInventory(itemstack1))
{
playerIn.dropItem(itemstack1, false);
}
else if (playerIn instanceof EntityPlayerMP)
{
((EntityPlayerMP)playerIn).sendContainerToPlayer(playerIn.inventoryContainer);
}
}
return true;
}
else
{
return false;
}
}
}
}
public void setWaterLevel(World worldIn, BlockPos pos, IBlockState state, int level)
{
worldIn.setBlockState(pos, state.withProperty(LEVEL, Integer.valueOf(MathHelper.clamp(level, 0, 3))), 2);
worldIn.updateComparatorOutputLevel(pos, this);
}
/**
* Called similar to random ticks, but only when it is raining.
*/
public void fillWithRain(World worldIn, BlockPos pos)
{
if (worldIn.rand.nextInt(20) == 1)
{
float f = worldIn.getBiome(pos).getTemperature(pos);
if (worldIn.getBiomeProvider().getTemperatureAtHeight(f, pos.getY()) >= 0.15F)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
if (((Integer)iblockstate.getValue(LEVEL)).intValue() < 3)
{
worldIn.setBlockState(pos, iblockstate.cycleProperty(LEVEL), 2);
}
}
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.CAULDRON;
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(Items.CAULDRON);
}
public boolean hasComparatorInputOverride(IBlockState state)
{
return true;
}
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
{
return ((Integer)blockState.getValue(LEVEL)).intValue();
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(LEVEL, Integer.valueOf(meta));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(LEVEL)).intValue();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {LEVEL});
}
/**
* Determines if an entity can path through this block
*/
public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
{
return true;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
if (face == EnumFacing.UP)
{
return BlockFaceShape.BOWL;
}
else
{
return face == EnumFacing.DOWN ? BlockFaceShape.UNDEFINED : BlockFaceShape.SOLID;
}
}
}

View File

@@ -0,0 +1,678 @@
package net.minecraft.block;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.inventory.InventoryLargeChest;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.ILockableContainer;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockChest extends BlockContainer
{
public static final PropertyDirection FACING = BlockHorizontal.FACING;
protected static final AxisAlignedBB NORTH_CHEST_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0D, 0.9375D, 0.875D, 0.9375D);
protected static final AxisAlignedBB SOUTH_CHEST_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.875D, 1.0D);
protected static final AxisAlignedBB WEST_CHEST_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0625D, 0.9375D, 0.875D, 0.9375D);
protected static final AxisAlignedBB EAST_CHEST_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 1.0D, 0.875D, 0.9375D);
protected static final AxisAlignedBB NOT_CONNECTED_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.875D, 0.9375D);
/** 0 : Normal chest, 1 : Trapped chest */
public final BlockChest.Type chestType;
protected BlockChest(BlockChest.Type chestTypeIn)
{
super(Material.WOOD);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
this.chestType = chestTypeIn;
this.setCreativeTab(chestTypeIn == BlockChest.Type.TRAP ? CreativeTabs.REDSTONE : CreativeTabs.DECORATIONS);
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
@SideOnly(Side.CLIENT)
public boolean hasCustomBreakingProgress(IBlockState state)
{
return true;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
if (source.getBlockState(pos.north()).getBlock() == this)
{
return NORTH_CHEST_AABB;
}
else if (source.getBlockState(pos.south()).getBlock() == this)
{
return SOUTH_CHEST_AABB;
}
else if (source.getBlockState(pos.west()).getBlock() == this)
{
return WEST_CHEST_AABB;
}
else
{
return source.getBlockState(pos.east()).getBlock() == this ? EAST_CHEST_AABB : NOT_CONNECTED_AABB;
}
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
this.checkForSurroundingChests(worldIn, pos, state);
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
BlockPos blockpos = pos.offset(enumfacing);
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.getBlock() == this)
{
this.checkForSurroundingChests(worldIn, blockpos, iblockstate);
}
}
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing());
}
/**
* Called by ItemBlocks after a block is set in the world, to allow post-place logic
*/
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
EnumFacing enumfacing = EnumFacing.getHorizontal(MathHelper.floor((double)(placer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3).getOpposite();
state = state.withProperty(FACING, enumfacing);
BlockPos blockpos = pos.north();
BlockPos blockpos1 = pos.south();
BlockPos blockpos2 = pos.west();
BlockPos blockpos3 = pos.east();
boolean flag = this == worldIn.getBlockState(blockpos).getBlock();
boolean flag1 = this == worldIn.getBlockState(blockpos1).getBlock();
boolean flag2 = this == worldIn.getBlockState(blockpos2).getBlock();
boolean flag3 = this == worldIn.getBlockState(blockpos3).getBlock();
if (!flag && !flag1 && !flag2 && !flag3)
{
worldIn.setBlockState(pos, state, 3);
}
else if (enumfacing.getAxis() != EnumFacing.Axis.X || !flag && !flag1)
{
if (enumfacing.getAxis() == EnumFacing.Axis.Z && (flag2 || flag3))
{
if (flag2)
{
worldIn.setBlockState(blockpos2, state, 3);
}
else
{
worldIn.setBlockState(blockpos3, state, 3);
}
worldIn.setBlockState(pos, state, 3);
}
}
else
{
if (flag)
{
worldIn.setBlockState(blockpos, state, 3);
}
else
{
worldIn.setBlockState(blockpos1, state, 3);
}
worldIn.setBlockState(pos, state, 3);
}
if (stack.hasDisplayName())
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityChest)
{
((TileEntityChest)tileentity).setCustomName(stack.getDisplayName());
}
}
}
public IBlockState checkForSurroundingChests(World worldIn, BlockPos pos, IBlockState state)
{
if (worldIn.isRemote)
{
return state;
}
else
{
IBlockState iblockstate = worldIn.getBlockState(pos.north());
IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
if (iblockstate.getBlock() != this && iblockstate1.getBlock() != this)
{
boolean flag = iblockstate.isFullBlock();
boolean flag1 = iblockstate1.isFullBlock();
if (iblockstate2.getBlock() == this || iblockstate3.getBlock() == this)
{
BlockPos blockpos1 = iblockstate2.getBlock() == this ? pos.west() : pos.east();
IBlockState iblockstate7 = worldIn.getBlockState(blockpos1.north());
IBlockState iblockstate6 = worldIn.getBlockState(blockpos1.south());
enumfacing = EnumFacing.SOUTH;
EnumFacing enumfacing2;
if (iblockstate2.getBlock() == this)
{
enumfacing2 = (EnumFacing)iblockstate2.getValue(FACING);
}
else
{
enumfacing2 = (EnumFacing)iblockstate3.getValue(FACING);
}
if (enumfacing2 == EnumFacing.NORTH)
{
enumfacing = EnumFacing.NORTH;
}
if ((flag || iblockstate7.isFullBlock()) && !flag1 && !iblockstate6.isFullBlock())
{
enumfacing = EnumFacing.SOUTH;
}
if ((flag1 || iblockstate6.isFullBlock()) && !flag && !iblockstate7.isFullBlock())
{
enumfacing = EnumFacing.NORTH;
}
}
}
else
{
BlockPos blockpos = iblockstate.getBlock() == this ? pos.north() : pos.south();
IBlockState iblockstate4 = worldIn.getBlockState(blockpos.west());
IBlockState iblockstate5 = worldIn.getBlockState(blockpos.east());
enumfacing = EnumFacing.EAST;
EnumFacing enumfacing1;
if (iblockstate.getBlock() == this)
{
enumfacing1 = (EnumFacing)iblockstate.getValue(FACING);
}
else
{
enumfacing1 = (EnumFacing)iblockstate1.getValue(FACING);
}
if (enumfacing1 == EnumFacing.WEST)
{
enumfacing = EnumFacing.WEST;
}
if ((iblockstate2.isFullBlock() || iblockstate4.isFullBlock()) && !iblockstate3.isFullBlock() && !iblockstate5.isFullBlock())
{
enumfacing = EnumFacing.EAST;
}
if ((iblockstate3.isFullBlock() || iblockstate5.isFullBlock()) && !iblockstate2.isFullBlock() && !iblockstate4.isFullBlock())
{
enumfacing = EnumFacing.WEST;
}
}
state = state.withProperty(FACING, enumfacing);
worldIn.setBlockState(pos, state, 3);
return state;
}
}
public IBlockState correctFacing(World worldIn, BlockPos pos, IBlockState state)
{
EnumFacing enumfacing = null;
for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
{
IBlockState iblockstate = worldIn.getBlockState(pos.offset(enumfacing1));
if (iblockstate.getBlock() == this)
{
return state;
}
if (iblockstate.isFullBlock())
{
if (enumfacing != null)
{
enumfacing = null;
break;
}
enumfacing = enumfacing1;
}
}
if (enumfacing != null)
{
return state.withProperty(FACING, enumfacing.getOpposite());
}
else
{
EnumFacing enumfacing2 = (EnumFacing)state.getValue(FACING);
if (worldIn.getBlockState(pos.offset(enumfacing2)).isFullBlock())
{
enumfacing2 = enumfacing2.getOpposite();
}
if (worldIn.getBlockState(pos.offset(enumfacing2)).isFullBlock())
{
enumfacing2 = enumfacing2.rotateY();
}
if (worldIn.getBlockState(pos.offset(enumfacing2)).isFullBlock())
{
enumfacing2 = enumfacing2.getOpposite();
}
return state.withProperty(FACING, enumfacing2);
}
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
int i = 0;
BlockPos blockpos = pos.west();
BlockPos blockpos1 = pos.east();
BlockPos blockpos2 = pos.north();
BlockPos blockpos3 = pos.south();
if (worldIn.getBlockState(blockpos).getBlock() == this)
{
if (this.isDoubleChest(worldIn, blockpos))
{
return false;
}
++i;
}
if (worldIn.getBlockState(blockpos1).getBlock() == this)
{
if (this.isDoubleChest(worldIn, blockpos1))
{
return false;
}
++i;
}
if (worldIn.getBlockState(blockpos2).getBlock() == this)
{
if (this.isDoubleChest(worldIn, blockpos2))
{
return false;
}
++i;
}
if (worldIn.getBlockState(blockpos3).getBlock() == this)
{
if (this.isDoubleChest(worldIn, blockpos3))
{
return false;
}
++i;
}
return i <= 1;
}
private boolean isDoubleChest(World worldIn, BlockPos pos)
{
if (worldIn.getBlockState(pos).getBlock() != this)
{
return false;
}
else
{
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
if (worldIn.getBlockState(pos.offset(enumfacing)).getBlock() == this)
{
return true;
}
}
return false;
}
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityChest)
{
tileentity.updateContainingBlockInfo();
}
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof IInventory)
{
InventoryHelper.dropInventoryItems(worldIn, pos, (IInventory)tileentity);
worldIn.updateComparatorOutputLevel(pos, this);
}
super.breakBlock(worldIn, pos, state);
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
else
{
ILockableContainer ilockablecontainer = this.getLockableContainer(worldIn, pos);
if (ilockablecontainer != null)
{
playerIn.displayGUIChest(ilockablecontainer);
if (this.chestType == BlockChest.Type.BASIC)
{
playerIn.addStat(StatList.CHEST_OPENED);
}
else if (this.chestType == BlockChest.Type.TRAP)
{
playerIn.addStat(StatList.TRAPPED_CHEST_TRIGGERED);
}
}
return true;
}
}
@Nullable
public ILockableContainer getLockableContainer(World worldIn, BlockPos pos)
{
return this.getContainer(worldIn, pos, false);
}
@Nullable
public ILockableContainer getContainer(World worldIn, BlockPos pos, boolean allowBlocking)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (!(tileentity instanceof TileEntityChest))
{
return null;
}
else
{
ILockableContainer ilockablecontainer = (TileEntityChest)tileentity;
if (!allowBlocking && this.isBlocked(worldIn, pos))
{
return null;
}
else
{
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
BlockPos blockpos = pos.offset(enumfacing);
Block block = worldIn.getBlockState(blockpos).getBlock();
if (block == this)
{
if (!allowBlocking && this.isBlocked(worldIn, blockpos)) // Forge: fix MC-99321
{
return null;
}
TileEntity tileentity1 = worldIn.getTileEntity(blockpos);
if (tileentity1 instanceof TileEntityChest)
{
if (enumfacing != EnumFacing.WEST && enumfacing != EnumFacing.NORTH)
{
ilockablecontainer = new InventoryLargeChest("container.chestDouble", ilockablecontainer, (TileEntityChest)tileentity1);
}
else
{
ilockablecontainer = new InventoryLargeChest("container.chestDouble", (TileEntityChest)tileentity1, ilockablecontainer);
}
}
}
}
return ilockablecontainer;
}
}
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityChest();
}
/**
* Can this block provide power. Only wire currently seems to have this change based on its state.
*/
public boolean canProvidePower(IBlockState state)
{
return this.chestType == BlockChest.Type.TRAP;
}
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
if (!blockState.canProvidePower())
{
return 0;
}
else
{
int i = 0;
TileEntity tileentity = blockAccess.getTileEntity(pos);
if (tileentity instanceof TileEntityChest)
{
i = ((TileEntityChest)tileentity).numPlayersUsing;
}
return MathHelper.clamp(i, 0, 15);
}
}
public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return side == EnumFacing.UP ? blockState.getWeakPower(blockAccess, pos, side) : 0;
}
private boolean isBlocked(World worldIn, BlockPos pos)
{
return this.isBelowSolidBlock(worldIn, pos) || this.isOcelotSittingOnChest(worldIn, pos);
}
private boolean isBelowSolidBlock(World worldIn, BlockPos pos)
{
return worldIn.getBlockState(pos.up()).doesSideBlockChestOpening(worldIn, pos.up(), EnumFacing.DOWN);
}
private boolean isOcelotSittingOnChest(World worldIn, BlockPos pos)
{
for (Entity entity : worldIn.getEntitiesWithinAABB(EntityOcelot.class, new AxisAlignedBB((double)pos.getX(), (double)(pos.getY() + 1), (double)pos.getZ(), (double)(pos.getX() + 1), (double)(pos.getY() + 2), (double)(pos.getZ() + 1))))
{
EntityOcelot entityocelot = (EntityOcelot)entity;
if (entityocelot.isSitting())
{
return true;
}
}
return false;
}
public boolean hasComparatorInputOverride(IBlockState state)
{
return true;
}
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
{
return Container.calcRedstoneFromInventory(this.getLockableContainer(worldIn, pos));
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
EnumFacing enumfacing = EnumFacing.getFront(meta);
if (enumfacing.getAxis() == EnumFacing.Axis.Y)
{
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(FACING, enumfacing);
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((EnumFacing)state.getValue(FACING)).getIndex();
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING});
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
public static enum Type
{
BASIC,
TRAP;
}
/* ======================================== FORGE START =====================================*/
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis)
{
return !isDoubleChest(world, pos) && super.rotateBlock(world, pos, axis);
}
}

View File

@@ -0,0 +1,367 @@
package net.minecraft.block;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockChorusFlower extends Block
{
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 5);
protected BlockChorusFlower()
{
super(Material.PLANTS, MapColor.PURPLE);
this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0)));
this.setCreativeTab(CreativeTabs.DECORATIONS);
this.setTickRandomly(true);
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.AIR;
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!this.canSurvive(worldIn, pos))
{
worldIn.destroyBlock(pos, true);
}
else
{
BlockPos blockpos = pos.up();
if (worldIn.isAirBlock(blockpos) && blockpos.getY() < 256)
{
int i = ((Integer)state.getValue(AGE)).intValue();
if (i < 5 && net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, blockpos, state, rand.nextInt(1) == 0))
{
boolean flag = false;
boolean flag1 = false;
IBlockState iblockstate = worldIn.getBlockState(pos.down());
Block block = iblockstate.getBlock();
if (block == Blocks.END_STONE)
{
flag = true;
}
else if (block == Blocks.CHORUS_PLANT)
{
int j = 1;
for (int k = 0; k < 4; ++k)
{
Block block1 = worldIn.getBlockState(pos.down(j + 1)).getBlock();
if (block1 != Blocks.CHORUS_PLANT)
{
if (block1 == Blocks.END_STONE)
{
flag1 = true;
}
break;
}
++j;
}
int i1 = 4;
if (flag1)
{
++i1;
}
if (j < 2 || rand.nextInt(i1) >= j)
{
flag = true;
}
}
else if (iblockstate.getMaterial() == Material.AIR)
{
flag = true;
}
if (flag && areAllNeighborsEmpty(worldIn, blockpos, (EnumFacing)null) && worldIn.isAirBlock(pos.up(2)))
{
worldIn.setBlockState(pos, Blocks.CHORUS_PLANT.getDefaultState(), 2);
this.placeGrownFlower(worldIn, blockpos, i);
}
else if (i < 4)
{
int l = rand.nextInt(4);
boolean flag2 = false;
if (flag1)
{
++l;
}
for (int j1 = 0; j1 < l; ++j1)
{
EnumFacing enumfacing = EnumFacing.Plane.HORIZONTAL.random(rand);
BlockPos blockpos1 = pos.offset(enumfacing);
if (worldIn.isAirBlock(blockpos1) && worldIn.isAirBlock(blockpos1.down()) && areAllNeighborsEmpty(worldIn, blockpos1, enumfacing.getOpposite()))
{
this.placeGrownFlower(worldIn, blockpos1, i + 1);
flag2 = true;
}
}
if (flag2)
{
worldIn.setBlockState(pos, Blocks.CHORUS_PLANT.getDefaultState(), 2);
}
else
{
this.placeDeadFlower(worldIn, pos);
}
}
else if (i == 4)
{
this.placeDeadFlower(worldIn, pos);
}
net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
}
}
}
}
private void placeGrownFlower(World worldIn, BlockPos pos, int age)
{
worldIn.setBlockState(pos, this.getDefaultState().withProperty(AGE, Integer.valueOf(age)), 2);
worldIn.playEvent(1033, pos, 0);
}
private void placeDeadFlower(World worldIn, BlockPos pos)
{
worldIn.setBlockState(pos, this.getDefaultState().withProperty(AGE, Integer.valueOf(5)), 2);
worldIn.playEvent(1034, pos, 0);
}
private static boolean areAllNeighborsEmpty(World worldIn, BlockPos pos, EnumFacing excludingSide)
{
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
if (enumfacing != excludingSide && !worldIn.isAirBlock(pos.offset(enumfacing)))
{
return false;
}
}
return true;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return super.canPlaceBlockAt(worldIn, pos) && this.canSurvive(worldIn, pos);
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (!this.canSurvive(worldIn, pos))
{
worldIn.scheduleUpdate(pos, this, 1);
}
}
public boolean canSurvive(World worldIn, BlockPos pos)
{
IBlockState iblockstate = worldIn.getBlockState(pos.down());
Block block = iblockstate.getBlock();
if (block != Blocks.CHORUS_PLANT && block != Blocks.END_STONE)
{
if (iblockstate.getMaterial() == Material.AIR)
{
int i = 0;
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
IBlockState iblockstate1 = worldIn.getBlockState(pos.offset(enumfacing));
Block block1 = iblockstate1.getBlock();
if (block1 == Blocks.CHORUS_PLANT)
{
++i;
}
else if (iblockstate1.getMaterial() != Material.AIR)
{
return false;
}
}
return i == 1;
}
else
{
return false;
}
}
else
{
return true;
}
}
/**
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via
* Block.removedByPlayer
*/
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
super.harvestBlock(worldIn, player, pos, state, te, stack);
spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(this)));
}
protected ItemStack getSilkTouchDrop(IBlockState state)
{
return ItemStack.EMPTY;
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(AGE, Integer.valueOf(meta));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(AGE)).intValue();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {AGE});
}
public static void generatePlant(World worldIn, BlockPos pos, Random rand, int p_185603_3_)
{
worldIn.setBlockState(pos, Blocks.CHORUS_PLANT.getDefaultState(), 2);
growTreeRecursive(worldIn, pos, rand, pos, p_185603_3_, 0);
}
private static void growTreeRecursive(World worldIn, BlockPos p_185601_1_, Random rand, BlockPos p_185601_3_, int p_185601_4_, int p_185601_5_)
{
int i = rand.nextInt(4) + 1;
if (p_185601_5_ == 0)
{
++i;
}
for (int j = 0; j < i; ++j)
{
BlockPos blockpos = p_185601_1_.up(j + 1);
if (!areAllNeighborsEmpty(worldIn, blockpos, (EnumFacing)null))
{
return;
}
worldIn.setBlockState(blockpos, Blocks.CHORUS_PLANT.getDefaultState(), 2);
}
boolean flag = false;
if (p_185601_5_ < 4)
{
int l = rand.nextInt(4);
if (p_185601_5_ == 0)
{
++l;
}
for (int k = 0; k < l; ++k)
{
EnumFacing enumfacing = EnumFacing.Plane.HORIZONTAL.random(rand);
BlockPos blockpos1 = p_185601_1_.up(i).offset(enumfacing);
if (Math.abs(blockpos1.getX() - p_185601_3_.getX()) < p_185601_4_ && Math.abs(blockpos1.getZ() - p_185601_3_.getZ()) < p_185601_4_ && worldIn.isAirBlock(blockpos1) && worldIn.isAirBlock(blockpos1.down()) && areAllNeighborsEmpty(worldIn, blockpos1, enumfacing.getOpposite()))
{
flag = true;
worldIn.setBlockState(blockpos1, Blocks.CHORUS_PLANT.getDefaultState(), 2);
growTreeRecursive(worldIn, blockpos1, rand, p_185601_3_, p_185601_4_, p_185601_5_ + 1);
}
}
}
if (!flag)
{
worldIn.setBlockState(p_185601_1_.up(i), Blocks.CHORUS_FLOWER.getDefaultState().withProperty(AGE, Integer.valueOf(5)), 2);
}
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,248 @@
package net.minecraft.block;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockChorusPlant extends Block
{
public static final PropertyBool NORTH = PropertyBool.create("north");
public static final PropertyBool EAST = PropertyBool.create("east");
public static final PropertyBool SOUTH = PropertyBool.create("south");
public static final PropertyBool WEST = PropertyBool.create("west");
public static final PropertyBool UP = PropertyBool.create("up");
public static final PropertyBool DOWN = PropertyBool.create("down");
protected BlockChorusPlant()
{
super(Material.PLANTS, MapColor.PURPLE);
this.setCreativeTab(CreativeTabs.DECORATIONS);
this.setDefaultState(this.blockState.getBaseState().withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false)).withProperty(UP, Boolean.valueOf(false)).withProperty(DOWN, Boolean.valueOf(false)));
}
/**
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
* metadata, such as fence connections.
*/
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
Block block = worldIn.getBlockState(pos.down()).getBlock();
Block block1 = worldIn.getBlockState(pos.up()).getBlock();
Block block2 = worldIn.getBlockState(pos.north()).getBlock();
Block block3 = worldIn.getBlockState(pos.east()).getBlock();
Block block4 = worldIn.getBlockState(pos.south()).getBlock();
Block block5 = worldIn.getBlockState(pos.west()).getBlock();
return state.withProperty(DOWN, Boolean.valueOf(block == this || block == Blocks.CHORUS_FLOWER || block == Blocks.END_STONE)).withProperty(UP, Boolean.valueOf(block1 == this || block1 == Blocks.CHORUS_FLOWER)).withProperty(NORTH, Boolean.valueOf(block2 == this || block2 == Blocks.CHORUS_FLOWER)).withProperty(EAST, Boolean.valueOf(block3 == this || block3 == Blocks.CHORUS_FLOWER)).withProperty(SOUTH, Boolean.valueOf(block4 == this || block4 == Blocks.CHORUS_FLOWER)).withProperty(WEST, Boolean.valueOf(block5 == this || block5 == Blocks.CHORUS_FLOWER));
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
state = state.getActualState(source, pos);
float f = 0.1875F;
float f1 = ((Boolean)state.getValue(WEST)).booleanValue() ? 0.0F : 0.1875F;
float f2 = ((Boolean)state.getValue(DOWN)).booleanValue() ? 0.0F : 0.1875F;
float f3 = ((Boolean)state.getValue(NORTH)).booleanValue() ? 0.0F : 0.1875F;
float f4 = ((Boolean)state.getValue(EAST)).booleanValue() ? 1.0F : 0.8125F;
float f5 = ((Boolean)state.getValue(UP)).booleanValue() ? 1.0F : 0.8125F;
float f6 = ((Boolean)state.getValue(SOUTH)).booleanValue() ? 1.0F : 0.8125F;
return new AxisAlignedBB((double)f1, (double)f2, (double)f3, (double)f4, (double)f5, (double)f6);
}
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState)
{
if (!isActualState)
{
state = state.getActualState(worldIn, pos);
}
float f = 0.1875F;
float f1 = 0.8125F;
addCollisionBoxToList(pos, entityBox, collidingBoxes, new AxisAlignedBB(0.1875D, 0.1875D, 0.1875D, 0.8125D, 0.8125D, 0.8125D));
if (((Boolean)state.getValue(WEST)).booleanValue())
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, new AxisAlignedBB(0.0D, 0.1875D, 0.1875D, 0.1875D, 0.8125D, 0.8125D));
}
if (((Boolean)state.getValue(EAST)).booleanValue())
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, new AxisAlignedBB(0.8125D, 0.1875D, 0.1875D, 1.0D, 0.8125D, 0.8125D));
}
if (((Boolean)state.getValue(UP)).booleanValue())
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, new AxisAlignedBB(0.1875D, 0.8125D, 0.1875D, 0.8125D, 1.0D, 0.8125D));
}
if (((Boolean)state.getValue(DOWN)).booleanValue())
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 0.8125D, 0.1875D, 0.8125D));
}
if (((Boolean)state.getValue(NORTH)).booleanValue())
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, new AxisAlignedBB(0.1875D, 0.1875D, 0.0D, 0.8125D, 0.8125D, 0.1875D));
}
if (((Boolean)state.getValue(SOUTH)).booleanValue())
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, new AxisAlignedBB(0.1875D, 0.1875D, 0.8125D, 0.8125D, 0.8125D, 1.0D));
}
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return 0;
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!this.canSurviveAt(worldIn, pos))
{
worldIn.destroyBlock(pos, true);
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.CHORUS_FRUIT;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return random.nextInt(2);
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return super.canPlaceBlockAt(worldIn, pos) ? this.canSurviveAt(worldIn, pos) : false;
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (!this.canSurviveAt(worldIn, pos))
{
worldIn.scheduleUpdate(pos, this, 1);
}
}
public boolean canSurviveAt(World wordIn, BlockPos pos)
{
boolean flag = wordIn.isAirBlock(pos.up());
boolean flag1 = wordIn.isAirBlock(pos.down());
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
BlockPos blockpos = pos.offset(enumfacing);
Block block = wordIn.getBlockState(blockpos).getBlock();
if (block == this)
{
if (!flag && !flag1)
{
return false;
}
Block block1 = wordIn.getBlockState(blockpos.down()).getBlock();
if (block1 == this || block1 == Blocks.END_STONE)
{
return true;
}
}
}
Block block2 = wordIn.getBlockState(pos.down()).getBlock();
return block2 == this || block2 == Blocks.END_STONE;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {NORTH, EAST, SOUTH, WEST, UP, DOWN});
}
/**
* Determines if an entity can path through this block
*/
public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
{
return false;
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
Block block = blockAccess.getBlockState(pos.offset(side)).getBlock();
return block != this && block != Blocks.CHORUS_FLOWER && (side != EnumFacing.DOWN || block != Blocks.END_STONE);
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,33 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
public class BlockClay extends Block
{
public BlockClay()
{
super(Material.CLAY);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.CLAY_BALL;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 4;
}
}

View File

@@ -0,0 +1,249 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockCocoa extends BlockHorizontal implements IGrowable
{
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 2);
protected static final AxisAlignedBB[] COCOA_EAST_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.6875D, 0.4375D, 0.375D, 0.9375D, 0.75D, 0.625D), new AxisAlignedBB(0.5625D, 0.3125D, 0.3125D, 0.9375D, 0.75D, 0.6875D), new AxisAlignedBB(0.4375D, 0.1875D, 0.25D, 0.9375D, 0.75D, 0.75D)};
protected static final AxisAlignedBB[] COCOA_WEST_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.0625D, 0.4375D, 0.375D, 0.3125D, 0.75D, 0.625D), new AxisAlignedBB(0.0625D, 0.3125D, 0.3125D, 0.4375D, 0.75D, 0.6875D), new AxisAlignedBB(0.0625D, 0.1875D, 0.25D, 0.5625D, 0.75D, 0.75D)};
protected static final AxisAlignedBB[] COCOA_NORTH_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.375D, 0.4375D, 0.0625D, 0.625D, 0.75D, 0.3125D), new AxisAlignedBB(0.3125D, 0.3125D, 0.0625D, 0.6875D, 0.75D, 0.4375D), new AxisAlignedBB(0.25D, 0.1875D, 0.0625D, 0.75D, 0.75D, 0.5625D)};
protected static final AxisAlignedBB[] COCOA_SOUTH_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.375D, 0.4375D, 0.6875D, 0.625D, 0.75D, 0.9375D), new AxisAlignedBB(0.3125D, 0.3125D, 0.5625D, 0.6875D, 0.75D, 0.9375D), new AxisAlignedBB(0.25D, 0.1875D, 0.4375D, 0.75D, 0.75D, 0.9375D)};
public BlockCocoa()
{
super(Material.PLANTS);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(AGE, Integer.valueOf(0)));
this.setTickRandomly(true);
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!this.canBlockStay(worldIn, pos, state))
{
this.dropBlock(worldIn, pos, state);
}
else
{
int i = ((Integer)state.getValue(AGE)).intValue();
if (i < 2 && net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt(5) == 0))
{
worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i + 1)), 2);
net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
}
}
}
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
pos = pos.offset((EnumFacing)state.getValue(FACING));
IBlockState iblockstate = worldIn.getBlockState(pos);
return iblockstate.getBlock() == Blocks.LOG && iblockstate.getValue(BlockOldLog.VARIANT) == BlockPlanks.EnumType.JUNGLE;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
int i = ((Integer)state.getValue(AGE)).intValue();
switch ((EnumFacing)state.getValue(FACING))
{
case SOUTH:
return COCOA_SOUTH_AABB[i];
case NORTH:
default:
return COCOA_NORTH_AABB[i];
case WEST:
return COCOA_WEST_AABB[i];
case EAST:
return COCOA_EAST_AABB[i];
}
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
/**
* Called by ItemBlocks after a block is set in the world, to allow post-place logic
*/
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
EnumFacing enumfacing = EnumFacing.fromAngle((double)placer.rotationYaw);
worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
if (!facing.getAxis().isHorizontal())
{
facing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(FACING, facing.getOpposite()).withProperty(AGE, Integer.valueOf(0));
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (!this.canBlockStay(worldIn, pos, state))
{
this.dropBlock(worldIn, pos, state);
}
}
private void dropBlock(World worldIn, BlockPos pos, IBlockState state)
{
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
this.dropBlockAsItem(worldIn, pos, state, 0);
}
/**
* Spawns this Block's drops into the World as EntityItems.
*/
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
}
@Override
public void getDrops(net.minecraft.util.NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
super.getDrops(drops, world, pos, state, fortune);
int i = ((Integer)state.getValue(AGE)).intValue();
int j = 1;
if (i >= 2)
{
j = 3;
}
for (int k = 0; k < j; ++k)
{
drops.add(new ItemStack(Items.DYE, 1, EnumDyeColor.BROWN.getDyeDamage()));
}
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(Items.DYE, 1, EnumDyeColor.BROWN.getDyeDamage());
}
/**
* Whether this IGrowable can grow
*/
public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
{
return ((Integer)state.getValue(AGE)).intValue() < 2;
}
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
return true;
}
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(((Integer)state.getValue(AGE)).intValue() + 1)), 2);
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)).withProperty(AGE, Integer.valueOf((meta & 15) >> 2));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
i = i | ((Integer)state.getValue(AGE)).intValue() << 2;
return i;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING, AGE});
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,75 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
public class BlockColored extends Block
{
public static final PropertyEnum<EnumDyeColor> COLOR = PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class);
public BlockColored(Material materialIn)
{
super(materialIn);
this.setDefaultState(this.blockState.getBaseState().withProperty(COLOR, EnumDyeColor.WHITE));
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
* returns the metadata of the dropped item based on the old metadata of the block.
*/
public int damageDropped(IBlockState state)
{
return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
for (EnumDyeColor enumdyecolor : EnumDyeColor.values())
{
items.add(new ItemStack(this, 1, enumdyecolor.getMetadata()));
}
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.getBlockColor((EnumDyeColor)state.getValue(COLOR));
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(COLOR, EnumDyeColor.byMetadata(meta));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {COLOR});
}
}

View File

@@ -0,0 +1,342 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.CommandBlockBaseLogic;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityCommandBlock;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.StringUtils;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameRules;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class BlockCommandBlock extends BlockContainer
{
private static final Logger LOGGER = LogManager.getLogger();
public static final PropertyDirection FACING = BlockDirectional.FACING;
public static final PropertyBool CONDITIONAL = PropertyBool.create("conditional");
public BlockCommandBlock(MapColor color)
{
super(Material.IRON, color);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(CONDITIONAL, Boolean.valueOf(false)));
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
TileEntityCommandBlock tileentitycommandblock = new TileEntityCommandBlock();
tileentitycommandblock.setAuto(this == Blocks.CHAIN_COMMAND_BLOCK);
return tileentitycommandblock;
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (!worldIn.isRemote)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityCommandBlock)
{
TileEntityCommandBlock tileentitycommandblock = (TileEntityCommandBlock)tileentity;
boolean flag = worldIn.isBlockPowered(pos);
boolean flag1 = tileentitycommandblock.isPowered();
tileentitycommandblock.setPowered(flag);
if (!flag1 && !tileentitycommandblock.isAuto() && tileentitycommandblock.getMode() != TileEntityCommandBlock.Mode.SEQUENCE)
{
if (flag)
{
tileentitycommandblock.setConditionMet();
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
}
}
}
}
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isRemote)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityCommandBlock)
{
TileEntityCommandBlock tileentitycommandblock = (TileEntityCommandBlock)tileentity;
CommandBlockBaseLogic commandblockbaselogic = tileentitycommandblock.getCommandBlockLogic();
boolean flag = !StringUtils.isNullOrEmpty(commandblockbaselogic.getCommand());
TileEntityCommandBlock.Mode tileentitycommandblock$mode = tileentitycommandblock.getMode();
boolean flag1 = tileentitycommandblock.isConditionMet();
if (tileentitycommandblock$mode == TileEntityCommandBlock.Mode.AUTO)
{
tileentitycommandblock.setConditionMet();
if (flag1)
{
this.execute(state, worldIn, pos, commandblockbaselogic, flag);
}
else if (tileentitycommandblock.isConditional())
{
commandblockbaselogic.setSuccessCount(0);
}
if (tileentitycommandblock.isPowered() || tileentitycommandblock.isAuto())
{
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
}
}
else if (tileentitycommandblock$mode == TileEntityCommandBlock.Mode.REDSTONE)
{
if (flag1)
{
this.execute(state, worldIn, pos, commandblockbaselogic, flag);
}
else if (tileentitycommandblock.isConditional())
{
commandblockbaselogic.setSuccessCount(0);
}
}
worldIn.updateComparatorOutputLevel(pos, this);
}
}
}
private void execute(IBlockState p_193387_1_, World p_193387_2_, BlockPos p_193387_3_, CommandBlockBaseLogic p_193387_4_, boolean p_193387_5_)
{
if (p_193387_5_)
{
p_193387_4_.trigger(p_193387_2_);
}
else
{
p_193387_4_.setSuccessCount(0);
}
executeChain(p_193387_2_, p_193387_3_, (EnumFacing)p_193387_1_.getValue(FACING));
}
/**
* How many world ticks before ticking
*/
public int tickRate(World worldIn)
{
return 1;
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityCommandBlock && playerIn.canUseCommandBlock())
{
playerIn.displayGuiCommandBlock((TileEntityCommandBlock)tileentity);
return true;
}
else
{
return false;
}
}
public boolean hasComparatorInputOverride(IBlockState state)
{
return true;
}
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
return tileentity instanceof TileEntityCommandBlock ? ((TileEntityCommandBlock)tileentity).getCommandBlockLogic().getSuccessCount() : 0;
}
/**
* Called by ItemBlocks after a block is set in the world, to allow post-place logic
*/
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityCommandBlock)
{
TileEntityCommandBlock tileentitycommandblock = (TileEntityCommandBlock)tileentity;
CommandBlockBaseLogic commandblockbaselogic = tileentitycommandblock.getCommandBlockLogic();
if (stack.hasDisplayName())
{
commandblockbaselogic.setName(stack.getDisplayName());
}
if (!worldIn.isRemote)
{
NBTTagCompound nbttagcompound = stack.getTagCompound();
if (nbttagcompound == null || !nbttagcompound.hasKey("BlockEntityTag", 10))
{
commandblockbaselogic.setTrackOutput(worldIn.getGameRules().getBoolean("sendCommandFeedback"));
tileentitycommandblock.setAuto(this == Blocks.CHAIN_COMMAND_BLOCK);
}
if (tileentitycommandblock.getMode() == TileEntityCommandBlock.Mode.SEQUENCE)
{
boolean flag = worldIn.isBlockPowered(pos);
tileentitycommandblock.setPowered(flag);
}
}
}
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 0;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta & 7)).withProperty(CONDITIONAL, Boolean.valueOf((meta & 8) != 0));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((EnumFacing)state.getValue(FACING)).getIndex() | (((Boolean)state.getValue(CONDITIONAL)).booleanValue() ? 8 : 0);
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING, CONDITIONAL});
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getDefaultState().withProperty(FACING, EnumFacing.getDirectionFromEntityLiving(pos, placer)).withProperty(CONDITIONAL, Boolean.valueOf(false));
}
private static void executeChain(World p_193386_0_, BlockPos p_193386_1_, EnumFacing p_193386_2_)
{
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(p_193386_1_);
GameRules gamerules = p_193386_0_.getGameRules();
int i;
IBlockState iblockstate;
for (i = gamerules.getInt("maxCommandChainLength"); i-- > 0; p_193386_2_ = (EnumFacing)iblockstate.getValue(FACING))
{
blockpos$mutableblockpos.move(p_193386_2_);
iblockstate = p_193386_0_.getBlockState(blockpos$mutableblockpos);
Block block = iblockstate.getBlock();
if (block != Blocks.CHAIN_COMMAND_BLOCK)
{
break;
}
TileEntity tileentity = p_193386_0_.getTileEntity(blockpos$mutableblockpos);
if (!(tileentity instanceof TileEntityCommandBlock))
{
break;
}
TileEntityCommandBlock tileentitycommandblock = (TileEntityCommandBlock)tileentity;
if (tileentitycommandblock.getMode() != TileEntityCommandBlock.Mode.SEQUENCE)
{
break;
}
if (tileentitycommandblock.isPowered() || tileentitycommandblock.isAuto())
{
CommandBlockBaseLogic commandblockbaselogic = tileentitycommandblock.getCommandBlockLogic();
if (tileentitycommandblock.setConditionMet())
{
if (!commandblockbaselogic.trigger(p_193386_0_))
{
break;
}
p_193386_0_.updateComparatorOutputLevel(blockpos$mutableblockpos, block);
}
else if (tileentitycommandblock.isConditional())
{
commandblockbaselogic.setSuccessCount(0);
}
}
}
if (i <= 0)
{
int j = Math.max(gamerules.getInt("maxCommandChainLength"), 0);
LOGGER.warn("Commandblock chain tried to execure more than " + j + " steps!");
}
}
}

View File

@@ -0,0 +1,29 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
public class BlockCompressedPowered extends Block
{
public BlockCompressedPowered(Material materialIn, MapColor color)
{
super(materialIn, color);
}
/**
* Can this block provide power. Only wire currently seems to have this change based on its state.
*/
public boolean canProvidePower(IBlockState state)
{
return true;
}
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return 15;
}
}

View File

@@ -0,0 +1,136 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockConcretePowder extends BlockFalling
{
public static final PropertyEnum<EnumDyeColor> COLOR = PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class);
public BlockConcretePowder()
{
super(Material.SAND);
this.setDefaultState(this.blockState.getBaseState().withProperty(COLOR, EnumDyeColor.WHITE));
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
public void onEndFalling(World worldIn, BlockPos pos, IBlockState p_176502_3_, IBlockState p_176502_4_)
{
if (p_176502_4_.getMaterial().isLiquid())
{
worldIn.setBlockState(pos, Blocks.CONCRETE.getDefaultState().withProperty(BlockColored.COLOR, p_176502_3_.getValue(COLOR)), 3);
}
}
protected boolean tryTouchWater(World worldIn, BlockPos pos, IBlockState state)
{
boolean flag = false;
for (EnumFacing enumfacing : EnumFacing.values())
{
if (enumfacing != EnumFacing.DOWN)
{
BlockPos blockpos = pos.offset(enumfacing);
if (worldIn.getBlockState(blockpos).getMaterial() == Material.WATER)
{
flag = true;
break;
}
}
}
if (flag)
{
worldIn.setBlockState(pos, Blocks.CONCRETE.getDefaultState().withProperty(BlockColored.COLOR, state.getValue(COLOR)), 3);
}
return flag;
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (!this.tryTouchWater(worldIn, pos, state))
{
super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
}
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
if (!this.tryTouchWater(worldIn, pos, state))
{
super.onBlockAdded(worldIn, pos, state);
}
}
/**
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
* returns the metadata of the dropped item based on the old metadata of the block.
*/
public int damageDropped(IBlockState state)
{
return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
for (EnumDyeColor enumdyecolor : EnumDyeColor.values())
{
items.add(new ItemStack(this, 1, enumdyecolor.getMetadata()));
}
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.getBlockColor((EnumDyeColor)state.getValue(COLOR));
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(COLOR, EnumDyeColor.byMetadata(meta));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {COLOR});
}
}

View File

@@ -0,0 +1,107 @@
package net.minecraft.block;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorldNameable;
import net.minecraft.world.World;
public abstract class BlockContainer extends Block implements ITileEntityProvider
{
protected BlockContainer(Material materialIn)
{
this(materialIn, materialIn.getMaterialMapColor());
}
protected BlockContainer(Material materialIn, MapColor color)
{
super(materialIn, color);
this.hasTileEntity = true;
}
protected boolean isInvalidNeighbor(World worldIn, BlockPos pos, EnumFacing facing)
{
return worldIn.getBlockState(pos.offset(facing)).getMaterial() == Material.CACTUS;
}
protected boolean hasInvalidNeighbor(World worldIn, BlockPos pos)
{
return this.isInvalidNeighbor(worldIn, pos, EnumFacing.NORTH) || this.isInvalidNeighbor(worldIn, pos, EnumFacing.SOUTH) || this.isInvalidNeighbor(worldIn, pos, EnumFacing.WEST) || this.isInvalidNeighbor(worldIn, pos, EnumFacing.EAST);
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.INVISIBLE;
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
super.breakBlock(worldIn, pos, state);
worldIn.removeTileEntity(pos);
}
/**
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via
* Block.removedByPlayer
*/
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
if (te instanceof IWorldNameable && ((IWorldNameable)te).hasCustomName())
{
player.addStat(StatList.getBlockStats(this));
player.addExhaustion(0.005F);
if (worldIn.isRemote)
{
return;
}
int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
Item item = this.getItemDropped(state, worldIn.rand, i);
if (item == Items.AIR)
{
return;
}
ItemStack itemstack = new ItemStack(item, this.quantityDropped(worldIn.rand));
itemstack.setStackDisplayName(((IWorldNameable)te).getName());
spawnAsEntity(worldIn, pos, itemstack);
}
else
{
super.harvestBlock(worldIn, player, pos, state, (TileEntity)null, stack);
}
}
/**
* Called on server when World#addBlockEvent is called. If server returns true, then also called on the client. On
* the Server, this may perform additional changes to the world, like pistons replacing the block with an extended
* base. On the client, the update may involve replacing tile entities or effects such as sounds or particles
*/
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param)
{
super.eventReceived(state, worldIn, pos, id, param);
TileEntity tileentity = worldIn.getTileEntity(pos);
return tileentity == null ? false : tileentity.receiveClientEvent(id, param);
}
}

View File

@@ -0,0 +1,281 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockCrops extends BlockBush implements IGrowable
{
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 7);
private static final AxisAlignedBB[] CROPS_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.125D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.25D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.375D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.75D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.875D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D)};
protected BlockCrops()
{
this.setDefaultState(this.blockState.getBaseState().withProperty(this.getAgeProperty(), Integer.valueOf(0)));
this.setTickRandomly(true);
this.setCreativeTab((CreativeTabs)null);
this.setHardness(0.0F);
this.setSoundType(SoundType.PLANT);
this.disableStats();
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return CROPS_AABB[((Integer)state.getValue(this.getAgeProperty())).intValue()];
}
/**
* Return true if the block can sustain a Bush
*/
protected boolean canSustainBush(IBlockState state)
{
return state.getBlock() == Blocks.FARMLAND;
}
protected PropertyInteger getAgeProperty()
{
return AGE;
}
public int getMaxAge()
{
return 7;
}
protected int getAge(IBlockState state)
{
return ((Integer)state.getValue(this.getAgeProperty())).intValue();
}
public IBlockState withAge(int age)
{
return this.getDefaultState().withProperty(this.getAgeProperty(), Integer.valueOf(age));
}
public boolean isMaxAge(IBlockState state)
{
return ((Integer)state.getValue(this.getAgeProperty())).intValue() >= this.getMaxAge();
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
super.updateTick(worldIn, pos, state, rand);
if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light
if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
{
int i = this.getAge(state);
if (i < this.getMaxAge())
{
float f = getGrowthChance(this, worldIn, pos);
if(net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt((int)(25.0F / f) + 1) == 0))
{
worldIn.setBlockState(pos, this.withAge(i + 1), 2);
net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
}
}
}
}
public void grow(World worldIn, BlockPos pos, IBlockState state)
{
int i = this.getAge(state) + this.getBonemealAgeIncrease(worldIn);
int j = this.getMaxAge();
if (i > j)
{
i = j;
}
worldIn.setBlockState(pos, this.withAge(i), 2);
}
protected int getBonemealAgeIncrease(World worldIn)
{
return MathHelper.getInt(worldIn.rand, 2, 5);
}
protected static float getGrowthChance(Block blockIn, World worldIn, BlockPos pos)
{
float f = 1.0F;
BlockPos blockpos = pos.down();
for (int i = -1; i <= 1; ++i)
{
for (int j = -1; j <= 1; ++j)
{
float f1 = 0.0F;
IBlockState iblockstate = worldIn.getBlockState(blockpos.add(i, 0, j));
if (iblockstate.getBlock().canSustainPlant(iblockstate, worldIn, blockpos.add(i, 0, j), net.minecraft.util.EnumFacing.UP, (net.minecraftforge.common.IPlantable)blockIn))
{
f1 = 1.0F;
if (iblockstate.getBlock().isFertile(worldIn, blockpos.add(i, 0, j)))
{
f1 = 3.0F;
}
}
if (i != 0 || j != 0)
{
f1 /= 4.0F;
}
f += f1;
}
}
BlockPos blockpos1 = pos.north();
BlockPos blockpos2 = pos.south();
BlockPos blockpos3 = pos.west();
BlockPos blockpos4 = pos.east();
boolean flag = blockIn == worldIn.getBlockState(blockpos3).getBlock() || blockIn == worldIn.getBlockState(blockpos4).getBlock();
boolean flag1 = blockIn == worldIn.getBlockState(blockpos1).getBlock() || blockIn == worldIn.getBlockState(blockpos2).getBlock();
if (flag && flag1)
{
f /= 2.0F;
}
else
{
boolean flag2 = blockIn == worldIn.getBlockState(blockpos3.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.south()).getBlock() || blockIn == worldIn.getBlockState(blockpos3.south()).getBlock();
if (flag2)
{
f /= 2.0F;
}
}
return f;
}
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
IBlockState soil = worldIn.getBlockState(pos.down());
return (worldIn.getLight(pos) >= 8 || worldIn.canSeeSky(pos)) && soil.getBlock().canSustainPlant(soil, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
}
protected Item getSeed()
{
return Items.WHEAT_SEEDS;
}
protected Item getCrop()
{
return Items.WHEAT;
}
@Override
public void getDrops(net.minecraft.util.NonNullList<ItemStack> drops, net.minecraft.world.IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
super.getDrops(drops, world, pos, state, 0);
int age = getAge(state);
Random rand = world instanceof World ? ((World)world).rand : new Random();
if (age >= getMaxAge())
{
int k = 3 + fortune;
for (int i = 0; i < 3 + fortune; ++i)
{
if (rand.nextInt(2 * getMaxAge()) <= age)
{
drops.add(new ItemStack(this.getSeed(), 1, 0));
}
}
}
}
/**
* Spawns this Block's drops into the World as EntityItems.
*/
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
if (false && !worldIn.isRemote) // Forge: NOP all this.
{
int i = this.getAge(state);
if (i >= this.getMaxAge())
{
int j = 3 + fortune;
for (int k = 0; k < j; ++k)
{
if (worldIn.rand.nextInt(2 * this.getMaxAge()) <= i)
{
spawnAsEntity(worldIn, pos, new ItemStack(this.getSeed()));
}
}
}
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return this.isMaxAge(state) ? this.getCrop() : this.getSeed();
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(this.getSeed());
}
/**
* Whether this IGrowable can grow
*/
public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
{
return !this.isMaxAge(state);
}
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
return true;
}
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
this.grow(worldIn, pos, state);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.withAge(meta);
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return this.getAge(state);
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {AGE});
}
}

View File

@@ -0,0 +1,213 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityDaylightDetector;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockDaylightDetector extends BlockContainer
{
public static final PropertyInteger POWER = PropertyInteger.create("power", 0, 15);
protected static final AxisAlignedBB DAYLIGHT_DETECTOR_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.375D, 1.0D);
private final boolean inverted;
public BlockDaylightDetector(boolean inverted)
{
super(Material.WOOD);
this.inverted = inverted;
this.setDefaultState(this.blockState.getBaseState().withProperty(POWER, Integer.valueOf(0)));
this.setCreativeTab(CreativeTabs.REDSTONE);
this.setHardness(0.2F);
this.setSoundType(SoundType.WOOD);
this.setUnlocalizedName("daylightDetector");
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return DAYLIGHT_DETECTOR_AABB;
}
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return ((Integer)blockState.getValue(POWER)).intValue();
}
public void updatePower(World worldIn, BlockPos pos)
{
if (worldIn.provider.hasSkyLight())
{
IBlockState iblockstate = worldIn.getBlockState(pos);
int i = worldIn.getLightFor(EnumSkyBlock.SKY, pos) - worldIn.getSkylightSubtracted();
float f = worldIn.getCelestialAngleRadians(1.0F);
if (this.inverted)
{
i = 15 - i;
}
if (i > 0 && !this.inverted)
{
float f1 = f < (float)Math.PI ? 0.0F : ((float)Math.PI * 2F);
f = f + (f1 - f) * 0.2F;
i = Math.round((float)i * MathHelper.cos(f));
}
i = MathHelper.clamp(i, 0, 15);
if (((Integer)iblockstate.getValue(POWER)).intValue() != i)
{
worldIn.setBlockState(pos, iblockstate.withProperty(POWER, Integer.valueOf(i)), 3);
}
}
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (playerIn.isAllowEdit())
{
if (worldIn.isRemote)
{
return true;
}
else
{
if (this.inverted)
{
worldIn.setBlockState(pos, Blocks.DAYLIGHT_DETECTOR.getDefaultState().withProperty(POWER, state.getValue(POWER)), 4);
Blocks.DAYLIGHT_DETECTOR.updatePower(worldIn, pos);
}
else
{
worldIn.setBlockState(pos, Blocks.DAYLIGHT_DETECTOR_INVERTED.getDefaultState().withProperty(POWER, state.getValue(POWER)), 4);
Blocks.DAYLIGHT_DETECTOR_INVERTED.updatePower(worldIn, pos);
}
return true;
}
}
else
{
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(Blocks.DAYLIGHT_DETECTOR);
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(Blocks.DAYLIGHT_DETECTOR);
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}
/**
* Can this block provide power. Only wire currently seems to have this change based on its state.
*/
public boolean canProvidePower(IBlockState state)
{
return true;
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityDaylightDetector();
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(POWER, Integer.valueOf(meta));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(POWER)).intValue();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {POWER});
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
if (!this.inverted)
{
super.getSubBlocks(itemIn, items);
}
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return face == EnumFacing.DOWN ? BlockFaceShape.SOLID : BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,97 @@
package net.minecraft.block;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockDeadBush extends BlockBush implements net.minecraftforge.common.IShearable
{
protected static final AxisAlignedBB DEAD_BUSH_AABB = new AxisAlignedBB(0.09999999403953552D, 0.0D, 0.09999999403953552D, 0.8999999761581421D, 0.800000011920929D, 0.8999999761581421D);
protected BlockDeadBush()
{
super(Material.VINE);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return DEAD_BUSH_AABB;
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.WOOD;
}
/**
* Return true if the block can sustain a Bush
*/
protected boolean canSustainBush(IBlockState state)
{
return state.getBlock() == Blocks.SAND || state.getBlock() == Blocks.HARDENED_CLAY || state.getBlock() == Blocks.STAINED_HARDENED_CLAY || state.getBlock() == Blocks.DIRT;
}
/**
* Whether this Block can be replaced directly by other blocks (true for e.g. tall grass)
*/
public boolean isReplaceable(IBlockAccess worldIn, BlockPos pos)
{
return true;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return random.nextInt(3);
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.STICK;
}
/**
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via
* Block.removedByPlayer
*/
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
if (!worldIn.isRemote && stack.getItem() == Items.SHEARS)
{
player.addStat(StatList.getBlockStats(this));
spawnAsEntity(worldIn, pos, new ItemStack(Blocks.DEADBUSH, 1, 0));
}
else
{
super.harvestBlock(worldIn, player, pos, state, te, stack);
}
}
@Override public boolean isShearable(ItemStack item, net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; }
@Override
public java.util.List<ItemStack> onSheared(ItemStack item, net.minecraft.world.IBlockAccess world, BlockPos pos, int fortune)
{
return java.util.Arrays.asList(new ItemStack(Blocks.DEADBUSH));
}
}

View File

@@ -0,0 +1,14 @@
package net.minecraft.block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
public abstract class BlockDirectional extends Block
{
public static final PropertyDirection FACING = PropertyDirection.create("facing");
protected BlockDirectional(Material materialIn)
{
super(materialIn);
}
}

View File

@@ -0,0 +1,174 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockDirt extends Block
{
public static final PropertyEnum<BlockDirt.DirtType> VARIANT = PropertyEnum.<BlockDirt.DirtType>create("variant", BlockDirt.DirtType.class);
public static final PropertyBool SNOWY = PropertyBool.create("snowy");
protected BlockDirt()
{
super(Material.GROUND);
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockDirt.DirtType.DIRT).withProperty(SNOWY, Boolean.valueOf(false)));
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return ((BlockDirt.DirtType)state.getValue(VARIANT)).getColor();
}
/**
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
* metadata, such as fence connections.
*/
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
if (state.getValue(VARIANT) == BlockDirt.DirtType.PODZOL)
{
Block block = worldIn.getBlockState(pos.up()).getBlock();
state = state.withProperty(SNOWY, Boolean.valueOf(block == Blocks.SNOW || block == Blocks.SNOW_LAYER));
}
return state;
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
items.add(new ItemStack(this, 1, BlockDirt.DirtType.DIRT.getMetadata()));
items.add(new ItemStack(this, 1, BlockDirt.DirtType.COARSE_DIRT.getMetadata()));
items.add(new ItemStack(this, 1, BlockDirt.DirtType.PODZOL.getMetadata()));
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(this, 1, ((BlockDirt.DirtType)state.getValue(VARIANT)).getMetadata());
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(VARIANT, BlockDirt.DirtType.byMetadata(meta));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((BlockDirt.DirtType)state.getValue(VARIANT)).getMetadata();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {VARIANT, SNOWY});
}
/**
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
* returns the metadata of the dropped item based on the old metadata of the block.
*/
public int damageDropped(IBlockState state)
{
BlockDirt.DirtType blockdirt$dirttype = (BlockDirt.DirtType)state.getValue(VARIANT);
if (blockdirt$dirttype == BlockDirt.DirtType.PODZOL)
{
blockdirt$dirttype = BlockDirt.DirtType.DIRT;
}
return blockdirt$dirttype.getMetadata();
}
public static enum DirtType implements IStringSerializable
{
DIRT(0, "dirt", "default", MapColor.DIRT),
COARSE_DIRT(1, "coarse_dirt", "coarse", MapColor.DIRT),
PODZOL(2, "podzol", MapColor.OBSIDIAN);
private static final BlockDirt.DirtType[] METADATA_LOOKUP = new BlockDirt.DirtType[values().length];
private final int metadata;
private final String name;
private final String unlocalizedName;
private final MapColor color;
private DirtType(int metadataIn, String nameIn, MapColor color)
{
this(metadataIn, nameIn, nameIn, color);
}
private DirtType(int metadataIn, String nameIn, String unlocalizedNameIn, MapColor color)
{
this.metadata = metadataIn;
this.name = nameIn;
this.unlocalizedName = unlocalizedNameIn;
this.color = color;
}
public int getMetadata()
{
return this.metadata;
}
public String getUnlocalizedName()
{
return this.unlocalizedName;
}
public MapColor getColor()
{
return this.color;
}
public String toString()
{
return this.name;
}
public static BlockDirt.DirtType byMetadata(int metadata)
{
if (metadata < 0 || metadata >= METADATA_LOOKUP.length)
{
metadata = 0;
}
return METADATA_LOOKUP[metadata];
}
public String getName()
{
return this.name;
}
static
{
for (BlockDirt.DirtType blockdirt$dirttype : values())
{
METADATA_LOOKUP[blockdirt$dirttype.getMetadata()] = blockdirt$dirttype;
}
}
}
}

View File

@@ -0,0 +1,321 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBehaviorDispenseItem;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.dispenser.IPosition;
import net.minecraft.dispenser.PositionImpl;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityDispenser;
import net.minecraft.tileentity.TileEntityDropper;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.RegistryDefaulted;
import net.minecraft.world.World;
public class BlockDispenser extends BlockContainer
{
public static final PropertyDirection FACING = BlockDirectional.FACING;
public static final PropertyBool TRIGGERED = PropertyBool.create("triggered");
/** Registry for all dispense behaviors. */
public static final RegistryDefaulted<Item, IBehaviorDispenseItem> DISPENSE_BEHAVIOR_REGISTRY = new RegistryDefaulted<Item, IBehaviorDispenseItem>(new BehaviorDefaultDispenseItem());
protected Random rand = new Random();
protected BlockDispenser()
{
super(Material.ROCK);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(TRIGGERED, Boolean.valueOf(false)));
this.setCreativeTab(CreativeTabs.REDSTONE);
}
/**
* How many world ticks before ticking
*/
public int tickRate(World worldIn)
{
return 4;
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
super.onBlockAdded(worldIn, pos, state);
this.setDefaultDirection(worldIn, pos, state);
}
private void setDefaultDirection(World worldIn, BlockPos pos, IBlockState state)
{
if (!worldIn.isRemote)
{
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
boolean flag = worldIn.getBlockState(pos.north()).isFullBlock();
boolean flag1 = worldIn.getBlockState(pos.south()).isFullBlock();
if (enumfacing == EnumFacing.NORTH && flag && !flag1)
{
enumfacing = EnumFacing.SOUTH;
}
else if (enumfacing == EnumFacing.SOUTH && flag1 && !flag)
{
enumfacing = EnumFacing.NORTH;
}
else
{
boolean flag2 = worldIn.getBlockState(pos.west()).isFullBlock();
boolean flag3 = worldIn.getBlockState(pos.east()).isFullBlock();
if (enumfacing == EnumFacing.WEST && flag2 && !flag3)
{
enumfacing = EnumFacing.EAST;
}
else if (enumfacing == EnumFacing.EAST && flag3 && !flag2)
{
enumfacing = EnumFacing.WEST;
}
}
worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing).withProperty(TRIGGERED, Boolean.valueOf(false)), 2);
}
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
else
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityDispenser)
{
playerIn.displayGUIChest((TileEntityDispenser)tileentity);
if (tileentity instanceof TileEntityDropper)
{
playerIn.addStat(StatList.DROPPER_INSPECTED);
}
else
{
playerIn.addStat(StatList.DISPENSER_INSPECTED);
}
}
return true;
}
}
protected void dispense(World worldIn, BlockPos pos)
{
BlockSourceImpl blocksourceimpl = new BlockSourceImpl(worldIn, pos);
TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
if (tileentitydispenser != null)
{
int i = tileentitydispenser.getDispenseSlot();
if (i < 0)
{
worldIn.playEvent(1001, pos, 0);
}
else
{
ItemStack itemstack = tileentitydispenser.getStackInSlot(i);
IBehaviorDispenseItem ibehaviordispenseitem = this.getBehavior(itemstack);
if (ibehaviordispenseitem != IBehaviorDispenseItem.DEFAULT_BEHAVIOR)
{
tileentitydispenser.setInventorySlotContents(i, ibehaviordispenseitem.dispense(blocksourceimpl, itemstack));
}
}
}
}
protected IBehaviorDispenseItem getBehavior(ItemStack stack)
{
return DISPENSE_BEHAVIOR_REGISTRY.getObject(stack.getItem());
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(pos.up());
boolean flag1 = ((Boolean)state.getValue(TRIGGERED)).booleanValue();
if (flag && !flag1)
{
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
worldIn.setBlockState(pos, state.withProperty(TRIGGERED, Boolean.valueOf(true)), 4);
}
else if (!flag && flag1)
{
worldIn.setBlockState(pos, state.withProperty(TRIGGERED, Boolean.valueOf(false)), 4);
}
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isRemote)
{
this.dispense(worldIn, pos);
}
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityDispenser();
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getDefaultState().withProperty(FACING, EnumFacing.getDirectionFromEntityLiving(pos, placer)).withProperty(TRIGGERED, Boolean.valueOf(false));
}
/**
* Called by ItemBlocks after a block is set in the world, to allow post-place logic
*/
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
worldIn.setBlockState(pos, state.withProperty(FACING, EnumFacing.getDirectionFromEntityLiving(pos, placer)), 2);
if (stack.hasDisplayName())
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityDispenser)
{
((TileEntityDispenser)tileentity).setCustomName(stack.getDisplayName());
}
}
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityDispenser)
{
InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityDispenser)tileentity);
worldIn.updateComparatorOutputLevel(pos, this);
}
super.breakBlock(worldIn, pos, state);
}
/**
* Get the position where the dispenser at the given Coordinates should dispense to.
*/
public static IPosition getDispensePosition(IBlockSource coords)
{
EnumFacing enumfacing = (EnumFacing)coords.getBlockState().getValue(FACING);
double d0 = coords.getX() + 0.7D * (double)enumfacing.getFrontOffsetX();
double d1 = coords.getY() + 0.7D * (double)enumfacing.getFrontOffsetY();
double d2 = coords.getZ() + 0.7D * (double)enumfacing.getFrontOffsetZ();
return new PositionImpl(d0, d1, d2);
}
public boolean hasComparatorInputOverride(IBlockState state)
{
return true;
}
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
{
return Container.calcRedstone(worldIn.getTileEntity(pos));
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta & 7)).withProperty(TRIGGERED, Boolean.valueOf((meta & 8) > 0));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((EnumFacing)state.getValue(FACING)).getIndex();
if (((Boolean)state.getValue(TRIGGERED)).booleanValue())
{
i |= 8;
}
return i;
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING, TRIGGERED});
}
}

View File

@@ -0,0 +1,540 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockDoor extends Block
{
public static final PropertyDirection FACING = BlockHorizontal.FACING;
public static final PropertyBool OPEN = PropertyBool.create("open");
public static final PropertyEnum<BlockDoor.EnumHingePosition> HINGE = PropertyEnum.<BlockDoor.EnumHingePosition>create("hinge", BlockDoor.EnumHingePosition.class);
public static final PropertyBool POWERED = PropertyBool.create("powered");
public static final PropertyEnum<BlockDoor.EnumDoorHalf> HALF = PropertyEnum.<BlockDoor.EnumDoorHalf>create("half", BlockDoor.EnumDoorHalf.class);
protected static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.1875D);
protected static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.8125D, 1.0D, 1.0D, 1.0D);
protected static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.8125D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
protected static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.1875D, 1.0D, 1.0D);
protected BlockDoor(Material materialIn)
{
super(materialIn);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(OPEN, Boolean.valueOf(false)).withProperty(HINGE, BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf(false)).withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER));
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
state = state.getActualState(source, pos);
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
boolean flag = !((Boolean)state.getValue(OPEN)).booleanValue();
boolean flag1 = state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT;
switch (enumfacing)
{
case EAST:
default:
return flag ? EAST_AABB : (flag1 ? NORTH_AABB : SOUTH_AABB);
case SOUTH:
return flag ? SOUTH_AABB : (flag1 ? EAST_AABB : WEST_AABB);
case WEST:
return flag ? WEST_AABB : (flag1 ? SOUTH_AABB : NORTH_AABB);
case NORTH:
return flag ? NORTH_AABB : (flag1 ? WEST_AABB : EAST_AABB);
}
}
/**
* Gets the localized name of this block. Used for the statistics page.
*/
public String getLocalizedName()
{
return I18n.translateToLocal((this.getUnlocalizedName() + ".name").replaceAll("tile", "item"));
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* Determines if an entity can path through this block
*/
public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
{
return isOpen(combineMetadata(worldIn, pos));
}
public boolean isFullCube(IBlockState state)
{
return false;
}
private int getCloseSound()
{
return this.blockMaterial == Material.IRON ? 1011 : 1012;
}
private int getOpenSound()
{
return this.blockMaterial == Material.IRON ? 1005 : 1006;
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
if (state.getBlock() == Blocks.IRON_DOOR)
{
return MapColor.IRON;
}
else if (state.getBlock() == Blocks.OAK_DOOR)
{
return BlockPlanks.EnumType.OAK.getMapColor();
}
else if (state.getBlock() == Blocks.SPRUCE_DOOR)
{
return BlockPlanks.EnumType.SPRUCE.getMapColor();
}
else if (state.getBlock() == Blocks.BIRCH_DOOR)
{
return BlockPlanks.EnumType.BIRCH.getMapColor();
}
else if (state.getBlock() == Blocks.JUNGLE_DOOR)
{
return BlockPlanks.EnumType.JUNGLE.getMapColor();
}
else if (state.getBlock() == Blocks.ACACIA_DOOR)
{
return BlockPlanks.EnumType.ACACIA.getMapColor();
}
else
{
return state.getBlock() == Blocks.DARK_OAK_DOOR ? BlockPlanks.EnumType.DARK_OAK.getMapColor() : super.getMapColor(state, worldIn, pos);
}
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (this.blockMaterial == Material.IRON)
{
return false;
}
else
{
BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
IBlockState iblockstate = pos.equals(blockpos) ? state : worldIn.getBlockState(blockpos);
if (iblockstate.getBlock() != this)
{
return false;
}
else
{
state = iblockstate.cycleProperty(OPEN);
worldIn.setBlockState(blockpos, state, 10);
worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
worldIn.playEvent(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? this.getOpenSound() : this.getCloseSound(), pos, 0);
return true;
}
}
}
public void toggleDoor(World worldIn, BlockPos pos, boolean open)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock() == this)
{
BlockPos blockpos = iblockstate.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
IBlockState iblockstate1 = pos == blockpos ? iblockstate : worldIn.getBlockState(blockpos);
if (iblockstate1.getBlock() == this && ((Boolean)iblockstate1.getValue(OPEN)).booleanValue() != open)
{
worldIn.setBlockState(blockpos, iblockstate1.withProperty(OPEN, Boolean.valueOf(open)), 10);
worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
worldIn.playEvent((EntityPlayer)null, open ? this.getOpenSound() : this.getCloseSound(), pos, 0);
}
}
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER)
{
BlockPos blockpos = pos.down();
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.getBlock() != this)
{
worldIn.setBlockToAir(pos);
}
else if (blockIn != this)
{
iblockstate.neighborChanged(worldIn, blockpos, blockIn, fromPos);
}
}
else
{
boolean flag1 = false;
BlockPos blockpos1 = pos.up();
IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);
if (iblockstate1.getBlock() != this)
{
worldIn.setBlockToAir(pos);
flag1 = true;
}
if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP))
{
worldIn.setBlockToAir(pos);
flag1 = true;
if (iblockstate1.getBlock() == this)
{
worldIn.setBlockToAir(blockpos1);
}
}
if (flag1)
{
if (!worldIn.isRemote)
{
this.dropBlockAsItem(worldIn, pos, state, 0);
}
}
else
{
boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos1);
if (blockIn != this && (flag || blockIn.getDefaultState().canProvidePower()) && flag != ((Boolean)iblockstate1.getValue(POWERED)).booleanValue())
{
worldIn.setBlockState(blockpos1, iblockstate1.withProperty(POWERED, Boolean.valueOf(flag)), 2);
if (flag != ((Boolean)state.getValue(OPEN)).booleanValue())
{
worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(flag)), 2);
worldIn.markBlockRangeForRenderUpdate(pos, pos);
worldIn.playEvent((EntityPlayer)null, flag ? this.getOpenSound() : this.getCloseSound(), pos, 0);
}
}
}
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? Items.AIR : this.getItem();
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
if (pos.getY() >= worldIn.getHeight() - 1)
{
return false;
}
else
{
IBlockState state = worldIn.getBlockState(pos.down());
return (state.isTopSolid() || state.getBlockFaceShape(worldIn, pos.down(), EnumFacing.UP) == BlockFaceShape.SOLID) && super.canPlaceBlockAt(worldIn, pos) && super.canPlaceBlockAt(worldIn, pos.up());
}
}
public EnumPushReaction getMobilityFlag(IBlockState state)
{
return EnumPushReaction.DESTROY;
}
public static int combineMetadata(IBlockAccess worldIn, BlockPos pos)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
int i = iblockstate.getBlock().getMetaFromState(iblockstate);
boolean flag = isTop(i);
IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
int j = iblockstate1.getBlock().getMetaFromState(iblockstate1);
int k = flag ? j : i;
IBlockState iblockstate2 = worldIn.getBlockState(pos.up());
int l = iblockstate2.getBlock().getMetaFromState(iblockstate2);
int i1 = flag ? i : l;
boolean flag1 = (i1 & 1) != 0;
boolean flag2 = (i1 & 2) != 0;
return removeHalfBit(k) | (flag ? 8 : 0) | (flag1 ? 16 : 0) | (flag2 ? 32 : 0);
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(this.getItem());
}
private Item getItem()
{
if (this == Blocks.IRON_DOOR)
{
return Items.IRON_DOOR;
}
else if (this == Blocks.SPRUCE_DOOR)
{
return Items.SPRUCE_DOOR;
}
else if (this == Blocks.BIRCH_DOOR)
{
return Items.BIRCH_DOOR;
}
else if (this == Blocks.JUNGLE_DOOR)
{
return Items.JUNGLE_DOOR;
}
else if (this == Blocks.ACACIA_DOOR)
{
return Items.ACACIA_DOOR;
}
else
{
return this == Blocks.DARK_OAK_DOOR ? Items.DARK_OAK_DOOR : Items.OAK_DOOR;
}
}
/**
* Called before the Block is set to air in the world. Called regardless of if the player's tool can actually
* collect this block
*/
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
BlockPos blockpos = pos.down();
BlockPos blockpos1 = pos.up();
if (player.capabilities.isCreativeMode && state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER && worldIn.getBlockState(blockpos).getBlock() == this)
{
worldIn.setBlockToAir(blockpos);
}
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER && worldIn.getBlockState(blockpos1).getBlock() == this)
{
if (player.capabilities.isCreativeMode)
{
worldIn.setBlockToAir(pos);
}
worldIn.setBlockToAir(blockpos1);
}
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
* metadata, such as fence connections.
*/
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER)
{
IBlockState iblockstate = worldIn.getBlockState(pos.up());
if (iblockstate.getBlock() == this)
{
state = state.withProperty(HINGE, iblockstate.getValue(HINGE)).withProperty(POWERED, iblockstate.getValue(POWERED));
}
}
else
{
IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
if (iblockstate1.getBlock() == this)
{
state = state.withProperty(FACING, iblockstate1.getValue(FACING)).withProperty(OPEN, iblockstate1.getValue(OPEN));
}
}
return state;
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.getValue(HALF) != BlockDoor.EnumDoorHalf.LOWER ? state : state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return mirrorIn == Mirror.NONE ? state : state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING))).cycleProperty(HINGE);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return (meta & 8) > 0 ? this.getDefaultState().withProperty(HALF, BlockDoor.EnumDoorHalf.UPPER).withProperty(HINGE, (meta & 1) > 0 ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf((meta & 2) > 0)) : this.getDefaultState().withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER).withProperty(FACING, EnumFacing.getHorizontal(meta & 3).rotateYCCW()).withProperty(OPEN, Boolean.valueOf((meta & 4) > 0));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER)
{
i = i | 8;
if (state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT)
{
i |= 1;
}
if (((Boolean)state.getValue(POWERED)).booleanValue())
{
i |= 2;
}
}
else
{
i = i | ((EnumFacing)state.getValue(FACING)).rotateY().getHorizontalIndex();
if (((Boolean)state.getValue(OPEN)).booleanValue())
{
i |= 4;
}
}
return i;
}
protected static int removeHalfBit(int meta)
{
return meta & 7;
}
public static boolean isOpen(IBlockAccess worldIn, BlockPos pos)
{
return isOpen(combineMetadata(worldIn, pos));
}
public static EnumFacing getFacing(IBlockAccess worldIn, BlockPos pos)
{
return getFacing(combineMetadata(worldIn, pos));
}
public static EnumFacing getFacing(int combinedMeta)
{
return EnumFacing.getHorizontal(combinedMeta & 3).rotateYCCW();
}
protected static boolean isOpen(int combinedMeta)
{
return (combinedMeta & 4) != 0;
}
protected static boolean isTop(int meta)
{
return (meta & 8) != 0;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {HALF, FACING, OPEN, HINGE, POWERED});
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
public static enum EnumDoorHalf implements IStringSerializable
{
UPPER,
LOWER;
public String toString()
{
return this.getName();
}
public String getName()
{
return this == UPPER ? "upper" : "lower";
}
}
public static enum EnumHingePosition implements IStringSerializable
{
LEFT,
RIGHT;
public String toString()
{
return this.getName();
}
public String getName()
{
return this == LEFT ? "left" : "right";
}
}
}

View File

@@ -0,0 +1,429 @@
package net.minecraft.block;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockDoublePlant extends BlockBush implements IGrowable, net.minecraftforge.common.IShearable
{
public static final PropertyEnum<BlockDoublePlant.EnumPlantType> VARIANT = PropertyEnum.<BlockDoublePlant.EnumPlantType>create("variant", BlockDoublePlant.EnumPlantType.class);
public static final PropertyEnum<BlockDoublePlant.EnumBlockHalf> HALF = PropertyEnum.<BlockDoublePlant.EnumBlockHalf>create("half", BlockDoublePlant.EnumBlockHalf.class);
public static final PropertyEnum<EnumFacing> FACING = BlockHorizontal.FACING;
public BlockDoublePlant()
{
super(Material.VINE);
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockDoublePlant.EnumPlantType.SUNFLOWER).withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(FACING, EnumFacing.NORTH));
this.setHardness(0.0F);
this.setSoundType(SoundType.PLANT);
this.setUnlocalizedName("doublePlant");
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return FULL_BLOCK_AABB;
}
private BlockDoublePlant.EnumPlantType getType(IBlockAccess blockAccess, BlockPos pos, IBlockState state)
{
if (state.getBlock() == this)
{
state = state.getActualState(blockAccess, pos);
return (BlockDoublePlant.EnumPlantType)state.getValue(VARIANT);
}
else
{
return BlockDoublePlant.EnumPlantType.FERN;
}
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return super.canPlaceBlockAt(worldIn, pos) && worldIn.isAirBlock(pos.up());
}
/**
* Whether this Block can be replaced directly by other blocks (true for e.g. tall grass)
*/
public boolean isReplaceable(IBlockAccess worldIn, BlockPos pos)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock() != this)
{
return true;
}
else
{
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)iblockstate.getActualState(worldIn, pos).getValue(VARIANT);
return blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.FERN || blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.GRASS;
}
}
protected void checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state)
{
if (!this.canBlockStay(worldIn, pos, state))
{
boolean flag = state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER;
BlockPos blockpos = flag ? pos : pos.up();
BlockPos blockpos1 = flag ? pos.down() : pos;
Block block = (Block)(flag ? this : worldIn.getBlockState(blockpos).getBlock());
Block block1 = (Block)(flag ? worldIn.getBlockState(blockpos1).getBlock() : this);
if (!flag) this.dropBlockAsItem(worldIn, pos, state, 0); //Forge move above the setting to air.
if (block == this)
{
worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 2);
}
if (block1 == this)
{
worldIn.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3);
}
}
}
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
if (state.getBlock() != this) return super.canBlockStay(worldIn, pos, state); //Forge: This function is called during world gen and placement, before this block is set, so if we are not 'here' then assume it's the pre-check.
if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
{
return worldIn.getBlockState(pos.down()).getBlock() == this;
}
else
{
IBlockState iblockstate = worldIn.getBlockState(pos.up());
return iblockstate.getBlock() == this && super.canBlockStay(worldIn, pos, iblockstate);
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
{
return Items.AIR;
}
else
{
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)state.getValue(VARIANT);
if (blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.FERN)
{
return Items.AIR;
}
else if (blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.GRASS)
{
return rand.nextInt(8) == 0 ? Items.WHEAT_SEEDS : Items.AIR;
}
else
{
return super.getItemDropped(state, rand, fortune);
}
}
}
/**
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
* returns the metadata of the dropped item based on the old metadata of the block.
*/
public int damageDropped(IBlockState state)
{
return state.getValue(HALF) != BlockDoublePlant.EnumBlockHalf.UPPER && state.getValue(VARIANT) != BlockDoublePlant.EnumPlantType.GRASS ? ((BlockDoublePlant.EnumPlantType)state.getValue(VARIANT)).getMeta() : 0;
}
public void placeAt(World worldIn, BlockPos lowerPos, BlockDoublePlant.EnumPlantType variant, int flags)
{
worldIn.setBlockState(lowerPos, this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(VARIANT, variant), flags);
worldIn.setBlockState(lowerPos.up(), this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.UPPER), flags);
}
/**
* Called by ItemBlocks after a block is set in the world, to allow post-place logic
*/
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
worldIn.setBlockState(pos.up(), this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.UPPER), 2);
}
/**
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via
* Block.removedByPlayer
*/
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
{
super.harvestBlock(worldIn, player, pos, state, te, stack);
}
}
/**
* Called before the Block is set to air in the world. Called regardless of if the player's tool can actually
* collect this block
*/
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
{
if (worldIn.getBlockState(pos.down()).getBlock() == this)
{
if (player.capabilities.isCreativeMode)
{
worldIn.setBlockToAir(pos.down());
}
else
{
IBlockState iblockstate = worldIn.getBlockState(pos.down());
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)iblockstate.getValue(VARIANT);
if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
{
worldIn.destroyBlock(pos.down(), true);
}
else if (worldIn.isRemote)
{
worldIn.setBlockToAir(pos.down());
}
else if (!player.getHeldItemMainhand().isEmpty() && player.getHeldItemMainhand().getItem() == Items.SHEARS)
{
this.onHarvest(worldIn, pos, iblockstate, player);
worldIn.setBlockToAir(pos.down());
}
else
{
worldIn.destroyBlock(pos.down(), true);
}
}
}
}
else if (worldIn.getBlockState(pos.up()).getBlock() == this)
{
worldIn.setBlockState(pos.up(), Blocks.AIR.getDefaultState(), 2);
}
super.onBlockHarvested(worldIn, pos, state, player);
}
private boolean onHarvest(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)state.getValue(VARIANT);
if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
{
return false;
}
else
{
player.addStat(StatList.getBlockStats(this));
return true;
}
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
for (BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype : BlockDoublePlant.EnumPlantType.values())
{
items.add(new ItemStack(this, 1, blockdoubleplant$enumplanttype.getMeta()));
}
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(this, 1, this.getType(worldIn, pos, state).getMeta());
}
/**
* Whether this IGrowable can grow
*/
public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
{
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = this.getType(worldIn, pos, state);
return blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN;
}
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
return true;
}
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
spawnAsEntity(worldIn, pos, new ItemStack(this, 1, this.getType(worldIn, pos, state).getMeta()));
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return (meta & 8) > 0 ? this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.UPPER) : this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(VARIANT, BlockDoublePlant.EnumPlantType.byMetadata(meta & 7));
}
/**
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
* metadata, such as fence connections.
*/
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
{
IBlockState iblockstate = worldIn.getBlockState(pos.down());
if (iblockstate.getBlock() == this)
{
state = state.withProperty(VARIANT, iblockstate.getValue(VARIANT));
}
}
return state;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER ? 8 | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex() : ((BlockDoublePlant.EnumPlantType)state.getValue(VARIANT)).getMeta();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {HALF, VARIANT, FACING});
}
/**
* Get the OffsetType for this Block. Determines if the model is rendered slightly offset.
*/
public Block.EnumOffsetType getOffsetType()
{
return Block.EnumOffsetType.XZ;
}
@Override
public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos)
{
IBlockState state = world.getBlockState(pos);
EnumPlantType type = (EnumPlantType)state.getValue(VARIANT);
return state.getValue(HALF) == EnumBlockHalf.LOWER && (type == EnumPlantType.FERN || type == EnumPlantType.GRASS);
}
@Override
public java.util.List<ItemStack> onSheared(ItemStack item, net.minecraft.world.IBlockAccess world, BlockPos pos, int fortune)
{
java.util.List<ItemStack> ret = new java.util.ArrayList<ItemStack>();
EnumPlantType type = (EnumPlantType)world.getBlockState(pos).getValue(VARIANT);
if (type == EnumPlantType.FERN) ret.add(new ItemStack(Blocks.TALLGRASS, 2, BlockTallGrass.EnumType.FERN.getMeta()));
if (type == EnumPlantType.GRASS) ret.add(new ItemStack(Blocks.TALLGRASS, 2, BlockTallGrass.EnumType.GRASS.getMeta()));
return ret;
}
public static enum EnumBlockHalf implements IStringSerializable
{
UPPER,
LOWER;
public String toString()
{
return this.getName();
}
public String getName()
{
return this == UPPER ? "upper" : "lower";
}
}
public static enum EnumPlantType implements IStringSerializable
{
SUNFLOWER(0, "sunflower"),
SYRINGA(1, "syringa"),
GRASS(2, "double_grass", "grass"),
FERN(3, "double_fern", "fern"),
ROSE(4, "double_rose", "rose"),
PAEONIA(5, "paeonia");
private static final BlockDoublePlant.EnumPlantType[] META_LOOKUP = new BlockDoublePlant.EnumPlantType[values().length];
private final int meta;
private final String name;
private final String unlocalizedName;
private EnumPlantType(int meta, String name)
{
this(meta, name, name);
}
private EnumPlantType(int meta, String name, String unlocalizedName)
{
this.meta = meta;
this.name = name;
this.unlocalizedName = unlocalizedName;
}
public int getMeta()
{
return this.meta;
}
public String toString()
{
return this.name;
}
public static BlockDoublePlant.EnumPlantType byMetadata(int meta)
{
if (meta < 0 || meta >= META_LOOKUP.length)
{
meta = 0;
}
return META_LOOKUP[meta];
}
public String getName()
{
return this.name;
}
public String getUnlocalizedName()
{
return this.unlocalizedName;
}
static
{
for (BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype : values())
{
META_LOOKUP[blockdoubleplant$enumplanttype.getMeta()] = blockdoubleplant$enumplanttype;
}
}
}
}

View File

@@ -0,0 +1,29 @@
package net.minecraft.block;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
public class BlockDoubleStoneSlab extends BlockStoneSlab
{
public boolean isDouble()
{
return true;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.SOLID;
}
}

View File

@@ -0,0 +1,9 @@
package net.minecraft.block;
public class BlockDoubleStoneSlabNew extends BlockStoneSlabNew
{
public boolean isDouble()
{
return true;
}
}

View File

@@ -0,0 +1,9 @@
package net.minecraft.block;
public class BlockDoubleWoodSlab extends BlockWoodSlab
{
public boolean isDouble()
{
return true;
}
}

View File

@@ -0,0 +1,177 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockDragonEgg extends Block
{
protected static final AxisAlignedBB DRAGON_EGG_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 1.0D, 0.9375D);
public BlockDragonEgg()
{
super(Material.DRAGON_EGG, MapColor.BLACK);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return DRAGON_EGG_AABB;
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
this.checkFall(worldIn, pos);
}
private void checkFall(World worldIn, BlockPos pos)
{
if (worldIn.isAirBlock(pos.down()) && BlockFalling.canFallThrough(worldIn.getBlockState(pos.down())) && pos.getY() >= 0)
{
int i = 32;
if (!BlockFalling.fallInstantly && worldIn.isAreaLoaded(pos.add(-32, -32, -32), pos.add(32, 32, 32)))
{
worldIn.spawnEntity(new EntityFallingBlock(worldIn, (double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F), this.getDefaultState()));
}
else
{
worldIn.setBlockToAir(pos);
BlockPos blockpos;
for (blockpos = pos; worldIn.isAirBlock(blockpos) && BlockFalling.canFallThrough(worldIn.getBlockState(blockpos)) && blockpos.getY() > 0; blockpos = blockpos.down())
{
;
}
if (blockpos.getY() > 0)
{
worldIn.setBlockState(blockpos, this.getDefaultState(), 2);
}
}
}
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
this.teleport(worldIn, pos);
return true;
}
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn)
{
this.teleport(worldIn, pos);
}
private void teleport(World worldIn, BlockPos pos)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock() == this)
{
for (int i = 0; i < 1000; ++i)
{
BlockPos blockpos = pos.add(worldIn.rand.nextInt(16) - worldIn.rand.nextInt(16), worldIn.rand.nextInt(8) - worldIn.rand.nextInt(8), worldIn.rand.nextInt(16) - worldIn.rand.nextInt(16));
if (worldIn.isAirBlock(blockpos))
{
if (worldIn.isRemote)
{
for (int j = 0; j < 128; ++j)
{
double d0 = worldIn.rand.nextDouble();
float f = (worldIn.rand.nextFloat() - 0.5F) * 0.2F;
float f1 = (worldIn.rand.nextFloat() - 0.5F) * 0.2F;
float f2 = (worldIn.rand.nextFloat() - 0.5F) * 0.2F;
double d1 = (double)blockpos.getX() + (double)(pos.getX() - blockpos.getX()) * d0 + (worldIn.rand.nextDouble() - 0.5D) + 0.5D;
double d2 = (double)blockpos.getY() + (double)(pos.getY() - blockpos.getY()) * d0 + worldIn.rand.nextDouble() - 0.5D;
double d3 = (double)blockpos.getZ() + (double)(pos.getZ() - blockpos.getZ()) * d0 + (worldIn.rand.nextDouble() - 0.5D) + 0.5D;
worldIn.spawnParticle(EnumParticleTypes.PORTAL, d1, d2, d3, (double)f, (double)f1, (double)f2);
}
}
else
{
worldIn.setBlockState(blockpos, iblockstate, 2);
worldIn.setBlockToAir(pos);
}
return;
}
}
}
}
/**
* How many world ticks before ticking
*/
public int tickRate(World worldIn)
{
return 5;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return true;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,80 @@
package net.minecraft.block;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBehaviorDispenseItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityDispenser;
import net.minecraft.tileentity.TileEntityDropper;
import net.minecraft.tileentity.TileEntityHopper;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockDropper extends BlockDispenser
{
private final IBehaviorDispenseItem dropBehavior = new BehaviorDefaultDispenseItem();
protected IBehaviorDispenseItem getBehavior(ItemStack stack)
{
return this.dropBehavior;
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityDropper();
}
protected void dispense(World worldIn, BlockPos pos)
{
BlockSourceImpl blocksourceimpl = new BlockSourceImpl(worldIn, pos);
TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
if (tileentitydispenser != null)
{
int i = tileentitydispenser.getDispenseSlot();
if (i < 0)
{
worldIn.playEvent(1001, pos, 0);
}
else
{
ItemStack itemstack = tileentitydispenser.getStackInSlot(i);
if (!itemstack.isEmpty() && net.minecraftforge.items.VanillaInventoryCodeHooks.dropperInsertHook(worldIn, pos, tileentitydispenser, i, itemstack))
{
EnumFacing enumfacing = (EnumFacing)worldIn.getBlockState(pos).getValue(FACING);
BlockPos blockpos = pos.offset(enumfacing);
IInventory iinventory = TileEntityHopper.getInventoryAtPosition(worldIn, (double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
ItemStack itemstack1;
if (iinventory == null)
{
itemstack1 = this.dropBehavior.dispense(blocksourceimpl, itemstack);
}
else
{
itemstack1 = TileEntityHopper.putStackInInventoryAllSlots(tileentitydispenser, iinventory, itemstack.copy().splitStack(1), enumfacing.getOpposite());
if (itemstack1.isEmpty())
{
itemstack1 = itemstack.copy();
itemstack1.shrink(1);
}
else
{
itemstack1 = itemstack.copy();
}
}
tileentitydispenser.setInventorySlotContents(i, itemstack1);
}
}
}
}
}

View File

@@ -0,0 +1,315 @@
package net.minecraft.block;
import java.util.EnumSet;
import java.util.Random;
import java.util.Set;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockDynamicLiquid extends BlockLiquid
{
int adjacentSourceBlocks;
protected BlockDynamicLiquid(Material materialIn)
{
super(materialIn);
}
private void placeStaticBlock(World worldIn, BlockPos pos, IBlockState currentState)
{
worldIn.setBlockState(pos, getStaticBlock(this.blockMaterial).getDefaultState().withProperty(LEVEL, currentState.getValue(LEVEL)), 2);
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isAreaLoaded(pos, this.getSlopeFindDistance(worldIn))) return; // Forge: avoid loading unloaded chunks
int i = ((Integer)state.getValue(LEVEL)).intValue();
int j = 1;
if (this.blockMaterial == Material.LAVA && !worldIn.provider.doesWaterVaporize())
{
j = 2;
}
int k = this.tickRate(worldIn);
if (i > 0)
{
int l = -100;
this.adjacentSourceBlocks = 0;
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
l = this.checkAdjacentBlock(worldIn, pos.offset(enumfacing), l);
}
int i1 = l + j;
if (i1 >= 8 || l < 0)
{
i1 = -1;
}
int j1 = this.getDepth(worldIn.getBlockState(pos.up()));
if (j1 >= 0)
{
if (j1 >= 8)
{
i1 = j1;
}
else
{
i1 = j1 + 8;
}
}
if (this.adjacentSourceBlocks >= 2 && net.minecraftforge.event.ForgeEventFactory.canCreateFluidSource(worldIn, pos, state, this.blockMaterial == Material.WATER))
{
IBlockState iblockstate = worldIn.getBlockState(pos.down());
if (iblockstate.getMaterial().isSolid())
{
i1 = 0;
}
else if (iblockstate.getMaterial() == this.blockMaterial && ((Integer)iblockstate.getValue(LEVEL)).intValue() == 0)
{
i1 = 0;
}
}
if (this.blockMaterial == Material.LAVA && i < 8 && i1 < 8 && i1 > i && rand.nextInt(4) != 0)
{
k *= 4;
}
if (i1 == i)
{
this.placeStaticBlock(worldIn, pos, state);
}
else
{
i = i1;
if (i1 < 0)
{
worldIn.setBlockToAir(pos);
}
else
{
state = state.withProperty(LEVEL, Integer.valueOf(i1));
worldIn.setBlockState(pos, state, 2);
worldIn.scheduleUpdate(pos, this, k);
worldIn.notifyNeighborsOfStateChange(pos, this, false);
}
}
}
else
{
this.placeStaticBlock(worldIn, pos, state);
}
IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
if (this.canFlowInto(worldIn, pos.down(), iblockstate1))
{
if (this.blockMaterial == Material.LAVA && worldIn.getBlockState(pos.down()).getMaterial() == Material.WATER)
{
worldIn.setBlockState(pos.down(), net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(worldIn, pos.down(), pos, Blocks.STONE.getDefaultState()));
this.triggerMixEffects(worldIn, pos.down());
return;
}
if (i >= 8)
{
this.tryFlowInto(worldIn, pos.down(), iblockstate1, i);
}
else
{
this.tryFlowInto(worldIn, pos.down(), iblockstate1, i + 8);
}
}
else if (i >= 0 && (i == 0 || this.isBlocked(worldIn, pos.down(), iblockstate1)))
{
Set<EnumFacing> set = this.getPossibleFlowDirections(worldIn, pos);
int k1 = i + j;
if (i >= 8)
{
k1 = 1;
}
if (k1 >= 8)
{
return;
}
for (EnumFacing enumfacing1 : set)
{
this.tryFlowInto(worldIn, pos.offset(enumfacing1), worldIn.getBlockState(pos.offset(enumfacing1)), k1);
}
}
}
private void tryFlowInto(World worldIn, BlockPos pos, IBlockState state, int level)
{
if (this.canFlowInto(worldIn, pos, state))
{
if (state.getMaterial() != Material.AIR)
{
if (this.blockMaterial == Material.LAVA)
{
this.triggerMixEffects(worldIn, pos);
}
else
{
if (state.getBlock() != Blocks.SNOW_LAYER) //Forge: Vanilla has a 'bug' where snowballs don't drop like every other block. So special case because ewww...
state.getBlock().dropBlockAsItem(worldIn, pos, state, 0);
}
}
worldIn.setBlockState(pos, this.getDefaultState().withProperty(LEVEL, Integer.valueOf(level)), 3);
}
}
private int getSlopeDistance(World worldIn, BlockPos pos, int distance, EnumFacing calculateFlowCost)
{
int i = 1000;
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
if (enumfacing != calculateFlowCost)
{
BlockPos blockpos = pos.offset(enumfacing);
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (!this.isBlocked(worldIn, blockpos, iblockstate) && (iblockstate.getMaterial() != this.blockMaterial || ((Integer)iblockstate.getValue(LEVEL)).intValue() > 0))
{
if (!this.isBlocked(worldIn, blockpos.down(), worldIn.getBlockState(blockpos.down())))
{
return distance;
}
if (distance < this.getSlopeFindDistance(worldIn))
{
int j = this.getSlopeDistance(worldIn, blockpos, distance + 1, enumfacing.getOpposite());
if (j < i)
{
i = j;
}
}
}
}
}
return i;
}
private int getSlopeFindDistance(World worldIn)
{
return this.blockMaterial == Material.LAVA && !worldIn.provider.doesWaterVaporize() ? 2 : 4;
}
/**
* This method returns a Set of EnumFacing
*/
private Set<EnumFacing> getPossibleFlowDirections(World worldIn, BlockPos pos)
{
int i = 1000;
Set<EnumFacing> set = EnumSet.<EnumFacing>noneOf(EnumFacing.class);
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
BlockPos blockpos = pos.offset(enumfacing);
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (!this.isBlocked(worldIn, blockpos, iblockstate) && (iblockstate.getMaterial() != this.blockMaterial || ((Integer)iblockstate.getValue(LEVEL)).intValue() > 0))
{
int j;
if (this.isBlocked(worldIn, blockpos.down(), worldIn.getBlockState(blockpos.down())))
{
j = this.getSlopeDistance(worldIn, blockpos, 1, enumfacing.getOpposite());
}
else
{
j = 0;
}
if (j < i)
{
set.clear();
}
if (j <= i)
{
set.add(enumfacing);
i = j;
}
}
}
return set;
}
private boolean isBlocked(World worldIn, BlockPos pos, IBlockState state)
{
Block block = state.getBlock(); //Forge: state must be valid for position
Material mat = state.getMaterial();
if (!(block instanceof BlockDoor) && block != Blocks.STANDING_SIGN && block != Blocks.LADDER && block != Blocks.REEDS)
{
return mat != Material.PORTAL && mat != Material.STRUCTURE_VOID ? mat.blocksMovement() : true;
}
else
{
return true;
}
}
protected int checkAdjacentBlock(World worldIn, BlockPos pos, int currentMinLevel)
{
int i = this.getDepth(worldIn.getBlockState(pos));
if (i < 0)
{
return currentMinLevel;
}
else
{
if (i == 0)
{
++this.adjacentSourceBlocks;
}
if (i >= 8)
{
i = 0;
}
return currentMinLevel >= 0 && i >= currentMinLevel ? currentMinLevel : i;
}
}
private boolean canFlowInto(World worldIn, BlockPos pos, IBlockState state)
{
Material material = state.getMaterial();
return material != this.blockMaterial && material != Material.LAVA && !this.isBlocked(worldIn, pos, state);
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
if (!this.checkForMixing(worldIn, pos, state))
{
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
}
}
}

View File

@@ -0,0 +1,31 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
public class BlockEmptyDrops extends Block
{
public BlockEmptyDrops(Material materialIn)
{
super(materialIn);
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 0;
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.AIR;
}
}

View File

@@ -0,0 +1,160 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityEnchantmentTable;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockEnchantmentTable extends BlockContainer
{
protected static final AxisAlignedBB AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.75D, 1.0D);
protected BlockEnchantmentTable()
{
super(Material.ROCK, MapColor.RED);
this.setLightOpacity(0);
this.setCreativeTab(CreativeTabs.DECORATIONS);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return AABB;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
super.randomDisplayTick(stateIn, worldIn, pos, rand);
for (int i = -2; i <= 2; ++i)
{
for (int j = -2; j <= 2; ++j)
{
if (i > -2 && i < 2 && j == -1)
{
j = 2;
}
if (rand.nextInt(16) == 0)
{
for (int k = 0; k <= 1; ++k)
{
BlockPos blockpos = pos.add(i, k, j);
if (net.minecraftforge.common.ForgeHooks.getEnchantPower(worldIn, blockpos) > 0)
{
if (!worldIn.isAirBlock(pos.add(i / 2, 0, j / 2)))
{
break;
}
worldIn.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, (double)pos.getX() + 0.5D, (double)pos.getY() + 2.0D, (double)pos.getZ() + 0.5D, (double)((float)i + rand.nextFloat()) - 0.5D, (double)((float)k - rand.nextFloat() - 1.0F), (double)((float)j + rand.nextFloat()) - 0.5D);
}
}
}
}
}
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityEnchantmentTable();
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
else
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityEnchantmentTable)
{
playerIn.displayGui((TileEntityEnchantmentTable)tileentity);
}
return true;
}
}
/**
* Called by ItemBlocks after a block is set in the world, to allow post-place logic
*/
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
if (stack.hasDisplayName())
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityEnchantmentTable)
{
((TileEntityEnchantmentTable)tileentity).setCustomName(stack.getDisplayName());
}
}
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return face == EnumFacing.DOWN ? BlockFaceShape.SOLID : BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,134 @@
package net.minecraft.block;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityEndGateway;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockEndGateway extends BlockContainer
{
protected BlockEndGateway(Material p_i46687_1_)
{
super(p_i46687_1_);
this.setLightLevel(1.0F);
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityEndGateway();
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
Block block = iblockstate.getBlock();
return !iblockstate.isOpaqueCube() && block != Blocks.END_GATEWAY;
}
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
return NULL_AABB;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 0;
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityEndGateway)
{
int i = ((TileEntityEndGateway)tileentity).getParticleAmount();
for (int j = 0; j < i; ++j)
{
double d0 = (double)((float)pos.getX() + rand.nextFloat());
double d1 = (double)((float)pos.getY() + rand.nextFloat());
double d2 = (double)((float)pos.getZ() + rand.nextFloat());
double d3 = ((double)rand.nextFloat() - 0.5D) * 0.5D;
double d4 = ((double)rand.nextFloat() - 0.5D) * 0.5D;
double d5 = ((double)rand.nextFloat() - 0.5D) * 0.5D;
int k = rand.nextInt(2) * 2 - 1;
if (rand.nextBoolean())
{
d2 = (double)pos.getZ() + 0.5D + 0.25D * (double)k;
d5 = (double)(rand.nextFloat() * 2.0F * (float)k);
}
else
{
d0 = (double)pos.getX() + 0.5D + 0.25D * (double)k;
d3 = (double)(rand.nextFloat() * 2.0F * (float)k);
}
worldIn.spawnParticle(EnumParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5);
}
}
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return ItemStack.EMPTY;
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.BLACK;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,126 @@
package net.minecraft.block;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityEndPortal;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockEndPortal extends BlockContainer
{
protected static final AxisAlignedBB END_PORTAL_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.75D, 1.0D);
protected BlockEndPortal(Material materialIn)
{
super(materialIn);
this.setLightLevel(1.0F);
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityEndPortal();
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return END_PORTAL_AABB;
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return side == EnumFacing.DOWN ? super.shouldSideBeRendered(blockState, blockAccess, pos, side) : false;
}
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState)
{
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 0;
}
/**
* Called When an Entity Collided with the Block
*/
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
if (!worldIn.isRemote && !entityIn.isRiding() && !entityIn.isBeingRidden() && entityIn.isNonBoss() && entityIn.getEntityBoundingBox().intersects(state.getBoundingBox(worldIn, pos).offset(pos)))
{
entityIn.changeDimension(1);
}
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
double d0 = (double)((float)pos.getX() + rand.nextFloat());
double d1 = (double)((float)pos.getY() + 0.8F);
double d2 = (double)((float)pos.getZ() + rand.nextFloat());
double d3 = 0.0D;
double d4 = 0.0D;
double d5 = 0.0D;
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return ItemStack.EMPTY;
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.BLACK;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,171 @@
package net.minecraft.block;
import com.google.common.base.Predicates;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.BlockWorldState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.state.pattern.BlockPattern;
import net.minecraft.block.state.pattern.BlockStateMatcher;
import net.minecraft.block.state.pattern.FactoryBlockPattern;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockEndPortalFrame extends Block
{
public static final PropertyDirection FACING = BlockHorizontal.FACING;
public static final PropertyBool EYE = PropertyBool.create("eye");
protected static final AxisAlignedBB AABB_BLOCK = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.8125D, 1.0D);
protected static final AxisAlignedBB AABB_EYE = new AxisAlignedBB(0.3125D, 0.8125D, 0.3125D, 0.6875D, 1.0D, 0.6875D);
private static BlockPattern portalShape;
public BlockEndPortalFrame()
{
super(Material.ROCK, MapColor.GREEN);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(EYE, Boolean.valueOf(false)));
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return AABB_BLOCK;
}
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_BLOCK);
if (((Boolean)worldIn.getBlockState(pos).getValue(EYE)).booleanValue())
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_EYE);
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.AIR;
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()).withProperty(EYE, Boolean.valueOf(false));
}
public boolean hasComparatorInputOverride(IBlockState state)
{
return true;
}
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
{
return ((Boolean)blockState.getValue(EYE)).booleanValue() ? 15 : 0;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(EYE, Boolean.valueOf((meta & 4) != 0)).withProperty(FACING, EnumFacing.getHorizontal(meta & 3));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
if (((Boolean)state.getValue(EYE)).booleanValue())
{
i |= 4;
}
return i;
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING, EYE});
}
public boolean isFullCube(IBlockState state)
{
return false;
}
public static BlockPattern getOrCreatePortalShape()
{
if (portalShape == null)
{
portalShape = FactoryBlockPattern.start().aisle("?vvv?", ">???<", ">???<", ">???<", "?^^^?").where('?', BlockWorldState.hasState(BlockStateMatcher.ANY)).where('^', BlockWorldState.hasState(BlockStateMatcher.forBlock(Blocks.END_PORTAL_FRAME).where(EYE, Predicates.equalTo(Boolean.valueOf(true))).where(FACING, Predicates.equalTo(EnumFacing.SOUTH)))).where('>', BlockWorldState.hasState(BlockStateMatcher.forBlock(Blocks.END_PORTAL_FRAME).where(EYE, Predicates.equalTo(Boolean.valueOf(true))).where(FACING, Predicates.equalTo(EnumFacing.WEST)))).where('v', BlockWorldState.hasState(BlockStateMatcher.forBlock(Blocks.END_PORTAL_FRAME).where(EYE, Predicates.equalTo(Boolean.valueOf(true))).where(FACING, Predicates.equalTo(EnumFacing.NORTH)))).where('<', BlockWorldState.hasState(BlockStateMatcher.forBlock(Blocks.END_PORTAL_FRAME).where(EYE, Predicates.equalTo(Boolean.valueOf(true))).where(FACING, Predicates.equalTo(EnumFacing.EAST)))).build();
}
return portalShape;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return face == EnumFacing.DOWN ? BlockFaceShape.SOLID : BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,174 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockEndRod extends BlockDirectional
{
protected static final AxisAlignedBB END_ROD_VERTICAL_AABB = new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D);
protected static final AxisAlignedBB END_ROD_NS_AABB = new AxisAlignedBB(0.375D, 0.375D, 0.0D, 0.625D, 0.625D, 1.0D);
protected static final AxisAlignedBB END_ROD_EW_AABB = new AxisAlignedBB(0.0D, 0.375D, 0.375D, 1.0D, 0.625D, 0.625D);
protected BlockEndRod()
{
super(Material.CIRCUITS);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.UP));
this.setCreativeTab(CreativeTabs.DECORATIONS);
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withProperty(FACING, mirrorIn.mirror((EnumFacing)state.getValue(FACING)));
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
switch (((EnumFacing)state.getValue(FACING)).getAxis())
{
case X:
default:
return END_ROD_EW_AABB;
case Z:
return END_ROD_NS_AABB;
case Y:
return END_ROD_VERTICAL_AABB;
}
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return true;
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
IBlockState iblockstate = worldIn.getBlockState(pos.offset(facing.getOpposite()));
if (iblockstate.getBlock() == Blocks.END_ROD)
{
EnumFacing enumfacing = (EnumFacing)iblockstate.getValue(FACING);
if (enumfacing == facing)
{
return this.getDefaultState().withProperty(FACING, facing.getOpposite());
}
}
return this.getDefaultState().withProperty(FACING, facing);
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
EnumFacing enumfacing = (EnumFacing)stateIn.getValue(FACING);
double d0 = (double)pos.getX() + 0.55D - (double)(rand.nextFloat() * 0.1F);
double d1 = (double)pos.getY() + 0.55D - (double)(rand.nextFloat() * 0.1F);
double d2 = (double)pos.getZ() + 0.55D - (double)(rand.nextFloat() * 0.1F);
double d3 = (double)(0.4F - (rand.nextFloat() + rand.nextFloat()) * 0.4F);
if (rand.nextInt(5) == 0)
{
worldIn.spawnParticle(EnumParticleTypes.END_ROD, d0 + (double)enumfacing.getFrontOffsetX() * d3, d1 + (double)enumfacing.getFrontOffsetY() * d3, d2 + (double)enumfacing.getFrontOffsetZ() * d3, rand.nextGaussian() * 0.005D, rand.nextGaussian() * 0.005D, rand.nextGaussian() * 0.005D);
}
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
IBlockState iblockstate = this.getDefaultState();
iblockstate = iblockstate.withProperty(FACING, EnumFacing.getFront(meta));
return iblockstate;
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((EnumFacing)state.getValue(FACING)).getIndex();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING});
}
public EnumPushReaction getMobilityFlag(IBlockState state)
{
return EnumPushReaction.NORMAL;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,232 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.InventoryEnderChest;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityEnderChest;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockEnderChest extends BlockContainer
{
public static final PropertyDirection FACING = BlockHorizontal.FACING;
protected static final AxisAlignedBB ENDER_CHEST_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.875D, 0.9375D);
protected BlockEnderChest()
{
super(Material.ROCK);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
this.setCreativeTab(CreativeTabs.DECORATIONS);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return ENDER_CHEST_AABB;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
@SideOnly(Side.CLIENT)
public boolean hasCustomBreakingProgress(IBlockState state)
{
return true;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(Blocks.OBSIDIAN);
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 8;
}
protected boolean canSilkHarvest()
{
return true;
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}
/**
* Called by ItemBlocks after a block is set in the world, to allow post-place logic
*/
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
InventoryEnderChest inventoryenderchest = playerIn.getInventoryEnderChest();
TileEntity tileentity = worldIn.getTileEntity(pos);
if (inventoryenderchest != null && tileentity instanceof TileEntityEnderChest)
{
if (worldIn.getBlockState(pos.up()).doesSideBlockChestOpening(worldIn, pos.up(), EnumFacing.DOWN))
{
return true;
}
else if (worldIn.isRemote)
{
return true;
}
else
{
inventoryenderchest.setChestTileEntity((TileEntityEnderChest)tileentity);
playerIn.displayGUIChest(inventoryenderchest);
playerIn.addStat(StatList.ENDERCHEST_OPENED);
return true;
}
}
else
{
return true;
}
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityEnderChest();
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
for (int i = 0; i < 3; ++i)
{
int j = rand.nextInt(2) * 2 - 1;
int k = rand.nextInt(2) * 2 - 1;
double d0 = (double)pos.getX() + 0.5D + 0.25D * (double)j;
double d1 = (double)((float)pos.getY() + rand.nextFloat());
double d2 = (double)pos.getZ() + 0.5D + 0.25D * (double)k;
double d3 = (double)(rand.nextFloat() * (float)j);
double d4 = ((double)rand.nextFloat() - 0.5D) * 0.125D;
double d5 = (double)(rand.nextFloat() * (float)k);
worldIn.spawnParticle(EnumParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5);
}
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
EnumFacing enumfacing = EnumFacing.getFront(meta);
if (enumfacing.getAxis() == EnumFacing.Axis.Y)
{
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(FACING, enumfacing);
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((EnumFacing)state.getValue(FACING)).getIndex();
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING});
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,61 @@
package net.minecraft.block;
import net.minecraft.util.math.BlockPos;
public class BlockEventData
{
private final BlockPos position;
private final Block blockType;
/** Different for each blockID */
private final int eventID;
private final int eventParameter;
public BlockEventData(BlockPos pos, Block blockType, int eventId, int p_i45756_4_)
{
this.position = pos;
this.eventID = eventId;
this.eventParameter = p_i45756_4_;
this.blockType = blockType;
}
public BlockPos getPosition()
{
return this.position;
}
/**
* Get the Event ID (different for each BlockID)
*/
public int getEventID()
{
return this.eventID;
}
public int getEventParameter()
{
return this.eventParameter;
}
public Block getBlock()
{
return this.blockType;
}
public boolean equals(Object p_equals_1_)
{
if (!(p_equals_1_ instanceof BlockEventData))
{
return false;
}
else
{
BlockEventData blockeventdata = (BlockEventData)p_equals_1_;
return this.position.equals(blockeventdata.position) && this.eventID == blockeventdata.eventID && this.eventParameter == blockeventdata.eventParameter && this.blockType == blockeventdata.blockType;
}
}
public String toString()
{
return "TE(" + this.position + ")," + this.eventID + "," + this.eventParameter + "," + this.blockType;
}
}

View File

@@ -0,0 +1,139 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockFalling extends Block
{
public static boolean fallInstantly;
public BlockFalling()
{
super(Material.SAND);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
public BlockFalling(Material materialIn)
{
super(materialIn);
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isRemote)
{
this.checkFallable(worldIn, pos);
}
}
private void checkFallable(World worldIn, BlockPos pos)
{
if ((worldIn.isAirBlock(pos.down()) || canFallThrough(worldIn.getBlockState(pos.down()))) && pos.getY() >= 0)
{
int i = 32;
if (!fallInstantly && worldIn.isAreaLoaded(pos.add(-32, -32, -32), pos.add(32, 32, 32)))
{
if (!worldIn.isRemote)
{
EntityFallingBlock entityfallingblock = new EntityFallingBlock(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D, worldIn.getBlockState(pos));
this.onStartFalling(entityfallingblock);
worldIn.spawnEntity(entityfallingblock);
}
}
else
{
IBlockState state = worldIn.getBlockState(pos);
worldIn.setBlockToAir(pos);
BlockPos blockpos;
for (blockpos = pos.down(); (worldIn.isAirBlock(blockpos) || canFallThrough(worldIn.getBlockState(blockpos))) && blockpos.getY() > 0; blockpos = blockpos.down())
{
;
}
if (blockpos.getY() > 0)
{
worldIn.setBlockState(blockpos.up(), state); //Forge: Fix loss of state information during world gen.
}
}
}
}
protected void onStartFalling(EntityFallingBlock fallingEntity)
{
}
/**
* How many world ticks before ticking
*/
public int tickRate(World worldIn)
{
return 2;
}
public static boolean canFallThrough(IBlockState state)
{
Block block = state.getBlock();
Material material = state.getMaterial();
return block == Blocks.FIRE || material == Material.AIR || material == Material.WATER || material == Material.LAVA;
}
public void onEndFalling(World worldIn, BlockPos pos, IBlockState p_176502_3_, IBlockState p_176502_4_)
{
}
public void onBroken(World worldIn, BlockPos pos)
{
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
if (rand.nextInt(16) == 0)
{
BlockPos blockpos = pos.down();
if (canFallThrough(worldIn.getBlockState(blockpos)))
{
double d0 = (double)((float)pos.getX() + rand.nextFloat());
double d1 = (double)pos.getY() - 0.05D;
double d2 = (double)((float)pos.getZ() + rand.nextFloat());
worldIn.spawnParticle(EnumParticleTypes.FALLING_DUST, d0, d1, d2, 0.0D, 0.0D, 0.0D, Block.getStateId(stateIn));
}
}
}
@SideOnly(Side.CLIENT)
public int getDustColor(IBlockState state)
{
return -16777216;
}
}

View File

@@ -0,0 +1,209 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockFarmland extends Block
{
public static final PropertyInteger MOISTURE = PropertyInteger.create("moisture", 0, 7);
protected static final AxisAlignedBB FARMLAND_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.9375D, 1.0D);
protected static final AxisAlignedBB field_194405_c = new AxisAlignedBB(0.0D, 0.9375D, 0.0D, 1.0D, 1.0D, 1.0D);
protected BlockFarmland()
{
super(Material.GROUND);
this.setDefaultState(this.blockState.getBaseState().withProperty(MOISTURE, Integer.valueOf(0)));
this.setTickRandomly(true);
this.setLightOpacity(255);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return FARMLAND_AABB;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
int i = ((Integer)state.getValue(MOISTURE)).intValue();
if (!this.hasWater(worldIn, pos) && !worldIn.isRainingAt(pos.up()))
{
if (i > 0)
{
worldIn.setBlockState(pos, state.withProperty(MOISTURE, Integer.valueOf(i - 1)), 2);
}
else if (!this.hasCrops(worldIn, pos))
{
turnToDirt(worldIn, pos);
}
}
else if (i < 7)
{
worldIn.setBlockState(pos, state.withProperty(MOISTURE, Integer.valueOf(7)), 2);
}
}
/**
* Block's chance to react to a living entity falling on it.
*/
public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance)
{
if (net.minecraftforge.common.ForgeHooks.onFarmlandTrample(worldIn, pos, Blocks.DIRT.getDefaultState(), fallDistance, entityIn)) // Forge: Move logic to Entity#canTrample
{
turnToDirt(worldIn, pos);
}
super.onFallenUpon(worldIn, pos, entityIn, fallDistance);
}
protected static void turnToDirt(World p_190970_0_, BlockPos worldIn)
{
p_190970_0_.setBlockState(worldIn, Blocks.DIRT.getDefaultState());
AxisAlignedBB axisalignedbb = field_194405_c.offset(worldIn);
for (Entity entity : p_190970_0_.getEntitiesWithinAABBExcludingEntity((Entity)null, axisalignedbb))
{
double d0 = Math.min(axisalignedbb.maxY - axisalignedbb.minY, axisalignedbb.maxY - entity.getEntityBoundingBox().minY);
entity.setPositionAndUpdate(entity.posX, entity.posY + d0 + 0.001D, entity.posZ);
}
}
private boolean hasCrops(World worldIn, BlockPos pos)
{
Block block = worldIn.getBlockState(pos.up()).getBlock();
return block instanceof net.minecraftforge.common.IPlantable && canSustainPlant(worldIn.getBlockState(pos), worldIn, pos, net.minecraft.util.EnumFacing.UP, (net.minecraftforge.common.IPlantable)block);
}
private boolean hasWater(World worldIn, BlockPos pos)
{
for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(pos.add(-4, 0, -4), pos.add(4, 1, 4)))
{
if (worldIn.getBlockState(blockpos$mutableblockpos).getMaterial() == Material.WATER)
{
return true;
}
}
return false;
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
if (worldIn.getBlockState(pos.up()).getMaterial().isSolid())
{
turnToDirt(worldIn, pos);
}
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
super.onBlockAdded(worldIn, pos, state);
if (worldIn.getBlockState(pos.up()).getMaterial().isSolid())
{
turnToDirt(worldIn, pos);
}
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
switch (side)
{
case UP:
return true;
case NORTH:
case SOUTH:
case WEST:
case EAST:
IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
Block block = iblockstate.getBlock();
return !iblockstate.isOpaqueCube() && block != Blocks.FARMLAND && block != Blocks.GRASS_PATH;
default:
return super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Blocks.DIRT.getItemDropped(Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT), rand, fortune);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(MOISTURE, Integer.valueOf(meta & 7));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(MOISTURE)).intValue();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {MOISTURE});
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return face == EnumFacing.DOWN ? BlockFaceShape.SOLID : BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,268 @@
package net.minecraft.block;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemLead;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockFence extends Block
{
/** Whether this fence connects in the northern direction */
public static final PropertyBool NORTH = PropertyBool.create("north");
/** Whether this fence connects in the eastern direction */
public static final PropertyBool EAST = PropertyBool.create("east");
/** Whether this fence connects in the southern direction */
public static final PropertyBool SOUTH = PropertyBool.create("south");
/** Whether this fence connects in the western direction */
public static final PropertyBool WEST = PropertyBool.create("west");
protected static final AxisAlignedBB[] BOUNDING_BOXES = new AxisAlignedBB[] {new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D), new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D), new AxisAlignedBB(0.0D, 0.0D, 0.375D, 0.625D, 1.0D, 1.0D), new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 0.625D), new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.625D, 1.0D, 0.625D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D), new AxisAlignedBB(0.375D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D), new AxisAlignedBB(0.375D, 0.0D, 0.375D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D), new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.375D, 0.0D, 0.0D, 1.0D, 1.0D, 0.625D), new AxisAlignedBB(0.375D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.625D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D)};
public static final AxisAlignedBB PILLAR_AABB = new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.5D, 0.625D);
public static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.375D, 0.0D, 0.625D, 0.625D, 1.5D, 1.0D);
public static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 0.375D, 1.5D, 0.625D);
public static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.5D, 0.375D);
public static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.625D, 0.0D, 0.375D, 1.0D, 1.5D, 0.625D);
public BlockFence(Material materialIn, MapColor mapColorIn)
{
super(materialIn, mapColorIn);
this.setDefaultState(this.blockState.getBaseState().withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false)));
this.setCreativeTab(CreativeTabs.DECORATIONS);
}
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState)
{
if (!isActualState)
{
state = state.getActualState(worldIn, pos);
}
addCollisionBoxToList(pos, entityBox, collidingBoxes, PILLAR_AABB);
if (((Boolean)state.getValue(NORTH)).booleanValue())
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, NORTH_AABB);
}
if (((Boolean)state.getValue(EAST)).booleanValue())
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, EAST_AABB);
}
if (((Boolean)state.getValue(SOUTH)).booleanValue())
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, SOUTH_AABB);
}
if (((Boolean)state.getValue(WEST)).booleanValue())
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, WEST_AABB);
}
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
state = this.getActualState(state, source, pos);
return BOUNDING_BOXES[getBoundingBoxIdx(state)];
}
/**
* Returns the correct index into boundingBoxes, based on what the fence is connected to.
*/
private static int getBoundingBoxIdx(IBlockState state)
{
int i = 0;
if (((Boolean)state.getValue(NORTH)).booleanValue())
{
i |= 1 << EnumFacing.NORTH.getHorizontalIndex();
}
if (((Boolean)state.getValue(EAST)).booleanValue())
{
i |= 1 << EnumFacing.EAST.getHorizontalIndex();
}
if (((Boolean)state.getValue(SOUTH)).booleanValue())
{
i |= 1 << EnumFacing.SOUTH.getHorizontalIndex();
}
if (((Boolean)state.getValue(WEST)).booleanValue())
{
i |= 1 << EnumFacing.WEST.getHorizontalIndex();
}
return i;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Determines if an entity can path through this block
*/
public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
{
return false;
}
public boolean canConnectTo(IBlockAccess worldIn, BlockPos pos, EnumFacing facing)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
BlockFaceShape blockfaceshape = iblockstate.getBlockFaceShape(worldIn, pos, facing);
Block block = iblockstate.getBlock();
boolean flag = blockfaceshape == BlockFaceShape.MIDDLE_POLE && (iblockstate.getMaterial() == this.blockMaterial || block instanceof BlockFenceGate);
return !isExcepBlockForAttachWithPiston(block) && blockfaceshape == BlockFaceShape.SOLID || flag;
}
protected static boolean isExcepBlockForAttachWithPiston(Block p_194142_0_)
{
return Block.isExceptBlockForAttachWithPiston(p_194142_0_) || p_194142_0_ == Blocks.BARRIER || p_194142_0_ == Blocks.MELON_BLOCK || p_194142_0_ == Blocks.PUMPKIN || p_194142_0_ == Blocks.LIT_PUMPKIN;
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return true;
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (!worldIn.isRemote)
{
return ItemLead.attachToFence(playerIn, worldIn, pos);
}
else
{
ItemStack itemstack = playerIn.getHeldItem(hand);
return itemstack.getItem() == Items.LEAD || itemstack.isEmpty();
}
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return 0;
}
/**
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
* metadata, such as fence connections.
*/
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return state.withProperty(NORTH, canFenceConnectTo(worldIn, pos, EnumFacing.NORTH))
.withProperty(EAST, canFenceConnectTo(worldIn, pos, EnumFacing.EAST))
.withProperty(SOUTH, canFenceConnectTo(worldIn, pos, EnumFacing.SOUTH))
.withProperty(WEST, canFenceConnectTo(worldIn, pos, EnumFacing.WEST));
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
switch (rot)
{
case CLOCKWISE_180:
return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(EAST, state.getValue(WEST)).withProperty(SOUTH, state.getValue(NORTH)).withProperty(WEST, state.getValue(EAST));
case COUNTERCLOCKWISE_90:
return state.withProperty(NORTH, state.getValue(EAST)).withProperty(EAST, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(WEST)).withProperty(WEST, state.getValue(NORTH));
case CLOCKWISE_90:
return state.withProperty(NORTH, state.getValue(WEST)).withProperty(EAST, state.getValue(NORTH)).withProperty(SOUTH, state.getValue(EAST)).withProperty(WEST, state.getValue(SOUTH));
default:
return state;
}
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
switch (mirrorIn)
{
case LEFT_RIGHT:
return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(NORTH));
case FRONT_BACK:
return state.withProperty(EAST, state.getValue(WEST)).withProperty(WEST, state.getValue(EAST));
default:
return super.withMirror(state, mirrorIn);
}
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {NORTH, EAST, WEST, SOUTH});
}
/* ======================================== FORGE START ======================================== */
@Override
public boolean canBeConnectedTo(IBlockAccess world, BlockPos pos, EnumFacing facing)
{
return canConnectTo(world, pos.offset(facing), facing.getOpposite());
}
private boolean canFenceConnectTo(IBlockAccess world, BlockPos pos, EnumFacing facing)
{
BlockPos other = pos.offset(facing);
Block block = world.getBlockState(other).getBlock();
return block.canBeConnectedTo(world, other, facing.getOpposite()) || canConnectTo(world, other, facing.getOpposite());
}
/* ======================================== FORGE END ======================================== */
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return face != EnumFacing.UP && face != EnumFacing.DOWN ? BlockFaceShape.MIDDLE_POLE : BlockFaceShape.CENTER;
}
}

View File

@@ -0,0 +1,271 @@
package net.minecraft.block;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockFenceGate extends BlockHorizontal
{
public static final PropertyBool OPEN = PropertyBool.create("open");
public static final PropertyBool POWERED = PropertyBool.create("powered");
public static final PropertyBool IN_WALL = PropertyBool.create("in_wall");
protected static final AxisAlignedBB AABB_HITBOX_ZAXIS = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D);
protected static final AxisAlignedBB AABB_HITBOX_XAXIS = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D);
protected static final AxisAlignedBB AABB_HITBOX_ZAXIS_INWALL = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 0.8125D, 0.625D);
protected static final AxisAlignedBB AABB_HITBOX_XAXIS_INWALL = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 0.8125D, 1.0D);
protected static final AxisAlignedBB AABB_COLLISION_BOX_ZAXIS = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.5D, 0.625D);
protected static final AxisAlignedBB AABB_COLLISION_BOX_XAXIS = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.5D, 1.0D);
public BlockFenceGate(BlockPlanks.EnumType p_i46394_1_)
{
super(Material.WOOD, p_i46394_1_.getMapColor());
this.setDefaultState(this.blockState.getBaseState().withProperty(OPEN, Boolean.valueOf(false)).withProperty(POWERED, Boolean.valueOf(false)).withProperty(IN_WALL, Boolean.valueOf(false)));
this.setCreativeTab(CreativeTabs.REDSTONE);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
state = this.getActualState(state, source, pos);
if (((Boolean)state.getValue(IN_WALL)).booleanValue())
{
return ((EnumFacing)state.getValue(FACING)).getAxis() == EnumFacing.Axis.X ? AABB_HITBOX_XAXIS_INWALL : AABB_HITBOX_ZAXIS_INWALL;
}
else
{
return ((EnumFacing)state.getValue(FACING)).getAxis() == EnumFacing.Axis.X ? AABB_HITBOX_XAXIS : AABB_HITBOX_ZAXIS;
}
}
/**
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
* metadata, such as fence connections.
*/
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
EnumFacing.Axis enumfacing$axis = ((EnumFacing)state.getValue(FACING)).getAxis();
if (enumfacing$axis == EnumFacing.Axis.Z && (worldIn.getBlockState(pos.west()).getBlock() instanceof BlockWall || worldIn.getBlockState(pos.east()).getBlock() instanceof BlockWall) || enumfacing$axis == EnumFacing.Axis.X && (worldIn.getBlockState(pos.north()).getBlock() instanceof BlockWall || worldIn.getBlockState(pos.south()).getBlock() instanceof BlockWall))
{
state = state.withProperty(IN_WALL, Boolean.valueOf(true));
}
return state;
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return worldIn.getBlockState(pos.down()).getMaterial().isSolid() ? super.canPlaceBlockAt(worldIn, pos) : false;
}
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
if (((Boolean)blockState.getValue(OPEN)).booleanValue())
{
return NULL_AABB;
}
else
{
return ((EnumFacing)blockState.getValue(FACING)).getAxis() == EnumFacing.Axis.Z ? AABB_COLLISION_BOX_ZAXIS : AABB_COLLISION_BOX_XAXIS;
}
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Determines if an entity can path through this block
*/
public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
{
return ((Boolean)worldIn.getBlockState(pos).getValue(OPEN)).booleanValue();
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
boolean flag = worldIn.isBlockPowered(pos);
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing()).withProperty(OPEN, Boolean.valueOf(flag)).withProperty(POWERED, Boolean.valueOf(flag)).withProperty(IN_WALL, Boolean.valueOf(false));
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (((Boolean)state.getValue(OPEN)).booleanValue())
{
state = state.withProperty(OPEN, Boolean.valueOf(false));
worldIn.setBlockState(pos, state, 10);
}
else
{
EnumFacing enumfacing = EnumFacing.fromAngle((double)playerIn.rotationYaw);
if (state.getValue(FACING) == enumfacing.getOpposite())
{
state = state.withProperty(FACING, enumfacing);
}
state = state.withProperty(OPEN, Boolean.valueOf(true));
worldIn.setBlockState(pos, state, 10);
}
worldIn.playEvent(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? 1008 : 1014, pos, 0);
return true;
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (!worldIn.isRemote)
{
boolean flag = worldIn.isBlockPowered(pos);
if (((Boolean)state.getValue(POWERED)).booleanValue() != flag)
{
worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(flag)).withProperty(OPEN, Boolean.valueOf(flag)), 2);
if (((Boolean)state.getValue(OPEN)).booleanValue() != flag)
{
worldIn.playEvent((EntityPlayer)null, flag ? 1008 : 1014, pos, 0);
}
}
}
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return true;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)).withProperty(OPEN, Boolean.valueOf((meta & 4) != 0)).withProperty(POWERED, Boolean.valueOf((meta & 8) != 0));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
if (((Boolean)state.getValue(POWERED)).booleanValue())
{
i |= 8;
}
if (((Boolean)state.getValue(OPEN)).booleanValue())
{
i |= 4;
}
return i;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING, OPEN, POWERED, IN_WALL});
}
/* ======================================== FORGE START ======================================== */
@Override
public boolean canBeConnectedTo(IBlockAccess world, BlockPos pos, EnumFacing facing)
{
IBlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof BlockFenceGate &&
state.getBlockFaceShape(world, pos, facing) == BlockFaceShape.MIDDLE_POLE)
{
Block connector = world.getBlockState(pos.offset(facing)).getBlock();
return connector instanceof BlockFence || connector instanceof BlockWall;
}
return false;
}
/* ======================================== FORGE END ======================================== */
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
if (face != EnumFacing.UP && face != EnumFacing.DOWN)
{
return ((EnumFacing)state.getValue(FACING)).getAxis() == face.rotateY().getAxis() ? BlockFaceShape.MIDDLE_POLE : BlockFaceShape.UNDEFINED;
}
else
{
return BlockFaceShape.UNDEFINED;
}
}
}

View File

@@ -0,0 +1,547 @@
package net.minecraft.block;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldProviderEnd;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockFire extends Block
{
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 15);
public static final PropertyBool NORTH = PropertyBool.create("north");
public static final PropertyBool EAST = PropertyBool.create("east");
public static final PropertyBool SOUTH = PropertyBool.create("south");
public static final PropertyBool WEST = PropertyBool.create("west");
public static final PropertyBool UPPER = PropertyBool.create("up");
private final Map<Block, Integer> encouragements = Maps.<Block, Integer>newIdentityHashMap();
private final Map<Block, Integer> flammabilities = Maps.<Block, Integer>newIdentityHashMap();
/**
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
* metadata, such as fence connections.
*/
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP) && !Blocks.FIRE.canCatchFire(worldIn, pos.down(), EnumFacing.UP))
{
return state.withProperty(NORTH, this.canCatchFire(worldIn, pos.north(), EnumFacing.SOUTH))
.withProperty(EAST, this.canCatchFire(worldIn, pos.east(), EnumFacing.WEST))
.withProperty(SOUTH, this.canCatchFire(worldIn, pos.south(), EnumFacing.NORTH))
.withProperty(WEST, this.canCatchFire(worldIn, pos.west(), EnumFacing.EAST))
.withProperty(UPPER, this.canCatchFire(worldIn, pos.up(), EnumFacing.DOWN));
}
return this.getDefaultState();
}
protected BlockFire()
{
super(Material.FIRE);
this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0)).withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false)).withProperty(UPPER, Boolean.valueOf(false)));
this.setTickRandomly(true);
}
public static void init()
{
Blocks.FIRE.setFireInfo(Blocks.PLANKS, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.DOUBLE_WOODEN_SLAB, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.WOODEN_SLAB, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.OAK_FENCE_GATE, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.SPRUCE_FENCE_GATE, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.BIRCH_FENCE_GATE, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.JUNGLE_FENCE_GATE, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.DARK_OAK_FENCE_GATE, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.ACACIA_FENCE_GATE, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.OAK_FENCE, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.SPRUCE_FENCE, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.BIRCH_FENCE, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.JUNGLE_FENCE, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.DARK_OAK_FENCE, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.ACACIA_FENCE, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.OAK_STAIRS, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.BIRCH_STAIRS, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.SPRUCE_STAIRS, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.JUNGLE_STAIRS, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.ACACIA_STAIRS, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.DARK_OAK_STAIRS, 5, 20);
Blocks.FIRE.setFireInfo(Blocks.LOG, 5, 5);
Blocks.FIRE.setFireInfo(Blocks.LOG2, 5, 5);
Blocks.FIRE.setFireInfo(Blocks.LEAVES, 30, 60);
Blocks.FIRE.setFireInfo(Blocks.LEAVES2, 30, 60);
Blocks.FIRE.setFireInfo(Blocks.BOOKSHELF, 30, 20);
Blocks.FIRE.setFireInfo(Blocks.TNT, 15, 100);
Blocks.FIRE.setFireInfo(Blocks.TALLGRASS, 60, 100);
Blocks.FIRE.setFireInfo(Blocks.DOUBLE_PLANT, 60, 100);
Blocks.FIRE.setFireInfo(Blocks.YELLOW_FLOWER, 60, 100);
Blocks.FIRE.setFireInfo(Blocks.RED_FLOWER, 60, 100);
Blocks.FIRE.setFireInfo(Blocks.DEADBUSH, 60, 100);
Blocks.FIRE.setFireInfo(Blocks.WOOL, 30, 60);
Blocks.FIRE.setFireInfo(Blocks.VINE, 15, 100);
Blocks.FIRE.setFireInfo(Blocks.COAL_BLOCK, 5, 5);
Blocks.FIRE.setFireInfo(Blocks.HAY_BLOCK, 60, 20);
Blocks.FIRE.setFireInfo(Blocks.CARPET, 60, 20);
}
public void setFireInfo(Block blockIn, int encouragement, int flammability)
{
if (blockIn == Blocks.AIR) throw new IllegalArgumentException("Tried to set air on fire... This is bad.");
this.encouragements.put(blockIn, Integer.valueOf(encouragement));
this.flammabilities.put(blockIn, Integer.valueOf(flammability));
}
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
return NULL_AABB;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 0;
}
/**
* How many world ticks before ticking
*/
public int tickRate(World worldIn)
{
return 30;
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (worldIn.getGameRules().getBoolean("doFireTick"))
{
if (!worldIn.isAreaLoaded(pos, 2)) return; // Forge: prevent loading unloaded chunks when spreading fire
if (!this.canPlaceBlockAt(worldIn, pos))
{
worldIn.setBlockToAir(pos);
}
Block block = worldIn.getBlockState(pos.down()).getBlock();
boolean flag = block.isFireSource(worldIn, pos.down(), EnumFacing.UP);
int i = ((Integer)state.getValue(AGE)).intValue();
if (!flag && worldIn.isRaining() && this.canDie(worldIn, pos) && rand.nextFloat() < 0.2F + (float)i * 0.03F)
{
worldIn.setBlockToAir(pos);
}
else
{
if (i < 15)
{
state = state.withProperty(AGE, Integer.valueOf(i + rand.nextInt(3) / 2));
worldIn.setBlockState(pos, state, 4);
}
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn) + rand.nextInt(10));
if (!flag)
{
if (!this.canNeighborCatchFire(worldIn, pos))
{
if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP) || i > 3)
{
worldIn.setBlockToAir(pos);
}
return;
}
if (!this.canCatchFire(worldIn, pos.down(), EnumFacing.UP) && i == 15 && rand.nextInt(4) == 0)
{
worldIn.setBlockToAir(pos);
return;
}
}
boolean flag1 = worldIn.isBlockinHighHumidity(pos);
int j = 0;
if (flag1)
{
j = -50;
}
this.tryCatchFire(worldIn, pos.east(), 300 + j, rand, i, EnumFacing.WEST);
this.tryCatchFire(worldIn, pos.west(), 300 + j, rand, i, EnumFacing.EAST);
this.tryCatchFire(worldIn, pos.down(), 250 + j, rand, i, EnumFacing.UP);
this.tryCatchFire(worldIn, pos.up(), 250 + j, rand, i, EnumFacing.DOWN);
this.tryCatchFire(worldIn, pos.north(), 300 + j, rand, i, EnumFacing.SOUTH);
this.tryCatchFire(worldIn, pos.south(), 300 + j, rand, i, EnumFacing.NORTH);
for (int k = -1; k <= 1; ++k)
{
for (int l = -1; l <= 1; ++l)
{
for (int i1 = -1; i1 <= 4; ++i1)
{
if (k != 0 || i1 != 0 || l != 0)
{
int j1 = 100;
if (i1 > 1)
{
j1 += (i1 - 1) * 100;
}
BlockPos blockpos = pos.add(k, i1, l);
int k1 = this.getNeighborEncouragement(worldIn, blockpos);
if (k1 > 0)
{
int l1 = (k1 + 40 + worldIn.getDifficulty().getDifficultyId() * 7) / (i + 30);
if (flag1)
{
l1 /= 2;
}
if (l1 > 0 && rand.nextInt(j1) <= l1 && (!worldIn.isRaining() || !this.canDie(worldIn, blockpos)))
{
int i2 = i + rand.nextInt(5) / 4;
if (i2 > 15)
{
i2 = 15;
}
worldIn.setBlockState(blockpos, state.withProperty(AGE, Integer.valueOf(i2)), 3);
}
}
}
}
}
}
}
}
}
protected boolean canDie(World worldIn, BlockPos pos)
{
return worldIn.isRainingAt(pos) || worldIn.isRainingAt(pos.west()) || worldIn.isRainingAt(pos.east()) || worldIn.isRainingAt(pos.north()) || worldIn.isRainingAt(pos.south());
}
public boolean requiresUpdates()
{
return false;
}
@Deprecated // Use Block.getFlammability
public int getFlammability(Block blockIn)
{
Integer integer = this.flammabilities.get(blockIn);
return integer == null ? 0 : integer.intValue();
}
@Deprecated // Use Block.getFireSpreadSpeed
public int getEncouragement(Block blockIn)
{
Integer integer = this.encouragements.get(blockIn);
return integer == null ? 0 : integer.intValue();
}
@Deprecated // Use tryCatchFire with face below
private void catchOnFire(World worldIn, BlockPos pos, int chance, Random random, int age)
{
this.tryCatchFire(worldIn, pos, chance, random, age, EnumFacing.UP);
}
private void tryCatchFire(World worldIn, BlockPos pos, int chance, Random random, int age, EnumFacing face)
{
int i = worldIn.getBlockState(pos).getBlock().getFlammability(worldIn, pos, face);
if (random.nextInt(chance) < i)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
if (random.nextInt(age + 10) < 5 && !worldIn.isRainingAt(pos))
{
int j = age + random.nextInt(5) / 4;
if (j > 15)
{
j = 15;
}
worldIn.setBlockState(pos, this.getDefaultState().withProperty(AGE, Integer.valueOf(j)), 3);
}
else
{
worldIn.setBlockToAir(pos);
}
if (iblockstate.getBlock() == Blocks.TNT)
{
Blocks.TNT.onBlockDestroyedByPlayer(worldIn, pos, iblockstate.withProperty(BlockTNT.EXPLODE, Boolean.valueOf(true)));
}
}
}
private boolean canNeighborCatchFire(World worldIn, BlockPos pos)
{
for (EnumFacing enumfacing : EnumFacing.values())
{
if (this.canCatchFire(worldIn, pos.offset(enumfacing), enumfacing.getOpposite()))
{
return true;
}
}
return false;
}
private int getNeighborEncouragement(World worldIn, BlockPos pos)
{
if (!worldIn.isAirBlock(pos))
{
return 0;
}
else
{
int i = 0;
for (EnumFacing enumfacing : EnumFacing.values())
{
i = Math.max(worldIn.getBlockState(pos.offset(enumfacing)).getBlock().getFireSpreadSpeed(worldIn, pos.offset(enumfacing), enumfacing.getOpposite()), i);
}
return i;
}
}
/**
* Returns if this block is collidable. Only used by fire, although stairs return that of the block that the stair
* is made of (though nobody's going to make fire stairs, right?)
*/
public boolean isCollidable()
{
return false;
}
/**
* Checks if the block can be caught on fire
*/
@Deprecated // Use canCatchFire with face sensitive version below
public boolean canCatchFire(IBlockAccess worldIn, BlockPos pos)
{
return canCatchFire(worldIn, pos, EnumFacing.UP);
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return worldIn.getBlockState(pos.down()).isTopSolid() || this.canNeighborCatchFire(worldIn, pos);
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (!worldIn.getBlockState(pos.down()).isTopSolid() && !this.canNeighborCatchFire(worldIn, pos))
{
worldIn.setBlockToAir(pos);
}
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
if (worldIn.provider.getDimensionType().getId() > 0 || !Blocks.PORTAL.trySpawnPortal(worldIn, pos))
{
if (!worldIn.getBlockState(pos.down()).isTopSolid() && !this.canNeighborCatchFire(worldIn, pos))
{
worldIn.setBlockToAir(pos);
}
else
{
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn) + worldIn.rand.nextInt(10));
}
}
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.TNT;
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
if (rand.nextInt(24) == 0)
{
worldIn.playSound((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), SoundEvents.BLOCK_FIRE_AMBIENT, SoundCategory.BLOCKS, 1.0F + rand.nextFloat(), rand.nextFloat() * 0.7F + 0.3F, false);
}
if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP) && !Blocks.FIRE.canCatchFire(worldIn, pos.down(), EnumFacing.UP))
{
if (Blocks.FIRE.canCatchFire(worldIn, pos.west(), EnumFacing.EAST))
{
for (int j = 0; j < 2; ++j)
{
double d3 = (double)pos.getX() + rand.nextDouble() * 0.10000000149011612D;
double d8 = (double)pos.getY() + rand.nextDouble();
double d13 = (double)pos.getZ() + rand.nextDouble();
worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d3, d8, d13, 0.0D, 0.0D, 0.0D);
}
}
if (Blocks.FIRE.canCatchFire(worldIn, pos.east(), EnumFacing.WEST))
{
for (int k = 0; k < 2; ++k)
{
double d4 = (double)(pos.getX() + 1) - rand.nextDouble() * 0.10000000149011612D;
double d9 = (double)pos.getY() + rand.nextDouble();
double d14 = (double)pos.getZ() + rand.nextDouble();
worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d4, d9, d14, 0.0D, 0.0D, 0.0D);
}
}
if (Blocks.FIRE.canCatchFire(worldIn, pos.north(), EnumFacing.SOUTH))
{
for (int l = 0; l < 2; ++l)
{
double d5 = (double)pos.getX() + rand.nextDouble();
double d10 = (double)pos.getY() + rand.nextDouble();
double d15 = (double)pos.getZ() + rand.nextDouble() * 0.10000000149011612D;
worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d5, d10, d15, 0.0D, 0.0D, 0.0D);
}
}
if (Blocks.FIRE.canCatchFire(worldIn, pos.south(), EnumFacing.NORTH))
{
for (int i1 = 0; i1 < 2; ++i1)
{
double d6 = (double)pos.getX() + rand.nextDouble();
double d11 = (double)pos.getY() + rand.nextDouble();
double d16 = (double)(pos.getZ() + 1) - rand.nextDouble() * 0.10000000149011612D;
worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d6, d11, d16, 0.0D, 0.0D, 0.0D);
}
}
if (Blocks.FIRE.canCatchFire(worldIn, pos.up(), EnumFacing.DOWN))
{
for (int j1 = 0; j1 < 2; ++j1)
{
double d7 = (double)pos.getX() + rand.nextDouble();
double d12 = (double)(pos.getY() + 1) - rand.nextDouble() * 0.10000000149011612D;
double d17 = (double)pos.getZ() + rand.nextDouble();
worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d7, d12, d17, 0.0D, 0.0D, 0.0D);
}
}
}
else
{
for (int i = 0; i < 3; ++i)
{
double d0 = (double)pos.getX() + rand.nextDouble();
double d1 = (double)pos.getY() + rand.nextDouble() * 0.5D + 0.5D;
double d2 = (double)pos.getZ() + rand.nextDouble();
worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
}
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(AGE, Integer.valueOf(meta));
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(AGE)).intValue();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {AGE, NORTH, EAST, SOUTH, WEST, UPPER});
}
/*================================= Forge Start ======================================*/
/**
* Side sensitive version that calls the block function.
*
* @param world The current world
* @param pos Block position
* @param face The side the fire is coming from
* @return True if the face can catch fire.
*/
public boolean canCatchFire(IBlockAccess world, BlockPos pos, EnumFacing face)
{
return world.getBlockState(pos).getBlock().isFlammable(world, pos, face);
}
/*================================= Forge Start ======================================*/
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,211 @@
package net.minecraft.block;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import java.util.Collection;
import javax.annotation.Nullable;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
public abstract class BlockFlower extends BlockBush
{
protected PropertyEnum<BlockFlower.EnumFlowerType> type;
protected BlockFlower()
{
this.setDefaultState(this.blockState.getBaseState().withProperty(this.getTypeProperty(), this.getBlockType() == BlockFlower.EnumFlowerColor.RED ? BlockFlower.EnumFlowerType.POPPY : BlockFlower.EnumFlowerType.DANDELION));
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return super.getBoundingBox(state, source, pos).offset(state.getOffset(source, pos));
}
/**
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
* returns the metadata of the dropped item based on the old metadata of the block.
*/
public int damageDropped(IBlockState state)
{
return ((BlockFlower.EnumFlowerType)state.getValue(this.getTypeProperty())).getMeta();
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
for (BlockFlower.EnumFlowerType blockflower$enumflowertype : BlockFlower.EnumFlowerType.getTypes(this.getBlockType()))
{
items.add(new ItemStack(this, 1, blockflower$enumflowertype.getMeta()));
}
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(this.getTypeProperty(), BlockFlower.EnumFlowerType.getType(this.getBlockType(), meta));
}
/**
* Get the Type of this flower (Yellow/Red)
*/
public abstract BlockFlower.EnumFlowerColor getBlockType();
public IProperty<BlockFlower.EnumFlowerType> getTypeProperty()
{
if (this.type == null)
{
this.type = PropertyEnum.<BlockFlower.EnumFlowerType>create("type", BlockFlower.EnumFlowerType.class, new Predicate<BlockFlower.EnumFlowerType>()
{
public boolean apply(@Nullable BlockFlower.EnumFlowerType p_apply_1_)
{
return p_apply_1_.getBlockType() == BlockFlower.this.getBlockType();
}
});
}
return this.type;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((BlockFlower.EnumFlowerType)state.getValue(this.getTypeProperty())).getMeta();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {this.getTypeProperty()});
}
/**
* Get the OffsetType for this Block. Determines if the model is rendered slightly offset.
*/
public Block.EnumOffsetType getOffsetType()
{
return Block.EnumOffsetType.XZ;
}
public static enum EnumFlowerColor
{
YELLOW,
RED;
public BlockFlower getBlock()
{
return this == YELLOW ? Blocks.YELLOW_FLOWER : Blocks.RED_FLOWER;
}
}
public static enum EnumFlowerType implements IStringSerializable
{
DANDELION(BlockFlower.EnumFlowerColor.YELLOW, 0, "dandelion"),
POPPY(BlockFlower.EnumFlowerColor.RED, 0, "poppy"),
BLUE_ORCHID(BlockFlower.EnumFlowerColor.RED, 1, "blue_orchid", "blueOrchid"),
ALLIUM(BlockFlower.EnumFlowerColor.RED, 2, "allium"),
HOUSTONIA(BlockFlower.EnumFlowerColor.RED, 3, "houstonia"),
RED_TULIP(BlockFlower.EnumFlowerColor.RED, 4, "red_tulip", "tulipRed"),
ORANGE_TULIP(BlockFlower.EnumFlowerColor.RED, 5, "orange_tulip", "tulipOrange"),
WHITE_TULIP(BlockFlower.EnumFlowerColor.RED, 6, "white_tulip", "tulipWhite"),
PINK_TULIP(BlockFlower.EnumFlowerColor.RED, 7, "pink_tulip", "tulipPink"),
OXEYE_DAISY(BlockFlower.EnumFlowerColor.RED, 8, "oxeye_daisy", "oxeyeDaisy");
private static final BlockFlower.EnumFlowerType[][] TYPES_FOR_BLOCK = new BlockFlower.EnumFlowerType[BlockFlower.EnumFlowerColor.values().length][];
private final BlockFlower.EnumFlowerColor blockType;
private final int meta;
private final String name;
private final String unlocalizedName;
private EnumFlowerType(BlockFlower.EnumFlowerColor blockType, int meta, String name)
{
this(blockType, meta, name, name);
}
private EnumFlowerType(BlockFlower.EnumFlowerColor blockType, int meta, String name, String unlocalizedName)
{
this.blockType = blockType;
this.meta = meta;
this.name = name;
this.unlocalizedName = unlocalizedName;
}
public BlockFlower.EnumFlowerColor getBlockType()
{
return this.blockType;
}
public int getMeta()
{
return this.meta;
}
/**
* Get the given FlowerType from BlockType & metadata
*/
public static BlockFlower.EnumFlowerType getType(BlockFlower.EnumFlowerColor blockType, int meta)
{
BlockFlower.EnumFlowerType[] ablockflower$enumflowertype = TYPES_FOR_BLOCK[blockType.ordinal()];
if (meta < 0 || meta >= ablockflower$enumflowertype.length)
{
meta = 0;
}
return ablockflower$enumflowertype[meta];
}
/**
* Get all FlowerTypes that are applicable for the given Flower block ("yellow", "red")
*/
public static BlockFlower.EnumFlowerType[] getTypes(BlockFlower.EnumFlowerColor flowerColor)
{
return TYPES_FOR_BLOCK[flowerColor.ordinal()];
}
public String toString()
{
return this.name;
}
public String getName()
{
return this.name;
}
public String getUnlocalizedName()
{
return this.unlocalizedName;
}
static
{
for (final BlockFlower.EnumFlowerColor blockflower$enumflowercolor : BlockFlower.EnumFlowerColor.values())
{
Collection<BlockFlower.EnumFlowerType> collection = Collections2.<BlockFlower.EnumFlowerType>filter(Lists.newArrayList(values()), new Predicate<BlockFlower.EnumFlowerType>()
{
public boolean apply(@Nullable BlockFlower.EnumFlowerType p_apply_1_)
{
return p_apply_1_.getBlockType() == blockflower$enumflowercolor;
}
});
TYPES_FOR_BLOCK[blockflower$enumflowercolor.ordinal()] = (BlockFlower.EnumFlowerType[])collection.toArray(new BlockFlower.EnumFlowerType[collection.size()]);
}
}
}
}

View File

@@ -0,0 +1,516 @@
package net.minecraft.block;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFlowerPot;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.ChunkCache;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockFlowerPot extends BlockContainer
{
public static final PropertyInteger LEGACY_DATA = PropertyInteger.create("legacy_data", 0, 15);
public static final PropertyEnum<BlockFlowerPot.EnumFlowerType> CONTENTS = PropertyEnum.<BlockFlowerPot.EnumFlowerType>create("contents", BlockFlowerPot.EnumFlowerType.class);
protected static final AxisAlignedBB FLOWER_POT_AABB = new AxisAlignedBB(0.3125D, 0.0D, 0.3125D, 0.6875D, 0.375D, 0.6875D);
public BlockFlowerPot()
{
super(Material.CIRCUITS);
this.setDefaultState(this.blockState.getBaseState().withProperty(CONTENTS, BlockFlowerPot.EnumFlowerType.EMPTY).withProperty(LEGACY_DATA, Integer.valueOf(0)));
}
/**
* Gets the localized name of this block. Used for the statistics page.
*/
public String getLocalizedName()
{
return I18n.translateToLocal("item.flowerPot.name");
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return FLOWER_POT_AABB;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
ItemStack itemstack = playerIn.getHeldItem(hand);
TileEntityFlowerPot tileentityflowerpot = this.getTileEntity(worldIn, pos);
if (tileentityflowerpot == null)
{
return false;
}
else
{
ItemStack itemstack1 = tileentityflowerpot.getFlowerItemStack();
if (itemstack1.isEmpty())
{
if (!this.canBePotted(itemstack))
{
return false;
}
tileentityflowerpot.setItemStack(itemstack);
playerIn.addStat(StatList.FLOWER_POTTED);
if (!playerIn.capabilities.isCreativeMode)
{
itemstack.shrink(1);
}
}
else
{
if (itemstack.isEmpty())
{
playerIn.setHeldItem(hand, itemstack1);
}
else if (!playerIn.addItemStackToInventory(itemstack1))
{
playerIn.dropItem(itemstack1, false);
}
tileentityflowerpot.setItemStack(ItemStack.EMPTY);
}
tileentityflowerpot.markDirty();
worldIn.notifyBlockUpdate(pos, state, state, 3);
return true;
}
}
private boolean canBePotted(ItemStack stack)
{
Block block = Block.getBlockFromItem(stack.getItem());
if (block != Blocks.YELLOW_FLOWER && block != Blocks.RED_FLOWER && block != Blocks.CACTUS && block != Blocks.BROWN_MUSHROOM && block != Blocks.RED_MUSHROOM && block != Blocks.SAPLING && block != Blocks.DEADBUSH)
{
int i = stack.getMetadata();
return block == Blocks.TALLGRASS && i == BlockTallGrass.EnumType.FERN.getMeta();
}
else
{
return true;
}
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
TileEntityFlowerPot tileentityflowerpot = this.getTileEntity(worldIn, pos);
if (tileentityflowerpot != null)
{
ItemStack itemstack = tileentityflowerpot.getFlowerItemStack();
if (!itemstack.isEmpty())
{
return itemstack;
}
}
return new ItemStack(Items.FLOWER_POT);
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
IBlockState downState = worldIn.getBlockState(pos.down());
return super.canPlaceBlockAt(worldIn, pos) && (downState.isTopSolid() || downState.getBlockFaceShape(worldIn, pos.down(), EnumFacing.UP) == BlockFaceShape.SOLID);
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
IBlockState downState = worldIn.getBlockState(pos.down());
if (!downState.isTopSolid() && downState.getBlockFaceShape(worldIn, pos.down(), EnumFacing.UP) != BlockFaceShape.SOLID)
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
super.breakBlock(worldIn, pos, state);
}
/**
* Called before the Block is set to air in the world. Called regardless of if the player's tool can actually
* collect this block
*/
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
super.onBlockHarvested(worldIn, pos, state, player);
if (player.capabilities.isCreativeMode)
{
TileEntityFlowerPot tileentityflowerpot = this.getTileEntity(worldIn, pos);
if (tileentityflowerpot != null)
{
tileentityflowerpot.setItemStack(ItemStack.EMPTY);
}
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.FLOWER_POT;
}
@Nullable
private TileEntityFlowerPot getTileEntity(World worldIn, BlockPos pos)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
return tileentity instanceof TileEntityFlowerPot ? (TileEntityFlowerPot)tileentity : null;
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
Block block = null;
int i = 0;
switch (meta)
{
case 1:
block = Blocks.RED_FLOWER;
i = BlockFlower.EnumFlowerType.POPPY.getMeta();
break;
case 2:
block = Blocks.YELLOW_FLOWER;
break;
case 3:
block = Blocks.SAPLING;
i = BlockPlanks.EnumType.OAK.getMetadata();
break;
case 4:
block = Blocks.SAPLING;
i = BlockPlanks.EnumType.SPRUCE.getMetadata();
break;
case 5:
block = Blocks.SAPLING;
i = BlockPlanks.EnumType.BIRCH.getMetadata();
break;
case 6:
block = Blocks.SAPLING;
i = BlockPlanks.EnumType.JUNGLE.getMetadata();
break;
case 7:
block = Blocks.RED_MUSHROOM;
break;
case 8:
block = Blocks.BROWN_MUSHROOM;
break;
case 9:
block = Blocks.CACTUS;
break;
case 10:
block = Blocks.DEADBUSH;
break;
case 11:
block = Blocks.TALLGRASS;
i = BlockTallGrass.EnumType.FERN.getMeta();
break;
case 12:
block = Blocks.SAPLING;
i = BlockPlanks.EnumType.ACACIA.getMetadata();
break;
case 13:
block = Blocks.SAPLING;
i = BlockPlanks.EnumType.DARK_OAK.getMetadata();
}
return new TileEntityFlowerPot(Item.getItemFromBlock(block), i);
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {CONTENTS, LEGACY_DATA});
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(LEGACY_DATA)).intValue();
}
/**
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
* metadata, such as fence connections.
*/
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
BlockFlowerPot.EnumFlowerType blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.EMPTY;
TileEntity tileentity = worldIn instanceof ChunkCache ? ((ChunkCache)worldIn).getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK) : worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityFlowerPot)
{
TileEntityFlowerPot tileentityflowerpot = (TileEntityFlowerPot)tileentity;
Item item = tileentityflowerpot.getFlowerPotItem();
if (item instanceof ItemBlock)
{
int i = tileentityflowerpot.getFlowerPotData();
Block block = Block.getBlockFromItem(item);
if (block == Blocks.SAPLING)
{
switch (BlockPlanks.EnumType.byMetadata(i))
{
case OAK:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.OAK_SAPLING;
break;
case SPRUCE:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.SPRUCE_SAPLING;
break;
case BIRCH:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.BIRCH_SAPLING;
break;
case JUNGLE:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.JUNGLE_SAPLING;
break;
case ACACIA:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.ACACIA_SAPLING;
break;
case DARK_OAK:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.DARK_OAK_SAPLING;
break;
default:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.EMPTY;
}
}
else if (block == Blocks.TALLGRASS)
{
switch (i)
{
case 0:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.DEAD_BUSH;
break;
case 2:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.FERN;
break;
default:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.EMPTY;
}
}
else if (block == Blocks.YELLOW_FLOWER)
{
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.DANDELION;
}
else if (block == Blocks.RED_FLOWER)
{
switch (BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.RED, i))
{
case POPPY:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.POPPY;
break;
case BLUE_ORCHID:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.BLUE_ORCHID;
break;
case ALLIUM:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.ALLIUM;
break;
case HOUSTONIA:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.HOUSTONIA;
break;
case RED_TULIP:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.RED_TULIP;
break;
case ORANGE_TULIP:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.ORANGE_TULIP;
break;
case WHITE_TULIP:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.WHITE_TULIP;
break;
case PINK_TULIP:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.PINK_TULIP;
break;
case OXEYE_DAISY:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.OXEYE_DAISY;
break;
default:
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.EMPTY;
}
}
else if (block == Blocks.RED_MUSHROOM)
{
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.MUSHROOM_RED;
}
else if (block == Blocks.BROWN_MUSHROOM)
{
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.MUSHROOM_BROWN;
}
else if (block == Blocks.DEADBUSH)
{
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.DEAD_BUSH;
}
else if (block == Blocks.CACTUS)
{
blockflowerpot$enumflowertype = BlockFlowerPot.EnumFlowerType.CACTUS;
}
}
}
return state.withProperty(CONTENTS, blockflowerpot$enumflowertype);
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
/*============================FORGE START=====================================*/
@Override
public void getDrops(net.minecraft.util.NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
super.getDrops(drops, world, pos, state, fortune);
TileEntityFlowerPot te = world.getTileEntity(pos) instanceof TileEntityFlowerPot ? (TileEntityFlowerPot)world.getTileEntity(pos) : null;
if (te != null && te.getFlowerPotItem() != null)
drops.add(new ItemStack(te.getFlowerPotItem(), 1, te.getFlowerPotData()));
}
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
{
if (willHarvest) return true; //If it will harvest, delay deletion of the block until after getDrops
return super.removedByPlayer(state, world, pos, player, willHarvest);
}
/**
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via
* Block.removedByPlayer
*/
@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack tool)
{
super.harvestBlock(world, player, pos, state, te, tool);
world.setBlockToAir(pos);
}
/*===========================FORGE END==========================================*/
public static enum EnumFlowerType implements IStringSerializable
{
EMPTY("empty"),
POPPY("rose"),
BLUE_ORCHID("blue_orchid"),
ALLIUM("allium"),
HOUSTONIA("houstonia"),
RED_TULIP("red_tulip"),
ORANGE_TULIP("orange_tulip"),
WHITE_TULIP("white_tulip"),
PINK_TULIP("pink_tulip"),
OXEYE_DAISY("oxeye_daisy"),
DANDELION("dandelion"),
OAK_SAPLING("oak_sapling"),
SPRUCE_SAPLING("spruce_sapling"),
BIRCH_SAPLING("birch_sapling"),
JUNGLE_SAPLING("jungle_sapling"),
ACACIA_SAPLING("acacia_sapling"),
DARK_OAK_SAPLING("dark_oak_sapling"),
MUSHROOM_RED("mushroom_red"),
MUSHROOM_BROWN("mushroom_brown"),
DEAD_BUSH("dead_bush"),
FERN("fern"),
CACTUS("cactus");
private final String name;
private EnumFlowerType(String name)
{
this.name = name;
}
public String toString()
{
return this.name;
}
public String getName()
{
return this.name;
}
}
}

View File

@@ -0,0 +1,127 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
public class BlockFrostedIce extends BlockIce
{
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 3);
public BlockFrostedIce()
{
this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0)));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(AGE)).intValue();
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(AGE, Integer.valueOf(MathHelper.clamp(meta, 0, 3)));
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if ((rand.nextInt(3) == 0 || this.countNeighbors(worldIn, pos) < 4) && worldIn.getLightFromNeighbors(pos) > 11 - ((Integer)state.getValue(AGE)).intValue() - state.getLightOpacity())
{
this.slightlyMelt(worldIn, pos, state, rand, true);
}
else
{
worldIn.scheduleUpdate(pos, this, MathHelper.getInt(rand, 20, 40));
}
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (blockIn == this)
{
int i = this.countNeighbors(worldIn, pos);
if (i < 2)
{
this.turnIntoWater(worldIn, pos);
}
}
}
private int countNeighbors(World worldIn, BlockPos pos)
{
int i = 0;
for (EnumFacing enumfacing : EnumFacing.values())
{
if (worldIn.getBlockState(pos.offset(enumfacing)).getBlock() == this)
{
++i;
if (i >= 4)
{
return i;
}
}
}
return i;
}
protected void slightlyMelt(World worldIn, BlockPos pos, IBlockState state, Random rand, boolean meltNeighbors)
{
int i = ((Integer)state.getValue(AGE)).intValue();
if (i < 3)
{
worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i + 1)), 2);
worldIn.scheduleUpdate(pos, this, MathHelper.getInt(rand, 20, 40));
}
else
{
this.turnIntoWater(worldIn, pos);
if (meltNeighbors)
{
for (EnumFacing enumfacing : EnumFacing.values())
{
BlockPos blockpos = pos.offset(enumfacing);
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.getBlock() == this)
{
this.slightlyMelt(worldIn, blockpos, iblockstate, rand, false);
}
}
}
}
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {AGE});
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return ItemStack.EMPTY;
}
}

View File

@@ -0,0 +1,303 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockFurnace extends BlockContainer
{
public static final PropertyDirection FACING = BlockHorizontal.FACING;
private final boolean isBurning;
private static boolean keepInventory;
protected BlockFurnace(boolean isBurning)
{
super(Material.ROCK);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
this.isBurning = isBurning;
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(Blocks.FURNACE);
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
this.setDefaultFacing(worldIn, pos, state);
}
private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
{
if (!worldIn.isRemote)
{
IBlockState iblockstate = worldIn.getBlockState(pos.north());
IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
{
enumfacing = EnumFacing.SOUTH;
}
else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
{
enumfacing = EnumFacing.NORTH;
}
else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
{
enumfacing = EnumFacing.EAST;
}
else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
{
enumfacing = EnumFacing.WEST;
}
worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
}
}
@SideOnly(Side.CLIENT)
@SuppressWarnings("incomplete-switch")
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
if (this.isBurning)
{
EnumFacing enumfacing = (EnumFacing)stateIn.getValue(FACING);
double d0 = (double)pos.getX() + 0.5D;
double d1 = (double)pos.getY() + rand.nextDouble() * 6.0D / 16.0D;
double d2 = (double)pos.getZ() + 0.5D;
double d3 = 0.52D;
double d4 = rand.nextDouble() * 0.6D - 0.3D;
if (rand.nextDouble() < 0.1D)
{
worldIn.playSound((double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
}
switch (enumfacing)
{
case WEST:
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 - 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 - 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
break;
case EAST:
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
break;
case NORTH:
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 - 0.52D, 0.0D, 0.0D, 0.0D);
worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 - 0.52D, 0.0D, 0.0D, 0.0D);
break;
case SOUTH:
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 + 0.52D, 0.0D, 0.0D, 0.0D);
worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 + 0.52D, 0.0D, 0.0D, 0.0D);
}
}
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
else
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityFurnace)
{
playerIn.displayGUIChest((TileEntityFurnace)tileentity);
playerIn.addStat(StatList.FURNACE_INTERACTION);
}
return true;
}
}
public static void setState(boolean active, World worldIn, BlockPos pos)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
TileEntity tileentity = worldIn.getTileEntity(pos);
keepInventory = true;
if (active)
{
worldIn.setBlockState(pos, Blocks.LIT_FURNACE.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
worldIn.setBlockState(pos, Blocks.LIT_FURNACE.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
}
else
{
worldIn.setBlockState(pos, Blocks.FURNACE.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
worldIn.setBlockState(pos, Blocks.FURNACE.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
}
keepInventory = false;
if (tileentity != null)
{
tileentity.validate();
worldIn.setTileEntity(pos, tileentity);
}
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityFurnace();
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}
/**
* Called by ItemBlocks after a block is set in the world, to allow post-place logic
*/
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
if (stack.hasDisplayName())
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityFurnace)
{
((TileEntityFurnace)tileentity).setCustomInventoryName(stack.getDisplayName());
}
}
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
if (!keepInventory)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityFurnace)
{
InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityFurnace)tileentity);
worldIn.updateComparatorOutputLevel(pos, this);
}
}
super.breakBlock(worldIn, pos, state);
}
public boolean hasComparatorInputOverride(IBlockState state)
{
return true;
}
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
{
return Container.calcRedstone(worldIn.getTileEntity(pos));
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(Blocks.FURNACE);
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
EnumFacing enumfacing = EnumFacing.getFront(meta);
if (enumfacing.getAxis() == EnumFacing.Axis.Y)
{
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(FACING, enumfacing);
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((EnumFacing)state.getValue(FACING)).getIndex();
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING});
}
}

View File

@@ -0,0 +1,42 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.util.BlockRenderLayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockGlass extends BlockBreakable
{
public BlockGlass(Material materialIn, boolean ignoreSimilarity)
{
super(materialIn, ignoreSimilarity);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 0;
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
protected boolean canSilkHarvest()
{
return true;
}
}

View File

@@ -0,0 +1,90 @@
package net.minecraft.block;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockGlazedTerracotta extends BlockHorizontal
{
public BlockGlazedTerracotta(EnumDyeColor color)
{
super(Material.ROCK, MapColor.getBlockColor(color));
this.setHardness(1.4F);
this.setSoundType(SoundType.STONE);
String s = color.getUnlocalizedName();
if (s.length() > 1)
{
String s1 = s.substring(0, 1).toUpperCase() + s.substring(1, s.length());
this.setUnlocalizedName("glazedTerracotta" + s1);
}
this.setCreativeTab(CreativeTabs.DECORATIONS);
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING});
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
return i;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
}
public EnumPushReaction getMobilityFlag(IBlockState state)
{
return EnumPushReaction.PUSH_ONLY;
}
}

View File

@@ -0,0 +1,53 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IBlockAccess;
public class BlockGlowstone extends Block
{
public BlockGlowstone(Material materialIn)
{
super(materialIn);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Get the quantity dropped based on the given fortune level
*/
public int quantityDroppedWithBonus(int fortune, Random random)
{
return MathHelper.clamp(this.quantityDropped(random) + random.nextInt(fortune + 1), 1, 4);
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 2 + random.nextInt(3);
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.GLOWSTONE_DUST;
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.SAND;
}
}

View File

@@ -0,0 +1,160 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockGrass extends Block implements IGrowable
{
public static final PropertyBool SNOWY = PropertyBool.create("snowy");
protected BlockGrass()
{
super(Material.GRASS);
this.setDefaultState(this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)));
this.setTickRandomly(true);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
* metadata, such as fence connections.
*/
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
Block block = worldIn.getBlockState(pos.up()).getBlock();
return state.withProperty(SNOWY, Boolean.valueOf(block == Blocks.SNOW || block == Blocks.SNOW_LAYER));
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isRemote)
{
if (!worldIn.isAreaLoaded(pos, 3)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light and spreading
if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2)
{
worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState());
}
else
{
if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
{
for (int i = 0; i < 4; ++i)
{
BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos))
{
return;
}
IBlockState iblockstate = worldIn.getBlockState(blockpos.up());
IBlockState iblockstate1 = worldIn.getBlockState(blockpos);
if (iblockstate1.getBlock() == Blocks.DIRT && iblockstate1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2)
{
worldIn.setBlockState(blockpos, Blocks.GRASS.getDefaultState());
}
}
}
}
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Blocks.DIRT.getItemDropped(Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT), rand, fortune);
}
/**
* Whether this IGrowable can grow
*/
public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
{
return true;
}
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
return true;
}
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
BlockPos blockpos = pos.up();
for (int i = 0; i < 128; ++i)
{
BlockPos blockpos1 = blockpos;
int j = 0;
while (true)
{
if (j >= i / 16)
{
if (worldIn.isAirBlock(blockpos1))
{
if (rand.nextInt(8) == 0)
{
worldIn.getBiome(blockpos1).plantFlower(worldIn, rand, blockpos1);
}
else
{
IBlockState iblockstate1 = Blocks.TALLGRASS.getDefaultState().withProperty(BlockTallGrass.TYPE, BlockTallGrass.EnumType.GRASS);
if (Blocks.TALLGRASS.canBlockStay(worldIn, blockpos1, iblockstate1))
{
worldIn.setBlockState(blockpos1, iblockstate1, 3);
}
}
}
break;
}
blockpos1 = blockpos1.add(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
if (worldIn.getBlockState(blockpos1.down()).getBlock() != Blocks.GRASS || worldIn.getBlockState(blockpos1).isNormalCube())
{
break;
}
++j;
}
}
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT_MIPPED;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return 0;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {SNOWY});
}
}

View File

@@ -0,0 +1,119 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockGrassPath extends Block
{
protected static final AxisAlignedBB GRASS_PATH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.9375D, 1.0D);
protected BlockGrassPath()
{
super(Material.GROUND);
this.setLightOpacity(255);
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
switch (side)
{
case UP:
return true;
case NORTH:
case SOUTH:
case WEST:
case EAST:
IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
Block block = iblockstate.getBlock();
return !iblockstate.isOpaqueCube() && block != Blocks.FARMLAND && block != Blocks.GRASS_PATH;
default:
return super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
super.onBlockAdded(worldIn, pos, state);
this.updateBlockState(worldIn, pos);
}
private void updateBlockState(World worldIn, BlockPos pos)
{
if (worldIn.getBlockState(pos.up()).getMaterial().isSolid())
{
BlockFarmland.turnToDirt(worldIn, pos);
}
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return GRASS_PATH_AABB;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Blocks.DIRT.getItemDropped(Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT), rand, fortune);
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(this);
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
this.updateBlockState(worldIn, pos);
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return face == EnumFacing.DOWN ? BlockFaceShape.SOLID : BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,41 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockGravel extends BlockFalling
{
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
if (fortune > 3)
{
fortune = 3;
}
return rand.nextInt(10 - fortune * 3) == 0 ? Items.FLINT : super.getItemDropped(state, rand, fortune);
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.STONE;
}
@SideOnly(Side.CLIENT)
public int getDustColor(IBlockState state)
{
return -8356741;
}
}

View File

@@ -0,0 +1,9 @@
package net.minecraft.block;
public class BlockHalfStoneSlab extends BlockStoneSlab
{
public boolean isDouble()
{
return false;
}
}

View File

@@ -0,0 +1,9 @@
package net.minecraft.block;
public class BlockHalfStoneSlabNew extends BlockStoneSlabNew
{
public boolean isDouble()
{
return false;
}
}

View File

@@ -0,0 +1,9 @@
package net.minecraft.block;
public class BlockHalfWoodSlab extends BlockWoodSlab
{
public boolean isDouble()
{
return false;
}
}

View File

@@ -0,0 +1,25 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
public class BlockHardenedClay extends Block
{
public BlockHardenedClay()
{
super(Material.ROCK);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.ADOBE;
}
}

View File

@@ -0,0 +1,27 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockHay extends BlockRotatedPillar
{
public BlockHay()
{
super(Material.GRASS, MapColor.YELLOW);
this.setDefaultState(this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.Y));
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Block's chance to react to a living entity falling on it.
*/
public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance)
{
entityIn.fall(fallDistance, 0.2F);
}
}

View File

@@ -0,0 +1,309 @@
package net.minecraft.block;
import com.google.common.base.Predicate;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityHopper;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockHopper extends BlockContainer
{
public static final PropertyDirection FACING = PropertyDirection.create("facing", new Predicate<EnumFacing>()
{
public boolean apply(@Nullable EnumFacing p_apply_1_)
{
return p_apply_1_ != EnumFacing.UP;
}
});
public static final PropertyBool ENABLED = PropertyBool.create("enabled");
protected static final AxisAlignedBB BASE_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.625D, 1.0D);
protected static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.125D);
protected static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.875D, 1.0D, 1.0D, 1.0D);
protected static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.875D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
protected static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.125D, 1.0D, 1.0D);
public BlockHopper()
{
super(Material.IRON, MapColor.STONE);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.DOWN).withProperty(ENABLED, Boolean.valueOf(true)));
this.setCreativeTab(CreativeTabs.REDSTONE);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return FULL_BLOCK_AABB;
}
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState)
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, BASE_AABB);
addCollisionBoxToList(pos, entityBox, collidingBoxes, EAST_AABB);
addCollisionBoxToList(pos, entityBox, collidingBoxes, WEST_AABB);
addCollisionBoxToList(pos, entityBox, collidingBoxes, SOUTH_AABB);
addCollisionBoxToList(pos, entityBox, collidingBoxes, NORTH_AABB);
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
EnumFacing enumfacing = facing.getOpposite();
if (enumfacing == EnumFacing.UP)
{
enumfacing = EnumFacing.DOWN;
}
return this.getDefaultState().withProperty(FACING, enumfacing).withProperty(ENABLED, Boolean.valueOf(true));
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityHopper();
}
/**
* Called by ItemBlocks after a block is set in the world, to allow post-place logic
*/
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
if (stack.hasDisplayName())
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityHopper)
{
((TileEntityHopper)tileentity).setCustomName(stack.getDisplayName());
}
}
}
/**
* Determines if the block is solid enough on the top side to support other blocks, like redstone components.
*/
public boolean isTopSolid(IBlockState state)
{
return true;
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
this.updateState(worldIn, pos, state);
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
else
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityHopper)
{
playerIn.displayGUIChest((TileEntityHopper)tileentity);
playerIn.addStat(StatList.HOPPER_INSPECTED);
}
return true;
}
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
this.updateState(worldIn, pos, state);
}
private void updateState(World worldIn, BlockPos pos, IBlockState state)
{
boolean flag = !worldIn.isBlockPowered(pos);
if (flag != ((Boolean)state.getValue(ENABLED)).booleanValue())
{
worldIn.setBlockState(pos, state.withProperty(ENABLED, Boolean.valueOf(flag)), 4);
}
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityHopper)
{
InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityHopper)tileentity);
worldIn.updateComparatorOutputLevel(pos, this);
}
super.breakBlock(worldIn, pos, state);
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public static EnumFacing getFacing(int meta)
{
return EnumFacing.getFront(meta & 7);
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return true;
}
/**
* Get's the hopper's active status from the 8-bit of the metadata. Note that the metadata stores whether the block
* is powered, so this returns true when that bit is 0.
*/
public static boolean isEnabled(int meta)
{
return (meta & 8) != 8;
}
public boolean hasComparatorInputOverride(IBlockState state)
{
return true;
}
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
{
return Container.calcRedstone(worldIn.getTileEntity(pos));
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT_MIPPED;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(FACING, getFacing(meta)).withProperty(ENABLED, Boolean.valueOf(isEnabled(meta)));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((EnumFacing)state.getValue(FACING)).getIndex();
if (!((Boolean)state.getValue(ENABLED)).booleanValue())
{
i |= 8;
}
return i;
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING, ENABLED});
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return face == EnumFacing.UP ? BlockFaceShape.BOWL : BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,21 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.util.EnumFacing;
public abstract class BlockHorizontal extends Block
{
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
protected BlockHorizontal(Material materialIn)
{
super(materialIn);
}
protected BlockHorizontal(Material materialIn, MapColor colorIn)
{
super(materialIn, colorIn);
}
}

View File

@@ -0,0 +1,326 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockHugeMushroom extends Block
{
public static final PropertyEnum<BlockHugeMushroom.EnumType> VARIANT = PropertyEnum.<BlockHugeMushroom.EnumType>create("variant", BlockHugeMushroom.EnumType.class);
private final Block smallBlock;
public BlockHugeMushroom(Material materialIn, MapColor color, Block smallBlockIn)
{
super(materialIn, color);
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockHugeMushroom.EnumType.ALL_OUTSIDE));
this.smallBlock = smallBlockIn;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return Math.max(0, random.nextInt(10) - 7);
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
switch ((BlockHugeMushroom.EnumType)state.getValue(VARIANT))
{
case ALL_STEM:
return MapColor.CLOTH;
case ALL_INSIDE:
return MapColor.SAND;
case STEM:
return MapColor.SAND;
default:
return super.getMapColor(state, worldIn, pos);
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(this.smallBlock);
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(this.smallBlock);
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getDefaultState();
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(VARIANT, BlockHugeMushroom.EnumType.byMetadata(meta));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((BlockHugeMushroom.EnumType)state.getValue(VARIANT)).getMetadata();
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
switch (rot)
{
case CLOCKWISE_180:
switch ((BlockHugeMushroom.EnumType)state.getValue(VARIANT))
{
case STEM:
break;
case NORTH_WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH_EAST);
case NORTH:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH);
case NORTH_EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH_WEST);
case WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.EAST);
case EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.WEST);
case SOUTH_WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH_EAST);
case SOUTH:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH);
case SOUTH_EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH_WEST);
default:
return state;
}
case COUNTERCLOCKWISE_90:
switch ((BlockHugeMushroom.EnumType)state.getValue(VARIANT))
{
case STEM:
break;
case NORTH_WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH_WEST);
case NORTH:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.WEST);
case NORTH_EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH_WEST);
case WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH);
case EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH);
case SOUTH_WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH_EAST);
case SOUTH:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.EAST);
case SOUTH_EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH_EAST);
default:
return state;
}
case CLOCKWISE_90:
switch ((BlockHugeMushroom.EnumType)state.getValue(VARIANT))
{
case STEM:
break;
case NORTH_WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH_EAST);
case NORTH:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.EAST);
case NORTH_EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH_EAST);
case WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH);
case EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH);
case SOUTH_WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH_WEST);
case SOUTH:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.WEST);
case SOUTH_EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH_WEST);
default:
return state;
}
default:
return state;
}
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
@SuppressWarnings("incomplete-switch")
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
BlockHugeMushroom.EnumType blockhugemushroom$enumtype = (BlockHugeMushroom.EnumType)state.getValue(VARIANT);
switch (mirrorIn)
{
case LEFT_RIGHT:
switch (blockhugemushroom$enumtype)
{
case NORTH_WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH_WEST);
case NORTH:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH);
case NORTH_EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH_EAST);
case WEST:
case EAST:
default:
return super.withMirror(state, mirrorIn);
case SOUTH_WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH_WEST);
case SOUTH:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH);
case SOUTH_EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH_EAST);
}
case FRONT_BACK:
switch (blockhugemushroom$enumtype)
{
case NORTH_WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH_EAST);
case NORTH:
case SOUTH:
default:
break;
case NORTH_EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.NORTH_WEST);
case WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.EAST);
case EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.WEST);
case SOUTH_WEST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH_EAST);
case SOUTH_EAST:
return state.withProperty(VARIANT, BlockHugeMushroom.EnumType.SOUTH_WEST);
}
}
return super.withMirror(state, mirrorIn);
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {VARIANT});
}
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis)
{
IBlockState state = world.getBlockState(pos);
for (IProperty prop : (java.util.Set<IProperty<?>>)state.getProperties().keySet())
{
if (prop.getName().equals("variant"))
{
world.setBlockState(pos, state.cycleProperty(prop));
return true;
}
}
return false;
}
public static enum EnumType implements IStringSerializable
{
NORTH_WEST(1, "north_west"),
NORTH(2, "north"),
NORTH_EAST(3, "north_east"),
WEST(4, "west"),
CENTER(5, "center"),
EAST(6, "east"),
SOUTH_WEST(7, "south_west"),
SOUTH(8, "south"),
SOUTH_EAST(9, "south_east"),
STEM(10, "stem"),
ALL_INSIDE(0, "all_inside"),
ALL_OUTSIDE(14, "all_outside"),
ALL_STEM(15, "all_stem");
private static final BlockHugeMushroom.EnumType[] META_LOOKUP = new BlockHugeMushroom.EnumType[16];
private final int meta;
private final String name;
private EnumType(int meta, String name)
{
this.meta = meta;
this.name = name;
}
public int getMetadata()
{
return this.meta;
}
public String toString()
{
return this.name;
}
public static BlockHugeMushroom.EnumType byMetadata(int meta)
{
if (meta < 0 || meta >= META_LOOKUP.length)
{
meta = 0;
}
BlockHugeMushroom.EnumType blockhugemushroom$enumtype = META_LOOKUP[meta];
return blockhugemushroom$enumtype == null ? META_LOOKUP[0] : blockhugemushroom$enumtype;
}
public String getName()
{
return this.name;
}
static
{
for (BlockHugeMushroom.EnumType blockhugemushroom$enumtype : values())
{
META_LOOKUP[blockhugemushroom$enumtype.getMetadata()] = blockhugemushroom$enumtype;
}
}
}
}

View File

@@ -0,0 +1,112 @@
package net.minecraft.block;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockIce extends BlockBreakable
{
public BlockIce()
{
super(Material.ICE, false);
this.slipperiness = 0.98F;
this.setTickRandomly(true);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.TRANSLUCENT;
}
/**
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via
* Block.removedByPlayer
*/
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
player.addStat(StatList.getBlockStats(this));
player.addExhaustion(0.005F);
if (this.canSilkHarvest(worldIn, pos, state, player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0)
{
java.util.List<ItemStack> items = new java.util.ArrayList<ItemStack>();
items.add(this.getSilkTouchDrop(state));
net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(items, worldIn, pos, state, 0, 1.0f, true, player);
for (ItemStack is : items)
spawnAsEntity(worldIn, pos, is);
}
else
{
if (worldIn.provider.doesWaterVaporize())
{
worldIn.setBlockToAir(pos);
return;
}
int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
harvesters.set(player);
this.dropBlockAsItem(worldIn, pos, state, i);
harvesters.set(null);
Material material = worldIn.getBlockState(pos.down()).getMaterial();
if (material.blocksMovement() || material.isLiquid())
{
worldIn.setBlockState(pos, Blocks.FLOWING_WATER.getDefaultState());
}
}
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 0;
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (worldIn.getLightFor(EnumSkyBlock.BLOCK, pos) > 11 - this.getDefaultState().getLightOpacity())
{
this.turnIntoWater(worldIn, pos);
}
}
protected void turnIntoWater(World worldIn, BlockPos pos)
{
if (worldIn.provider.doesWaterVaporize())
{
worldIn.setBlockToAir(pos);
}
else
{
this.dropBlockAsItem(worldIn, pos, worldIn.getBlockState(pos), 0);
worldIn.setBlockState(pos, Blocks.WATER.getDefaultState());
worldIn.neighborChanged(pos, Blocks.WATER, pos);
}
}
public EnumPushReaction getMobilityFlag(IBlockState state)
{
return EnumPushReaction.NORMAL;
}
}

View File

@@ -0,0 +1,222 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.walkers.ItemStackData;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockJukebox extends BlockContainer
{
public static final PropertyBool HAS_RECORD = PropertyBool.create("has_record");
public static void registerFixesJukebox(DataFixer fixer)
{
fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackData(BlockJukebox.TileEntityJukebox.class, new String[] {"RecordItem"}));
}
protected BlockJukebox()
{
super(Material.WOOD, MapColor.DIRT);
this.setDefaultState(this.blockState.getBaseState().withProperty(HAS_RECORD, Boolean.valueOf(false)));
this.setCreativeTab(CreativeTabs.DECORATIONS);
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (((Boolean)state.getValue(HAS_RECORD)).booleanValue())
{
this.dropRecord(worldIn, pos, state);
state = state.withProperty(HAS_RECORD, Boolean.valueOf(false));
worldIn.setBlockState(pos, state, 2);
return true;
}
else
{
return false;
}
}
public void insertRecord(World worldIn, BlockPos pos, IBlockState state, ItemStack recordStack)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof BlockJukebox.TileEntityJukebox)
{
((BlockJukebox.TileEntityJukebox)tileentity).setRecord(recordStack.copy());
worldIn.setBlockState(pos, state.withProperty(HAS_RECORD, Boolean.valueOf(true)), 2);
}
}
private void dropRecord(World worldIn, BlockPos pos, IBlockState state)
{
if (!worldIn.isRemote)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof BlockJukebox.TileEntityJukebox)
{
BlockJukebox.TileEntityJukebox blockjukebox$tileentityjukebox = (BlockJukebox.TileEntityJukebox)tileentity;
ItemStack itemstack = blockjukebox$tileentityjukebox.getRecord();
if (!itemstack.isEmpty())
{
worldIn.playEvent(1010, pos, 0);
worldIn.playRecord(pos, (SoundEvent)null);
blockjukebox$tileentityjukebox.setRecord(ItemStack.EMPTY);
float f = 0.7F;
double d0 = (double)(worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
double d1 = (double)(worldIn.rand.nextFloat() * 0.7F) + 0.06000000238418579D + 0.6D;
double d2 = (double)(worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
ItemStack itemstack1 = itemstack.copy();
EntityItem entityitem = new EntityItem(worldIn, (double)pos.getX() + d0, (double)pos.getY() + d1, (double)pos.getZ() + d2, itemstack1);
entityitem.setDefaultPickupDelay();
worldIn.spawnEntity(entityitem);
}
}
}
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
this.dropRecord(worldIn, pos, state);
super.breakBlock(worldIn, pos, state);
}
/**
* Spawns this Block's drops into the World as EntityItems.
*/
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
if (!worldIn.isRemote)
{
super.dropBlockAsItemWithChance(worldIn, pos, state, chance, 0);
}
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new BlockJukebox.TileEntityJukebox();
}
public boolean hasComparatorInputOverride(IBlockState state)
{
return true;
}
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof BlockJukebox.TileEntityJukebox)
{
ItemStack itemstack = ((BlockJukebox.TileEntityJukebox)tileentity).getRecord();
if (!itemstack.isEmpty())
{
return Item.getIdFromItem(itemstack.getItem()) + 1 - Item.getIdFromItem(Items.RECORD_13);
}
}
return 0;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(HAS_RECORD, Boolean.valueOf(meta > 0));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Boolean)state.getValue(HAS_RECORD)).booleanValue() ? 1 : 0;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {HAS_RECORD});
}
public static class TileEntityJukebox extends TileEntity
{
private ItemStack record = ItemStack.EMPTY;
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
if (compound.hasKey("RecordItem", 10))
{
this.setRecord(new ItemStack(compound.getCompoundTag("RecordItem")));
}
else if (compound.getInteger("Record") > 0)
{
this.setRecord(new ItemStack(Item.getItemById(compound.getInteger("Record"))));
}
}
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
if (!this.getRecord().isEmpty())
{
compound.setTag("RecordItem", this.getRecord().writeToNBT(new NBTTagCompound()));
}
return compound;
}
public ItemStack getRecord()
{
return this.record;
}
public void setRecord(ItemStack recordStack)
{
this.record = recordStack;
this.markDirty();
}
}
}

View File

@@ -0,0 +1,205 @@
package net.minecraft.block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockLadder extends Block
{
public static final PropertyDirection FACING = BlockHorizontal.FACING;
protected static final AxisAlignedBB LADDER_EAST_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.1875D, 1.0D, 1.0D);
protected static final AxisAlignedBB LADDER_WEST_AABB = new AxisAlignedBB(0.8125D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
protected static final AxisAlignedBB LADDER_SOUTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.1875D);
protected static final AxisAlignedBB LADDER_NORTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.8125D, 1.0D, 1.0D, 1.0D);
protected BlockLadder()
{
super(Material.CIRCUITS);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
this.setCreativeTab(CreativeTabs.DECORATIONS);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
switch ((EnumFacing)state.getValue(FACING))
{
case NORTH:
return LADDER_NORTH_AABB;
case SOUTH:
return LADDER_SOUTH_AABB;
case WEST:
return LADDER_WEST_AABB;
case EAST:
default:
return LADDER_EAST_AABB;
}
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Check whether this Block can be placed at pos, while aiming at the specified side of an adjacent block
*/
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side)
{
if (this.canAttachTo(worldIn, pos.west(), side))
{
return true;
}
else if (this.canAttachTo(worldIn, pos.east(), side))
{
return true;
}
else if (this.canAttachTo(worldIn, pos.north(), side))
{
return true;
}
else
{
return this.canAttachTo(worldIn, pos.south(), side);
}
}
private boolean canAttachTo(World p_193392_1_, BlockPos p_193392_2_, EnumFacing p_193392_3_)
{
IBlockState iblockstate = p_193392_1_.getBlockState(p_193392_2_);
boolean flag = isExceptBlockForAttachWithPiston(iblockstate.getBlock());
return !flag && iblockstate.getBlockFaceShape(p_193392_1_, p_193392_2_, p_193392_3_) == BlockFaceShape.SOLID && !iblockstate.canProvidePower();
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
if (facing.getAxis().isHorizontal() && this.canAttachTo(worldIn, pos.offset(facing.getOpposite()), facing))
{
return this.getDefaultState().withProperty(FACING, facing);
}
else
{
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
if (this.canAttachTo(worldIn, pos.offset(enumfacing.getOpposite()), enumfacing))
{
return this.getDefaultState().withProperty(FACING, enumfacing);
}
}
return this.getDefaultState();
}
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
if (!this.canAttachTo(worldIn, pos.offset(enumfacing.getOpposite()), enumfacing))
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
EnumFacing enumfacing = EnumFacing.getFront(meta);
if (enumfacing.getAxis() == EnumFacing.Axis.Y)
{
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(FACING, enumfacing);
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((EnumFacing)state.getValue(FACING)).getIndex();
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING});
}
@Override public boolean isLadder(IBlockState state, IBlockAccess world, BlockPos pos, EntityLivingBase entity) { return true; }
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
}

View File

@@ -0,0 +1,313 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class BlockLeaves extends Block implements net.minecraftforge.common.IShearable
{
public static final PropertyBool DECAYABLE = PropertyBool.create("decayable");
public static final PropertyBool CHECK_DECAY = PropertyBool.create("check_decay");
protected boolean leavesFancy;
int[] surroundings;
public BlockLeaves()
{
super(Material.LEAVES);
this.setTickRandomly(true);
this.setCreativeTab(CreativeTabs.DECORATIONS);
this.setHardness(0.2F);
this.setLightOpacity(1);
this.setSoundType(SoundType.PLANT);
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
int i = 1;
int j = 2;
int k = pos.getX();
int l = pos.getY();
int i1 = pos.getZ();
if (worldIn.isAreaLoaded(new BlockPos(k - 2, l - 2, i1 - 2), new BlockPos(k + 2, l + 2, i1 + 2)))
{
for (int j1 = -1; j1 <= 1; ++j1)
{
for (int k1 = -1; k1 <= 1; ++k1)
{
for (int l1 = -1; l1 <= 1; ++l1)
{
BlockPos blockpos = pos.add(j1, k1, l1);
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.getBlock().isLeaves(iblockstate, worldIn, blockpos))
{
iblockstate.getBlock().beginLeavesDecay(iblockstate, worldIn, blockpos);
}
}
}
}
}
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isRemote)
{
if (((Boolean)state.getValue(CHECK_DECAY)).booleanValue() && ((Boolean)state.getValue(DECAYABLE)).booleanValue())
{
int i = 4;
int j = 5;
int k = pos.getX();
int l = pos.getY();
int i1 = pos.getZ();
int j1 = 32;
int k1 = 1024;
int l1 = 16;
if (this.surroundings == null)
{
this.surroundings = new int[32768];
}
if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent decaying leaves from updating neighbors and loading unloaded chunks
if (worldIn.isAreaLoaded(pos, 6)) // Forge: extend range from 5 to 6 to account for neighbor checks in world.markAndNotifyBlock -> world.updateObservingBlocksAt
{
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
for (int i2 = -4; i2 <= 4; ++i2)
{
for (int j2 = -4; j2 <= 4; ++j2)
{
for (int k2 = -4; k2 <= 4; ++k2)
{
IBlockState iblockstate = worldIn.getBlockState(blockpos$mutableblockpos.setPos(k + i2, l + j2, i1 + k2));
Block block = iblockstate.getBlock();
if (!block.canSustainLeaves(iblockstate, worldIn, blockpos$mutableblockpos.setPos(k + i2, l + j2, i1 + k2)))
{
if (block.isLeaves(iblockstate, worldIn, blockpos$mutableblockpos.setPos(k + i2, l + j2, i1 + k2)))
{
this.surroundings[(i2 + 16) * 1024 + (j2 + 16) * 32 + k2 + 16] = -2;
}
else
{
this.surroundings[(i2 + 16) * 1024 + (j2 + 16) * 32 + k2 + 16] = -1;
}
}
else
{
this.surroundings[(i2 + 16) * 1024 + (j2 + 16) * 32 + k2 + 16] = 0;
}
}
}
}
for (int i3 = 1; i3 <= 4; ++i3)
{
for (int j3 = -4; j3 <= 4; ++j3)
{
for (int k3 = -4; k3 <= 4; ++k3)
{
for (int l3 = -4; l3 <= 4; ++l3)
{
if (this.surroundings[(j3 + 16) * 1024 + (k3 + 16) * 32 + l3 + 16] == i3 - 1)
{
if (this.surroundings[(j3 + 16 - 1) * 1024 + (k3 + 16) * 32 + l3 + 16] == -2)
{
this.surroundings[(j3 + 16 - 1) * 1024 + (k3 + 16) * 32 + l3 + 16] = i3;
}
if (this.surroundings[(j3 + 16 + 1) * 1024 + (k3 + 16) * 32 + l3 + 16] == -2)
{
this.surroundings[(j3 + 16 + 1) * 1024 + (k3 + 16) * 32 + l3 + 16] = i3;
}
if (this.surroundings[(j3 + 16) * 1024 + (k3 + 16 - 1) * 32 + l3 + 16] == -2)
{
this.surroundings[(j3 + 16) * 1024 + (k3 + 16 - 1) * 32 + l3 + 16] = i3;
}
if (this.surroundings[(j3 + 16) * 1024 + (k3 + 16 + 1) * 32 + l3 + 16] == -2)
{
this.surroundings[(j3 + 16) * 1024 + (k3 + 16 + 1) * 32 + l3 + 16] = i3;
}
if (this.surroundings[(j3 + 16) * 1024 + (k3 + 16) * 32 + (l3 + 16 - 1)] == -2)
{
this.surroundings[(j3 + 16) * 1024 + (k3 + 16) * 32 + (l3 + 16 - 1)] = i3;
}
if (this.surroundings[(j3 + 16) * 1024 + (k3 + 16) * 32 + l3 + 16 + 1] == -2)
{
this.surroundings[(j3 + 16) * 1024 + (k3 + 16) * 32 + l3 + 16 + 1] = i3;
}
}
}
}
}
}
}
int l2 = this.surroundings[16912];
if (l2 >= 0)
{
worldIn.setBlockState(pos, state.withProperty(CHECK_DECAY, Boolean.valueOf(false)), 4);
}
else
{
this.destroy(worldIn, pos);
}
}
}
}
private void destroy(World worldIn, BlockPos pos)
{
this.dropBlockAsItem(worldIn, pos, worldIn.getBlockState(pos), 0);
worldIn.setBlockToAir(pos);
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
if (worldIn.isRainingAt(pos.up()) && !worldIn.getBlockState(pos.down()).isTopSolid() && rand.nextInt(15) == 1)
{
double d0 = (double)((float)pos.getX() + rand.nextFloat());
double d1 = (double)pos.getY() - 0.05D;
double d2 = (double)((float)pos.getZ() + rand.nextFloat());
worldIn.spawnParticle(EnumParticleTypes.DRIP_WATER, d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return random.nextInt(20) == 0 ? 1 : 0;
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(Blocks.SAPLING);
}
/**
* Spawns this Block's drops into the World as EntityItems.
*/
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
}
protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance)
{
}
protected int getSaplingDropChance(IBlockState state)
{
return 20;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return !this.leavesFancy;
}
/**
* Pass true to draw this block using fancy graphics, or false for fast graphics.
*/
@SideOnly(Side.CLIENT)
public void setGraphicsLevel(boolean fancy)
{
this.leavesFancy = fancy;
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return this.leavesFancy ? BlockRenderLayer.CUTOUT_MIPPED : BlockRenderLayer.SOLID;
}
public boolean causesSuffocation(IBlockState state)
{
return false;
}
public abstract BlockPlanks.EnumType getWoodType(int meta);
@Override public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos){ return true; }
@Override public boolean isLeaves(IBlockState state, IBlockAccess world, BlockPos pos){ return true; }
@Override
public void beginLeavesDecay(IBlockState state, World world, BlockPos pos)
{
if (!(Boolean)state.getValue(CHECK_DECAY))
{
world.setBlockState(pos, state.withProperty(CHECK_DECAY, true), 4);
}
}
@Override
public void getDrops(net.minecraft.util.NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
Random rand = world instanceof World ? ((World)world).rand : new Random();
int chance = this.getSaplingDropChance(state);
if (fortune > 0)
{
chance -= 2 << fortune;
if (chance < 10) chance = 10;
}
if (rand.nextInt(chance) == 0)
{
ItemStack drop = new ItemStack(getItemDropped(state, rand, fortune), 1, damageDropped(state));
if (!drop.isEmpty())
drops.add(drop);
}
chance = 200;
if (fortune > 0)
{
chance -= 10 << fortune;
if (chance < 40) chance = 40;
}
this.captureDrops(true);
if (world instanceof World)
this.dropApple((World)world, pos, state, chance); // Dammet mojang
drops.addAll(this.captureDrops(false));
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return !this.leavesFancy && blockAccess.getBlockState(pos.offset(side)).getBlock() == this ? false : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
}

View File

@@ -0,0 +1,464 @@
package net.minecraft.block;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockLever extends Block
{
public static final PropertyEnum<BlockLever.EnumOrientation> FACING = PropertyEnum.<BlockLever.EnumOrientation>create("facing", BlockLever.EnumOrientation.class);
public static final PropertyBool POWERED = PropertyBool.create("powered");
protected static final AxisAlignedBB LEVER_NORTH_AABB = new AxisAlignedBB(0.3125D, 0.20000000298023224D, 0.625D, 0.6875D, 0.800000011920929D, 1.0D);
protected static final AxisAlignedBB LEVER_SOUTH_AABB = new AxisAlignedBB(0.3125D, 0.20000000298023224D, 0.0D, 0.6875D, 0.800000011920929D, 0.375D);
protected static final AxisAlignedBB LEVER_WEST_AABB = new AxisAlignedBB(0.625D, 0.20000000298023224D, 0.3125D, 1.0D, 0.800000011920929D, 0.6875D);
protected static final AxisAlignedBB LEVER_EAST_AABB = new AxisAlignedBB(0.0D, 0.20000000298023224D, 0.3125D, 0.375D, 0.800000011920929D, 0.6875D);
protected static final AxisAlignedBB LEVER_UP_AABB = new AxisAlignedBB(0.25D, 0.0D, 0.25D, 0.75D, 0.6000000238418579D, 0.75D);
protected static final AxisAlignedBB LEVER_DOWN_AABB = new AxisAlignedBB(0.25D, 0.4000000059604645D, 0.25D, 0.75D, 1.0D, 0.75D);
protected BlockLever()
{
super(Material.CIRCUITS);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, BlockLever.EnumOrientation.NORTH).withProperty(POWERED, Boolean.valueOf(false)));
this.setCreativeTab(CreativeTabs.REDSTONE);
}
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
return NULL_AABB;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Check whether this Block can be placed at pos, while aiming at the specified side of an adjacent block
*/
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side)
{
return canAttachTo(worldIn, pos, side);
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
for (EnumFacing enumfacing : EnumFacing.values())
{
if (canAttachTo(worldIn, pos, enumfacing))
{
return true;
}
}
return false;
}
protected static boolean canAttachTo(World worldIn, BlockPos p_181090_1_, EnumFacing p_181090_2_)
{
return BlockButton.canPlaceBlock(worldIn, p_181090_1_, p_181090_2_);
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
IBlockState iblockstate = this.getDefaultState().withProperty(POWERED, Boolean.valueOf(false));
if (canAttachTo(worldIn, pos, facing))
{
return iblockstate.withProperty(FACING, BlockLever.EnumOrientation.forFacings(facing, placer.getHorizontalFacing()));
}
else
{
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
if (enumfacing != facing && canAttachTo(worldIn, pos, enumfacing))
{
return iblockstate.withProperty(FACING, BlockLever.EnumOrientation.forFacings(enumfacing, placer.getHorizontalFacing()));
}
}
if (worldIn.getBlockState(pos.down()).isTopSolid())
{
return iblockstate.withProperty(FACING, BlockLever.EnumOrientation.forFacings(EnumFacing.UP, placer.getHorizontalFacing()));
}
else
{
return iblockstate;
}
}
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (this.checkCanSurvive(worldIn, pos, state) && !canAttachTo(worldIn, pos, ((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing()))
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
}
private boolean checkCanSurvive(World worldIn, BlockPos pos, IBlockState state)
{
if (this.canPlaceBlockAt(worldIn, pos))
{
return true;
}
else
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
return false;
}
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
switch ((BlockLever.EnumOrientation)state.getValue(FACING))
{
case EAST:
default:
return LEVER_EAST_AABB;
case WEST:
return LEVER_WEST_AABB;
case SOUTH:
return LEVER_SOUTH_AABB;
case NORTH:
return LEVER_NORTH_AABB;
case UP_Z:
case UP_X:
return LEVER_UP_AABB;
case DOWN_X:
case DOWN_Z:
return LEVER_DOWN_AABB;
}
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
else
{
state = state.cycleProperty(POWERED);
worldIn.setBlockState(pos, state, 3);
float f = ((Boolean)state.getValue(POWERED)).booleanValue() ? 0.6F : 0.5F;
worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.3F, f);
worldIn.notifyNeighborsOfStateChange(pos, this, false);
EnumFacing enumfacing = ((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing();
worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing.getOpposite()), this, false);
return true;
}
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
if (((Boolean)state.getValue(POWERED)).booleanValue())
{
worldIn.notifyNeighborsOfStateChange(pos, this, false);
EnumFacing enumfacing = ((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing();
worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing.getOpposite()), this, false);
}
super.breakBlock(worldIn, pos, state);
}
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return ((Boolean)blockState.getValue(POWERED)).booleanValue() ? 15 : 0;
}
public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
if (!((Boolean)blockState.getValue(POWERED)).booleanValue())
{
return 0;
}
else
{
return ((BlockLever.EnumOrientation)blockState.getValue(FACING)).getFacing() == side ? 15 : 0;
}
}
/**
* Can this block provide power. Only wire currently seems to have this change based on its state.
*/
public boolean canProvidePower(IBlockState state)
{
return true;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(FACING, BlockLever.EnumOrientation.byMetadata(meta & 7)).withProperty(POWERED, Boolean.valueOf((meta & 8) > 0));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((BlockLever.EnumOrientation)state.getValue(FACING)).getMetadata();
if (((Boolean)state.getValue(POWERED)).booleanValue())
{
i |= 8;
}
return i;
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
switch (rot)
{
case CLOCKWISE_180:
switch ((BlockLever.EnumOrientation)state.getValue(FACING))
{
case EAST:
return state.withProperty(FACING, BlockLever.EnumOrientation.WEST);
case WEST:
return state.withProperty(FACING, BlockLever.EnumOrientation.EAST);
case SOUTH:
return state.withProperty(FACING, BlockLever.EnumOrientation.NORTH);
case NORTH:
return state.withProperty(FACING, BlockLever.EnumOrientation.SOUTH);
default:
return state;
}
case COUNTERCLOCKWISE_90:
switch ((BlockLever.EnumOrientation)state.getValue(FACING))
{
case EAST:
return state.withProperty(FACING, BlockLever.EnumOrientation.NORTH);
case WEST:
return state.withProperty(FACING, BlockLever.EnumOrientation.SOUTH);
case SOUTH:
return state.withProperty(FACING, BlockLever.EnumOrientation.EAST);
case NORTH:
return state.withProperty(FACING, BlockLever.EnumOrientation.WEST);
case UP_Z:
return state.withProperty(FACING, BlockLever.EnumOrientation.UP_X);
case UP_X:
return state.withProperty(FACING, BlockLever.EnumOrientation.UP_Z);
case DOWN_X:
return state.withProperty(FACING, BlockLever.EnumOrientation.DOWN_Z);
case DOWN_Z:
return state.withProperty(FACING, BlockLever.EnumOrientation.DOWN_X);
}
case CLOCKWISE_90:
switch ((BlockLever.EnumOrientation)state.getValue(FACING))
{
case EAST:
return state.withProperty(FACING, BlockLever.EnumOrientation.SOUTH);
case WEST:
return state.withProperty(FACING, BlockLever.EnumOrientation.NORTH);
case SOUTH:
return state.withProperty(FACING, BlockLever.EnumOrientation.WEST);
case NORTH:
return state.withProperty(FACING, BlockLever.EnumOrientation.EAST);
case UP_Z:
return state.withProperty(FACING, BlockLever.EnumOrientation.UP_X);
case UP_X:
return state.withProperty(FACING, BlockLever.EnumOrientation.UP_Z);
case DOWN_X:
return state.withProperty(FACING, BlockLever.EnumOrientation.DOWN_Z);
case DOWN_Z:
return state.withProperty(FACING, BlockLever.EnumOrientation.DOWN_X);
}
default:
return state;
}
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation(((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing()));
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING, POWERED});
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
public static enum EnumOrientation implements IStringSerializable
{
DOWN_X(0, "down_x", EnumFacing.DOWN),
EAST(1, "east", EnumFacing.EAST),
WEST(2, "west", EnumFacing.WEST),
SOUTH(3, "south", EnumFacing.SOUTH),
NORTH(4, "north", EnumFacing.NORTH),
UP_Z(5, "up_z", EnumFacing.UP),
UP_X(6, "up_x", EnumFacing.UP),
DOWN_Z(7, "down_z", EnumFacing.DOWN);
private static final BlockLever.EnumOrientation[] META_LOOKUP = new BlockLever.EnumOrientation[values().length];
private final int meta;
private final String name;
private final EnumFacing facing;
private EnumOrientation(int meta, String name, EnumFacing facing)
{
this.meta = meta;
this.name = name;
this.facing = facing;
}
public int getMetadata()
{
return this.meta;
}
public EnumFacing getFacing()
{
return this.facing;
}
public String toString()
{
return this.name;
}
public static BlockLever.EnumOrientation byMetadata(int meta)
{
if (meta < 0 || meta >= META_LOOKUP.length)
{
meta = 0;
}
return META_LOOKUP[meta];
}
public static BlockLever.EnumOrientation forFacings(EnumFacing clickedSide, EnumFacing entityFacing)
{
switch (clickedSide)
{
case DOWN:
switch (entityFacing.getAxis())
{
case X:
return DOWN_X;
case Z:
return DOWN_Z;
default:
throw new IllegalArgumentException("Invalid entityFacing " + entityFacing + " for facing " + clickedSide);
}
case UP:
switch (entityFacing.getAxis())
{
case X:
return UP_X;
case Z:
return UP_Z;
default:
throw new IllegalArgumentException("Invalid entityFacing " + entityFacing + " for facing " + clickedSide);
}
case NORTH:
return NORTH;
case SOUTH:
return SOUTH;
case WEST:
return WEST;
case EAST:
return EAST;
default:
throw new IllegalArgumentException("Invalid facing: " + clickedSide);
}
}
public String getName()
{
return this.name;
}
static
{
for (BlockLever.EnumOrientation blocklever$enumorientation : values())
{
META_LOOKUP[blocklever$enumorientation.getMetadata()] = blocklever$enumorientation;
}
}
}
}

View File

@@ -0,0 +1,80 @@
package net.minecraft.block;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockLilyPad extends BlockBush
{
protected static final AxisAlignedBB LILY_PAD_AABB = new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.09375D, 0.9375D);
protected BlockLilyPad()
{
this.setCreativeTab(CreativeTabs.DECORATIONS);
}
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean isActualState)
{
if (!(entityIn instanceof EntityBoat))
{
addCollisionBoxToList(pos, entityBox, collidingBoxes, LILY_PAD_AABB);
}
}
/**
* Called When an Entity Collided with the Block
*/
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);
if (entityIn instanceof EntityBoat)
{
worldIn.destroyBlock(new BlockPos(pos), true);
}
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return LILY_PAD_AABB;
}
/**
* Return true if the block can sustain a Bush
*/
protected boolean canSustainBush(IBlockState state)
{
return state.getBlock() == Blocks.WATER || state.getMaterial() == Material.ICE;
}
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
if (pos.getY() >= 0 && pos.getY() < 256)
{
IBlockState iblockstate = worldIn.getBlockState(pos.down());
Material material = iblockstate.getMaterial();
return material == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 || material == Material.ICE;
}
else
{
return false;
}
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return 0;
}
}

View File

@@ -0,0 +1,529 @@
package net.minecraft.block;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class BlockLiquid extends Block
{
public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 15);
protected BlockLiquid(Material materialIn)
{
super(materialIn);
this.setDefaultState(this.blockState.getBaseState().withProperty(LEVEL, Integer.valueOf(0)));
this.setTickRandomly(true);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return FULL_BLOCK_AABB;
}
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
{
return NULL_AABB;
}
/**
* Determines if an entity can path through this block
*/
public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
{
return this.blockMaterial != Material.LAVA;
}
/**
* Returns the percentage of the liquid block that is air, based on the given flow decay of the liquid
*/
public static float getLiquidHeightPercent(int meta)
{
if (meta >= 8)
{
meta = 0;
}
return (float)(meta + 1) / 9.0F;
}
protected int getDepth(IBlockState state)
{
return state.getMaterial() == this.blockMaterial ? ((Integer)state.getValue(LEVEL)).intValue() : -1;
}
protected int getRenderedDepth(IBlockState state)
{
int i = this.getDepth(state);
return i >= 8 ? 0 : i;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean canCollideCheck(IBlockState state, boolean hitIfLiquid)
{
return hitIfLiquid && ((Integer)state.getValue(LEVEL)).intValue() == 0;
}
/**
* Checks if an additional {@code -6} vertical drag should be applied to the entity. See {#link
* net.minecraft.block.BlockLiquid#getFlow()}
*/
private boolean causesDownwardCurrent(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
Material material = iblockstate.getMaterial();
if (material == this.blockMaterial)
{
return false;
}
else if (side == EnumFacing.UP)
{
return true;
}
else if (material == Material.ICE)
{
return false;
}
else
{
boolean flag = isExceptBlockForAttachWithPiston(block) || block instanceof BlockStairs;
return !flag && iblockstate.getBlockFaceShape(worldIn, pos, side) == BlockFaceShape.SOLID;
}
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
if (blockAccess.getBlockState(pos.offset(side)).getMaterial() == this.blockMaterial)
{
return false;
}
else
{
return side == EnumFacing.UP ? true : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.LIQUID;
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.AIR;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 0;
}
protected Vec3d getFlow(IBlockAccess worldIn, BlockPos pos, IBlockState state)
{
double d0 = 0.0D;
double d1 = 0.0D;
double d2 = 0.0D;
int i = this.getRenderedDepth(state);
BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain();
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
blockpos$pooledmutableblockpos.setPos(pos).move(enumfacing);
int j = this.getRenderedDepth(worldIn.getBlockState(blockpos$pooledmutableblockpos));
if (j < 0)
{
if (!worldIn.getBlockState(blockpos$pooledmutableblockpos).getMaterial().blocksMovement())
{
j = this.getRenderedDepth(worldIn.getBlockState(blockpos$pooledmutableblockpos.down()));
if (j >= 0)
{
int k = j - (i - 8);
d0 += (double)(enumfacing.getFrontOffsetX() * k);
d1 += (double)(enumfacing.getFrontOffsetY() * k);
d2 += (double)(enumfacing.getFrontOffsetZ() * k);
}
}
}
else if (j >= 0)
{
int l = j - i;
d0 += (double)(enumfacing.getFrontOffsetX() * l);
d1 += (double)(enumfacing.getFrontOffsetY() * l);
d2 += (double)(enumfacing.getFrontOffsetZ() * l);
}
}
Vec3d vec3d = new Vec3d(d0, d1, d2);
if (((Integer)state.getValue(LEVEL)).intValue() >= 8)
{
for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
{
blockpos$pooledmutableblockpos.setPos(pos).move(enumfacing1);
if (this.causesDownwardCurrent(worldIn, blockpos$pooledmutableblockpos, enumfacing1) || this.causesDownwardCurrent(worldIn, blockpos$pooledmutableblockpos.up(), enumfacing1))
{
vec3d = vec3d.normalize().addVector(0.0D, -6.0D, 0.0D);
break;
}
}
}
blockpos$pooledmutableblockpos.release();
return vec3d.normalize();
}
public Vec3d modifyAcceleration(World worldIn, BlockPos pos, Entity entityIn, Vec3d motion)
{
return motion.add(this.getFlow(worldIn, pos, worldIn.getBlockState(pos)));
}
/**
* How many world ticks before ticking
*/
public int tickRate(World worldIn)
{
if (this.blockMaterial == Material.WATER)
{
return 5;
}
else if (this.blockMaterial == Material.LAVA)
{
return worldIn.provider.isNether() ? 10 : 30;
}
else
{
return 0;
}
}
@SideOnly(Side.CLIENT)
public boolean shouldRenderSides(IBlockAccess blockAccess, BlockPos pos)
{
for (int i = -1; i <= 1; ++i)
{
for (int j = -1; j <= 1; ++j)
{
IBlockState iblockstate = blockAccess.getBlockState(pos.add(i, 0, j));
if (iblockstate.getMaterial() != this.blockMaterial && !iblockstate.isFullBlock())
{
return true;
}
}
}
return false;
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
this.checkForMixing(worldIn, pos, state);
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
this.checkForMixing(worldIn, pos, state);
}
@SideOnly(Side.CLIENT)
public int getPackedLightmapCoords(IBlockState state, IBlockAccess source, BlockPos pos)
{
int i = source.getCombinedLight(pos, 0);
int j = source.getCombinedLight(pos.up(), 0);
int k = i & 255;
int l = j & 255;
int i1 = i >> 16 & 255;
int j1 = j >> 16 & 255;
return (k > l ? k : l) | (i1 > j1 ? i1 : j1) << 16;
}
public boolean checkForMixing(World worldIn, BlockPos pos, IBlockState state)
{
if (this.blockMaterial == Material.LAVA)
{
boolean flag = false;
for (EnumFacing enumfacing : EnumFacing.values())
{
if (enumfacing != EnumFacing.DOWN && worldIn.getBlockState(pos.offset(enumfacing)).getMaterial() == Material.WATER)
{
flag = true;
break;
}
}
if (flag)
{
Integer integer = (Integer)state.getValue(LEVEL);
if (integer.intValue() == 0)
{
worldIn.setBlockState(pos, net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(worldIn, pos, pos, Blocks.OBSIDIAN.getDefaultState()));
this.triggerMixEffects(worldIn, pos);
return true;
}
if (integer.intValue() <= 4)
{
worldIn.setBlockState(pos, net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(worldIn, pos, pos, Blocks.COBBLESTONE.getDefaultState()));
this.triggerMixEffects(worldIn, pos);
return true;
}
}
}
return false;
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return this.blockMaterial == Material.WATER ? BlockRenderLayer.TRANSLUCENT : BlockRenderLayer.SOLID;
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
double d0 = (double)pos.getX();
double d1 = (double)pos.getY();
double d2 = (double)pos.getZ();
if (this.blockMaterial == Material.WATER)
{
int i = ((Integer)stateIn.getValue(LEVEL)).intValue();
if (i > 0 && i < 8)
{
if (rand.nextInt(64) == 0)
{
worldIn.playSound(d0 + 0.5D, d1 + 0.5D, d2 + 0.5D, SoundEvents.BLOCK_WATER_AMBIENT, SoundCategory.BLOCKS, rand.nextFloat() * 0.25F + 0.75F, rand.nextFloat() + 0.5F, false);
}
}
else if (rand.nextInt(10) == 0)
{
worldIn.spawnParticle(EnumParticleTypes.SUSPENDED, d0 + (double)rand.nextFloat(), d1 + (double)rand.nextFloat(), d2 + (double)rand.nextFloat(), 0.0D, 0.0D, 0.0D);
}
}
if (this.blockMaterial == Material.LAVA && worldIn.getBlockState(pos.up()).getMaterial() == Material.AIR && !worldIn.getBlockState(pos.up()).isOpaqueCube())
{
if (rand.nextInt(100) == 0)
{
double d8 = d0 + (double)rand.nextFloat();
double d4 = d1 + stateIn.getBoundingBox(worldIn, pos).maxY;
double d6 = d2 + (double)rand.nextFloat();
worldIn.spawnParticle(EnumParticleTypes.LAVA, d8, d4, d6, 0.0D, 0.0D, 0.0D);
worldIn.playSound(d8, d4, d6, SoundEvents.BLOCK_LAVA_POP, SoundCategory.BLOCKS, 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false);
}
if (rand.nextInt(200) == 0)
{
worldIn.playSound(d0, d1, d2, SoundEvents.BLOCK_LAVA_AMBIENT, SoundCategory.BLOCKS, 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false);
}
}
if (rand.nextInt(10) == 0 && worldIn.getBlockState(pos.down()).isTopSolid())
{
Material material = worldIn.getBlockState(pos.down(2)).getMaterial();
if (!material.blocksMovement() && !material.isLiquid())
{
double d3 = d0 + (double)rand.nextFloat();
double d5 = d1 - 1.05D;
double d7 = d2 + (double)rand.nextFloat();
if (this.blockMaterial == Material.WATER)
{
worldIn.spawnParticle(EnumParticleTypes.DRIP_WATER, d3, d5, d7, 0.0D, 0.0D, 0.0D);
}
else
{
worldIn.spawnParticle(EnumParticleTypes.DRIP_LAVA, d3, d5, d7, 0.0D, 0.0D, 0.0D);
}
}
}
}
@SideOnly(Side.CLIENT)
public static float getSlopeAngle(IBlockAccess worldIn, BlockPos pos, Material materialIn, IBlockState state)
{
Vec3d vec3d = getFlowingBlock(materialIn).getFlow(worldIn, pos, state);
return vec3d.x == 0.0D && vec3d.z == 0.0D ? -1000.0F : (float)MathHelper.atan2(vec3d.z, vec3d.x) - ((float)Math.PI / 2F);
}
protected void triggerMixEffects(World worldIn, BlockPos pos)
{
double d0 = (double)pos.getX();
double d1 = (double)pos.getY();
double d2 = (double)pos.getZ();
worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);
for (int i = 0; i < 8; ++i)
{
worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d0 + Math.random(), d1 + 1.2D, d2 + Math.random(), 0.0D, 0.0D, 0.0D);
}
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(LEVEL, Integer.valueOf(meta));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(LEVEL)).intValue();
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {LEVEL});
}
public static BlockDynamicLiquid getFlowingBlock(Material materialIn)
{
if (materialIn == Material.WATER)
{
return Blocks.FLOWING_WATER;
}
else if (materialIn == Material.LAVA)
{
return Blocks.FLOWING_LAVA;
}
else
{
throw new IllegalArgumentException("Invalid material");
}
}
public static BlockStaticLiquid getStaticBlock(Material materialIn)
{
if (materialIn == Material.WATER)
{
return Blocks.WATER;
}
else if (materialIn == Material.LAVA)
{
return Blocks.LAVA;
}
else
{
throw new IllegalArgumentException("Invalid material");
}
}
public static float getBlockLiquidHeight(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
int i = ((Integer)state.getValue(LEVEL)).intValue();
return (i & 7) == 0 && worldIn.getBlockState(pos.up()).getMaterial() == Material.WATER ? 1.0F : 1.0F - getLiquidHeightPercent(i);
}
public static float getLiquidHeight(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return (float)pos.getY() + getBlockLiquidHeight(state, worldIn, pos);
}
/**
* Get the geometry of the queried face at the given position and state. This is used to decide whether things like
* buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
* <p>
* Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
* does not fit the other descriptions and will generally cause other things not to connect to the face.
*
* @return an approximation of the form of the given face
*/
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
return BlockFaceShape.UNDEFINED;
}
@Override
@SideOnly (Side.CLIENT)
public Vec3d getFogColor(World world, BlockPos pos, IBlockState state, Entity entity, Vec3d originalColor, float partialTicks)
{
Vec3d viewport = net.minecraft.client.renderer.ActiveRenderInfo.projectViewFromEntity(entity, partialTicks);
if (state.getMaterial().isLiquid())
{
float height = 0.0F;
if (state.getBlock() instanceof BlockLiquid)
{
height = getLiquidHeightPercent(state.getValue(LEVEL)) - 0.11111111F;
}
float f1 = (float) (pos.getY() + 1) - height;
if (viewport.y > (double)f1)
{
BlockPos upPos = pos.up();
IBlockState upState = world.getBlockState(upPos);
return upState.getBlock().getFogColor(world, upPos, upState, entity, originalColor, partialTicks);
}
}
return super.getFogColor(world, pos, state, entity, originalColor, partialTicks);
}
}

View File

@@ -0,0 +1,125 @@
package net.minecraft.block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public abstract class BlockLog extends BlockRotatedPillar
{
public static final PropertyEnum<BlockLog.EnumAxis> LOG_AXIS = PropertyEnum.<BlockLog.EnumAxis>create("axis", BlockLog.EnumAxis.class);
public BlockLog()
{
super(Material.WOOD);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
this.setHardness(2.0F);
this.setSoundType(SoundType.WOOD);
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
int i = 4;
int j = 5;
if (worldIn.isAreaLoaded(pos.add(-5, -5, -5), pos.add(5, 5, 5)))
{
for (BlockPos blockpos : BlockPos.getAllInBox(pos.add(-4, -4, -4), pos.add(4, 4, 4)))
{
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.getBlock().isLeaves(iblockstate, worldIn, blockpos))
{
iblockstate.getBlock().beginLeavesDecay(iblockstate, worldIn, blockpos);
}
}
}
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getStateFromMeta(meta).withProperty(LOG_AXIS, BlockLog.EnumAxis.fromFacingAxis(facing.getAxis()));
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
switch (rot)
{
case COUNTERCLOCKWISE_90:
case CLOCKWISE_90:
switch ((BlockLog.EnumAxis)state.getValue(LOG_AXIS))
{
case X:
return state.withProperty(LOG_AXIS, BlockLog.EnumAxis.Z);
case Z:
return state.withProperty(LOG_AXIS, BlockLog.EnumAxis.X);
default:
return state;
}
default:
return state;
}
}
@Override public boolean canSustainLeaves(IBlockState state, net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; }
@Override public boolean isWood(net.minecraft.world.IBlockAccess world, BlockPos pos){ return true; }
public static enum EnumAxis implements IStringSerializable
{
X("x"),
Y("y"),
Z("z"),
NONE("none");
private final String name;
private EnumAxis(String name)
{
this.name = name;
}
public String toString()
{
return this.name;
}
public static BlockLog.EnumAxis fromFacingAxis(EnumFacing.Axis axis)
{
switch (axis)
{
case X:
return X;
case Y:
return Y;
case Z:
return Z;
default:
return NONE;
}
}
public String getName()
{
return this.name;
}
}
}

View File

@@ -0,0 +1,82 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockMagma extends Block
{
public BlockMagma()
{
super(Material.ROCK);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
this.setLightLevel(0.2F);
this.setTickRandomly(true);
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.NETHERRACK;
}
/**
* Called when the given entity walks on this Block
*/
public void onEntityWalk(World worldIn, BlockPos pos, Entity entityIn)
{
if (!entityIn.isImmuneToFire() && entityIn instanceof EntityLivingBase && !EnchantmentHelper.hasFrostWalkerEnchantment((EntityLivingBase)entityIn))
{
entityIn.attackEntityFrom(DamageSource.HOT_FLOOR, 1.0F);
}
super.onEntityWalk(worldIn, pos, entityIn);
}
@SideOnly(Side.CLIENT)
public int getPackedLightmapCoords(IBlockState state, IBlockAccess source, BlockPos pos)
{
return 15728880;
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
BlockPos blockpos = pos.up();
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.getBlock() == Blocks.WATER || iblockstate.getBlock() == Blocks.FLOWING_WATER)
{
worldIn.setBlockToAir(blockpos);
worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);
if (worldIn instanceof WorldServer)
{
((WorldServer)worldIn).spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.25D, (double)blockpos.getZ() + 0.5D, 8, 0.5D, 0.25D, 0.5D, 0.0D);
}
}
}
public boolean canEntitySpawn(IBlockState state, Entity entityIn)
{
return entityIn.isImmuneToFire();
}
}

View File

@@ -0,0 +1,42 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
public class BlockMelon extends Block
{
protected BlockMelon()
{
super(Material.GOURD, MapColor.LIME);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.MELON;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 3 + random.nextInt(5);
}
/**
* Get the quantity dropped based on the given fortune level
*/
public int quantityDroppedWithBonus(int fortune, Random random)
{
return Math.min(9, this.quantityDropped(random) + random.nextInt(1 + fortune));
}
}

View File

@@ -0,0 +1,90 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockMobSpawner extends BlockContainer
{
protected BlockMobSpawner()
{
super(Material.ROCK);
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityMobSpawner();
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.AIR;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 0;
}
/**
* Spawns this Block's drops into the World as EntityItems.
*/
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
}
@Override
public int getExpDrop(IBlockState state, net.minecraft.world.IBlockAccess world, BlockPos pos, int fortune)
{
return 15 + RANDOM.nextInt(15) + RANDOM.nextInt(15);
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return ItemStack.EMPTY;
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
}

View File

@@ -0,0 +1,149 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenBigMushroom;
import net.minecraft.world.gen.feature.WorldGenerator;
public class BlockMushroom extends BlockBush implements IGrowable
{
protected static final AxisAlignedBB MUSHROOM_AABB = new AxisAlignedBB(0.30000001192092896D, 0.0D, 0.30000001192092896D, 0.699999988079071D, 0.4000000059604645D, 0.699999988079071D);
protected BlockMushroom()
{
this.setTickRandomly(true);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return MUSHROOM_AABB;
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (rand.nextInt(25) == 0)
{
int i = 5;
int j = 4;
for (BlockPos blockpos : BlockPos.getAllInBoxMutable(pos.add(-4, -1, -4), pos.add(4, 1, 4)))
{
if (worldIn.getBlockState(blockpos).getBlock() == this)
{
--i;
if (i <= 0)
{
return;
}
}
}
BlockPos blockpos1 = pos.add(rand.nextInt(3) - 1, rand.nextInt(2) - rand.nextInt(2), rand.nextInt(3) - 1);
for (int k = 0; k < 4; ++k)
{
if (worldIn.isAirBlock(blockpos1) && this.canBlockStay(worldIn, blockpos1, this.getDefaultState()))
{
pos = blockpos1;
}
blockpos1 = pos.add(rand.nextInt(3) - 1, rand.nextInt(2) - rand.nextInt(2), rand.nextInt(3) - 1);
}
if (worldIn.isAirBlock(blockpos1) && this.canBlockStay(worldIn, blockpos1, this.getDefaultState()))
{
worldIn.setBlockState(blockpos1, this.getDefaultState(), 2);
}
}
}
/**
* Checks if this block can be placed exactly at the given position.
*/
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return super.canPlaceBlockAt(worldIn, pos) && this.canBlockStay(worldIn, pos, this.getDefaultState());
}
/**
* Return true if the block can sustain a Bush
*/
protected boolean canSustainBush(IBlockState state)
{
return state.isFullBlock();
}
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
if (pos.getY() >= 0 && pos.getY() < 256)
{
IBlockState iblockstate = worldIn.getBlockState(pos.down());
if (iblockstate.getBlock() == Blocks.MYCELIUM)
{
return true;
}
else if (iblockstate.getBlock() == Blocks.DIRT && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.PODZOL)
{
return true;
}
else
{
return worldIn.getLight(pos) < 13 && iblockstate.getBlock().canSustainPlant(iblockstate, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
}
}
else
{
return false;
}
}
public boolean generateBigMushroom(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
worldIn.setBlockToAir(pos);
WorldGenerator worldgenerator = null;
if (this == Blocks.BROWN_MUSHROOM)
{
worldgenerator = new WorldGenBigMushroom(Blocks.BROWN_MUSHROOM_BLOCK);
}
else if (this == Blocks.RED_MUSHROOM)
{
worldgenerator = new WorldGenBigMushroom(Blocks.RED_MUSHROOM_BLOCK);
}
if (worldgenerator != null && worldgenerator.generate(worldIn, rand, pos))
{
return true;
}
else
{
worldIn.setBlockState(pos, state, 3);
return false;
}
}
/**
* Whether this IGrowable can grow
*/
public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
{
return true;
}
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
return (double)rand.nextFloat() < 0.4D;
}
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
this.generateBigMushroom(worldIn, pos, state, rand);
}
}

View File

@@ -0,0 +1,102 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockMycelium extends Block
{
public static final PropertyBool SNOWY = PropertyBool.create("snowy");
protected BlockMycelium()
{
super(Material.GRASS, MapColor.PURPLE);
this.setDefaultState(this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)));
this.setTickRandomly(true);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
* metadata, such as fence connections.
*/
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
Block block = worldIn.getBlockState(pos.up()).getBlock();
return state.withProperty(SNOWY, Boolean.valueOf(block == Blocks.SNOW || block == Blocks.SNOW_LAYER));
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isRemote)
{
if (!worldIn.isAreaLoaded(pos, 2)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light and spreading
if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2)
{
worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
}
else
{
if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
{
for (int i = 0; i < 4; ++i)
{
BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
IBlockState iblockstate = worldIn.getBlockState(blockpos);
IBlockState iblockstate1 = worldIn.getBlockState(blockpos.up());
if (iblockstate.getBlock() == Blocks.DIRT && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate1.getLightOpacity(worldIn, blockpos.up()) <= 2)
{
worldIn.setBlockState(blockpos, this.getDefaultState());
}
}
}
}
}
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
super.randomDisplayTick(stateIn, worldIn, pos, rand);
if (rand.nextInt(10) == 0)
{
worldIn.spawnParticle(EnumParticleTypes.TOWN_AURA, (double)((float)pos.getX() + rand.nextFloat()), (double)((float)pos.getY() + 1.1F), (double)((float)pos.getZ() + rand.nextFloat()), 0.0D, 0.0D, 0.0D);
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Blocks.DIRT.getItemDropped(Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT), rand, fortune);
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return 0;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {SNOWY});
}
}

View File

@@ -0,0 +1,25 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
public class BlockNetherBrick extends Block
{
public BlockNetherBrick()
{
super(Material.ROCK);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.NETHERRACK;
}
}

View File

@@ -0,0 +1,151 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockNetherWart extends BlockBush
{
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 3);
private static final AxisAlignedBB[] NETHER_WART_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.3125D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.6875D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.875D, 1.0D)};
protected BlockNetherWart()
{
super(Material.PLANTS, MapColor.RED);
this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0)));
this.setTickRandomly(true);
this.setCreativeTab((CreativeTabs)null);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return NETHER_WART_AABB[((Integer)state.getValue(AGE)).intValue()];
}
/**
* Return true if the block can sustain a Bush
*/
protected boolean canSustainBush(IBlockState state)
{
return state.getBlock() == Blocks.SOUL_SAND;
}
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
return super.canBlockStay(worldIn, pos, state);
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
int i = ((Integer)state.getValue(AGE)).intValue();
if (i < 3 && net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt(10) == 0))
{
IBlockState newState = state.withProperty(AGE, Integer.valueOf(i + 1));
worldIn.setBlockState(pos, newState, 2);
net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, newState);
}
super.updateTick(worldIn, pos, state, rand);
}
/**
* Spawns this Block's drops into the World as EntityItems.
*/
@SuppressWarnings("unused")
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
if (false && !worldIn.isRemote)
{
int i = 1;
if (((Integer)state.getValue(AGE)).intValue() >= 3)
{
i = 2 + worldIn.rand.nextInt(3);
if (fortune > 0)
{
i += worldIn.rand.nextInt(fortune + 1);
}
}
for (int j = 0; j < i; ++j)
{
spawnAsEntity(worldIn, pos, new ItemStack(Items.NETHER_WART));
}
}
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Items.AIR;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random)
{
return 0;
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(Items.NETHER_WART);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(AGE, Integer.valueOf(meta));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((Integer)state.getValue(AGE)).intValue();
}
@Override
public void getDrops(net.minecraft.util.NonNullList<ItemStack> drops, net.minecraft.world.IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
Random rand = world instanceof World ? ((World)world).rand : new Random();
int count = 1;
if (((Integer)state.getValue(AGE)) >= 3)
{
count = 2 + rand.nextInt(3) + (fortune > 0 ? rand.nextInt(fortune + 1) : 0);
}
for (int i = 0; i < count; i++)
{
drops.add(new ItemStack(Items.NETHER_WART));
}
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {AGE});
}
}

View File

@@ -0,0 +1,25 @@
package net.minecraft.block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
public class BlockNetherrack extends Block
{
public BlockNetherrack()
{
super(Material.ROCK);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.NETHERRACK;
}
}

View File

@@ -0,0 +1,132 @@
package net.minecraft.block;
import com.google.common.base.Predicate;
import javax.annotation.Nullable;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockNewLeaf extends BlockLeaves
{
public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class, new Predicate<BlockPlanks.EnumType>()
{
public boolean apply(@Nullable BlockPlanks.EnumType p_apply_1_)
{
return p_apply_1_.getMetadata() >= 4;
}
});
public BlockNewLeaf()
{
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPlanks.EnumType.ACACIA).withProperty(CHECK_DECAY, Boolean.valueOf(true)).withProperty(DECAYABLE, Boolean.valueOf(true)));
}
protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance)
{
if (state.getValue(VARIANT) == BlockPlanks.EnumType.DARK_OAK && worldIn.rand.nextInt(chance) == 0)
{
spawnAsEntity(worldIn, pos, new ItemStack(Items.APPLE));
}
}
/**
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
* returns the metadata of the dropped item based on the old metadata of the block.
*/
public int damageDropped(IBlockState state)
{
return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(this, 1, state.getBlock().getMetaFromState(state) & 3);
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
items.add(new ItemStack(this, 1, 0));
items.add(new ItemStack(this, 1, 1));
}
protected ItemStack getSilkTouchDrop(IBlockState state)
{
return new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4);
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(VARIANT, this.getWoodType(meta)).withProperty(DECAYABLE, Boolean.valueOf((meta & 4) == 0)).withProperty(CHECK_DECAY, Boolean.valueOf((meta & 8) > 0));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4;
if (!((Boolean)state.getValue(DECAYABLE)).booleanValue())
{
i |= 4;
}
if (((Boolean)state.getValue(CHECK_DECAY)).booleanValue())
{
i |= 8;
}
return i;
}
public BlockPlanks.EnumType getWoodType(int meta)
{
return BlockPlanks.EnumType.byMetadata((meta & 3) + 4);
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {VARIANT, CHECK_DECAY, DECAYABLE});
}
/**
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via
* Block.removedByPlayer
*/
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
if (!worldIn.isRemote && stack.getItem() == Items.SHEARS)
{
player.addStat(StatList.getBlockStats(this));
spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4));
}
else
{
super.harvestBlock(worldIn, player, pos, state, te, stack);
}
}
@Override
public NonNullList<ItemStack> onSheared(ItemStack item, net.minecraft.world.IBlockAccess world, BlockPos pos, int fortune)
{
return NonNullList.withSize(1, new ItemStack(this, 1, world.getBlockState(pos).getValue(VARIANT).getMetadata() - 4));
}
}

View File

@@ -0,0 +1,136 @@
package net.minecraft.block;
import com.google.common.base.Predicate;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
public class BlockNewLog extends BlockLog
{
public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class, new Predicate<BlockPlanks.EnumType>()
{
public boolean apply(@Nullable BlockPlanks.EnumType p_apply_1_)
{
return p_apply_1_.getMetadata() >= 4;
}
});
public BlockNewLog()
{
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPlanks.EnumType.ACACIA).withProperty(LOG_AXIS, BlockLog.EnumAxis.Y));
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
BlockPlanks.EnumType blockplanks$enumtype = (BlockPlanks.EnumType)state.getValue(VARIANT);
switch ((BlockLog.EnumAxis)state.getValue(LOG_AXIS))
{
case X:
case Z:
case NONE:
default:
switch (blockplanks$enumtype)
{
case ACACIA:
default:
return MapColor.STONE;
case DARK_OAK:
return BlockPlanks.EnumType.DARK_OAK.getMapColor();
}
case Y:
return blockplanks$enumtype.getMapColor();
}
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
items.add(new ItemStack(this, 1, BlockPlanks.EnumType.ACACIA.getMetadata() - 4));
items.add(new ItemStack(this, 1, BlockPlanks.EnumType.DARK_OAK.getMetadata() - 4));
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockPlanks.EnumType.byMetadata((meta & 3) + 4));
switch (meta & 12)
{
case 0:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Y);
break;
case 4:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.X);
break;
case 8:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Z);
break;
default:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.NONE);
}
return iblockstate;
}
/**
* Convert the BlockState into the correct metadata value
*/
@SuppressWarnings("incomplete-switch")
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4;
switch ((BlockLog.EnumAxis)state.getValue(LOG_AXIS))
{
case X:
i |= 4;
break;
case Z:
i |= 8;
break;
case NONE:
i |= 12;
}
return i;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {VARIANT, LOG_AXIS});
}
protected ItemStack getSilkTouchDrop(IBlockState state)
{
return new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4);
}
/**
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
* returns the metadata of the dropped item based on the old metadata of the block.
*/
public int damageDropped(IBlockState state)
{
return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata() - 4;
}
}

View File

@@ -0,0 +1,142 @@
package net.minecraft.block;
import com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityNote;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockNote extends BlockContainer
{
private static final List<SoundEvent> INSTRUMENTS = Lists.newArrayList(SoundEvents.BLOCK_NOTE_HARP, SoundEvents.BLOCK_NOTE_BASEDRUM, SoundEvents.BLOCK_NOTE_SNARE, SoundEvents.BLOCK_NOTE_HAT, SoundEvents.BLOCK_NOTE_BASS, SoundEvents.BLOCK_NOTE_FLUTE, SoundEvents.BLOCK_NOTE_BELL, SoundEvents.BLOCK_NOTE_GUITAR, SoundEvents.BLOCK_NOTE_CHIME, SoundEvents.BLOCK_NOTE_XYLOPHONE);
public BlockNote()
{
super(Material.WOOD);
this.setCreativeTab(CreativeTabs.REDSTONE);
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
boolean flag = worldIn.isBlockPowered(pos);
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityNote)
{
TileEntityNote tileentitynote = (TileEntityNote)tileentity;
if (tileentitynote.previousRedstoneState != flag)
{
if (flag)
{
tileentitynote.triggerNote(worldIn, pos);
}
tileentitynote.previousRedstoneState = flag;
}
}
}
/**
* Called when the block is right clicked by a player.
*/
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
else
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityNote)
{
TileEntityNote tileentitynote = (TileEntityNote)tileentity;
int old = tileentitynote.note;
tileentitynote.changePitch();
if (old == tileentitynote.note) return false;
tileentitynote.triggerNote(worldIn, pos);
playerIn.addStat(StatList.NOTEBLOCK_TUNED);
}
return true;
}
}
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn)
{
if (!worldIn.isRemote)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityNote)
{
((TileEntityNote)tileentity).triggerNote(worldIn, pos);
playerIn.addStat(StatList.NOTEBLOCK_PLAYED);
}
}
}
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityNote();
}
private SoundEvent getInstrument(int eventId)
{
if (eventId < 0 || eventId >= INSTRUMENTS.size())
{
eventId = 0;
}
return INSTRUMENTS.get(eventId);
}
/**
* Called on server when World#addBlockEvent is called. If server returns true, then also called on the client. On
* the Server, this may perform additional changes to the world, like pistons replacing the block with an extended
* base. On the client, the update may involve replacing tile entities or effects such as sounds or particles
*/
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param)
{
net.minecraftforge.event.world.NoteBlockEvent.Play e = new net.minecraftforge.event.world.NoteBlockEvent.Play(worldIn, pos, state, param, id);
if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(e)) return false;
id = e.getInstrument().ordinal();
param = e.getVanillaNoteId();
float f = (float)Math.pow(2.0D, (double)(param - 12) / 12.0D);
worldIn.playSound((EntityPlayer)null, pos, this.getInstrument(id), SoundCategory.RECORDS, 3.0F, f);
worldIn.spawnParticle(EnumParticleTypes.NOTE, (double)pos.getX() + 0.5D, (double)pos.getY() + 1.2D, (double)pos.getZ() + 0.5D, (double)param / 24.0D, 0.0D, 0.0D);
return true;
}
/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}
}

View File

@@ -0,0 +1,188 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockObserver extends BlockDirectional
{
public static final PropertyBool POWERED = PropertyBool.create("powered");
public BlockObserver()
{
super(Material.ROCK);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.SOUTH).withProperty(POWERED, Boolean.valueOf(false)));
this.setCreativeTab(CreativeTabs.REDSTONE);
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING, POWERED});
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (((Boolean)state.getValue(POWERED)).booleanValue())
{
worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)), 2);
}
else
{
worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)), 2);
worldIn.scheduleUpdate(pos, this, 2);
}
this.updateNeighborsInFront(worldIn, pos, state);
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
}
public void observedNeighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if (!worldIn.isRemote && pos.offset((EnumFacing)state.getValue(FACING)).equals(fromPos))
{
this.startSignal(state, worldIn, pos);
}
}
private void startSignal(IBlockState p_190960_1_, World p_190960_2_, BlockPos pos)
{
if (!((Boolean)p_190960_1_.getValue(POWERED)).booleanValue())
{
if (!p_190960_2_.isUpdateScheduled(pos, this))
{
p_190960_2_.scheduleUpdate(pos, this, 2);
}
}
}
protected void updateNeighborsInFront(World worldIn, BlockPos pos, IBlockState state)
{
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
BlockPos blockpos = pos.offset(enumfacing.getOpposite());
worldIn.neighborChanged(blockpos, this, pos);
worldIn.notifyNeighborsOfStateExcept(blockpos, this, enumfacing);
}
/**
* Can this block provide power. Only wire currently seems to have this change based on its state.
*/
public boolean canProvidePower(IBlockState state)
{
return true;
}
public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return blockState.getWeakPower(blockAccess, pos, side);
}
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
return ((Boolean)blockState.getValue(POWERED)).booleanValue() && blockState.getValue(FACING) == side ? 15 : 0;
}
/**
* Called after the block is set in the Chunk data, but before the Tile Entity is set
*/
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
if (!worldIn.isRemote)
{
if (((Boolean)state.getValue(POWERED)).booleanValue())
{
this.updateTick(worldIn, pos, state, worldIn.rand);
}
this.startSignal(state, worldIn, pos);
}
}
/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
if (((Boolean)state.getValue(POWERED)).booleanValue() && worldIn.isUpdateScheduled(pos, this))
{
this.updateNeighborsInFront(worldIn, pos, state.withProperty(POWERED, Boolean.valueOf(false)));
}
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getDefaultState().withProperty(FACING, EnumFacing.getDirectionFromEntityLiving(pos, placer).getOpposite());
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((EnumFacing)state.getValue(FACING)).getIndex();
if (((Boolean)state.getValue(POWERED)).booleanValue())
{
i |= 8;
}
return i;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta & 7));
}
/* ======================================== FORGE START =====================================*/
@Override
public void observedNeighborChange(IBlockState observerState, World world, BlockPos observerPos, Block changedBlock, BlockPos changedBlockPos)
{
observedNeighborChanged(observerState, world, observerPos, changedBlock, changedBlockPos);
}
/* ========================================= FORGE END ======================================*/
}

View File

@@ -0,0 +1,36 @@
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
public class BlockObsidian extends Block
{
public BlockObsidian()
{
super(Material.ROCK);
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(Blocks.OBSIDIAN);
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return MapColor.BLACK;
}
}

View File

@@ -0,0 +1,133 @@
package net.minecraft.block;
import com.google.common.base.Predicate;
import javax.annotation.Nullable;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockOldLeaf extends BlockLeaves
{
public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class, new Predicate<BlockPlanks.EnumType>()
{
public boolean apply(@Nullable BlockPlanks.EnumType p_apply_1_)
{
return p_apply_1_.getMetadata() < 4;
}
});
public BlockOldLeaf()
{
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPlanks.EnumType.OAK).withProperty(CHECK_DECAY, Boolean.valueOf(true)).withProperty(DECAYABLE, Boolean.valueOf(true)));
}
protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance)
{
if (state.getValue(VARIANT) == BlockPlanks.EnumType.OAK && worldIn.rand.nextInt(chance) == 0)
{
spawnAsEntity(worldIn, pos, new ItemStack(Items.APPLE));
}
}
protected int getSaplingDropChance(IBlockState state)
{
return state.getValue(VARIANT) == BlockPlanks.EnumType.JUNGLE ? 40 : super.getSaplingDropChance(state);
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
items.add(new ItemStack(this, 1, BlockPlanks.EnumType.OAK.getMetadata()));
items.add(new ItemStack(this, 1, BlockPlanks.EnumType.SPRUCE.getMetadata()));
items.add(new ItemStack(this, 1, BlockPlanks.EnumType.BIRCH.getMetadata()));
items.add(new ItemStack(this, 1, BlockPlanks.EnumType.JUNGLE.getMetadata()));
}
protected ItemStack getSilkTouchDrop(IBlockState state)
{
return new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata());
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(VARIANT, this.getWoodType(meta)).withProperty(DECAYABLE, Boolean.valueOf((meta & 4) == 0)).withProperty(CHECK_DECAY, Boolean.valueOf((meta & 8) > 0));
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
if (!((Boolean)state.getValue(DECAYABLE)).booleanValue())
{
i |= 4;
}
if (((Boolean)state.getValue(CHECK_DECAY)).booleanValue())
{
i |= 8;
}
return i;
}
public BlockPlanks.EnumType getWoodType(int meta)
{
return BlockPlanks.EnumType.byMetadata((meta & 3) % 4);
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {VARIANT, CHECK_DECAY, DECAYABLE});
}
/**
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
* returns the metadata of the dropped item based on the old metadata of the block.
*/
public int damageDropped(IBlockState state)
{
return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
}
/**
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via
* Block.removedByPlayer
*/
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
if (!worldIn.isRemote && stack.getItem() == Items.SHEARS)
{
player.addStat(StatList.getBlockStats(this));
}
else
{
super.harvestBlock(worldIn, player, pos, state, te, stack);
}
}
@Override
public NonNullList<ItemStack> onSheared(ItemStack item, net.minecraft.world.IBlockAccess world, BlockPos pos, int fortune)
{
return NonNullList.withSize(1, new ItemStack(this, 1, world.getBlockState(pos).getValue(VARIANT).getMetadata()));
}
}

View File

@@ -0,0 +1,142 @@
package net.minecraft.block;
import com.google.common.base.Predicate;
import javax.annotation.Nullable;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
public class BlockOldLog extends BlockLog
{
public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class, new Predicate<BlockPlanks.EnumType>()
{
public boolean apply(@Nullable BlockPlanks.EnumType p_apply_1_)
{
return p_apply_1_.getMetadata() < 4;
}
});
public BlockOldLog()
{
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPlanks.EnumType.OAK).withProperty(LOG_AXIS, BlockLog.EnumAxis.Y));
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
BlockPlanks.EnumType blockplanks$enumtype = (BlockPlanks.EnumType)state.getValue(VARIANT);
switch ((BlockLog.EnumAxis)state.getValue(LOG_AXIS))
{
case X:
case Z:
case NONE:
default:
switch (blockplanks$enumtype)
{
case OAK:
default:
return BlockPlanks.EnumType.SPRUCE.getMapColor();
case SPRUCE:
return BlockPlanks.EnumType.DARK_OAK.getMapColor();
case BIRCH:
return MapColor.QUARTZ;
case JUNGLE:
return BlockPlanks.EnumType.SPRUCE.getMapColor();
}
case Y:
return blockplanks$enumtype.getMapColor();
}
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
items.add(new ItemStack(this, 1, BlockPlanks.EnumType.OAK.getMetadata()));
items.add(new ItemStack(this, 1, BlockPlanks.EnumType.SPRUCE.getMetadata()));
items.add(new ItemStack(this, 1, BlockPlanks.EnumType.BIRCH.getMetadata()));
items.add(new ItemStack(this, 1, BlockPlanks.EnumType.JUNGLE.getMetadata()));
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockPlanks.EnumType.byMetadata((meta & 3) % 4));
switch (meta & 12)
{
case 0:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Y);
break;
case 4:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.X);
break;
case 8:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Z);
break;
default:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.NONE);
}
return iblockstate;
}
/**
* Convert the BlockState into the correct metadata value
*/
@SuppressWarnings("incomplete-switch")
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
switch ((BlockLog.EnumAxis)state.getValue(LOG_AXIS))
{
case X:
i |= 4;
break;
case Z:
i |= 8;
break;
case NONE:
i |= 12;
}
return i;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {VARIANT, LOG_AXIS});
}
protected ItemStack getSilkTouchDrop(IBlockState state)
{
return new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata());
}
/**
* Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
* returns the metadata of the dropped item based on the old metadata of the block.
*/
public int damageDropped(IBlockState state)
{
return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
}
}

Some files were not shown because too many files have changed in this diff Show More