package com.mrcrayfish.furniture.blocks; import java.util.List; import com.mrcrayfish.furniture.MrCrayfishFurnitureMod; import com.mrcrayfish.furniture.init.FurnitureSounds; import net.minecraft.block.Block; 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.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.BlockRenderLayer; 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.WorldServer; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class BlockTrampoline extends Block { public static final PropertyBool BACK = PropertyBool.create("back"); public static final PropertyBool FORWARD = PropertyBool.create("forward"); public static final PropertyBool LEFT = PropertyBool.create("left"); public static final PropertyBool RIGHT = PropertyBool.create("right"); private static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 13 * 0.0625, 1.0); public BlockTrampoline(Material materialIn) { super(materialIn); this.setHardness(0.5F); this.setDefaultState(this.blockState.getBaseState().withProperty(BACK, false).withProperty(FORWARD, false).withProperty(LEFT, false).withProperty(RIGHT, false)); this.setCreativeTab(MrCrayfishFurnitureMod.tabFurniture); } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return BOUNDING_BOX; } @Override public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean p_185477_7_) { super.addCollisionBoxToList(pos, entityBox, collidingBoxes, BOUNDING_BOX); } @Override public void onLanded(World worldIn, Entity entityIn) {} @Override public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance) { if(entityIn instanceof EntityLivingBase) { float height = entityIn.fallDistance; if(height > 0 && !entityIn.isSneaking()) { if(height > 9) height = 9; entityIn.motionY = 0; entityIn.addVelocity(0, getRequiredVelocity(height + 1), 0); worldIn.playSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, FurnitureSounds.boing, SoundCategory.BLOCKS, 0.75F, 1.0F, false); if(worldIn.isRemote) { for(int i = 0; i < 5; i++) { double offsetX = -0.1 + 0.2 * RANDOM.nextDouble(); double offsetZ = -0.1 + 0.2 * RANDOM.nextDouble(); worldIn.spawnParticle(EnumParticleTypes.SPELL_MOB, entityIn.posX, entityIn.posY, entityIn.posZ, 1, 1, 1, 0); } } } entityIn.fallDistance = 0; } } @Override public boolean addLandingEffects(IBlockState state, WorldServer worldObj, BlockPos blockPosition, IBlockState iblockstate, EntityLivingBase entity, int numberOfParticles) { return true; } public double getRequiredVelocity(float height) { return Math.sqrt(0.22 * height); } @Override public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) { boolean forward = world.getBlockState(pos.north()).getBlock() == this; boolean back = world.getBlockState(pos.south()).getBlock() == this; boolean left = world.getBlockState(pos.west()).getBlock() == this; boolean right = world.getBlockState(pos.east()).getBlock() == this; return state.withProperty(BACK, back).withProperty(FORWARD, forward).withProperty(LEFT, left).withProperty(RIGHT, right); } @Override public int getMetaFromState(IBlockState state) { return 0; } @Override public IBlockState getStateFromMeta(int meta) { return this.getDefaultState(); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] { BACK, FORWARD, LEFT, RIGHT }); } @SideOnly(Side.CLIENT) public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.CUTOUT; } }