Make track deploying advancement work in schematics

This commit is contained in:
cakeGit 2024-08-12 21:55:59 +01:00
parent 041e06b0b7
commit a56a214091

View file

@ -73,7 +73,7 @@ public class DeployerMovementBehaviour implements MovementBehaviour {
return; return;
activate(context, pos, player, mode); activate(context, pos, player, mode);
checkForPlacementAdvancement(context, player); checkForTrackPlacementAdvancement(context, player);
tryDisposeOfExcess(context); tryDisposeOfExcess(context);
context.stall = player.blockBreakingProgress != null; 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) { public void activate(MovementContext context, BlockPos pos, DeployerFakePlayer player, Mode mode) {
Level world = context.world; Level world = context.world;
player.placedTracks = false;
FilterItemStack filter = context.getFilterFromBE(); FilterItemStack filter = context.getFilterFromBE();
if (AllItems.SCHEMATIC.isIn(filter.item())) { if (AllItems.SCHEMATIC.isIn(filter.item())) {
activateAsSchematicPrinter(context, pos, player, world, filter.item()); activateAsSchematicPrinter(context, pos, player, world, filter.item());
@ -104,12 +106,11 @@ public class DeployerMovementBehaviour implements MovementBehaviour {
player.setYRot(AbstractContraptionEntity.yawFromVector(facingVec)); player.setYRot(AbstractContraptionEntity.yawFromVector(facingVec));
player.setXRot(xRot); player.setXRot(xRot);
player.placedTracks = false;
DeployerHandler.activate(player, vec, pos, facingVec, mode); 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) if ((context.contraption instanceof MountedContraption || context.contraption instanceof CarriageContraption)
&& player.placedTracks && context.blockEntityData != null && context.blockEntityData.contains("Owner")) && player.placedTracks && context.blockEntityData != null && context.blockEntityData.contains("Owner"))
AllAdvancements.SELF_DEPLOYING.awardTo(context.world.getPlayerByUUID(context.blockEntityData.getUUID("Owner"))); AllAdvancements.SELF_DEPLOYING.awardTo(context.world.getPlayerByUUID(context.blockEntityData.getUUID("Owner")));
@ -160,8 +161,11 @@ public class DeployerMovementBehaviour implements MovementBehaviour {
CompoundTag data = BlockHelper.prepareBlockEntityData(blockState, schematicWorld.getBlockEntity(pos)); CompoundTag data = BlockHelper.prepareBlockEntityData(blockState, schematicWorld.getBlockEntity(pos));
BlockSnapshot blocksnapshot = BlockSnapshot.create(world.dimension(), world, pos); BlockSnapshot blocksnapshot = BlockSnapshot.create(world.dimension(), world, pos);
BlockHelper.placeSchematicBlock(world, blockState, pos, contextStack, data); BlockHelper.placeSchematicBlock(world, blockState, pos, contextStack, data);
if (ForgeEventFactory.onBlockPlace(player, blocksnapshot, Direction.UP)) if (ForgeEventFactory.onBlockPlace(player, blocksnapshot, Direction.UP))
blocksnapshot.restore(true, false); blocksnapshot.restore(true, false);
else if (AllBlocks.TRACK.has(blockState))
player.placedTracks = true;
} }
@Override @Override