ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockWallAA.java

152 lines
6.6 KiB
Java
Raw Normal View History

2015-11-08 18:29:05 +01:00
/*
* This file ("BlockWallAA.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-01-03 16:05:51 +01:00
* http://ellpeck.de/actaddlicense/
2015-11-08 18:29:05 +01:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-01-03 16:05:51 +01:00
* © 2016 Ellpeck
2015-11-08 18:29:05 +01:00
*/
2016-03-18 18:38:39 +01:00
package de.ellpeck.actuallyadditions.mod.blocks;
2015-11-08 18:29:05 +01:00
2016-03-18 18:38:39 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBase;
2016-03-18 15:42:06 +01:00
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
2015-11-08 18:29:05 +01:00
import net.minecraft.block.Block;
import net.minecraft.block.BlockFenceGate;
2015-11-08 18:29:05 +01:00
import net.minecraft.block.BlockWall;
import net.minecraft.block.material.Material;
2016-03-18 23:47:22 +01:00
import net.minecraft.block.state.BlockStateBase;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
2015-11-08 18:29:05 +01:00
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
2015-11-08 18:29:05 +01:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-11-08 18:29:05 +01:00
import java.util.List;
public class BlockWallAA extends BlockBase{
2015-11-08 18:29:05 +01:00
2015-12-17 20:18:22 +01:00
private int meta;
2015-11-08 18:29:05 +01:00
2015-12-19 10:30:39 +01:00
public BlockWallAA(String name, Block base){
this(name, base, 0);
}
2016-03-18 23:47:22 +01:00
protected static final AxisAlignedBB[] field_185751_g = 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[] field_185750_B = new AxisAlignedBB[]{field_185751_g[0].setMaxY(1.5D), field_185751_g[1].setMaxY(1.5D), field_185751_g[2].setMaxY(1.5D), field_185751_g[3].setMaxY(1.5D), field_185751_g[4].setMaxY(1.5D), field_185751_g[5].setMaxY(1.5D), field_185751_g[6].setMaxY(1.5D), field_185751_g[7].setMaxY(1.5D), field_185751_g[8].setMaxY(1.5D), field_185751_g[9].setMaxY(1.5D), field_185751_g[10].setMaxY(1.5D), field_185751_g[11].setMaxY(1.5D), field_185751_g[12].setMaxY(1.5D), field_185751_g[13].setMaxY(1.5D), field_185751_g[14].setMaxY(1.5D), field_185751_g[15].setMaxY(1.5D)};
2015-12-17 20:18:22 +01:00
public BlockWallAA(String name, Block base, int meta){
2016-03-18 23:47:22 +01:00
super(base.getMaterial(base.getDefaultState()), name);
2015-12-17 20:18:22 +01:00
this.meta = meta;
this.setHardness(1.5F);
this.setResistance(10F);
2016-04-20 21:39:03 +02:00
this.setSoundType(base.getSoundType());
this.setDefaultState(this.blockState.getBaseState().withProperty(BlockWall.UP, false).withProperty(BlockWall.NORTH, false).withProperty(BlockWall.EAST, false).withProperty(BlockWall.SOUTH, false).withProperty(BlockWall.WEST, false));
}
@Override
2016-02-01 17:49:55 +01:00
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos){
return state.withProperty(BlockWall.UP, !worldIn.isAirBlock(pos.up())).withProperty(BlockWall.NORTH, this.canConnectTo(worldIn, pos.north())).withProperty(BlockWall.EAST, this.canConnectTo(worldIn, pos.east())).withProperty(BlockWall.SOUTH, this.canConnectTo(worldIn, pos.south())).withProperty(BlockWall.WEST, this.canConnectTo(worldIn, pos.west()));
}
@Override
2016-03-18 23:47:22 +01:00
public boolean isFullCube(IBlockState state){
return false;
}
@Override
public boolean isPassable(IBlockAccess worldIn, BlockPos pos){
return false;
}
2016-02-01 17:49:55 +01:00
@Override
@SideOnly(Side.CLIENT)
2016-03-18 23:47:22 +01:00
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side){
return side != EnumFacing.DOWN || super.shouldSideBeRendered(blockState, blockAccess, pos, side);
2016-02-01 17:49:55 +01:00
}
2016-05-02 17:09:23 +02:00
@Override
2016-03-18 23:47:22 +01:00
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos){
state = this.getActualState(state, source, pos);
return field_185751_g[figureOutSomeWallStuff(state)];
2016-02-01 17:49:55 +01:00
}
2016-05-02 17:09:23 +02:00
@Override
2016-03-18 23:47:22 +01:00
public AxisAlignedBB getSelectedBoundingBox(IBlockState blockState, World worldIn, BlockPos pos){
blockState = this.getActualState(blockState, worldIn, pos);
return field_185750_B[figureOutSomeWallStuff(blockState)];
}
2016-03-18 23:47:22 +01:00
private static int figureOutSomeWallStuff(IBlockState state){
int i = 0;
2016-02-01 17:49:55 +01:00
2016-03-18 23:47:22 +01:00
if(state.getValue(BlockWall.NORTH)){
i |= 1 << EnumFacing.NORTH.getHorizontalIndex();
}
2016-03-18 23:47:22 +01:00
if(state.getValue(BlockWall.EAST)){
i |= 1 << EnumFacing.EAST.getHorizontalIndex();
}
2016-01-08 16:52:53 +01:00
2016-03-18 23:47:22 +01:00
if(state.getValue(BlockWall.SOUTH)){
i |= 1 << EnumFacing.SOUTH.getHorizontalIndex();
}
2016-03-18 23:47:22 +01:00
if(state.getValue(BlockWall.WEST)){
i |= 1 << EnumFacing.WEST.getHorizontalIndex();
}
2016-03-18 23:47:22 +01:00
return i;
}
@Override
public boolean isOpaqueCube(IBlockState state){
return false;
}
@Override
public int damageDropped(IBlockState state){
return meta;
2016-01-08 20:51:03 +01:00
}
2016-02-01 17:49:55 +01:00
@SuppressWarnings("unchecked")
@Override
2016-02-01 17:49:55 +01:00
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs tab, List list){
list.add(new ItemStack(item, 1, 0));
}
public boolean canConnectTo(IBlockAccess worldIn, BlockPos pos){
2016-03-18 15:42:06 +01:00
Block block = PosUtil.getBlock(pos, worldIn);
2016-03-18 23:47:22 +01:00
IBlockState state = worldIn.getBlockState(pos);
2016-04-20 21:39:03 +02:00
return block != Blocks.BARRIER && (!(block != this && !(block instanceof BlockFenceGate)) || ((block.getMaterial(state).isOpaque() && block.isFullCube(state)) && block.getMaterial(state) != Material.GOURD));
}
@Override
2016-02-01 17:49:55 +01:00
public IBlockState getStateFromMeta(int meta){
return this.getDefaultState();
}
@Override
2016-02-01 17:49:55 +01:00
public int getMetaFromState(IBlockState state){
return 0;
2015-12-19 10:30:39 +01:00
}
@Override
2016-03-18 23:47:22 +01:00
protected BlockStateContainer createBlockState(){
return new BlockStateContainer(this, BlockWall.UP, BlockWall.NORTH, BlockWall.EAST, BlockWall.WEST, BlockWall.SOUTH);
2015-11-08 18:29:05 +01:00
}
}