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

@ -25,27 +25,23 @@
package techreborn.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.DirectionProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.state.StateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
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.util.math.shapes.VoxelShape;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import reborncore.api.ToolManager;
@ -62,34 +58,34 @@ import java.util.List;
public class BlockAlarm extends BaseTileBlock {
public static DirectionProperty FACING;
public static BooleanProperty ACTIVE;
private AxisAlignedBB[] bbs;
protected final VoxelShape[] shape;
public BlockAlarm() {
super(Block.Properties.create(Material.ROCK));
this.setDefaultState(this.blockState.getBaseState().with(FACING, EnumFacing.NORTH).with(ACTIVE, false));
this.bbs = GenBoundingBoxes(0.19, 0.81);
this.setDefaultState(this.stateContainer.getBaseState().with(FACING, EnumFacing.NORTH).with(ACTIVE, false));
this.shape = GenCuboidShapes(0.19, 0.81);
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/lighting"));
BlockWrenchEventHandler.wrenableBlocks.add(this);
}
private static AxisAlignedBB[] GenBoundingBoxes(double depth, double width) {
AxisAlignedBB[] dimm = {
new AxisAlignedBB(width, 1.0 - depth, width, 1.0 - width, 1.0D, 1.0 - width),
new AxisAlignedBB(width, 0.0D, width, 1.0 - width, depth, 1.0 - width),
new AxisAlignedBB(width, width, 1.0 - depth, 1.0 - width, 1.0 - width, 1.0D),
new AxisAlignedBB(width, width, 0.0D, 1.0 - width, 1.0 - width, depth),
new AxisAlignedBB(1.0 - depth, width, width, 1.0D, 1.0 - width, 1.0 - width),
new AxisAlignedBB(0.0D, width, width, depth, 1.0 - width, 1.0 - width),
private VoxelShape[] GenCuboidShapes(double depth, double width) {
VoxelShape[] shapes = {
Block.makeCuboidShape(width, 1.0 - depth, width, 1.0 - width, 1.0D, 1.0 - width),
Block.makeCuboidShape(width, 0.0D, width, 1.0 - width, depth, 1.0 - width),
Block.makeCuboidShape(width, width, 1.0 - depth, 1.0 - width, 1.0 - width, 1.0D),
Block.makeCuboidShape(width, width, 0.0D, 1.0 - width, 1.0 - width, depth),
Block.makeCuboidShape(1.0 - depth, width, width, 1.0D, 1.0 - width, 1.0 - width),
Block.makeCuboidShape(0.0D, width, width, depth, 1.0 - width, 1.0 - width),
};
return dimm;
return shapes;
}
public static boolean isActive(IBlockState state) {
return state.getValue(ACTIVE);
return state.get(ACTIVE);
}
public static EnumFacing getFacing(IBlockState state) {
return (EnumFacing) state.getValue(FACING);
return (EnumFacing) state.get(FACING);
}
public static void setFacing(EnumFacing facing, World world, BlockPos pos) {
@ -97,18 +93,20 @@ public class BlockAlarm extends BaseTileBlock {
}
public static void setActive(boolean active, World world, BlockPos pos) {
EnumFacing facing = world.getBlockState(pos).getValue(FACING);
EnumFacing facing = world.getBlockState(pos).get(FACING);
IBlockState state = world.getBlockState(pos).with(ACTIVE, active).with(FACING, facing);
world.setBlockState(pos, state, 3);
}
// 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);
}
@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);
@ -140,40 +138,23 @@ public class BlockAlarm extends BaseTileBlock {
return new TileAlarm();
}
@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);
}
@Override
public EnumBlockRenderType getRenderType(IBlockState state) {
return EnumBlockRenderType.MODEL;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Override
public boolean isFullBlock(IBlockState state) {
return false;
}
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return this.bbs[getFacing(state).getIndex()];
}
@Override
public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
tooltip.add(new TextComponentTranslation("techreborn.tooltip.alarm").applyTextStyle(TextFormatting.GRAY));
}
@Override
public VoxelShape getShape(IBlockState state, IBlockReader worldIn, BlockPos pos) {
return shape[getFacing(state).getIndex()];
}
}

View file

@ -30,6 +30,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Rotation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -71,7 +72,7 @@ public class BlockComputerCube extends BlockMachineBase {
return true;
}
else {
rotateBlock(worldIn, pos, side);
rotate(worldIn.getBlockState(pos), worldIn, pos, Rotation.CLOCKWISE_90);
return true;
}
}

View file

@ -82,26 +82,11 @@ public class BlockFlare extends BlockContainer {
}
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().with(COLOR, EnumDyeColor.byMetadata(meta));
}
@Override
public int getMetaFromState(IBlockState state) {
return (state.getValue(COLOR)).getMetadata();
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, COLOR);
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Override
@OnlyIn(Dist.CLIENT)
public BlockRenderLayer getRenderLayer() {

View file

@ -27,15 +27,13 @@ package techreborn.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.state.BooleanProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.state.StateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
@ -50,11 +48,11 @@ import techreborn.entities.EntityNukePrimed;
* Created by Mark on 13/03/2016.
*/
public class BlockNuke extends BaseBlock {
public static final BooleanProperty OVERLAY = BooleanProperty.create("overlay");
public static BooleanProperty OVERLAY = BooleanProperty.create("overlay");
public BlockNuke() {
super(Material.TNT);
this.setDefaultState(this.blockState.getBaseState().with(OVERLAY, false));
super(Block.Properties.create(Material.TNT));
this.setDefaultState(this.stateContainer.getBaseState().with(OVERLAY, false));
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this));
}
@ -93,6 +91,7 @@ public class BlockNuke extends BaseBlock {
}
}
@SuppressWarnings("deprecation")
@Override
public void onBlockAdded(IBlockState state, World worldIn, BlockPos pos, IBlockState oldState) {
super.onBlockAdded(state, worldIn, pos, oldState);
@ -109,20 +108,10 @@ public class BlockNuke extends BaseBlock {
worldIn.removeBlock(pos);
}
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(OVERLAY) ? 1 : 0;
protected void fillStateContainer(StateContainer.Builder<Block, IBlockState> builder) {
OVERLAY = BooleanProperty.create("overlay");
builder.add(OVERLAY);
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().with(OVERLAY, (meta & 1) > 0);
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, OVERLAY);
}
}

View file

@ -24,16 +24,15 @@
package techreborn.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFence;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
public class BlockRefinedIronFence extends BlockFence {
public BlockRefinedIronFence() {
super(Material.IRON, BlockPlanks.EnumType.OAK.getMapColor());
setHardness(2.0F);
setHarvestLevel("pickaxe", 2);
super(Block.Properties.create(Material.IRON, MaterialColor.WOOD).hardnessAndResistance(2.0F, 3.0F).sound(SoundType.METAL));
}
}

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);
}
}

View file

@ -27,10 +27,9 @@ package techreborn.blocks.transformers;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.state.DirectionProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.state.StateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@ -59,7 +58,7 @@ public abstract class BlockTransformer extends BaseTileBlock {
public BlockTransformer(String name) {
super(Block.Properties.create(Material.IRON).hardnessAndResistance(2f));
this.setDefaultState(this.blockState.getBaseState().with(FACING, EnumFacing.NORTH));
this.setDefaultState(this.stateContainer.getBaseState().with(FACING, EnumFacing.NORTH));
this.name = name;
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/energy"));
BlockWrenchEventHandler.wrenableBlocks.add(this);
@ -70,81 +69,13 @@ public abstract class BlockTransformer extends BaseTileBlock {
}
public EnumFacing getFacing(IBlockState state) {
return state.getValue(FACING);
}
public EnumFacing getSideFromint(int i) {
if (i == 0) {
return EnumFacing.NORTH;
} else if (i == 1) {
return EnumFacing.SOUTH;
} else if (i == 2) {
return EnumFacing.EAST;
} else if (i == 3) {
return EnumFacing.WEST;
} else if (i == 4) {
return EnumFacing.UP;
} else if (i == 5) {
return EnumFacing.DOWN;
}
return EnumFacing.NORTH;
}
public int getSideFromEnum(EnumFacing facing) {
if (facing == EnumFacing.NORTH) {
return 0;
} else if (facing == EnumFacing.SOUTH) {
return 1;
} else if (facing == EnumFacing.EAST) {
return 2;
} else if (facing == EnumFacing.WEST) {
return 3;
} else if (facing == EnumFacing.UP) {
return 4;
} else if (facing == EnumFacing.DOWN) {
return 5;
}
return 0;
}
private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state) {
if (!worldIn.isRemote) {
IBlockState state0 = worldIn.getBlockState(pos.north());
IBlockState state1 = worldIn.getBlockState(pos.south());
IBlockState state2 = worldIn.getBlockState(pos.west());
IBlockState state3 = worldIn.getBlockState(pos.east());
EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
if (enumfacing == EnumFacing.NORTH && state0.isFullBlock() && !state1.isFullBlock()) {
enumfacing = EnumFacing.SOUTH;
} else if (enumfacing == EnumFacing.SOUTH && state1.isFullBlock() && !state0.isFullBlock()) {
enumfacing = EnumFacing.NORTH;
} else if (enumfacing == EnumFacing.WEST && state2.isFullBlock() && !state3.isFullBlock()) {
enumfacing = EnumFacing.EAST;
} else if (enumfacing == EnumFacing.EAST && state3.isFullBlock() && !state2.isFullBlock()) {
enumfacing = EnumFacing.WEST;
}
worldIn.setBlockState(pos, state.with(FACING, enumfacing), 2);
}
return state.get(FACING);
}
// Block
@Override
protected BlockStateContainer createBlockState() {
FACING = DirectionProperty.create("facing", Facings.ALL);
return new BlockStateContainer(this, FACING);
}
@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
super.onBlockAdded(worldIn, pos, state);
this.setDefaultFacing(worldIn, pos, state);
}
// BaseTileBlock
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
ItemStack stack) {
ItemStack stack) {
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
EnumFacing facing = placer.getHorizontalFacing().getOpposite();
if (placer.rotationPitch < -50) {
@ -154,7 +85,15 @@ public abstract class BlockTransformer extends BaseTileBlock {
}
setFacing(facing, worldIn, pos);
}
// Block
@Override
protected void fillStateContainer(StateContainer.Builder<Block, IBlockState> builder) {
FACING = DirectionProperty.create("facing", EnumFacing.Plane.HORIZONTAL);
builder.add(FACING);
}
@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,24 +113,6 @@ public abstract class BlockTransformer extends BaseTileBlock {
return super.onBlockActivated(state, worldIn, pos, playerIn, hand, side, hitX, hitY, hitZ);
}
@Override
public boolean rotateBlock(World world, BlockPos pos, EnumFacing side) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block instanceof BlockTransformer) {
EnumFacing facing = state.getValue(BlockTransformer.FACING);
if (facing.getOpposite() == side) {
facing = side;
} else {
facing = side.getOpposite();
}
world.setBlockState(pos, state.with(BlockTransformer.FACING, facing));
return true;
}
return false;
}
public enum Facings implements Predicate<EnumFacing>, Iterable<EnumFacing> {
ALL;