From 1d2da077561394f6c7df81ebfa506b6c7a09b3a4 Mon Sep 17 00:00:00 2001 From: Cake <65340665+cakeGit@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:29:57 +0100 Subject: [PATCH 1/3] Added return after schematic activation to prevent double interaction --- .../kinetics/deployer/DeployerMovementBehaviour.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java index 8e5c17140..9c9761b32 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java @@ -73,6 +73,7 @@ public class DeployerMovementBehaviour implements MovementBehaviour { return; activate(context, pos, player, mode); + checkForPlacementAdvancement(); tryDisposeOfExcess(context); context.stall = player.blockBreakingProgress != null; } @@ -81,8 +82,10 @@ public class DeployerMovementBehaviour implements MovementBehaviour { Level world = context.world; FilterItemStack filter = context.getFilterFromBE(); - if (AllItems.SCHEMATIC.isIn(filter.item())) + if (AllItems.SCHEMATIC.isIn(filter.item())) { activateAsSchematicPrinter(context, pos, player, world, filter.item()); + return; + } Vec3 facingVec = Vec3.atLowerCornerOf(context.state.getValue(DeployerBlock.FACING) .getNormal()); @@ -104,7 +107,9 @@ public class DeployerMovementBehaviour implements MovementBehaviour { player.placedTracks = false; DeployerHandler.activate(player, vec, pos, facingVec, mode); + } + protected void checkForPlacementAdvancement() { if ((context.contraption instanceof MountedContraption || context.contraption instanceof CarriageContraption) && player.placedTracks && context.blockEntityData != null && context.blockEntityData.contains("Owner")) AllAdvancements.SELF_DEPLOYING.awardTo(world.getPlayerByUUID(context.blockEntityData.getUUID("Owner"))); From 041e06b0b78ac8e90a39aad36b44bc249e4ae8df Mon Sep 17 00:00:00 2001 From: cakeGit <65340665+cakeGit@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:49:31 +0100 Subject: [PATCH 2/3] Testing implementation --- .../kinetics/deployer/DeployerMovementBehaviour.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java index 9c9761b32..728b11b16 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java @@ -73,7 +73,7 @@ public class DeployerMovementBehaviour implements MovementBehaviour { return; activate(context, pos, player, mode); - checkForPlacementAdvancement(); + checkForPlacementAdvancement(context, player); tryDisposeOfExcess(context); context.stall = player.blockBreakingProgress != null; } @@ -109,10 +109,10 @@ public class DeployerMovementBehaviour implements MovementBehaviour { DeployerHandler.activate(player, vec, pos, facingVec, mode); } - protected void checkForPlacementAdvancement() { + protected void checkForPlacementAdvancement(MovementContext context, DeployerFakePlayer player) { if ((context.contraption instanceof MountedContraption || context.contraption instanceof CarriageContraption) && player.placedTracks && context.blockEntityData != null && context.blockEntityData.contains("Owner")) - AllAdvancements.SELF_DEPLOYING.awardTo(world.getPlayerByUUID(context.blockEntityData.getUUID("Owner"))); + AllAdvancements.SELF_DEPLOYING.awardTo(context.world.getPlayerByUUID(context.blockEntityData.getUUID("Owner"))); } protected void activateAsSchematicPrinter(MovementContext context, BlockPos pos, DeployerFakePlayer player, From a56a214091e74961b18adc2739cd1e5bd193d43b Mon Sep 17 00:00:00 2001 From: cakeGit <65340665+cakeGit@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:55:59 +0100 Subject: [PATCH 3/3] Make track deploying advancement work in schematics --- .../kinetics/deployer/DeployerMovementBehaviour.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java index 728b11b16..4ced96591 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerMovementBehaviour.java @@ -73,7 +73,7 @@ public class DeployerMovementBehaviour implements MovementBehaviour { return; activate(context, pos, player, mode); - checkForPlacementAdvancement(context, player); + checkForTrackPlacementAdvancement(context, player); tryDisposeOfExcess(context); context.stall = player.blockBreakingProgress != null; } @@ -81,6 +81,8 @@ public class DeployerMovementBehaviour implements MovementBehaviour { public void activate(MovementContext context, BlockPos pos, DeployerFakePlayer player, Mode mode) { Level world = context.world; + player.placedTracks = false; + FilterItemStack filter = context.getFilterFromBE(); if (AllItems.SCHEMATIC.isIn(filter.item())) { activateAsSchematicPrinter(context, pos, player, world, filter.item()); @@ -104,12 +106,11 @@ public class DeployerMovementBehaviour implements MovementBehaviour { player.setYRot(AbstractContraptionEntity.yawFromVector(facingVec)); player.setXRot(xRot); - player.placedTracks = false; DeployerHandler.activate(player, vec, pos, facingVec, mode); } - protected void checkForPlacementAdvancement(MovementContext context, DeployerFakePlayer player) { + protected void checkForTrackPlacementAdvancement(MovementContext context, DeployerFakePlayer player) { if ((context.contraption instanceof MountedContraption || context.contraption instanceof CarriageContraption) && player.placedTracks && context.blockEntityData != null && context.blockEntityData.contains("Owner")) AllAdvancements.SELF_DEPLOYING.awardTo(context.world.getPlayerByUUID(context.blockEntityData.getUUID("Owner"))); @@ -146,7 +147,7 @@ public class DeployerMovementBehaviour implements MovementBehaviour { if (!context.contraption.hasUniversalCreativeCrate) { IItemHandler itemHandler = context.contraption.getSharedInventory(); for (ItemRequirement.StackRequirement required : requiredItems) { - ItemStack stack= ItemHelper + ItemStack stack = ItemHelper .extract(itemHandler, required::matches, ExtractionCountMode.EXACTLY, required.stack.getCount(), true); if (stack.isEmpty()) @@ -160,8 +161,11 @@ public class DeployerMovementBehaviour implements MovementBehaviour { CompoundTag data = BlockHelper.prepareBlockEntityData(blockState, schematicWorld.getBlockEntity(pos)); BlockSnapshot blocksnapshot = BlockSnapshot.create(world.dimension(), world, pos); BlockHelper.placeSchematicBlock(world, blockState, pos, contextStack, data); + if (ForgeEventFactory.onBlockPlace(player, blocksnapshot, Direction.UP)) blocksnapshot.restore(true, false); + else if (AllBlocks.TRACK.has(blockState)) + player.placedTracks = true; } @Override