From a62e377801e3654e1ae90e2b9922abe9325caf91 Mon Sep 17 00:00:00 2001 From: Nicholas Ignoffo Date: Mon, 5 Sep 2016 11:40:25 -0700 Subject: [PATCH] Walls render in inventory now Includes a bit of cleanup and fixes pickblock on Pillars and Caps --- .../bloodmagic/block/BlockDemonWallBase.java | 14 ++------ .../block/base/BlockStringPillar.java | 32 ++++++++++------- .../block/base/BlockStringPillarCap.java | 34 ++++++++----------- .../block/base/BlockStringWall.java | 32 ++++++++--------- 4 files changed, 52 insertions(+), 60 deletions(-) diff --git a/src/main/java/WayofTime/bloodmagic/block/BlockDemonWallBase.java b/src/main/java/WayofTime/bloodmagic/block/BlockDemonWallBase.java index 6c6b9610..b4b02adc 100644 --- a/src/main/java/WayofTime/bloodmagic/block/BlockDemonWallBase.java +++ b/src/main/java/WayofTime/bloodmagic/block/BlockDemonWallBase.java @@ -37,18 +37,8 @@ public class BlockDemonWallBase extends BlockStringWall implements IVariantProvi { List> ret = new ArrayList>(); - for (int i = 0; i < 32; i++) - { - boolean up = (i & 1) == 0; - boolean north = (i & 2) == 2; - boolean south = (i & 4) == 4; - boolean east = (i & 8) == 8; - boolean west = (i & 16) == 16; - for (int j = 0; j < names.length; j++) - { - ret.add(new ImmutablePair(i * names.length + j, "up=" + (up ? "true" : "false") + ",north=" + (north ? "true" : "false") + ",south=" + (south ? "true" : "false") + ",east=" + (east ? "true" : "false") + ",west=" + (west ? "true" : "false") + ",type=" + names[j])); - } - } + for (int i = 0; i < names.length; i++) + ret.add(Pair.of(i, "east=false,north=false,south=false,type=" + names[i] + ",up=true,west=false")); return ret; } diff --git a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillar.java b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillar.java index a0c67ab8..3f07047e 100644 --- a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillar.java +++ b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillar.java @@ -6,11 +6,12 @@ import net.minecraft.block.properties.IProperty; 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.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.IUnlistedProperty; @@ -30,35 +31,40 @@ public class BlockStringPillar extends BlockString @Override public IBlockState getStateFromMeta(int meta) { - IBlockState iblockstate = getBlockState().getBaseState().withProperty(this.getStringProp(), this.getValues().get(meta % 5)); + IBlockState state = getBlockState().getBaseState().withProperty(this.getStringProp(), this.getValues().get(meta % 5)); switch (meta / 5) { case 0: - iblockstate = iblockstate.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.Y); + state = state.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.Y); break; case 1: - iblockstate = iblockstate.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.X); + state = state.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.X); break; case 2: - iblockstate = iblockstate.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.Z); + state = state.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.Z); break; default: - iblockstate.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.Y); + state.withProperty(BlockRotatedPillar.AXIS, EnumFacing.Axis.Y); break; } - return iblockstate; + return state; + } + + @Override + public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) + { + return new ItemStack(this, 1, damageDropped(state)); } @SuppressWarnings("incomplete-switch") @Override public int getMetaFromState(IBlockState state) { - int i = 0; - i = this.getValues().indexOf(String.valueOf(state.getValue(this.getStringProp()))); + int i = this.getValues().indexOf(state.getValue(this.getStringProp())); - switch ((EnumFacing.Axis) state.getValue(BlockRotatedPillar.AXIS)) + switch (state.getValue(BlockRotatedPillar.AXIS)) { case X: i = i + 5; @@ -72,7 +78,7 @@ public class BlockStringPillar extends BlockString } @Override - public boolean rotateBlock(net.minecraft.world.World world, BlockPos pos, EnumFacing axis) + public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) { IBlockState state = world.getBlockState(pos); for (IProperty prop : state.getProperties().keySet()) @@ -123,7 +129,7 @@ public class BlockStringPillar extends BlockString @Override protected ItemStack createStackedBlock(IBlockState state) { - return new ItemStack(Item.getItemFromBlock(this), 1, this.getValues().indexOf(String.valueOf(state.getValue(this.getStringProp())))); + return new ItemStack(this, 1, damageDropped(state)); } @Override @@ -135,6 +141,6 @@ public class BlockStringPillar extends BlockString @Override public int damageDropped(IBlockState state) { - return this.getValues().indexOf(String.valueOf(state.getValue(this.getStringProp()))); + return this.getValues().indexOf(state.getValue(this.getStringProp())); } } diff --git a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillarCap.java b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillarCap.java index 502f4e1b..eded7d9c 100644 --- a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillarCap.java +++ b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringPillarCap.java @@ -6,12 +6,14 @@ 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.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.IUnlistedProperty; @@ -33,38 +35,33 @@ public class BlockStringPillarCap extends BlockString @Override public IBlockState getStateFromMeta(int meta) { - IBlockState iblockstate = getBlockState().getBaseState().withProperty(this.getStringProp(), this.getValues().get(meta % 2)); - - int index = meta / 2; - EnumFacing facing = EnumFacing.getFront(index); - iblockstate = iblockstate.withProperty(FACING, facing); - - return iblockstate; + IBlockState state = getBlockState().getBaseState().withProperty(this.getStringProp(), this.getValues().get(meta % 2)); + return state.withProperty(FACING, EnumFacing.getFront(meta / 2)); } @Override public int getMetaFromState(IBlockState state) { - int i = 0; - i = this.getValues().indexOf(String.valueOf(state.getValue(this.getStringProp()))); + int i = this.getValues().indexOf(state.getValue(this.getStringProp())); + return i + 2 * state.getValue(FACING).getIndex(); + } - EnumFacing facing = (EnumFacing) state.getValue(FACING); - int index = facing.getIndex(); - i = i + 2 * index; - - return i; + @Override + public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) + { + return new ItemStack(this, 1, damageDropped(state)); } @Override public IBlockState withRotation(IBlockState state, Rotation rot) { - return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING))); + return state.withProperty(FACING, rot.rotate(state.getValue(FACING))); } @Override public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { - return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING))); + return state.withRotation(mirrorIn.toRotation(state.getValue(FACING))); } @Override @@ -82,19 +79,18 @@ public class BlockStringPillarCap extends BlockString @Override protected ItemStack createStackedBlock(IBlockState state) { - return new ItemStack(Item.getItemFromBlock(this), 1, this.getValues().indexOf(String.valueOf(state.getValue(this.getStringProp())))); + return new ItemStack(this, 1, damageDropped(state)); } @Override public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { - System.out.println("Facing: " + facing); return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(FACING, facing); } @Override public int damageDropped(IBlockState state) { - return this.getValues().indexOf(String.valueOf(state.getValue(this.getStringProp()))); + return this.getValues().indexOf(state.getValue(this.getStringProp())); } } diff --git a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringWall.java b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringWall.java index 8c2bc750..af061879 100644 --- a/src/main/java/WayofTime/bloodmagic/block/base/BlockStringWall.java +++ b/src/main/java/WayofTime/bloodmagic/block/base/BlockStringWall.java @@ -63,22 +63,22 @@ public class BlockStringWall extends BlockString { int i = 0; - if (((Boolean) state.getValue(NORTH)).booleanValue()) + if (state.getValue(NORTH)) { i |= 1 << EnumFacing.NORTH.getHorizontalIndex(); } - if (((Boolean) state.getValue(EAST)).booleanValue()) + if (state.getValue(EAST)) { i |= 1 << EnumFacing.EAST.getHorizontalIndex(); } - if (((Boolean) state.getValue(SOUTH)).booleanValue()) + if (state.getValue(SOUTH)) { i |= 1 << EnumFacing.SOUTH.getHorizontalIndex(); } - if (((Boolean) state.getValue(WEST)).booleanValue()) + if (state.getValue(WEST)) { i |= 1 << EnumFacing.WEST.getHorizontalIndex(); } @@ -104,27 +104,27 @@ public class BlockStringWall extends BlockString 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); + IBlockState worldState = worldIn.getBlockState(pos); + Block block = worldState.getBlock(); + return block != Blocks.BARRIER && (!(block != this && !(block instanceof BlockFenceGate)) || ((worldState.getMaterial().isOpaque() && worldState.isFullCube()) && worldState.getMaterial() != Material.GOURD)); } @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; + return side != EnumFacing.DOWN || super.shouldSideBeRendered(blockState, blockAccess, pos, side); } @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)); + boolean canNorth = this.canConnectTo(worldIn, pos.north()); + boolean canEast = this.canConnectTo(worldIn, pos.east()); + boolean canSouth = this.canConnectTo(worldIn, pos.south()); + boolean canWest = this.canConnectTo(worldIn, pos.west()); + boolean flag4 = canNorth && !canEast && canSouth && !canWest || !canNorth && canEast && !canSouth && canWest; + return state.withProperty(UP, !flag4 || !worldIn.isAirBlock(pos.up())).withProperty(NORTH, canNorth).withProperty(EAST, canEast).withProperty(SOUTH, canSouth).withProperty(WEST, canWest); } @Override @@ -142,12 +142,12 @@ public class BlockStringWall extends BlockString @Override protected ItemStack createStackedBlock(IBlockState state) { - return new ItemStack(Item.getItemFromBlock(this), 1, this.getValues().indexOf(String.valueOf(state.getValue(this.getStringProp())))); + return new ItemStack(this, 1, damageDropped(state)); } @Override public int damageDropped(IBlockState state) { - return this.getValues().indexOf(String.valueOf(state.getValue(this.getStringProp()))); + return this.getValues().indexOf(state.getValue(this.getStringProp())); } }