154 lines
7.1 KiB
Java
154 lines
7.1 KiB
Java
package WayofTime.bloodmagic.block.base;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockFenceGate;
|
|
import net.minecraft.block.BlockRotatedPillar;
|
|
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.EntityLivingBase;
|
|
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.common.property.ExtendedBlockState;
|
|
import net.minecraftforge.common.property.IUnlistedProperty;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
public class BlockStringWall extends BlockString
|
|
{
|
|
public static final PropertyBool UP = PropertyBool.create("up");
|
|
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");
|
|
protected static final AxisAlignedBB[] AABB_BY_INDEX = new AxisAlignedBB[] { new AxisAlignedBB(0.25D, 0.0D, 0.25D, 0.75D, 1.0D, 0.75D), new AxisAlignedBB(0.25D, 0.0D, 0.25D, 0.75D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.25D, 0.75D, 1.0D, 0.75D), new AxisAlignedBB(0.0D, 0.0D, 0.25D, 0.75D, 1.0D, 1.0D), new AxisAlignedBB(0.25D, 0.0D, 0.0D, 0.75D, 1.0D, 0.75D), new AxisAlignedBB(0.3125D, 0.0D, 0.0D, 0.6875D, 0.875D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.75D, 1.0D, 0.75D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.75D, 1.0D, 1.0D),
|
|
new AxisAlignedBB(0.25D, 0.0D, 0.25D, 1.0D, 1.0D, 0.75D), new AxisAlignedBB(0.25D, 0.0D, 0.25D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.3125D, 1.0D, 0.875D, 0.6875D), new AxisAlignedBB(0.0D, 0.0D, 0.25D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.25D, 0.0D, 0.0D, 1.0D, 1.0D, 0.75D), new AxisAlignedBB(0.25D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.75D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D) };
|
|
protected static final AxisAlignedBB[] CLIP_AABB_BY_INDEX = new AxisAlignedBB[] { AABB_BY_INDEX[0].setMaxY(1.5D), AABB_BY_INDEX[1].setMaxY(1.5D), AABB_BY_INDEX[2].setMaxY(1.5D), AABB_BY_INDEX[3].setMaxY(1.5D), AABB_BY_INDEX[4].setMaxY(1.5D), AABB_BY_INDEX[5].setMaxY(1.5D), AABB_BY_INDEX[6].setMaxY(1.5D), AABB_BY_INDEX[7].setMaxY(1.5D), AABB_BY_INDEX[8].setMaxY(1.5D), AABB_BY_INDEX[9].setMaxY(1.5D), AABB_BY_INDEX[10].setMaxY(1.5D), AABB_BY_INDEX[11].setMaxY(1.5D), AABB_BY_INDEX[12].setMaxY(1.5D), AABB_BY_INDEX[13].setMaxY(1.5D), AABB_BY_INDEX[14].setMaxY(1.5D),
|
|
AABB_BY_INDEX[15].setMaxY(1.5D) };
|
|
|
|
// Most of this is copied from BlockWall - if there is an issue when porting, look there first.
|
|
public BlockStringWall(Material material, String[] values, String propName)
|
|
{
|
|
super(material, values, propName);
|
|
}
|
|
|
|
public BlockStringWall(Material material, String[] values)
|
|
{
|
|
this(material, values, "type");
|
|
}
|
|
|
|
@Override
|
|
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
|
|
{
|
|
state = state.getActualState(source, pos);
|
|
return AABB_BY_INDEX[getAABBIndex(state)];
|
|
}
|
|
|
|
@Override
|
|
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos)
|
|
{
|
|
blockState = blockState.getActualState(worldIn, pos);
|
|
return CLIP_AABB_BY_INDEX[getAABBIndex(blockState)];
|
|
}
|
|
|
|
private static int getAABBIndex(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;
|
|
}
|
|
|
|
public boolean isFullCube(IBlockState state)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isOpaqueCube(IBlockState state)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
private boolean canConnectTo(IBlockAccess worldIn, BlockPos pos)
|
|
{
|
|
IBlockState iblockstate = worldIn.getBlockState(pos);
|
|
Block block = iblockstate.getBlock();
|
|
return block == Blocks.BARRIER ? false : (block != this && !(block instanceof BlockFenceGate) ? (iblockstate.getMaterial().isOpaque() && iblockstate.isFullCube() ? iblockstate.getMaterial() != Material.GOURD : false) : true);
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
@Override
|
|
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
|
|
{
|
|
return side == EnumFacing.DOWN ? super.shouldSideBeRendered(blockState, blockAccess, pos, side) : true;
|
|
}
|
|
|
|
@Override
|
|
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
|
|
{
|
|
boolean flag = this.canConnectTo(worldIn, pos.north());
|
|
boolean flag1 = this.canConnectTo(worldIn, pos.east());
|
|
boolean flag2 = this.canConnectTo(worldIn, pos.south());
|
|
boolean flag3 = this.canConnectTo(worldIn, pos.west());
|
|
boolean flag4 = flag && !flag1 && flag2 && !flag3 || !flag && flag1 && !flag2 && flag3;
|
|
return state.withProperty(UP, Boolean.valueOf(!flag4 || !worldIn.isAirBlock(pos.up()))).withProperty(NORTH, Boolean.valueOf(flag)).withProperty(EAST, Boolean.valueOf(flag1)).withProperty(SOUTH, Boolean.valueOf(flag2)).withProperty(WEST, Boolean.valueOf(flag3));
|
|
}
|
|
|
|
@Override
|
|
protected void setupStates()
|
|
{
|
|
this.setDefaultState(getExtendedBlockState().withProperty(this.getUnlistedStringProp(), this.getValues().get(0)).withProperty(this.getStringProp(), this.getValues().get(0)).withProperty(UP, true).withProperty(NORTH, false).withProperty(SOUTH, false).withProperty(EAST, false).withProperty(WEST, false));
|
|
}
|
|
|
|
@Override
|
|
protected BlockStateContainer createRealBlockState()
|
|
{
|
|
return new ExtendedBlockState(this, new IProperty[] { UP, NORTH, SOUTH, EAST, WEST, this.getStringProp() }, new IUnlistedProperty[] { this.getUnlistedStringProp() });
|
|
}
|
|
|
|
@Override
|
|
protected ItemStack createStackedBlock(IBlockState state)
|
|
{
|
|
return new ItemStack(Item.getItemFromBlock(this), 1, this.getValues().indexOf(String.valueOf(state.getValue(this.getStringProp()))));
|
|
}
|
|
|
|
@Override
|
|
public int damageDropped(IBlockState state)
|
|
{
|
|
return this.getValues().indexOf(String.valueOf(state.getValue(this.getStringProp())));
|
|
}
|
|
}
|