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

138 lines
6.6 KiB
Java
Raw Normal View History

2015-11-08 18:29:05 +01:00
/*
2016-05-16 22:52:27 +02:00
* This file ("BlockWallAA.java") is part of the Actually Additions mod for Minecraft.
2015-11-08 18:29:05 +01:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-11-08 18:29:05 +01:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 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;
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.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.ItemStack;
import net.minecraft.util.EnumFacing;
2016-11-19 21:11:17 +01:00
import net.minecraft.util.NonNullList;
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;
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
2019-05-02 09:10:29 +02:00
public class BlockWallAA extends BlockBase {
2015-11-08 18:29:05 +01:00
2019-05-02 09:10:29 +02:00
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) };
2016-05-03 21:26:02 +02:00
@SuppressWarnings("deprecation")
2019-05-02 09:10:29 +02:00
public BlockWallAA(String name, Block blocc) {
2018-05-05 10:01:54 +02:00
super(blocc.getDefaultState().getMaterial(), name);
this.setHardness(1.5F);
this.setResistance(10F);
2018-05-05 10:01:54 +02:00
this.setSoundType(blocc.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));
}
2019-05-02 09:10:29 +02:00
private static int yesThisIsCopyPastedFromBlockWallAndIHaveNoIdeaWhatThisMethodDoes(IBlockState state) {
2016-05-02 17:12:31 +02:00
int i = 0;
2019-05-02 09:10:29 +02:00
if (state.getValue(BlockWall.NORTH)) {
2016-05-02 17:12:31 +02:00
i |= 1 << EnumFacing.NORTH.getHorizontalIndex();
}
2019-05-02 09:10:29 +02:00
if (state.getValue(BlockWall.EAST)) {
2016-05-02 17:12:31 +02:00
i |= 1 << EnumFacing.EAST.getHorizontalIndex();
}
2019-05-02 09:10:29 +02:00
if (state.getValue(BlockWall.SOUTH)) {
2016-05-02 17:12:31 +02:00
i |= 1 << EnumFacing.SOUTH.getHorizontalIndex();
}
2019-05-02 09:10:29 +02:00
if (state.getValue(BlockWall.WEST)) {
2016-05-02 17:12:31 +02:00
i |= 1 << EnumFacing.WEST.getHorizontalIndex();
}
return i;
}
@Override
2019-05-02 09:10:29 +02:00
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
2016-05-03 21:26:02 +02:00
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(BlockWall.UP, !flag4 || !worldIn.isAirBlock(pos.up())).withProperty(BlockWall.NORTH, flag).withProperty(BlockWall.EAST, flag1).withProperty(BlockWall.SOUTH, flag2).withProperty(BlockWall.WEST, flag3);
}
@Override
2019-05-02 09:10:29 +02:00
public boolean isFullCube(IBlockState state) {
return false;
}
@Override
2019-05-02 09:10:29 +02:00
public boolean isPassable(IBlockAccess worldIn, BlockPos pos) {
return false;
}
2016-02-01 17:49:55 +01:00
@Override
@SideOnly(Side.CLIENT)
@Deprecated
2019-05-02 09:10:29 +02:00
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
2016-03-18 23:47:22 +01:00
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
2019-05-02 09:10:29 +02:00
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
2016-03-18 23:47:22 +01:00
state = this.getActualState(state, source, pos);
2016-05-03 21:26:02 +02:00
return AABB_BY_INDEX[yesThisIsCopyPastedFromBlockWallAndIHaveNoIdeaWhatThisMethodDoes(state)];
2016-02-01 17:49:55 +01:00
}
2016-05-02 17:09:23 +02:00
@Override
2019-05-02 09:10:29 +02:00
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
2016-03-18 23:47:22 +01:00
blockState = this.getActualState(blockState, worldIn, pos);
2016-05-03 21:26:02 +02:00
return CLIP_AABB_BY_INDEX[yesThisIsCopyPastedFromBlockWallAndIHaveNoIdeaWhatThisMethodDoes(blockState)];
}
2016-03-18 23:47:22 +01:00
@Override
2019-05-02 09:10:29 +02:00
public boolean isOpaqueCube(IBlockState state) {
2016-03-18 23:47:22 +01:00
return false;
}
@Override
2016-02-01 17:49:55 +01:00
@SideOnly(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
2017-06-17 00:48:49 +02:00
list.add(new ItemStack(this, 1, 0));
}
2019-05-02 09:10:29 +02:00
public boolean canConnectTo(IBlockAccess worldIn, BlockPos pos) {
2016-03-18 23:47:22 +01:00
IBlockState state = worldIn.getBlockState(pos);
2016-07-04 20:15:41 +02:00
Block block = state.getBlock();
2019-02-27 19:53:05 +01:00
return block != Blocks.BARRIER && (!(block != this && !(block instanceof BlockFenceGate)) || state.getMaterial().isOpaque() && state.isFullCube() && state.getMaterial() != Material.GOURD);
}
@Override
2019-05-02 09:10:29 +02:00
public IBlockState getStateFromMeta(int meta) {
2016-02-01 17:49:55 +01:00
return this.getDefaultState();
}
@Override
2019-05-02 09:10:29 +02:00
public int getMetaFromState(IBlockState state) {
2016-02-01 17:49:55 +01:00
return 0;
2015-12-19 10:30:39 +01:00
}
@Override
2019-05-02 09:10:29 +02:00
protected BlockStateContainer createBlockState() {
2016-03-18 23:47:22 +01:00
return new BlockStateContainer(this, BlockWall.UP, BlockWall.NORTH, BlockWall.EAST, BlockWall.WEST, BlockWall.SOUTH);
2015-11-08 18:29:05 +01:00
}
}