MOre work on blocks. Less then 1200 errors left

This commit is contained in:
drcrazy 2019-02-21 18:21:40 +03:00
parent 93cf0a97d5
commit 0b0435a1a2
7 changed files with 77 additions and 217 deletions

View file

@ -24,11 +24,12 @@
package techreborn.blocks.lighting;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@ -39,7 +40,6 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import reborncore.api.ToolManager;
@ -61,8 +61,8 @@ public class BlockLamp extends BaseTileBlock {
private int brightness;
public BlockLamp(int brightness, int cost, double depth, double width) {
super(Material.REDSTONE_LIGHT);
this.setDefaultState(this.blockState.getBaseState().with(FACING, EnumFacing.NORTH).with(ACTIVE, false));
super(Block.Properties.create(Material.REDSTONE_LIGHT));
this.setDefaultState(this.stateContainer.getBaseState().with(FACING, EnumFacing.NORTH).with(ACTIVE, false));
this.bbs = GenBoundingBoxes(depth, width);
this.cost = cost;
this.brightness = brightness;
@ -83,14 +83,11 @@ public class BlockLamp extends BaseTileBlock {
}
public static boolean isActive(IBlockState state) {
return state.getValue(ACTIVE);
return state.get(ACTIVE);
}
public static EnumFacing getFacing(IBlockState state) {
if(!state.getProperties().containsKey(FACING)){
return EnumFacing.NORTH;
}
return state.getValue(FACING);
return state.get(FACING);
}
public static void setFacing(EnumFacing facing, World world, BlockPos pos) {
@ -98,7 +95,7 @@ public class BlockLamp extends BaseTileBlock {
}
public static void setActive(Boolean active, World world, BlockPos pos) {
EnumFacing facing = (EnumFacing)world.getBlockState(pos).getValue(FACING);
EnumFacing facing = (EnumFacing)world.getBlockState(pos).get(FACING);
IBlockState state = world.getBlockState(pos).with(ACTIVE, active).with(FACING, facing);
world.setBlockState(pos, state, 3);
}
@ -115,21 +112,21 @@ public class BlockLamp extends BaseTileBlock {
// Block
@Override
protected BlockStateContainer createBlockState() {
FACING = DirectionProperty.create("facing");
protected void fillStateContainer(StateContainer.Builder<Block, IBlockState> builder) {
FACING = DirectionProperty.create("facing", EnumFacing.Plane.HORIZONTAL);
ACTIVE = BooleanProperty.create("active");
return new BlockStateContainer(this, FACING, ACTIVE);
builder.add(FACING, ACTIVE);
}
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
return this.getDefaultState().with(FACING, facing);
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
setFacing(placer.getHorizontalFacing().getOpposite(), worldIn, pos);
}
@Override
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) {
return state.getValue(ACTIVE) ? brightness : 0;
public int getLightValue(IBlockState state) {
return state.get(ACTIVE) ? brightness : 0;
}
@Override
@ -143,7 +140,7 @@ public class BlockLamp extends BaseTileBlock {
}
@Override
public BlockFaceShape getBlockFaceShape(IBlockAccess access, IBlockState state, BlockPos pos, EnumFacing facing) {
public BlockFaceShape getBlockFaceShape(IBlockReader worldIn, IBlockState state, BlockPos pos, EnumFacing facing) {
// This makes only the back face of lamps connect to fences.
if (getFacing(state).getOpposite() == facing)
return BlockFaceShape.SOLID;
@ -152,10 +149,11 @@ public class BlockLamp extends BaseTileBlock {
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockReader worldIn, BlockPos pos) {
return this.bbs[getFacing(state).getIndex()];
}
@SuppressWarnings("deprecation")
@Override
public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
@ -174,18 +172,4 @@ public class BlockLamp extends BaseTileBlock {
return super.onBlockActivated(state, worldIn, pos, playerIn, hand, side, hitX, hitY, hitZ);
}
@Override
public int getMetaFromState(IBlockState state) {
int facingInt = state.getValue(FACING).getIndex();
int activeInt = state.getValue(ACTIVE) ? 8 : 0;
return facingInt + activeInt;
}
@Override
public IBlockState getStateFromMeta(int meta) {
Boolean active = (meta&8)==8;
EnumFacing facing = EnumFacing.byIndex(meta&7);
return this.getDefaultState().with(FACING, facing).with(ACTIVE, active);
}
}