water logging and contraptions

This commit is contained in:
LordGrimmauld 2020-06-17 23:16:27 +02:00
parent dc43f10451
commit c51e2abf48
9 changed files with 1329 additions and 1174 deletions

View file

@ -1,25 +1,5 @@
package com.simibubi.create.content.contraptions.components.structureMovement;
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isExtensionPole;
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isPistonHead;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.components.saw.SawBlock;
@ -42,20 +22,15 @@ import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.NBTHelper;
import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld;
import net.minecraft.block.AbstractButtonBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.DoorBlock;
import net.minecraft.block.PressurePlateBlock;
import net.minecraft.block.SlimeBlock;
import net.minecraft.block.*;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderTypeLookup;
import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.IFluidState;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.state.properties.ChestType;
import net.minecraft.state.properties.DoubleBlockHalf;
import net.minecraft.tileentity.TileEntity;
@ -72,6 +47,17 @@ import net.minecraft.world.gen.feature.template.Template.BlockInfo;
import net.minecraftforge.common.util.Constants.BlockFlags;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.stream.Collectors;
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isExtensionPole;
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isPistonHead;
public abstract class Contraption {
@ -88,9 +74,8 @@ public abstract class Contraption {
protected Set<BlockPos> cachedColliders;
protected Direction cachedColliderDirection;
protected BlockPos anchor;
List<BlockPos> renderOrder;
protected List<SuperGlueEntity> glueToRemove;
List<BlockPos> renderOrder;
public Contraption() {
blocks = new HashMap<>();
@ -102,6 +87,40 @@ public abstract class Contraption {
glueToRemove = new ArrayList<>();
}
protected static boolean isChassis(BlockState state) {
return state.getBlock() instanceof AbstractChassisBlock;
}
public static CompoundNBT getTileEntityNBT(World world, BlockPos pos) {
TileEntity tileentity = world.getTileEntity(pos);
CompoundNBT compoundnbt = null;
if (tileentity != null) {
compoundnbt = tileentity.write(new CompoundNBT());
compoundnbt.remove("x");
compoundnbt.remove("y");
compoundnbt.remove("z");
}
return compoundnbt;
}
public static Contraption fromNBT(World world, CompoundNBT nbt) {
String type = nbt.getString("Type");
Contraption contraption = AllContraptionTypes.fromType(type);
contraption.readNBT(world, nbt);
return contraption;
}
public static boolean isFrozen() {
return AllConfigs.SERVER.control.freezeContraptions.get();
}
protected static MovementBehaviour getMovement(BlockState state) {
Block block = state.getBlock();
if (!(block instanceof IPortableBlock))
return null;
return ((IPortableBlock) block).getMovementBehaviour();
}
public Set<BlockPos> getColliders(World world, Direction movementDirection) {
if (blocks == null)
return null;
@ -286,20 +305,13 @@ public abstract class Contraption {
}
add(pos, capture(world, pos));
if (blocks.size() > AllConfigs.SERVER.kinetics.maxBlocksMoved.get())
return false;
return true;
return blocks.size() <= AllConfigs.SERVER.kinetics.maxBlocksMoved.get();
}
protected boolean isAnchoringBlockAt(BlockPos pos) {
return pos.equals(anchor);
}
protected static boolean isChassis(BlockState state) {
return state.getBlock() instanceof AbstractChassisBlock;
}
private boolean moveChassis(World world, BlockPos pos, Direction movementDirection, List<BlockPos> frontier,
Set<BlockPos> visited) {
TileEntity te = world.getTileEntity(pos);
@ -341,18 +353,6 @@ public abstract class Contraption {
return Pair.of(new BlockInfo(pos, blockstate, compoundnbt), tileentity);
}
public static CompoundNBT getTileEntityNBT(World world, BlockPos pos) {
TileEntity tileentity = world.getTileEntity(pos);
CompoundNBT compoundnbt = null;
if (tileentity != null) {
compoundnbt = tileentity.write(new CompoundNBT());
compoundnbt.remove("x");
compoundnbt.remove("y");
compoundnbt.remove("z");
}
return compoundnbt;
}
public void addGlue(SuperGlueEntity entity) {
BlockPos pos = entity.getHangingPosition();
Direction direction = entity.getFacingDirection();
@ -377,13 +377,6 @@ public abstract class Contraption {
getActors().add(MutablePair.of(blockInfo, null));
}
public static Contraption fromNBT(World world, CompoundNBT nbt) {
String type = nbt.getString("Type");
Contraption contraption = AllContraptionTypes.fromType(type);
contraption.readNBT(world, nbt);
return contraption;
}
public void readNBT(World world, CompoundNBT nbt) {
blocks.clear();
renderOrder.clear();
@ -524,10 +517,6 @@ public abstract class Contraption {
return nbt;
}
public static boolean isFrozen() {
return AllConfigs.SERVER.control.freezeContraptions.get();
}
public void removeBlocksFromWorld(IWorld world, BlockPos offset) {
removeBlocksFromWorld(world, offset, (pos, state) -> false);
}
@ -548,8 +537,8 @@ public abstract class Contraption {
.add(offset);
if (customRemoval.test(add, block.state))
continue;
Block blockIn = world.getBlockState(add)
.getBlock();
BlockState oldState = world.getBlockState(add);
Block blockIn = oldState.getBlock();
if (block.state.getBlock() != blockIn)
iterator.remove();
world.getWorld()
@ -557,6 +546,10 @@ public abstract class Contraption {
int flags = 67;
if (blockIn instanceof DoorBlock)
flags = flags | 32 | 16;
if (blockIn instanceof IWaterLoggable && oldState.has(BlockStateProperties.WATERLOGGED) && oldState.get(BlockStateProperties.WATERLOGGED).booleanValue()) {
world.setBlockState(add, Blocks.WATER.getDefaultState(), flags);
continue;
}
world.setBlockState(add, Blocks.AIR.getDefaultState(), flags);
}
}
@ -569,7 +562,6 @@ public abstract class Contraption {
public void addBlocksToWorld(World world, BlockPos offset, Vec3d rotation,
BiPredicate<BlockPos, BlockState> customPlacement) {
stop(world);
StructureTransform transform = new StructureTransform(offset, rotation);
for (boolean nonBrittles : Iterate.trueAndFalse) {
@ -578,6 +570,7 @@ public abstract class Contraption {
continue;
BlockPos targetPos = transform.apply(block.pos);
BlockState state = transform.apply(block.state);
if (customPlacement.test(targetPos, state))
@ -602,6 +595,10 @@ public abstract class Contraption {
Block.spawnDrops(state, world, targetPos, null);
continue;
}
if (state.getBlock() instanceof IWaterLoggable && state.has(BlockStateProperties.WATERLOGGED)) {
IFluidState ifluidstate = world.getFluidState(targetPos);
state = state.with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
}
world.destroyBlock(targetPos, true);
world.setBlockState(targetPos, state, 3 | BlockFlags.IS_MOVING);
@ -686,13 +683,6 @@ public abstract class Contraption {
callBack.accept(getMovement(pair.getLeft().state), pair.getRight());
}
protected static MovementBehaviour getMovement(BlockState state) {
Block block = state.getBlock();
if (!(block instanceof IPortableBlock))
return null;
return ((IPortableBlock) block).getMovementBehaviour();
}
public void expandBoundsAroundAxis(Axis axis) {
AxisAlignedBB bb = bounds;
double maxXDiff = Math.max(bb.maxX - 1, -bb.minX);

View file

@ -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,19 +23,23 @@ 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 class MechanicalPistonHeadBlock extends ProperDirectionalBlock implements IWaterLoggable {
public static final EnumProperty<PistonType> TYPE = BlockStateProperties.PISTON_TYPE;
public MechanicalPistonHeadBlock(Properties p_i48415_1_) {
super(p_i48415_1_);
setDefaultState(super.getDefaultState().with(BlockStateProperties.WATERLOGGED, false));
}
@Override
protected void fillStateContainer(Builder<Block, BlockState> builder) {
builder.add(TYPE);
builder.add(TYPE, BlockStateProperties.WATERLOGGED);
super.fillStateContainer(builder);
}
@ -85,4 +90,24 @@ public class MechanicalPistonHeadBlock extends ProperDirectionalBlock {
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));
}
}

View file

@ -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,13 +21,16 @@ 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 class PistonExtensionPoleBlock extends ProperDirectionalBlock implements IWrenchable, IWaterLoggable {
public PistonExtensionPoleBlock(Properties properties) {
super(properties);
setDefaultState(getDefaultState().with(FACING, Direction.UP));
setDefaultState(getDefaultState().with(FACING, Direction.UP).with(BlockStateProperties.WATERLOGGED, false));
}
@Override
@ -88,8 +91,28 @@ public class PistonExtensionPoleBlock extends ProperDirectionalBlock implements
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
return getDefaultState().with(FACING, context.getFace()
.getOpposite());
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;
}
}

View file

@ -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,6 +28,7 @@ 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> {
@ -34,6 +39,15 @@ public class PulleyBlock extends HorizontalAxisKineticBlock implements ITE<Pulle
super(properties);
}
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 TileEntity createTileEntity(BlockState state, IBlockReader world) {
return AllTileEntities.ROPE_PULLEY.create();
@ -71,19 +85,16 @@ public class PulleyBlock extends HorizontalAxisKineticBlock implements ITE<Pulle
return AllShapes.PULLEY.get(state.get(HORIZONTAL_AXIS));
}
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 Class<PulleyTileEntity> getTileEntityClass() {
return PulleyTileEntity.class;
}
private static class RopeBlockBase extends Block {
private static class RopeBlockBase extends Block implements IWaterLoggable {
public RopeBlockBase(Properties properties) {
super(properties);
setDefaultState(super.getDefaultState().with(BlockStateProperties.WATERLOGGED, false));
}
@Override
@ -99,7 +110,7 @@ public class PulleyBlock extends HorizontalAxisKineticBlock implements ITE<Pulle
@Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (!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());
@ -115,6 +126,33 @@ public class PulleyBlock extends HorizontalAxisKineticBlock implements ITE<Pulle
}
}
@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));
}
}
public static class MagnetBlock extends RopeBlockBase {
@ -140,12 +178,6 @@ public class PulleyBlock extends HorizontalAxisKineticBlock implements ITE<Pulle
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return AllShapes.FOUR_VOXEL_POLE.get(Direction.UP);
}
}
@Override
public Class<PulleyTileEntity> getTileEntityClass() {
return PulleyTileEntity.class;
}
}

View file

@ -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;
@ -65,6 +69,11 @@ public class PulleyTileEntity extends LinearActuatorTileEntity {
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);
}
@ -95,20 +104,25 @@ public class PulleyTileEntity extends LinearActuatorTileEntity {
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(), 66);
world.setBlockState(magnetPos, AllBlocks.PULLEY_MAGNET.getDefaultState().with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER)), 66);
}
boolean[] waterlog = new boolean[(int) offset];
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(), 66);
world.setBlockState(pos.down(i), AllBlocks.ROPE.getDefaultState().with(BlockStateProperties.WATERLOGGED, waterlog[i]), 66);
}
if (movedContraption != null)

View file

@ -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

View file

@ -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,12 +18,14 @@ 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_);
setDefaultState(super.getDefaultState().with(BlockStateProperties.WATERLOGGED, false));
}
@Override
@ -53,4 +61,30 @@ public class PumpBlock extends DirectionalKineticBlock {
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));
}
}

View file

@ -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;
@ -24,6 +26,11 @@ public class CogWheelBlock extends ShaftBlock {
boolean isLarge;
private CogWheelBlock(boolean large, Properties properties) {
super(properties);
isLarge = large;
}
public static CogWheelBlock small(Properties properties) {
return new CogWheelBlock(false, properties);
}
@ -32,9 +39,12 @@ public class CogWheelBlock extends ShaftBlock {
return new CogWheelBlock(true, properties);
}
private CogWheelBlock(boolean large, Properties properties) {
super(properties);
isLarge = large;
public static boolean isSmallCog(BlockState state) {
return AllBlocks.COGWHEEL.has(state);
}
public static boolean isLargeCog(BlockState state) {
return AllBlocks.LARGE_COGWHEEL.has(state);
}
@Override
@ -66,8 +76,9 @@ public class CogWheelBlock extends ShaftBlock {
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()
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);
}
@ -76,10 +87,10 @@ public class CogWheelBlock extends ShaftBlock {
Axis preferredAxis = getPreferredAxis(context);
if (preferredAxis != null)
return this.getDefaultState()
.with(AXIS, preferredAxis);
.with(AXIS, preferredAxis).with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
return this.getDefaultState()
.with(AXIS, context.getFace()
.getAxis());
.getAxis()).with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
}
return getDefaultState().with(AXIS, ((IRotate) block).getRotationAxis(placedAgainst));
@ -95,14 +106,6 @@ public class CogWheelBlock extends ShaftBlock {
return isLarge ? 1f : .75f;
}
public static boolean isSmallCog(BlockState state) {
return AllBlocks.COGWHEEL.has(state);
}
public static boolean isLargeCog(BlockState state) {
return AllBlocks.LARGE_COGWHEEL.has(state);
}
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
items.add(new ItemStack(this));
}

View file

@ -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,12 +24,18 @@ 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);
setDefaultState(super.getDefaultState().with(BlockStateProperties.WATERLOGGED, false));
}
public static boolean isShaft(BlockState state) {
return AllBlocks.SHAFT.has(state);
}
@Override
@ -61,10 +73,6 @@ public class ShaftBlock extends RotatedPillarKineticBlock {
super.fillItemGroup(group, items);
}
public static boolean isShaft(BlockState state) {
return AllBlocks.SHAFT.has(state);
}
// IRotate:
@Override
@ -77,4 +85,29 @@ public class ShaftBlock extends RotatedPillarKineticBlock {
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));
}
}