From 33daccc39769aeea8677eb9b07092b0debe33bf5 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 13 Aug 2022 14:29:18 +0200 Subject: [PATCH] Committing self-wrench - Fluid Pumps now orient themselves at adjacent pipes when placed - Deployers mounted on minecart contraptions can no longer pick up minecart contraptions using a wrench --- .../deployer/DeployerFakePlayer.java | 1 + .../deployer/DeployerMovementBehaviour.java | 1 + .../deployer/DeployerMovingInteraction.java | 2 ++ .../mounted/MinecartContraptionItem.java | 3 ++ .../contraptions/fluids/PumpBlock.java | 33 +++++++++++++++---- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerFakePlayer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerFakePlayer.java index 682b626d7..15f408253 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerFakePlayer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerFakePlayer.java @@ -51,6 +51,7 @@ public class DeployerFakePlayer extends FakePlayer { Pair blockBreakingProgress; ItemStack spawnedItemEffects; public boolean placedTracks; + public boolean onMinecartContraption; public DeployerFakePlayer(ServerLevel world) { super(world, DEPLOYER_PROFILE); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java index 116918e76..e64bfce04 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java @@ -275,6 +275,7 @@ public class DeployerMovementBehaviour implements MovementBehaviour { private DeployerFakePlayer getPlayer(MovementContext context) { if (!(context.temporaryData instanceof DeployerFakePlayer) && context.world instanceof ServerLevel) { DeployerFakePlayer deployerFakePlayer = new DeployerFakePlayer((ServerLevel) context.world); + deployerFakePlayer.onMinecartContraption = context.contraption instanceof MountedContraption; deployerFakePlayer.getInventory() .load(context.tileData.getList("Inventory", Tag.TAG_COMPOUND)); if (context.data.contains("HeldItem")) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovingInteraction.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovingInteraction.java index 401d77731..58bedbfd1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovingInteraction.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovingInteraction.java @@ -6,6 +6,7 @@ import com.simibubi.create.AllItems; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.MovingInteractionBehaviour; +import com.simibubi.create.content.contraptions.components.structureMovement.mounted.MountedContraption; import com.simibubi.create.foundation.utility.NBTHelper; import net.minecraft.core.BlockPos; @@ -55,6 +56,7 @@ public class DeployerMovingInteraction extends MovingInteractionBehaviour { if (!(ctx.temporaryData instanceof DeployerFakePlayer) && ctx.world instanceof ServerLevel) { DeployerFakePlayer deployerFakePlayer = new DeployerFakePlayer((ServerLevel) ctx.world); + deployerFakePlayer.onMinecartContraption = ctx.contraption instanceof MountedContraption; deployerFakePlayer.getInventory() .load(ctx.tileData.getList("Inventory", Tag.TAG_COMPOUND)); ctx.temporaryData = fake = deployerFakePlayer; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java index 28c22731a..50bd66123 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java @@ -8,6 +8,7 @@ import javax.annotation.Nullable; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import com.simibubi.create.AllItems; +import com.simibubi.create.content.contraptions.components.deployer.DeployerFakePlayer; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity; @@ -208,6 +209,8 @@ public class MinecartContraptionItem extends Item { return; if (!entity.isAlive()) return; + if (player instanceof DeployerFakePlayer dfp && dfp.onMinecartContraption) + return; AbstractMinecart cart = (AbstractMinecart) entity; Type type = cart.getMinecartType(); if (type != Type.RIDEABLE && type != Type.FURNACE && type != Type.CHEST) diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpBlock.java index 7bf15694d..93956008f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpBlock.java @@ -5,14 +5,18 @@ import java.util.Random; import com.simibubi.create.AllShapes; import com.simibubi.create.AllTileEntities; import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock; +import com.simibubi.create.content.contraptions.fluids.pipes.FluidPipeBlock; import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel; import com.simibubi.create.foundation.block.ITE; +import com.simibubi.create.foundation.block.ProperWaterloggedBlock; +import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; import net.minecraft.network.protocol.game.DebugPackets; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.BlockGetter; @@ -32,7 +36,8 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.ticks.TickPriority; -public class PumpBlock extends DirectionalKineticBlock implements SimpleWaterloggedBlock, ICogWheel, ITE { +public class PumpBlock extends DirectionalKineticBlock + implements SimpleWaterloggedBlock, ICogWheel, ITE { public PumpBlock(Properties p_i48415_1_) { super(p_i48415_1_); @@ -96,10 +101,26 @@ public class PumpBlock extends DirectionalKineticBlock implements SimpleWaterlog @Override public BlockState getStateForPlacement(BlockPlaceContext context) { - FluidState FluidState = context.getLevel() - .getFluidState(context.getClickedPos()); - return super.getStateForPlacement(context).setValue(BlockStateProperties.WATERLOGGED, - Boolean.valueOf(FluidState.getType() == Fluids.WATER)); + BlockState toPlace = super.getStateForPlacement(context); + Level level = context.getLevel(); + BlockPos pos = context.getClickedPos(); + Player player = context.getPlayer(); + toPlace = ProperWaterloggedBlock.withWater(level, toPlace, pos); + + if (player != null && player.isSteppingCarefully()) + return toPlace; + + for (Direction d : Iterate.directions) { + BlockPos adjPos = pos.relative(d); + BlockState adjState = level.getBlockState(adjPos); + if (!FluidPipeBlock.canConnectTo(level, adjPos, adjState, d)) + continue; + toPlace = toPlace.setValue(FACING, d); + if (context.getClickedFace() == d.getOpposite()) + break; + } + + return toPlace; } public static boolean isPump(BlockState state) { @@ -113,7 +134,7 @@ public class PumpBlock extends DirectionalKineticBlock implements SimpleWaterlog return; if (state != oldState) world.scheduleTick(pos, this, 1, TickPriority.HIGH); - + if (isPump(state) && isPump(oldState) && state.getValue(FACING) == oldState.getValue(FACING) .getOpposite()) { BlockEntity tileEntity = world.getBlockEntity(pos);