mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-16 09:33:42 +01:00
water logging and contraptions
This commit is contained in:
parent
dc43f10451
commit
c51e2abf48
9 changed files with 1329 additions and 1174 deletions
File diff suppressed because it is too large
Load diff
|
@ -1,16 +1,17 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.piston;
|
||||
|
||||
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isExtensionPole;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllShapes;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.PistonState;
|
||||
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.IWaterLoggable;
|
||||
import net.minecraft.block.material.PushReaction;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.EnumProperty;
|
||||
import net.minecraft.state.StateContainer.Builder;
|
||||
|
@ -22,67 +23,91 @@ import net.minecraft.util.math.RayTraceResult;
|
|||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class MechanicalPistonHeadBlock extends ProperDirectionalBlock {
|
||||
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isExtensionPole;
|
||||
|
||||
public static final EnumProperty<PistonType> TYPE = BlockStateProperties.PISTON_TYPE;
|
||||
public class MechanicalPistonHeadBlock extends ProperDirectionalBlock implements IWaterLoggable {
|
||||
|
||||
public MechanicalPistonHeadBlock(Properties p_i48415_1_) {
|
||||
super(p_i48415_1_);
|
||||
}
|
||||
public static final EnumProperty<PistonType> TYPE = BlockStateProperties.PISTON_TYPE;
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
||||
builder.add(TYPE);
|
||||
super.fillStateContainer(builder);
|
||||
}
|
||||
public MechanicalPistonHeadBlock(Properties p_i48415_1_) {
|
||||
super(p_i48415_1_);
|
||||
setDefaultState(super.getDefaultState().with(BlockStateProperties.WATERLOGGED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PushReaction getPushReaction(BlockState state) {
|
||||
return PushReaction.NORMAL;
|
||||
}
|
||||
@Override
|
||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
||||
builder.add(TYPE, BlockStateProperties.WATERLOGGED);
|
||||
super.fillStateContainer(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(BlockState state, RayTraceResult target, IBlockReader world, BlockPos pos,
|
||||
PlayerEntity player) {
|
||||
return AllBlocks.PISTON_EXTENSION_POLE.asStack();
|
||||
}
|
||||
@Override
|
||||
public PushReaction getPushReaction(BlockState state) {
|
||||
return PushReaction.NORMAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||
Direction direction = state.get(FACING);
|
||||
BlockPos pistonHead = pos;
|
||||
BlockPos pistonBase = null;
|
||||
@Override
|
||||
public ItemStack getPickBlock(BlockState state, RayTraceResult target, IBlockReader world, BlockPos pos,
|
||||
PlayerEntity player) {
|
||||
return AllBlocks.PISTON_EXTENSION_POLE.asStack();
|
||||
}
|
||||
|
||||
for (int offset = 1; offset < MechanicalPistonBlock.maxAllowedPistonPoles(); offset++) {
|
||||
BlockPos currentPos = pos.offset(direction.getOpposite(), offset);
|
||||
BlockState block = worldIn.getBlockState(currentPos);
|
||||
@Override
|
||||
public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||
Direction direction = state.get(FACING);
|
||||
BlockPos pistonHead = pos;
|
||||
BlockPos pistonBase = null;
|
||||
|
||||
if (isExtensionPole(block) && direction.getAxis() == block.get(BlockStateProperties.FACING)
|
||||
.getAxis())
|
||||
continue;
|
||||
for (int offset = 1; offset < MechanicalPistonBlock.maxAllowedPistonPoles(); offset++) {
|
||||
BlockPos currentPos = pos.offset(direction.getOpposite(), offset);
|
||||
BlockState block = worldIn.getBlockState(currentPos);
|
||||
|
||||
if (MechanicalPistonBlock.isPiston(block) && block.get(BlockStateProperties.FACING) == direction)
|
||||
pistonBase = currentPos;
|
||||
if (isExtensionPole(block) && direction.getAxis() == block.get(BlockStateProperties.FACING)
|
||||
.getAxis())
|
||||
continue;
|
||||
|
||||
break;
|
||||
}
|
||||
if (MechanicalPistonBlock.isPiston(block) && block.get(BlockStateProperties.FACING) == direction)
|
||||
pistonBase = currentPos;
|
||||
|
||||
if (pistonHead != null && pistonBase != null) {
|
||||
final BlockPos basePos = pistonBase;
|
||||
BlockPos.getAllInBox(pistonBase, pistonHead)
|
||||
.filter(p -> !p.equals(pos) && !p.equals(basePos))
|
||||
.forEach(p -> worldIn.destroyBlock(p, !player.isCreative()));
|
||||
worldIn.setBlockState(basePos, worldIn.getBlockState(basePos)
|
||||
.with(MechanicalPistonBlock.STATE, PistonState.RETRACTED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
super.onBlockHarvested(worldIn, pos, state, player);
|
||||
}
|
||||
if (pistonHead != null && pistonBase != null) {
|
||||
final BlockPos basePos = pistonBase;
|
||||
BlockPos.getAllInBox(pistonBase, pistonHead)
|
||||
.filter(p -> !p.equals(pos) && !p.equals(basePos))
|
||||
.forEach(p -> worldIn.destroyBlock(p, !player.isCreative()));
|
||||
worldIn.setBlockState(basePos, worldIn.getBlockState(basePos)
|
||||
.with(MechanicalPistonBlock.STATE, PistonState.RETRACTED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return AllShapes.MECHANICAL_PISTON_HEAD.get(state.get(FACING));
|
||||
}
|
||||
super.onBlockHarvested(worldIn, pos, state, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return AllShapes.MECHANICAL_PISTON_HEAD.get(state.get(FACING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidState getFluidState(BlockState state) {
|
||||
return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : Fluids.EMPTY.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updatePostPlacement(BlockState state, Direction direction, BlockState neighbourState,
|
||||
IWorld world, BlockPos pos, BlockPos neighbourPos) {
|
||||
if (state.get(BlockStateProperties.WATERLOGGED)) {
|
||||
world.getPendingFluidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
IFluidState ifluidstate = context.getWorld().getFluidState(context.getPos());
|
||||
return super.getStateForPlacement(context).with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.piston;
|
||||
|
||||
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isExtensionPole;
|
||||
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isPiston;
|
||||
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isPistonHead;
|
||||
|
||||
import com.simibubi.create.AllShapes;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.PistonState;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.*;
|
||||
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
|
||||
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.IWaterLoggable;
|
||||
import net.minecraft.block.material.PushReaction;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.state.StateContainer.Builder;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
|
@ -21,75 +21,98 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PistonExtensionPoleBlock extends ProperDirectionalBlock implements IWrenchable {
|
||||
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.*;
|
||||
|
||||
public PistonExtensionPoleBlock(Properties properties) {
|
||||
super(properties);
|
||||
setDefaultState(getDefaultState().with(FACING, Direction.UP));
|
||||
}
|
||||
public class PistonExtensionPoleBlock extends ProperDirectionalBlock implements IWrenchable, IWaterLoggable {
|
||||
|
||||
@Override
|
||||
public PushReaction getPushReaction(BlockState state) {
|
||||
return PushReaction.NORMAL;
|
||||
}
|
||||
public PistonExtensionPoleBlock(Properties properties) {
|
||||
super(properties);
|
||||
setDefaultState(getDefaultState().with(FACING, Direction.UP).with(BlockStateProperties.WATERLOGGED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||
Axis axis = state.get(FACING)
|
||||
.getAxis();
|
||||
Direction direction = Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis);
|
||||
BlockPos pistonHead = null;
|
||||
BlockPos pistonBase = null;
|
||||
@Override
|
||||
public PushReaction getPushReaction(BlockState state) {
|
||||
return PushReaction.NORMAL;
|
||||
}
|
||||
|
||||
for (int modifier : new int[] { 1, -1 }) {
|
||||
for (int offset = modifier; modifier * offset < MechanicalPistonBlock.maxAllowedPistonPoles(); offset +=
|
||||
modifier) {
|
||||
BlockPos currentPos = pos.offset(direction, offset);
|
||||
BlockState block = worldIn.getBlockState(currentPos);
|
||||
@Override
|
||||
public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||
Axis axis = state.get(FACING)
|
||||
.getAxis();
|
||||
Direction direction = Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis);
|
||||
BlockPos pistonHead = null;
|
||||
BlockPos pistonBase = null;
|
||||
|
||||
if (isExtensionPole(block) && axis == block.get(FACING)
|
||||
.getAxis())
|
||||
continue;
|
||||
for (int modifier : new int[]{1, -1}) {
|
||||
for (int offset = modifier; modifier * offset < MechanicalPistonBlock.maxAllowedPistonPoles(); offset +=
|
||||
modifier) {
|
||||
BlockPos currentPos = pos.offset(direction, offset);
|
||||
BlockState block = worldIn.getBlockState(currentPos);
|
||||
|
||||
if (isPiston(block) && block.get(BlockStateProperties.FACING)
|
||||
.getAxis() == axis)
|
||||
pistonBase = currentPos;
|
||||
if (isExtensionPole(block) && axis == block.get(FACING)
|
||||
.getAxis())
|
||||
continue;
|
||||
|
||||
if (isPistonHead(block) && block.get(BlockStateProperties.FACING)
|
||||
.getAxis() == axis)
|
||||
pistonHead = currentPos;
|
||||
if (isPiston(block) && block.get(BlockStateProperties.FACING)
|
||||
.getAxis() == axis)
|
||||
pistonBase = currentPos;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isPistonHead(block) && block.get(BlockStateProperties.FACING)
|
||||
.getAxis() == axis)
|
||||
pistonHead = currentPos;
|
||||
|
||||
if (pistonHead != null && pistonBase != null && worldIn.getBlockState(pistonHead)
|
||||
.get(BlockStateProperties.FACING) == worldIn.getBlockState(pistonBase)
|
||||
.get(BlockStateProperties.FACING)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final BlockPos basePos = pistonBase;
|
||||
BlockPos.getAllInBox(pistonBase, pistonHead)
|
||||
.filter(p -> !p.equals(pos) && !p.equals(basePos))
|
||||
.forEach(p -> worldIn.destroyBlock(p, !player.isCreative()));
|
||||
worldIn.setBlockState(basePos, worldIn.getBlockState(basePos)
|
||||
.with(MechanicalPistonBlock.STATE, PistonState.RETRACTED));
|
||||
}
|
||||
if (pistonHead != null && pistonBase != null && worldIn.getBlockState(pistonHead)
|
||||
.get(BlockStateProperties.FACING) == worldIn.getBlockState(pistonBase)
|
||||
.get(BlockStateProperties.FACING)) {
|
||||
|
||||
super.onBlockHarvested(worldIn, pos, state, player);
|
||||
}
|
||||
final BlockPos basePos = pistonBase;
|
||||
BlockPos.getAllInBox(pistonBase, pistonHead)
|
||||
.filter(p -> !p.equals(pos) && !p.equals(basePos))
|
||||
.forEach(p -> worldIn.destroyBlock(p, !player.isCreative()));
|
||||
worldIn.setBlockState(basePos, worldIn.getBlockState(basePos)
|
||||
.with(MechanicalPistonBlock.STATE, PistonState.RETRACTED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return AllShapes.FOUR_VOXEL_POLE.get(state.get(FACING)
|
||||
.getAxis());
|
||||
}
|
||||
super.onBlockHarvested(worldIn, pos, state, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
return getDefaultState().with(FACING, context.getFace()
|
||||
.getOpposite());
|
||||
}
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return AllShapes.FOUR_VOXEL_POLE.get(state.get(FACING)
|
||||
.getAxis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
IFluidState ifluidstate = context.getWorld().getFluidState(context.getPos());
|
||||
return getDefaultState().with(FACING, context.getFace().getOpposite())
|
||||
.with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidState getFluidState(BlockState state) {
|
||||
return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : Fluids.EMPTY.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
||||
builder.add(BlockStateProperties.WATERLOGGED);
|
||||
super.fillStateContainer(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updatePostPlacement(BlockState state, Direction direction, BlockState neighbourState,
|
||||
IWorld world, BlockPos pos, BlockPos neighbourPos) {
|
||||
if (state.get(BlockStateProperties.WATERLOGGED)) {
|
||||
world.getPendingFluidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,17 @@ import com.simibubi.create.AllShapes;
|
|||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.content.contraptions.base.HorizontalAxisKineticBlock;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.IWaterLoggable;
|
||||
import net.minecraft.block.material.PushReaction;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.EnumProperty;
|
||||
import net.minecraft.state.StateContainer.Builder;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
|
@ -24,128 +28,156 @@ import net.minecraft.util.math.RayTraceResult;
|
|||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PulleyBlock extends HorizontalAxisKineticBlock implements ITE<PulleyTileEntity> {
|
||||
|
||||
public static EnumProperty<Axis> HORIZONTAL_AXIS = BlockStateProperties.HORIZONTAL_AXIS;
|
||||
public static EnumProperty<Axis> HORIZONTAL_AXIS = BlockStateProperties.HORIZONTAL_AXIS;
|
||||
|
||||
public PulleyBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
public PulleyBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return AllTileEntities.ROPE_PULLEY.create();
|
||||
}
|
||||
private static void onRopeBroken(World world, BlockPos pulleyPos) {
|
||||
TileEntity te = world.getTileEntity(pulleyPos);
|
||||
if (!(te instanceof PulleyTileEntity))
|
||||
return;
|
||||
PulleyTileEntity pulley = (PulleyTileEntity) te;
|
||||
pulley.offset = 0;
|
||||
pulley.sendData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (state.getBlock() != newState.getBlock()) {
|
||||
if (!worldIn.isRemote) {
|
||||
BlockState below = worldIn.getBlockState(pos.down());
|
||||
if (below.getBlock() instanceof RopeBlockBase)
|
||||
worldIn.destroyBlock(pos.down(), true);
|
||||
}
|
||||
if (state.hasTileEntity())
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return AllTileEntities.ROPE_PULLEY.create();
|
||||
}
|
||||
|
||||
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
|
||||
BlockRayTraceResult hit) {
|
||||
if (!player.isAllowEdit())
|
||||
return ActionResultType.PASS;
|
||||
if (player.isSneaking())
|
||||
return ActionResultType.PASS;
|
||||
if (player.getHeldItem(handIn)
|
||||
.isEmpty()) {
|
||||
withTileEntityDo(worldIn, pos, te -> te.assembleNextTick = true);
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (state.getBlock() != newState.getBlock()) {
|
||||
if (!worldIn.isRemote) {
|
||||
BlockState below = worldIn.getBlockState(pos.down());
|
||||
if (below.getBlock() instanceof RopeBlockBase)
|
||||
worldIn.destroyBlock(pos.down(), true);
|
||||
}
|
||||
if (state.hasTileEntity())
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return AllShapes.PULLEY.get(state.get(HORIZONTAL_AXIS));
|
||||
}
|
||||
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
|
||||
BlockRayTraceResult hit) {
|
||||
if (!player.isAllowEdit())
|
||||
return ActionResultType.PASS;
|
||||
if (player.isSneaking())
|
||||
return ActionResultType.PASS;
|
||||
if (player.getHeldItem(handIn)
|
||||
.isEmpty()) {
|
||||
withTileEntityDo(worldIn, pos, te -> te.assembleNextTick = true);
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
|
||||
private static void onRopeBroken(World world, BlockPos pulleyPos) {
|
||||
TileEntity te = world.getTileEntity(pulleyPos);
|
||||
if (!(te instanceof PulleyTileEntity))
|
||||
return;
|
||||
PulleyTileEntity pulley = (PulleyTileEntity) te;
|
||||
pulley.offset = 0;
|
||||
pulley.sendData();
|
||||
}
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return AllShapes.PULLEY.get(state.get(HORIZONTAL_AXIS));
|
||||
}
|
||||
|
||||
private static class RopeBlockBase extends Block {
|
||||
@Override
|
||||
public Class<PulleyTileEntity> getTileEntityClass() {
|
||||
return PulleyTileEntity.class;
|
||||
}
|
||||
|
||||
public RopeBlockBase(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
private static class RopeBlockBase extends Block implements IWaterLoggable {
|
||||
|
||||
@Override
|
||||
public PushReaction getPushReaction(BlockState state) {
|
||||
return PushReaction.BLOCK;
|
||||
}
|
||||
public RopeBlockBase(Properties properties) {
|
||||
super(properties);
|
||||
setDefaultState(super.getDefaultState().with(BlockStateProperties.WATERLOGGED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(BlockState state, RayTraceResult target, IBlockReader world, BlockPos pos,
|
||||
PlayerEntity player) {
|
||||
return AllBlocks.ROPE_PULLEY.asStack();
|
||||
}
|
||||
@Override
|
||||
public PushReaction getPushReaction(BlockState state) {
|
||||
return PushReaction.BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (!isMoving) {
|
||||
onRopeBroken(worldIn, pos.up());
|
||||
if (!worldIn.isRemote) {
|
||||
BlockState above = worldIn.getBlockState(pos.up());
|
||||
BlockState below = worldIn.getBlockState(pos.down());
|
||||
if (above.getBlock() instanceof RopeBlockBase)
|
||||
worldIn.destroyBlock(pos.up(), true);
|
||||
if (below.getBlock() instanceof RopeBlockBase)
|
||||
worldIn.destroyBlock(pos.down(), true);
|
||||
}
|
||||
}
|
||||
if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) {
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public ItemStack getPickBlock(BlockState state, RayTraceResult target, IBlockReader world, BlockPos pos,
|
||||
PlayerEntity player) {
|
||||
return AllBlocks.ROPE_PULLEY.asStack();
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (!isMoving && (!state.has(BlockStateProperties.WATERLOGGED) || !newState.has(BlockStateProperties.WATERLOGGED) || state.get(BlockStateProperties.WATERLOGGED) == newState.get(BlockStateProperties.WATERLOGGED))) {
|
||||
onRopeBroken(worldIn, pos.up());
|
||||
if (!worldIn.isRemote) {
|
||||
BlockState above = worldIn.getBlockState(pos.up());
|
||||
BlockState below = worldIn.getBlockState(pos.down());
|
||||
if (above.getBlock() instanceof RopeBlockBase)
|
||||
worldIn.destroyBlock(pos.up(), true);
|
||||
if (below.getBlock() instanceof RopeBlockBase)
|
||||
worldIn.destroyBlock(pos.down(), true);
|
||||
}
|
||||
}
|
||||
if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) {
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
}
|
||||
|
||||
public static class MagnetBlock extends RopeBlockBase {
|
||||
|
||||
public MagnetBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
@Override
|
||||
public IFluidState getFluidState(BlockState state) {
|
||||
return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : Fluids.EMPTY.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return AllShapes.PULLEY_MAGNET;
|
||||
}
|
||||
@Override
|
||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
||||
builder.add(BlockStateProperties.WATERLOGGED);
|
||||
super.fillStateContainer(builder);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public BlockState updatePostPlacement(BlockState state, Direction direction, BlockState neighbourState,
|
||||
IWorld world, BlockPos pos, BlockPos neighbourPos) {
|
||||
if (state.get(BlockStateProperties.WATERLOGGED)) {
|
||||
world.getPendingFluidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
public static class RopeBlock extends RopeBlockBase {
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
IFluidState ifluidstate = context.getWorld().getFluidState(context.getPos());
|
||||
return super.getStateForPlacement(context).with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
|
||||
}
|
||||
|
||||
public RopeBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return AllShapes.FOUR_VOXEL_POLE.get(Direction.UP);
|
||||
}
|
||||
public static class MagnetBlock extends RopeBlockBase {
|
||||
|
||||
}
|
||||
public MagnetBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<PulleyTileEntity> getTileEntityClass() {
|
||||
return PulleyTileEntity.class;
|
||||
}
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return AllShapes.PULLEY_MAGNET;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class RopeBlock extends RopeBlockBase {
|
||||
|
||||
public RopeBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return AllShapes.FOUR_VOXEL_POLE.get(Direction.UP);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,9 +8,13 @@ import com.simibubi.create.content.contraptions.components.structureMovement.pis
|
|||
import com.simibubi.create.foundation.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.tileEntity.behaviour.CenteredSideValueBoxTransform;
|
||||
import com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.IWaterLoggable;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
@ -19,170 +23,180 @@ import net.minecraft.util.math.Vec3d;
|
|||
|
||||
public class PulleyTileEntity extends LinearActuatorTileEntity {
|
||||
|
||||
protected int initialOffset;
|
||||
protected int initialOffset;
|
||||
|
||||
public PulleyTileEntity(TileEntityType<? extends PulleyTileEntity> type) {
|
||||
super(type);
|
||||
}
|
||||
public PulleyTileEntity(TileEntityType<? extends PulleyTileEntity> type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return super.getRenderBoundingBox().expand(0, -offset, 0);
|
||||
}
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return super.getRenderBoundingBox().expand(0, -offset, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
return super.getMaxRenderDistanceSquared() + offset * offset;
|
||||
}
|
||||
@Override
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
return super.getMaxRenderDistanceSquared() + offset * offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assemble() {
|
||||
if (!(world.getBlockState(pos)
|
||||
.getBlock() instanceof PulleyBlock))
|
||||
return;
|
||||
if (speed == 0)
|
||||
return;
|
||||
if (offset >= getExtensionRange() && getSpeed() > 0)
|
||||
return;
|
||||
if (offset <= 0 && getSpeed() < 0)
|
||||
return;
|
||||
@Override
|
||||
protected void assemble() {
|
||||
if (!(world.getBlockState(pos)
|
||||
.getBlock() instanceof PulleyBlock))
|
||||
return;
|
||||
if (speed == 0)
|
||||
return;
|
||||
if (offset >= getExtensionRange() && getSpeed() > 0)
|
||||
return;
|
||||
if (offset <= 0 && getSpeed() < 0)
|
||||
return;
|
||||
|
||||
// Collect Construct
|
||||
if (!world.isRemote) {
|
||||
BlockPos anchor = pos.down((int) (offset + 1));
|
||||
initialOffset = (int) (offset);
|
||||
PulleyContraption contraption = PulleyContraption.assemblePulleyAt(world, anchor, (int) offset);
|
||||
// Collect Construct
|
||||
if (!world.isRemote) {
|
||||
BlockPos anchor = pos.down((int) (offset + 1));
|
||||
initialOffset = (int) (offset);
|
||||
PulleyContraption contraption = PulleyContraption.assemblePulleyAt(world, anchor, (int) offset);
|
||||
|
||||
if (contraption != null) {
|
||||
Direction movementDirection = getSpeed() > 0 ? Direction.DOWN : Direction.UP;
|
||||
if (ContraptionCollider.isCollidingWithWorld(world, contraption, anchor.offset(movementDirection),
|
||||
movementDirection))
|
||||
contraption = null;
|
||||
}
|
||||
if (contraption != null) {
|
||||
Direction movementDirection = getSpeed() > 0 ? Direction.DOWN : Direction.UP;
|
||||
if (ContraptionCollider.isCollidingWithWorld(world, contraption, anchor.offset(movementDirection),
|
||||
movementDirection))
|
||||
contraption = null;
|
||||
}
|
||||
|
||||
if (contraption == null && getSpeed() > 0)
|
||||
return;
|
||||
if (contraption == null && getSpeed() > 0)
|
||||
return;
|
||||
|
||||
for (int i = ((int) offset); i > 0; i--) {
|
||||
BlockPos offset = pos.down(i);
|
||||
world.setBlockState(offset, Blocks.AIR.getDefaultState(), 66);
|
||||
}
|
||||
for (int i = ((int) offset); i > 0; i--) {
|
||||
BlockPos offset = pos.down(i);
|
||||
BlockState oldState = world.getBlockState(offset);
|
||||
if (oldState.getBlock() instanceof IWaterLoggable && oldState.has(BlockStateProperties.WATERLOGGED) && oldState.get(BlockStateProperties.WATERLOGGED)) {
|
||||
world.setBlockState(offset, Blocks.WATER.getDefaultState(), 66);
|
||||
continue;
|
||||
}
|
||||
world.setBlockState(offset, Blocks.AIR.getDefaultState(), 66);
|
||||
}
|
||||
|
||||
if (contraption != null && !contraption.blocks.isEmpty()) {
|
||||
contraption.removeBlocksFromWorld(world, BlockPos.ZERO);
|
||||
movedContraption = ContraptionEntity.createStationary(world, contraption)
|
||||
.controlledBy(this);
|
||||
movedContraption.setPosition(anchor.getX(), anchor.getY(), anchor.getZ());
|
||||
world.addEntity(movedContraption);
|
||||
forceMove = true;
|
||||
}
|
||||
}
|
||||
if (contraption != null && !contraption.blocks.isEmpty()) {
|
||||
contraption.removeBlocksFromWorld(world, BlockPos.ZERO);
|
||||
movedContraption = ContraptionEntity.createStationary(world, contraption)
|
||||
.controlledBy(this);
|
||||
movedContraption.setPosition(anchor.getX(), anchor.getY(), anchor.getZ());
|
||||
world.addEntity(movedContraption);
|
||||
forceMove = true;
|
||||
}
|
||||
}
|
||||
|
||||
clientOffsetDiff = 0;
|
||||
running = true;
|
||||
sendData();
|
||||
}
|
||||
clientOffsetDiff = 0;
|
||||
running = true;
|
||||
sendData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disassemble() {
|
||||
if (!running && movedContraption == null)
|
||||
return;
|
||||
offset = getGridOffset(offset);
|
||||
if (movedContraption != null)
|
||||
applyContraptionPosition();
|
||||
@Override
|
||||
public void disassemble() {
|
||||
if (!running && movedContraption == null)
|
||||
return;
|
||||
offset = getGridOffset(offset);
|
||||
if (movedContraption != null)
|
||||
applyContraptionPosition();
|
||||
|
||||
if (!world.isRemote) {
|
||||
if (!removed) {
|
||||
if (offset > 0) {
|
||||
BlockPos magnetPos = pos.down((int) offset);
|
||||
world.destroyBlock(magnetPos, world.getBlockState(magnetPos)
|
||||
.getCollisionShape(world, magnetPos)
|
||||
.isEmpty());
|
||||
world.setBlockState(magnetPos, AllBlocks.PULLEY_MAGNET.getDefaultState(), 66);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= ((int) offset) - 1; i++) {
|
||||
BlockPos ropePos = pos.down(i);
|
||||
world.destroyBlock(ropePos, world.getBlockState(ropePos)
|
||||
.getCollisionShape(world, ropePos)
|
||||
.isEmpty());
|
||||
}
|
||||
for (int i = 1; i <= ((int) offset) - 1; i++)
|
||||
world.setBlockState(pos.down(i), AllBlocks.ROPE.getDefaultState(), 66);
|
||||
}
|
||||
if (!world.isRemote) {
|
||||
if (!removed) {
|
||||
if (offset > 0) {
|
||||
BlockPos magnetPos = pos.down((int) offset);
|
||||
IFluidState ifluidstate = world.getFluidState(magnetPos);
|
||||
world.destroyBlock(magnetPos, world.getBlockState(magnetPos)
|
||||
.getCollisionShape(world, magnetPos)
|
||||
.isEmpty());
|
||||
world.setBlockState(magnetPos, AllBlocks.PULLEY_MAGNET.getDefaultState().with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER)), 66);
|
||||
}
|
||||
|
||||
if (movedContraption != null)
|
||||
movedContraption.disassemble();
|
||||
}
|
||||
boolean[] waterlog = new boolean[(int) offset];
|
||||
|
||||
if (movedContraption != null)
|
||||
movedContraption.remove();
|
||||
movedContraption = null;
|
||||
initialOffset = 0;
|
||||
running = false;
|
||||
sendData();
|
||||
}
|
||||
for (int i = 1; i <= ((int) offset) - 1; i++) {
|
||||
BlockPos ropePos = pos.down(i);
|
||||
IFluidState ifluidstate = world.getFluidState(ropePos);
|
||||
waterlog[i] = ifluidstate.getFluid() == Fluids.WATER;
|
||||
world.destroyBlock(ropePos, world.getBlockState(ropePos)
|
||||
.getCollisionShape(world, ropePos)
|
||||
.isEmpty());
|
||||
}
|
||||
for (int i = 1; i <= ((int) offset) - 1; i++)
|
||||
world.setBlockState(pos.down(i), AllBlocks.ROPE.getDefaultState().with(BlockStateProperties.WATERLOGGED, waterlog[i]), 66);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Vec3d toPosition(float offset) {
|
||||
if (movedContraption.getContraption() instanceof PulleyContraption) {
|
||||
PulleyContraption contraption = (PulleyContraption) movedContraption.getContraption();
|
||||
return new Vec3d(contraption.getAnchor()).add(0, contraption.initialOffset - offset, 0);
|
||||
if (movedContraption != null)
|
||||
movedContraption.disassemble();
|
||||
}
|
||||
|
||||
}
|
||||
return Vec3d.ZERO;
|
||||
}
|
||||
if (movedContraption != null)
|
||||
movedContraption.remove();
|
||||
movedContraption = null;
|
||||
initialOffset = 0;
|
||||
running = false;
|
||||
sendData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visitNewPosition() {
|
||||
super.visitNewPosition();
|
||||
if (world.isRemote)
|
||||
return;
|
||||
if (movedContraption != null)
|
||||
return;
|
||||
if (getSpeed() <= 0)
|
||||
return;
|
||||
@Override
|
||||
protected Vec3d toPosition(float offset) {
|
||||
if (movedContraption.getContraption() instanceof PulleyContraption) {
|
||||
PulleyContraption contraption = (PulleyContraption) movedContraption.getContraption();
|
||||
return new Vec3d(contraption.getAnchor()).add(0, contraption.initialOffset - offset, 0);
|
||||
|
||||
BlockPos posBelow = pos.down((int) (offset + getMovementSpeed()) + 1);
|
||||
if (!BlockMovementTraits.movementNecessary(world, posBelow))
|
||||
return;
|
||||
if (BlockMovementTraits.isBrittle(world.getBlockState(posBelow)))
|
||||
return;
|
||||
}
|
||||
return Vec3d.ZERO;
|
||||
}
|
||||
|
||||
disassemble();
|
||||
assembleNextTick = true;
|
||||
}
|
||||
@Override
|
||||
protected void visitNewPosition() {
|
||||
super.visitNewPosition();
|
||||
if (world.isRemote)
|
||||
return;
|
||||
if (movedContraption != null)
|
||||
return;
|
||||
if (getSpeed() <= 0)
|
||||
return;
|
||||
|
||||
@Override
|
||||
public void read(CompoundNBT tag) {
|
||||
initialOffset = tag.getInt("InitialOffset");
|
||||
super.read(tag);
|
||||
}
|
||||
BlockPos posBelow = pos.down((int) (offset + getMovementSpeed()) + 1);
|
||||
if (!BlockMovementTraits.movementNecessary(world, posBelow))
|
||||
return;
|
||||
if (BlockMovementTraits.isBrittle(world.getBlockState(posBelow)))
|
||||
return;
|
||||
|
||||
@Override
|
||||
public CompoundNBT write(CompoundNBT tag) {
|
||||
tag.putInt("InitialOffset", initialOffset);
|
||||
return super.write(tag);
|
||||
}
|
||||
disassemble();
|
||||
assembleNextTick = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getExtensionRange() {
|
||||
return Math.max(0, Math.min(AllConfigs.SERVER.kinetics.maxRopeLength.get(), pos.getY() - 1));
|
||||
}
|
||||
@Override
|
||||
public void read(CompoundNBT tag) {
|
||||
initialOffset = tag.getInt("InitialOffset");
|
||||
super.read(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getInitialOffset() {
|
||||
return initialOffset;
|
||||
}
|
||||
@Override
|
||||
public CompoundNBT write(CompoundNBT tag) {
|
||||
tag.putInt("InitialOffset", initialOffset);
|
||||
return super.write(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Vec3d toMotionVector(float speed) {
|
||||
return new Vec3d(0, -speed, 0);
|
||||
}
|
||||
@Override
|
||||
protected int getExtensionRange() {
|
||||
return Math.max(0, Math.min(AllConfigs.SERVER.kinetics.maxRopeLength.get(), pos.getY() - 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValueBoxTransform getMovementModeSlot() {
|
||||
return new CenteredSideValueBoxTransform((state, d) -> d == Direction.UP);
|
||||
}
|
||||
@Override
|
||||
protected int getInitialOffset() {
|
||||
return initialOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Vec3d toMotionVector(float speed) {
|
||||
return new Vec3d(0, -speed, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValueBoxTransform getMovementModeSlot() {
|
||||
return new CenteredSideValueBoxTransform((state, d) -> d == Direction.UP);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ public class FluidPipeBlock extends SixWayBlock implements IWaterLoggable {
|
|||
@Override
|
||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
||||
builder.add(NORTH, EAST, SOUTH, WEST, UP, DOWN, BlockStateProperties.WATERLOGGED);
|
||||
super.fillStateContainer(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,8 +3,14 @@ package com.simibubi.create.content.contraptions.fluids;
|
|||
import com.simibubi.create.AllShapes;
|
||||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.IWaterLoggable;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.state.StateContainer.Builder;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
|
@ -12,45 +18,73 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
|
||||
public class PumpBlock extends DirectionalKineticBlock {
|
||||
public class PumpBlock extends DirectionalKineticBlock implements IWaterLoggable {
|
||||
|
||||
public PumpBlock(Properties p_i48415_1_) {
|
||||
super(p_i48415_1_);
|
||||
}
|
||||
public PumpBlock(Properties p_i48415_1_) {
|
||||
super(p_i48415_1_);
|
||||
setDefaultState(super.getDefaultState().with(BlockStateProperties.WATERLOGGED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean hasTileEntity(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return AllTileEntities.MECHANICAL_PUMP.create();
|
||||
}
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return AllTileEntities.MECHANICAL_PUMP.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getRotatedBlockState(BlockState originalState, Direction targetedFace) {
|
||||
return originalState.with(FACING, originalState.get(FACING)
|
||||
.getOpposite());
|
||||
}
|
||||
@Override
|
||||
public BlockState getRotatedBlockState(BlockState originalState, Direction targetedFace) {
|
||||
return originalState.with(FACING, originalState.get(FACING)
|
||||
.getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Axis getRotationAxis(BlockState state) {
|
||||
return state.get(FACING)
|
||||
.getAxis();
|
||||
}
|
||||
@Override
|
||||
public Axis getRotationAxis(BlockState state) {
|
||||
return state.get(FACING)
|
||||
.getAxis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader p_220053_2_, BlockPos p_220053_3_,
|
||||
ISelectionContext p_220053_4_) {
|
||||
return AllShapes.PUMP.get(state.get(FACING));
|
||||
}
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader p_220053_2_, BlockPos p_220053_3_,
|
||||
ISelectionContext p_220053_4_) {
|
||||
return AllShapes.PUMP.get(state.get(FACING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidState getFluidState(BlockState state) {
|
||||
return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : Fluids.EMPTY.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
||||
builder.add(BlockStateProperties.WATERLOGGED);
|
||||
super.fillStateContainer(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updatePostPlacement(BlockState state, Direction direction, BlockState neighbourState,
|
||||
IWorld world, BlockPos pos, BlockPos neighbourPos) {
|
||||
if (state.get(BlockStateProperties.WATERLOGGED)) {
|
||||
world.getPendingFluidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
IFluidState ifluidstate = context.getWorld().getFluidState(context.getPos());
|
||||
return super.getStateForPlacement(context).with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,12 +4,14 @@ import com.simibubi.create.AllBlocks;
|
|||
import com.simibubi.create.AllShapes;
|
||||
import com.simibubi.create.content.contraptions.base.IRotate;
|
||||
import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
@ -22,95 +24,96 @@ import net.minecraft.world.World;
|
|||
|
||||
public class CogWheelBlock extends ShaftBlock {
|
||||
|
||||
boolean isLarge;
|
||||
boolean isLarge;
|
||||
|
||||
public static CogWheelBlock small(Properties properties) {
|
||||
return new CogWheelBlock(false, properties);
|
||||
}
|
||||
private CogWheelBlock(boolean large, Properties properties) {
|
||||
super(properties);
|
||||
isLarge = large;
|
||||
}
|
||||
|
||||
public static CogWheelBlock large(Properties properties) {
|
||||
return new CogWheelBlock(true, properties);
|
||||
}
|
||||
public static CogWheelBlock small(Properties properties) {
|
||||
return new CogWheelBlock(false, properties);
|
||||
}
|
||||
|
||||
private CogWheelBlock(boolean large, Properties properties) {
|
||||
super(properties);
|
||||
isLarge = large;
|
||||
}
|
||||
public static CogWheelBlock large(Properties properties) {
|
||||
return new CogWheelBlock(true, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return (isLarge ? AllShapes.LARGE_GEAR : AllShapes.SMALL_GEAR).get(state.get(AXIS));
|
||||
}
|
||||
public static boolean isSmallCog(BlockState state) {
|
||||
return AllBlocks.COGWHEEL.has(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
|
||||
for (Direction facing : Direction.values()) {
|
||||
if (facing.getAxis() == state.get(AXIS))
|
||||
continue;
|
||||
public static boolean isLargeCog(BlockState state) {
|
||||
return AllBlocks.LARGE_COGWHEEL.has(state);
|
||||
}
|
||||
|
||||
BlockState blockState = worldIn.getBlockState(pos.offset(facing));
|
||||
if (isLargeCog(blockState) || isLarge && isSmallCog(blockState))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return (isLarge ? AllShapes.LARGE_GEAR : AllShapes.SMALL_GEAR).get(state.get(AXIS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
BlockPos placedOnPos = context.getPos()
|
||||
.offset(context.getFace()
|
||||
.getOpposite());
|
||||
World world = context.getWorld();
|
||||
BlockState placedAgainst = world.getBlockState(placedOnPos);
|
||||
Block block = placedAgainst.getBlock();
|
||||
@Override
|
||||
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
|
||||
for (Direction facing : Direction.values()) {
|
||||
if (facing.getAxis() == state.get(AXIS))
|
||||
continue;
|
||||
|
||||
BlockState stateBelow = world.getBlockState(context.getPos()
|
||||
.down());
|
||||
if (AllBlocks.ROTATION_SPEED_CONTROLLER.has(stateBelow) && isLarge) {
|
||||
return this.getDefaultState()
|
||||
.with(AXIS, stateBelow.get(SpeedControllerBlock.HORIZONTAL_AXIS) == Axis.X ? Axis.Z : Axis.X);
|
||||
}
|
||||
BlockState blockState = worldIn.getBlockState(pos.offset(facing));
|
||||
if (isLargeCog(blockState) || isLarge && isSmallCog(blockState))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(block instanceof IRotate)
|
||||
|| !(((IRotate) block).hasIntegratedCogwheel(world, placedOnPos, placedAgainst))) {
|
||||
Axis preferredAxis = getPreferredAxis(context);
|
||||
if (preferredAxis != null)
|
||||
return this.getDefaultState()
|
||||
.with(AXIS, preferredAxis);
|
||||
return this.getDefaultState()
|
||||
.with(AXIS, context.getFace()
|
||||
.getAxis());
|
||||
}
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
BlockPos placedOnPos = context.getPos()
|
||||
.offset(context.getFace()
|
||||
.getOpposite());
|
||||
World world = context.getWorld();
|
||||
BlockState placedAgainst = world.getBlockState(placedOnPos);
|
||||
Block block = placedAgainst.getBlock();
|
||||
|
||||
return getDefaultState().with(AXIS, ((IRotate) block).getRotationAxis(placedAgainst));
|
||||
}
|
||||
BlockState stateBelow = world.getBlockState(context.getPos()
|
||||
.down());
|
||||
IFluidState ifluidstate = context.getWorld().getFluidState(context.getPos());
|
||||
if (AllBlocks.ROTATION_SPEED_CONTROLLER.has(stateBelow) && isLarge) {
|
||||
return this.getDefaultState().with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER))
|
||||
.with(AXIS, stateBelow.get(SpeedControllerBlock.HORIZONTAL_AXIS) == Axis.X ? Axis.Z : Axis.X);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getParticleTargetRadius() {
|
||||
return isLarge ? 1.125f : .65f;
|
||||
}
|
||||
if (!(block instanceof IRotate)
|
||||
|| !(((IRotate) block).hasIntegratedCogwheel(world, placedOnPos, placedAgainst))) {
|
||||
Axis preferredAxis = getPreferredAxis(context);
|
||||
if (preferredAxis != null)
|
||||
return this.getDefaultState()
|
||||
.with(AXIS, preferredAxis).with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
|
||||
return this.getDefaultState()
|
||||
.with(AXIS, context.getFace()
|
||||
.getAxis()).with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getParticleInitialRadius() {
|
||||
return isLarge ? 1f : .75f;
|
||||
}
|
||||
return getDefaultState().with(AXIS, ((IRotate) block).getRotationAxis(placedAgainst));
|
||||
}
|
||||
|
||||
public static boolean isSmallCog(BlockState state) {
|
||||
return AllBlocks.COGWHEEL.has(state);
|
||||
}
|
||||
@Override
|
||||
public float getParticleTargetRadius() {
|
||||
return isLarge ? 1.125f : .65f;
|
||||
}
|
||||
|
||||
public static boolean isLargeCog(BlockState state) {
|
||||
return AllBlocks.LARGE_COGWHEEL.has(state);
|
||||
}
|
||||
@Override
|
||||
public float getParticleInitialRadius() {
|
||||
return isLarge ? 1f : .75f;
|
||||
}
|
||||
|
||||
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
|
||||
items.add(new ItemStack(this));
|
||||
}
|
||||
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
|
||||
items.add(new ItemStack(this));
|
||||
}
|
||||
|
||||
// IRotate
|
||||
// IRotate
|
||||
|
||||
@Override
|
||||
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
|
||||
return !isLarge;
|
||||
}
|
||||
@Override
|
||||
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
|
||||
return !isLarge;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,18 @@ import com.simibubi.create.AllBlocks;
|
|||
import com.simibubi.create.AllShapes;
|
||||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.IWaterLoggable;
|
||||
import net.minecraft.block.material.PushReaction;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.StateContainer.Builder;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
|
@ -18,63 +24,90 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
|
||||
public class ShaftBlock extends RotatedPillarKineticBlock {
|
||||
public class ShaftBlock extends RotatedPillarKineticBlock implements IWaterLoggable {
|
||||
|
||||
public ShaftBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PushReaction getPushReaction(BlockState state) {
|
||||
return PushReaction.NORMAL;
|
||||
}
|
||||
public ShaftBlock(Properties properties) {
|
||||
super(properties);
|
||||
setDefaultState(super.getDefaultState().with(BlockStateProperties.WATERLOGGED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return AllTileEntities.SIMPLE_KINETIC.create();
|
||||
}
|
||||
public static boolean isShaft(BlockState state) {
|
||||
return AllBlocks.SHAFT.has(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return AllShapes.SIX_VOXEL_POLE.get(state.get(AXIS));
|
||||
}
|
||||
@Override
|
||||
public PushReaction getPushReaction(BlockState state) {
|
||||
return PushReaction.NORMAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getParticleTargetRadius() {
|
||||
return .25f;
|
||||
}
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getParticleInitialRadius() {
|
||||
return 0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
|
||||
super.fillItemGroup(group, items);
|
||||
}
|
||||
|
||||
public static boolean isShaft(BlockState state) {
|
||||
return AllBlocks.SHAFT.has(state);
|
||||
}
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return AllTileEntities.SIMPLE_KINETIC.create();
|
||||
}
|
||||
|
||||
// IRotate:
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return AllShapes.SIX_VOXEL_POLE.get(state.get(AXIS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||
return face.getAxis() == state.get(AXIS);
|
||||
}
|
||||
@Override
|
||||
public float getParticleTargetRadius() {
|
||||
return .25f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Axis getRotationAxis(BlockState state) {
|
||||
return state.get(AXIS);
|
||||
}
|
||||
@Override
|
||||
public float getParticleInitialRadius() {
|
||||
return 0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
|
||||
super.fillItemGroup(group, items);
|
||||
}
|
||||
|
||||
// IRotate:
|
||||
|
||||
@Override
|
||||
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||
return face.getAxis() == state.get(AXIS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Axis getRotationAxis(BlockState state) {
|
||||
return state.get(AXIS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidState getFluidState(BlockState state) {
|
||||
return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : Fluids.EMPTY.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
||||
builder.add(BlockStateProperties.WATERLOGGED);
|
||||
super.fillStateContainer(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updatePostPlacement(BlockState state, Direction direction, BlockState neighbourState,
|
||||
IWorld world, BlockPos pos, BlockPos neighbourPos) {
|
||||
if (state.get(BlockStateProperties.WATERLOGGED)) {
|
||||
world.getPendingFluidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
IFluidState ifluidstate = context.getWorld().getFluidState(context.getPos());
|
||||
return super.getStateForPlacement(context).with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue