From 7221f72ddfac9a59ad78103cdf94b36c31117a4f Mon Sep 17 00:00:00 2001 From: Snownee Date: Sat, 30 Jan 2021 21:09:04 +0800 Subject: [PATCH 1/6] Optimize contraption assembling --- .../base/GeneratingKineticTileEntity.java | 2 +- .../BlockMovementTraits.java | 20 ++++----- .../structureMovement/Contraption.java | 45 ++++++++++--------- .../bearing/ClockworkContraption.java | 10 +++-- .../chassis/ChassisTileEntity.java | 11 ++--- .../glue/SuperGlueEntity.java | 2 +- .../mounted/MountedContraption.java | 13 +++--- .../piston/PistonContraption.java | 9 ++-- .../pulley/PulleyTileEntity.java | 5 ++- 9 files changed, 62 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/GeneratingKineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/GeneratingKineticTileEntity.java index 279f177cc..fa0d6f017 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/GeneratingKineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/GeneratingKineticTileEntity.java @@ -38,7 +38,7 @@ public abstract class GeneratingKineticTileEntity extends KineticTileEntity { if (!(tileEntity instanceof KineticTileEntity)) return; KineticTileEntity sourceTe = (KineticTileEntity) tileEntity; - if (reActivateSource && sourceTe != null && Math.abs(sourceTe.getSpeed()) >= Math.abs(getGeneratedSpeed())) + if (reActivateSource && Math.abs(sourceTe.getSpeed()) >= Math.abs(getGeneratedSpeed())) reActivateSource = false; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementTraits.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementTraits.java index ad25a1b97..aaaef728b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementTraits.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementTraits.java @@ -53,8 +53,7 @@ import net.minecraft.world.World; public class BlockMovementTraits { - public static boolean movementNecessary(World world, BlockPos pos) { - BlockState state = world.getBlockState(pos); + public static boolean movementNecessary(BlockState state, World world, BlockPos pos) { if (isBrittle(state)) return true; if (state.getBlock() instanceof FenceGateBlock) @@ -68,18 +67,17 @@ public class BlockMovementTraits { return true; } - public static boolean movementAllowed(World world, BlockPos pos) { - BlockState blockState = world.getBlockState(pos); - Block block = blockState.getBlock(); + public static boolean movementAllowed(BlockState state, World world, BlockPos pos) { + Block block = state.getBlock(); if (block instanceof AbstractChassisBlock) return true; - if (blockState.getBlockHardness(world, pos) == -1) + if (state.getBlockHardness(world, pos) == -1) return false; - if (AllBlockTags.NON_MOVABLE.matches(blockState)) + if (AllBlockTags.NON_MOVABLE.matches(state)) return false; // Move controllers only when they aren't moving - if (block instanceof MechanicalPistonBlock && blockState.get(MechanicalPistonBlock.STATE) != PistonState.MOVING) + if (block instanceof MechanicalPistonBlock && state.get(MechanicalPistonBlock.STATE) != PistonState.MOVING) return true; if (block instanceof MechanicalBearingBlock) { TileEntity te = world.getTileEntity(pos); @@ -97,11 +95,11 @@ public class BlockMovementTraits { return !((PulleyTileEntity) te).running; } - if (AllBlocks.BELT.has(blockState)) + if (AllBlocks.BELT.has(state)) return true; - if (blockState.getBlock() instanceof GrindstoneBlock) + if (state.getBlock() instanceof GrindstoneBlock) return true; - return blockState.getPushReaction() != PushReaction.BLOCK; + return state.getPushReaction() != PushReaction.BLOCK; } /** diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index bb4dadb7f..8ed8f16fe 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -8,9 +8,11 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Queue; import java.util.Set; import java.util.UUID; import java.util.function.BiConsumer; @@ -148,7 +150,7 @@ public abstract class Contraption { } protected boolean addToInitialFrontier(World world, BlockPos pos, Direction forcedDirection, - List frontier) { + Queue frontier) { return true; } @@ -161,7 +163,7 @@ public abstract class Contraption { public boolean searchMovedStructure(World world, BlockPos pos, @Nullable Direction forcedDirection) { initialPassengers.clear(); - List frontier = new ArrayList<>(); + Queue frontier = new LinkedList<>(); Set visited = new HashSet<>(); anchor = pos; @@ -175,7 +177,7 @@ public abstract class Contraption { for (int limit = 100000; limit > 0; limit--) { if (frontier.isEmpty()) return true; - if (!moveBlock(world, frontier.remove(0), forcedDirection, frontier, visited)) + if (!moveBlock(world, forcedDirection, frontier, visited)) return false; } return false; @@ -241,20 +243,22 @@ public abstract class Contraption { fluidStorage.forEach((pos, mfs) -> mfs.tick(entity, pos, world.isRemote)); } - protected boolean moveBlock(World world, BlockPos pos, @Nullable Direction forcedDirection, List frontier, + protected boolean moveBlock(World world, @Nullable Direction forcedDirection, Queue frontier, Set visited) { + BlockPos pos = frontier.poll(); + if (pos == null) + return false; visited.add(pos); - frontier.remove(pos); if (!world.isBlockPresent(pos)) return false; if (isAnchoringBlockAt(pos)) return true; - if (!BlockMovementTraits.movementNecessary(world, pos)) - return true; - if (!movementAllowed(world, pos)) - return false; BlockState state = world.getBlockState(pos); + if (!BlockMovementTraits.movementNecessary(state, world, pos)) + return true; + if (!movementAllowed(state, world, pos)) + return false; if (state.getBlock() instanceof AbstractChassisBlock && !moveChassis(world, pos, forcedDirection, frontier, visited)) return false; @@ -290,9 +294,10 @@ public abstract class Contraption { } // Cart assemblers attach themselves - BlockState stateBelow = world.getBlockState(pos.down()); - if (!visited.contains(pos.down()) && AllBlocks.CART_ASSEMBLER.has(stateBelow)) - frontier.add(pos.down()); + BlockPos posDown = pos.down(); + BlockState stateBelow = world.getBlockState(posDown); + if (!visited.contains(posDown) && AllBlocks.CART_ASSEMBLER.has(stateBelow)) + frontier.add(posDown); Map superglue = SuperGlueHandler.gatherGlue(world, pos); @@ -302,7 +307,7 @@ public abstract class Contraption { BlockState blockState = world.getBlockState(offsetPos); if (isAnchoringBlockAt(offsetPos)) continue; - if (!movementAllowed(world, offsetPos)) { + if (!movementAllowed(blockState, world, offsetPos)) { if (offset == forcedDirection) return false; continue; @@ -336,7 +341,7 @@ public abstract class Contraption { return blocks.size() <= AllConfigs.SERVER.kinetics.maxBlocksMoved.get(); } - private void moveBearing(BlockPos pos, List frontier, Set visited, BlockState state) { + private void moveBearing(BlockPos pos, Queue frontier, Set visited, BlockState state) { Direction facing = state.get(MechanicalBearingBlock.FACING); if (!canAxisBeStabilized(facing.getAxis())) { BlockPos offset = pos.offset(facing); @@ -347,7 +352,7 @@ public abstract class Contraption { pendingSubContraptions.add(new BlockFace(pos, facing)); } - private void moveBelt(BlockPos pos, List frontier, Set visited, BlockState state) { + private void moveBelt(BlockPos pos, Queue frontier, Set visited, BlockState state) { BlockPos nextPos = BeltBlock.nextSegmentPosition(state, pos, true); BlockPos prevPos = BeltBlock.nextSegmentPosition(state, pos, false); if (nextPos != null && !visited.contains(nextPos)) @@ -368,7 +373,7 @@ public abstract class Contraption { } } - private void movePulley(World world, BlockPos pos, List frontier, Set visited) { + private void movePulley(World world, BlockPos pos, Queue frontier, Set visited) { int limit = AllConfigs.SERVER.kinetics.maxRopeLength.get(); BlockPos ropePos = pos; while (limit-- >= 0) { @@ -386,7 +391,7 @@ public abstract class Contraption { } } - private boolean moveMechanicalPiston(World world, BlockPos pos, List frontier, Set visited, + private boolean moveMechanicalPiston(World world, BlockPos pos, Queue frontier, Set visited, BlockState state) { int limit = AllConfigs.SERVER.kinetics.maxPistonPoles.get(); Direction direction = state.get(MechanicalPistonBlock.FACING); @@ -432,7 +437,7 @@ public abstract class Contraption { return true; } - private boolean moveChassis(World world, BlockPos pos, Direction movementDirection, List frontier, + private boolean moveChassis(World world, BlockPos pos, Direction movementDirection, Queue frontier, Set visited) { TileEntity te = world.getTileEntity(pos); if (!(te instanceof ChassisTileEntity)) @@ -517,8 +522,8 @@ public abstract class Contraption { return globalPos.subtract(anchor); } - protected boolean movementAllowed(World world, BlockPos pos) { - return BlockMovementTraits.movementAllowed(world, pos); + protected boolean movementAllowed(BlockState state, World world, BlockPos pos) { + return BlockMovementTraits.movementAllowed(state, world, pos); } protected boolean isAnchoringBlockAt(BlockPos pos) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java index 31b7709f3..785a4c2ad 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; import java.util.HashSet; -import java.util.List; +import java.util.Queue; import java.util.Set; import org.apache.commons.lang3.tuple.Pair; @@ -92,11 +92,13 @@ public class ClockworkContraption extends Contraption { } @Override - protected boolean moveBlock(World world, BlockPos pos, Direction direction, List frontier, + protected boolean moveBlock(World world, Direction direction, Queue frontier, Set visited) { - if (ignoreBlocks.contains(pos)) + if (ignoreBlocks.contains(frontier.peek())) { + frontier.poll(); return true; - return super.moveBlock(world, pos, direction, frontier, visited); + } + return super.moveBlock(world, direction, frontier, visited); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/ChassisTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/ChassisTileEntity.java index 832b656da..fcb4f1c1b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/ChassisTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/ChassisTileEntity.java @@ -7,6 +7,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Queue; import java.util.Set; import com.simibubi.create.AllBlocks; @@ -76,12 +77,12 @@ public class ChassisTileEntity extends SmartTileEntity { } public List collectChassisGroup() { - List frontier = new ArrayList<>(); + Queue frontier = new LinkedList<>(); List collected = new ArrayList<>(); Set visited = new HashSet<>(); frontier.add(pos); while (!frontier.isEmpty()) { - BlockPos current = frontier.remove(0); + BlockPos current = frontier.poll(); if (visited.contains(current)) continue; visited.add(current); @@ -96,7 +97,7 @@ public class ChassisTileEntity extends SmartTileEntity { return collected; } - public boolean addAttachedChasses(List frontier, Set visited) { + public boolean addAttachedChasses(Queue frontier, Set visited) { BlockState state = getBlockState(); if (!(state.getBlock() instanceof AbstractChassisBlock)) return false; @@ -166,7 +167,7 @@ public class ChassisTileEntity extends SmartTileEntity { break; // Ignore replaceable Blocks and Air-like - if (!BlockMovementTraits.movementNecessary(world, current)) + if (!BlockMovementTraits.movementNecessary(currentState, world, current)) break; if (BlockMovementTraits.isBrittle(currentState)) break; @@ -207,7 +208,7 @@ public class ChassisTileEntity extends SmartTileEntity { continue; if (!searchPos.withinDistance(pos, chassisRange + .5f)) continue; - if (!BlockMovementTraits.movementNecessary(world, searchPos)) + if (!BlockMovementTraits.movementNecessary(searchedState, world, searchPos)) continue; if (BlockMovementTraits.isBrittle(searchedState)) continue; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java index f677487af..eba72ea54 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java @@ -180,7 +180,7 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat BlockState state = world.getBlockState(pos); if (BlockMovementTraits.isBlockAttachedTowards(world, pos, state, direction)) return true; - if (!BlockMovementTraits.movementNecessary(world, pos)) + if (!BlockMovementTraits.movementNecessary(state, world, pos)) return false; if (BlockMovementTraits.notSupportive(state, direction)) return false; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java index 3d6a28dd8..b8b219a5b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java @@ -2,7 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.mo import static com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerBlock.RAIL_SHAPE; -import java.util.List; +import java.util.Queue; import org.apache.commons.lang3.tuple.Pair; @@ -70,7 +70,7 @@ public class MountedContraption extends Contraption { } @Override - protected boolean addToInitialFrontier(World world, BlockPos pos, Direction direction, List frontier) { + protected boolean addToInitialFrontier(World world, BlockPos pos, Direction direction, Queue frontier) { frontier.clear(); frontier.add(pos.up()); return true; @@ -104,11 +104,10 @@ public class MountedContraption extends Contraption { } @Override - protected boolean movementAllowed(World world, BlockPos pos) { - BlockState blockState = world.getBlockState(pos); - if (!pos.equals(anchor) && AllBlocks.CART_ASSEMBLER.has(blockState)) - return testSecondaryCartAssembler(world, blockState, pos); - return super.movementAllowed(world, pos); + protected boolean movementAllowed(BlockState state, World world, BlockPos pos) { + if (!pos.equals(anchor) && AllBlocks.CART_ASSEMBLER.has(state)) + return testSecondaryCartAssembler(world, state, pos); + return super.movementAllowed(state, world, pos); } protected boolean testSecondaryCartAssembler(World world, BlockState state, BlockPos pos) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java index 1e101fd94..0eada3483 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java @@ -23,6 +23,7 @@ import org.apache.commons.lang3.tuple.Pair; import java.util.ArrayList; import java.util.List; +import java.util.Queue; import static com.simibubi.create.AllBlocks.MECHANICAL_PISTON_HEAD; import static com.simibubi.create.AllBlocks.PISTON_EXTENSION_POLE; @@ -144,7 +145,7 @@ public class PistonContraption extends TranslatingContraption { } @Override - protected boolean addToInitialFrontier(World world, BlockPos pos, Direction direction, List frontier) { + protected boolean addToInitialFrontier(World world, BlockPos pos, Direction direction, Queue frontier) { frontier.clear(); boolean sticky = isStickyPiston(world.getBlockState(pos.offset(orientation, -1))); boolean retracting = direction != orientation; @@ -156,14 +157,14 @@ public class PistonContraption extends TranslatingContraption { BlockPos currentPos = pos.offset(orientation, offset + initialExtensionProgress); if (!world.isBlockPresent(currentPos)) return false; - if (!BlockMovementTraits.movementNecessary(world, currentPos)) - return true; BlockState state = world.getBlockState(currentPos); + if (!BlockMovementTraits.movementNecessary(state, world, currentPos)) + return true; if (BlockMovementTraits.isBrittle(state) && !(state.getBlock() instanceof CarpetBlock)) return true; if (isPistonHead(state) && state.get(FACING) == direction.getOpposite()) return true; - if (!BlockMovementTraits.movementAllowed(world, currentPos)) + if (!BlockMovementTraits.movementAllowed(state, world, currentPos)) return retracting; if (retracting && state.getPushReaction() == PushReaction.PUSH_ONLY) return true; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java index e2d4b7c0d..54cee9d6a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java @@ -176,9 +176,10 @@ public class PulleyTileEntity extends LinearActuatorTileEntity { return; BlockPos posBelow = pos.down((int) (offset + getMovementSpeed()) + 1); - if (!BlockMovementTraits.movementNecessary(world, posBelow)) + BlockState state = world.getBlockState(posBelow); + if (!BlockMovementTraits.movementNecessary(state, world, posBelow)) return; - if (BlockMovementTraits.isBrittle(world.getBlockState(posBelow))) + if (BlockMovementTraits.isBrittle(state)) return; disassemble(); From 3525ce49ce9b7afba5e5ffb38edf439774de7cbe Mon Sep 17 00:00:00 2001 From: Snownee Date: Sun, 31 Jan 2021 02:12:31 +0800 Subject: [PATCH 2/6] Player Feedback, Part I --- .../structureMovement/AssemblyException.java | 23 +++++++++++++++ .../structureMovement/Contraption.java | 28 +++++++++++++------ .../bearing/BearingContraption.java | 3 +- .../bearing/ClockworkBearingTileEntity.java | 27 ++++++++++++++++-- .../bearing/ClockworkContraption.java | 5 ++-- .../bearing/MechanicalBearingTileEntity.java | 24 +++++++++++++++- .../bearing/StabilizedContraption.java | 3 +- .../mounted/CartAssemblerBlock.java | 14 ++++++++-- .../mounted/CartAssemblerTileEntity.java | 11 +++++++- .../mounted/MountedContraption.java | 3 +- .../piston/LinearActuatorTileEntity.java | 26 +++++++++++++++-- .../piston/MechanicalPistonTileEntity.java | 3 +- .../piston/PistonContraption.java | 18 ++++++++---- .../pulley/PulleyContraption.java | 3 +- .../pulley/PulleyTileEntity.java | 10 ++++++- 15 files changed, 169 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java new file mode 100644 index 000000000..67e595602 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java @@ -0,0 +1,23 @@ +package com.simibubi.create.content.contraptions.components.structureMovement; + +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; + +public class AssemblyException extends RuntimeException { + public final ITextComponent message; + + public AssemblyException(ITextComponent message) { + this.message = message; + } + + public AssemblyException(String langKey, Object... objects) { + this(new TranslationTextComponent("gui.goggles.contraptions." + langKey, objects)); + } + + public static AssemblyException unmovableBlock(BlockPos pos, BlockState state) { + return new AssemblyException("unmovableBlock", pos.getX(), pos.getY(), pos.getZ(), + new TranslationTextComponent(state.getBlock().getTranslationKey())); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index 8ed8f16fe..e2344c503 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -135,7 +135,7 @@ public abstract class Contraption { stabilizedSubContraptions = new HashMap<>(); } - public abstract boolean assemble(World world, BlockPos pos); + public abstract boolean assemble(World world, BlockPos pos) throws AssemblyException; protected abstract boolean canAxisBeStabilized(Axis axis); @@ -180,7 +180,7 @@ public abstract class Contraption { if (!moveBlock(world, forcedDirection, frontier, visited)) return false; } - return false; + throw new AssemblyException("structureTooLarge"); } public void onEntityCreated(AbstractContraptionEntity entity) { @@ -192,8 +192,12 @@ public abstract class Contraption { StabilizedContraption subContraption = new StabilizedContraption(face); World world = entity.world; BlockPos pos = blockFace.getPos(); - if (!subContraption.assemble(world, pos)) + try { + if (!subContraption.assemble(world, pos)) + continue; + } catch (AssemblyException e) { continue; + } subContraption.removeBlocksFromWorld(world, BlockPos.ZERO); OrientedContraptionEntity movedContraption = OrientedContraptionEntity.create(world, subContraption, Optional.of(face)); @@ -243,6 +247,7 @@ public abstract class Contraption { fluidStorage.forEach((pos, mfs) -> mfs.tick(entity, pos, world.isRemote)); } + /** move the first block in frontier queue */ protected boolean moveBlock(World world, @Nullable Direction forcedDirection, Queue frontier, Set visited) { BlockPos pos = frontier.poll(); @@ -250,15 +255,17 @@ public abstract class Contraption { return false; visited.add(pos); + if (World.isOutsideBuildHeight(pos)) + return true; if (!world.isBlockPresent(pos)) - return false; + throw new AssemblyException("chunkNotLoaded"); if (isAnchoringBlockAt(pos)) return true; BlockState state = world.getBlockState(pos); if (!BlockMovementTraits.movementNecessary(state, world, pos)) return true; if (!movementAllowed(state, world, pos)) - return false; + throw AssemblyException.unmovableBlock(pos, state); if (state.getBlock() instanceof AbstractChassisBlock && !moveChassis(world, pos, forcedDirection, frontier, visited)) return false; @@ -309,7 +316,7 @@ public abstract class Contraption { continue; if (!movementAllowed(blockState, world, offsetPos)) { if (offset == forcedDirection) - return false; + throw AssemblyException.unmovableBlock(pos, state); continue; } @@ -338,7 +345,10 @@ public abstract class Contraption { } addBlock(pos, capture(world, pos)); - return blocks.size() <= AllConfigs.SERVER.kinetics.maxBlocksMoved.get(); + if (blocks.size() <= AllConfigs.SERVER.kinetics.maxBlocksMoved.get()) + return true; + else + throw new AssemblyException("structureTooLarge"); } private void moveBearing(BlockPos pos, Queue frontier, Set visited, BlockState state) { @@ -414,7 +424,7 @@ public abstract class Contraption { break; } if (limit <= -1) - return false; + throw new AssemblyException("tooManyPistonPoles"); } BlockPos searchPos = pos; @@ -433,7 +443,7 @@ public abstract class Contraption { } if (limit <= -1) - return false; + throw new AssemblyException("tooManyPistonPoles"); return true; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java index 76db5bd8b..135a94ea0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.AllTags.AllBlockTags; import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import net.minecraft.nbt.CompoundNBT; @@ -29,7 +30,7 @@ public class BearingContraption extends Contraption { } @Override - public boolean assemble(World world, BlockPos pos) { + public boolean assemble(World world, BlockPos pos) throws AssemblyException { BlockPos offset = pos.offset(facing); if (!searchMovedStructure(world, offset, null)) return false; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java index aa465f4e9..35a036a50 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java @@ -6,6 +6,7 @@ import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.bearing.ClockworkContraption.HandType; import com.simibubi.create.foundation.advancement.AllTriggers; @@ -25,6 +26,7 @@ import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.text.ITextComponent; public class ClockworkBearingTileEntity extends KineticTileEntity implements IBearingTileEntity { @@ -37,6 +39,7 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe protected boolean running; protected boolean assembleNextTick; + protected ITextComponent lastException; protected ScrollOptionBehaviour operationMode; @@ -199,8 +202,14 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe Direction direction = getBlockState().get(BlockStateProperties.FACING); // Collect Construct - Pair contraption = - ClockworkContraption.assembleClockworkAt(world, pos, direction); + Pair contraption; + try { + contraption = ClockworkContraption.assembleClockworkAt(world, pos, direction); + lastException = null; + } catch (AssemblyException e) { + lastException = e.message; + return; + } if (contraption == null) return; if (contraption.getLeft() == null) @@ -284,6 +293,8 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe compound.putBoolean("Running", running); compound.putFloat("HourAngle", hourAngle); compound.putFloat("MinuteAngle", minuteAngle); + if (lastException != null) + compound.putString("LastException", ITextComponent.Serializer.toJson(lastException)); super.write(compound, clientPacket); } @@ -295,6 +306,10 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe running = compound.getBoolean("Running"); hourAngle = compound.getFloat("HourAngle"); minuteAngle = compound.getFloat("MinuteAngle"); + if (compound.contains("LastException")) + lastException = ITextComponent.Serializer.fromJson(compound.getString("LastException")); + else + lastException = null; super.read(compound, clientPacket); if (!clientPacket) @@ -393,4 +408,12 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe return pos; } + @Override + public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { + boolean added = super.addToGoggleTooltip(tooltip, isPlayerSneaking); + if (lastException != null) + tooltip.add(lastException.getFormattedText()); + return lastException != null || added; + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java index 785a4c2ad..be481d66e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java @@ -7,6 +7,7 @@ import java.util.Set; import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.foundation.utility.NBTHelper; @@ -39,7 +40,7 @@ public class ClockworkContraption extends Contraption { } public static Pair assembleClockworkAt(World world, BlockPos pos, - Direction direction) { + Direction direction) throws AssemblyException { int hourArmBlocks = 0; ClockworkContraption hourArm = new ClockworkContraption(); @@ -82,7 +83,7 @@ public class ClockworkContraption extends Contraption { } @Override - public boolean assemble(World world, BlockPos pos) { + public boolean assemble(World world, BlockPos pos) throws AssemblyException { return searchMovedStructure(world, pos, facing); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java index b4dde3bc4..1bb979484 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java @@ -6,6 +6,7 @@ import java.util.List; import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity; import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.item.TooltipHelper; @@ -22,6 +23,7 @@ import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.text.ITextComponent; public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity implements IBearingTileEntity { @@ -31,6 +33,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp protected boolean running; protected boolean assembleNextTick; protected float clientAngleDiff; + protected ITextComponent lastException; public MechanicalBearingTileEntity(TileEntityType type) { super(type); @@ -62,6 +65,8 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp public void write(CompoundNBT compound, boolean clientPacket) { compound.putBoolean("Running", running); compound.putFloat("Angle", angle); + if (lastException != null) + compound.putString("LastException", ITextComponent.Serializer.toJson(lastException)); super.write(compound, clientPacket); } @@ -70,6 +75,10 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp float angleBefore = angle; running = compound.getBoolean("Running"); angle = compound.getFloat("Angle"); + if (compound.contains("LastException")) + lastException = ITextComponent.Serializer.fromJson(compound.getString("LastException")); + else + lastException = null; super.read(compound, clientPacket); if (!clientPacket) return; @@ -120,8 +129,14 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp Direction direction = getBlockState().get(FACING); BearingContraption contraption = new BearingContraption(isWindmill(), direction); - if (!contraption.assemble(world, pos)) + try { + lastException = null; + if (!contraption.assemble(world, pos)) + return; + } catch (AssemblyException e) { + lastException = e.message; return; + } if (isWindmill()) AllTriggers.triggerForNearbyPlayers(AllTriggers.WINDMILL, world, pos, 5); @@ -282,4 +297,11 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp return true; } + @Override + public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { + boolean added = super.addToGoggleTooltip(tooltip, isPlayerSneaking); + if (lastException != null) + tooltip.add(lastException.getFormattedText()); + return lastException != null || added; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java index f54d09beb..3e5aaab58 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import net.minecraft.nbt.CompoundNBT; @@ -20,7 +21,7 @@ public class StabilizedContraption extends Contraption { } @Override - public boolean assemble(World world, BlockPos pos) { + public boolean assemble(World world, BlockPos pos) throws AssemblyException { BlockPos offset = pos.offset(facing); if (!searchMovedStructure(world, offset, null)) return false; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java index 49c337697..5813f6afe 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.mo import com.simibubi.create.AllBlocks; import com.simibubi.create.AllShapes; import com.simibubi.create.AllTileEntities; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity.CartMovementMode; import com.simibubi.create.content.contraptions.components.structureMovement.train.CouplingHandler; @@ -229,13 +230,20 @@ public class CartAssemblerBlock extends AbstractRailBlock .isCoupledThroughContraption()) return; - CartMovementMode mode = - getTileEntityOptional(world, pos).map(te -> CartMovementMode.values()[te.movementMode.value]) + + Optional assembler = getTileEntityOptional(world, pos); + CartMovementMode mode = assembler.map(te -> CartMovementMode.values()[te.movementMode.value]) .orElse(CartMovementMode.ROTATE); MountedContraption contraption = new MountedContraption(mode); - if (!contraption.assemble(world, pos)) + try { + assembler.ifPresent(te -> te.lastException = null); + if (!contraption.assemble(world, pos)) + return; + } catch (AssemblyException e) { + assembler.ifPresent(te -> te.lastException = e.message); return; + } boolean couplingFound = contraption.connectedCart != null; Optional initialOrientation = cart.getMotion() diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerTileEntity.java index 4e98a97be..6e1c3be7a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerTileEntity.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.mo import java.util.List; +import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation; import com.simibubi.create.foundation.gui.AllIcons; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; @@ -16,12 +17,14 @@ import net.minecraft.state.properties.RailShape; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.Vec3d; +import net.minecraft.util.text.ITextComponent; -public class CartAssemblerTileEntity extends SmartTileEntity { +public class CartAssemblerTileEntity extends SmartTileEntity implements IHaveGoggleInformation { private static final int assemblyCooldown = 8; protected ScrollOptionBehaviour movementMode; private int ticksSinceMinecartUpdate; + protected ITextComponent lastException; //TODO public CartAssemblerTileEntity(TileEntityType type) { super(type); @@ -104,4 +107,10 @@ public class CartAssemblerTileEntity extends SmartTileEntity { return ticksSinceMinecartUpdate >= assemblyCooldown; } + @Override + public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { + if (lastException != null) + tooltip.add(lastException.getFormattedText()); + return lastException != null; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java index b8b219a5b..a38ad48fe 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java @@ -8,6 +8,7 @@ import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity.CartMovementMode; import com.simibubi.create.foundation.utility.Iterate; @@ -52,7 +53,7 @@ public class MountedContraption extends Contraption { } @Override - public boolean assemble(World world, BlockPos pos) { + public boolean assemble(World world, BlockPos pos) throws AssemblyException { BlockState state = world.getBlockState(pos); if (!state.has(RAIL_SHAPE)) return false; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java index 603f5b5e6..e92f2d807 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java @@ -4,6 +4,7 @@ import java.util.List; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.IControlContraption; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; @@ -17,6 +18,7 @@ import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; +import net.minecraft.util.text.ITextComponent; public abstract class LinearActuatorTileEntity extends KineticTileEntity implements IControlContraption { @@ -27,6 +29,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme protected boolean forceMove; protected ScrollOptionBehaviour movementMode; protected boolean waitingForSpeedChange; + protected ITextComponent lastException; // Custom position sync protected float clientOffsetDiff; @@ -80,7 +83,12 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme return; } else { if (getSpeed() != 0) - assemble(); + try { + assemble(); + lastException = null; + } catch (AssemblyException e) { + lastException = e.message; + } } return; } @@ -153,6 +161,8 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme compound.putBoolean("Running", running); compound.putBoolean("Waiting", waitingForSpeedChange); compound.putFloat("Offset", offset); + if (lastException != null) + compound.putString("LastException", ITextComponent.Serializer.toJson(lastException)); super.write(compound, clientPacket); if (clientPacket && forceMove) { @@ -169,6 +179,10 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme running = compound.getBoolean("Running"); waitingForSpeedChange = compound.getBoolean("Waiting"); offset = compound.getFloat("Offset"); + if (compound.contains("LastException")) + lastException = ITextComponent.Serializer.fromJson(compound.getString("LastException")); + else + lastException = null; super.read(compound, clientPacket); if (!clientPacket) @@ -185,7 +199,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme public abstract void disassemble(); - protected abstract void assemble(); + protected abstract void assemble() throws AssemblyException; protected abstract int getExtensionRange(); @@ -289,4 +303,12 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme return pos; } + @Override + public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { + boolean added = super.addToGoggleTooltip(tooltip, isPlayerSneaking); + if (lastException != null) + tooltip.add(lastException.getFormattedText()); + return lastException != null || added; + } + } \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/MechanicalPistonTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/MechanicalPistonTileEntity.java index f84a04b97..b04120c7d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/MechanicalPistonTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/MechanicalPistonTileEntity.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.pi import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.base.IRotate; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionCollider; import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.DirectionalExtenderScrollOptionSlot; @@ -41,7 +42,7 @@ public class MechanicalPistonTileEntity extends LinearActuatorTileEntity { } @Override - public void assemble() { + public void assemble() throws AssemblyException { if (!(world.getBlockState(pos) .getBlock() instanceof MechanicalPistonBlock)) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java index 0eada3483..39a48d58e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.piston; import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.BlockMovementTraits; import com.simibubi.create.content.contraptions.components.structureMovement.TranslatingContraption; import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.*; @@ -52,7 +53,7 @@ public class PistonContraption extends TranslatingContraption { } @Override - public boolean assemble(World world, BlockPos pos) { + public boolean assemble(World world, BlockPos pos) throws AssemblyException { if (!collectExtensions(world, pos, orientation)) return false; int count = blocks.size(); @@ -90,7 +91,7 @@ public class PistonContraption extends TranslatingContraption { nextBlock = world.getBlockState(actualStart.offset(direction)); if (extensionsInFront > MechanicalPistonBlock.maxAllowedPistonPoles()) - return false; + throw new AssemblyException("tooManyPistonPoles"); } } @@ -113,7 +114,7 @@ public class PistonContraption extends TranslatingContraption { nextBlock = world.getBlockState(end.offset(direction.getOpposite())); if (extensionsInFront + extensionsInBack > MechanicalPistonBlock.maxAllowedPistonPoles()) - return false; + throw new AssemblyException("tooManyPistonPoles"); } anchor = pos.offset(direction, initialExtensionProgress + 1); @@ -125,7 +126,7 @@ public class PistonContraption extends TranslatingContraption { 1, 1); if (extensionLength == 0) - return false; + throw new AssemblyException("noPistonPoles"); bounds = new AxisAlignedBB(0, 0, 0, 0, 0, 0); @@ -155,8 +156,10 @@ public class PistonContraption extends TranslatingContraption { if (offset == 1 && retracting) return true; BlockPos currentPos = pos.offset(orientation, offset + initialExtensionProgress); + if (retracting && World.isOutsideBuildHeight(currentPos)) + return true; if (!world.isBlockPresent(currentPos)) - return false; + throw new AssemblyException("chunkNotLoaded"); BlockState state = world.getBlockState(currentPos); if (!BlockMovementTraits.movementNecessary(state, world, currentPos)) return true; @@ -165,7 +168,10 @@ public class PistonContraption extends TranslatingContraption { if (isPistonHead(state) && state.get(FACING) == direction.getOpposite()) return true; if (!BlockMovementTraits.movementAllowed(state, world, currentPos)) - return retracting; + if (retracting) + return true; + else + throw AssemblyException.unmovableBlock(currentPos, state); if (retracting && state.getPushReaction() == PushReaction.PUSH_ONLY) return true; frontier.add(currentPos); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyContraption.java index d4a48a889..4453fdadd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyContraption.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.pulley; import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.TranslatingContraption; import net.minecraft.nbt.CompoundNBT; @@ -23,7 +24,7 @@ public class PulleyContraption extends TranslatingContraption { } @Override - public boolean assemble(World world, BlockPos pos) { + public boolean assemble(World world, BlockPos pos) throws AssemblyException { if (!searchMovedStructure(world, pos, null)) return false; startMoving(world); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java index 54cee9d6a..b1894d543 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.pulley; import com.simibubi.create.AllBlocks; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.BlockMovementTraits; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionCollider; import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity; @@ -22,6 +23,7 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; +import net.minecraft.util.text.ITextComponent; public class PulleyTileEntity extends LinearActuatorTileEntity { @@ -42,7 +44,7 @@ public class PulleyTileEntity extends LinearActuatorTileEntity { } @Override - protected void assemble() { + protected void assemble() throws AssemblyException { if (!(world.getBlockState(pos) .getBlock() instanceof PulleyBlock)) return; @@ -189,12 +191,18 @@ public class PulleyTileEntity extends LinearActuatorTileEntity { @Override protected void read(CompoundNBT compound, boolean clientPacket) { initialOffset = compound.getInt("InitialOffset"); + if (compound.contains("LastException")) + lastException = ITextComponent.Serializer.fromJson(compound.getString("LastException")); + else + lastException = null; super.read(compound, clientPacket); } @Override public void write(CompoundNBT compound, boolean clientPacket) { compound.putInt("InitialOffset", initialOffset); + if (lastException != null) + compound.putString("LastException", ITextComponent.Serializer.toJson(lastException)); super.write(compound, clientPacket); } From cb2c56d772e23fd1405d2d89b11e7a041b2cbc6a Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sun, 7 Feb 2021 18:09:08 +0100 Subject: [PATCH 3/6] Gantry shaft placement assist --- .../structureMovement/bearing/SailBlock.java | 11 ---- .../relays/advanced/GantryShaftBlock.java | 54 +++++++++++++++++++ 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/SailBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/SailBlock.java index fbc1517c7..8e12c734a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/SailBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/SailBlock.java @@ -72,17 +72,6 @@ public class SailBlock extends ProperDirectionalBlock { return ActionResultType.PASS; offset.placeInWorld(world, ((BlockItem) heldItem.getItem()).getBlock().getDefaultState(), player, heldItem); - - /*BlockState blockState = ((BlockItem) heldItem.getItem()).getBlock() - .getDefaultState() - .with(FACING, state.get(FACING)); - BlockPos offsetPos = new BlockPos(offset.getPos()); - if (!world.isRemote && world.getBlockState(offsetPos).getMaterial().isReplaceable()) { - world.setBlockState(offsetPos, blockState); - if (!player.isCreative()) - heldItem.shrink(1); - }*/ - return ActionResultType.SUCCESS; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/GantryShaftBlock.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/GantryShaftBlock.java index 6fa9bd927..cca015c0a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/GantryShaftBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/GantryShaftBlock.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.relays.advanced; import java.util.ArrayList; import java.util.List; +import java.util.function.Predicate; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllShapes; @@ -10,11 +11,18 @@ import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.placement.IPlacementHelper; +import com.simibubi.create.foundation.utility.placement.PlacementHelpers; +import com.simibubi.create.foundation.utility.placement.PlacementOffset; +import com.simibubi.create.foundation.utility.placement.util.PoleHelper; import net.minecraft.block.Block; import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItemUseContext; +import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUseContext; import net.minecraft.state.BooleanProperty; import net.minecraft.state.EnumProperty; @@ -25,8 +33,10 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; +import net.minecraft.util.Hand; import net.minecraft.util.IStringSerializable; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; @@ -39,6 +49,8 @@ public class GantryShaftBlock extends DirectionalKineticBlock { public static final IProperty PART = EnumProperty.create("part", Part.class); public static final BooleanProperty POWERED = BlockStateProperties.POWERED; + private static final int placementHelperId = PlacementHelpers.register(new PlacementHelper()); + public enum Part implements IStringSerializable { START, MIDDLE, END, SINGLE; @@ -53,6 +65,25 @@ public class GantryShaftBlock extends DirectionalKineticBlock { super.fillStateContainer(builder.add(PART, POWERED)); } + @Override + public ActionResultType onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, + BlockRayTraceResult ray) { + ItemStack heldItem = player.getHeldItem(hand); + + IPlacementHelper placementHelper = PlacementHelpers.get(placementHelperId); + if (!placementHelper.matchesItem(heldItem)) + return ActionResultType.PASS; + + PlacementOffset offset = placementHelper.getOffset(world, state, pos, ray); + + if (!offset.isReplaceable(world)) + return ActionResultType.PASS; + + offset.placeInWorld(world, ((BlockItem) heldItem.getItem()).getBlock() + .getDefaultState(), player, heldItem); + return ActionResultType.SUCCESS; + } + @Override public VoxelShape getShape(BlockState state, IBlockReader p_220053_2_, BlockPos p_220053_3_, ISelectionContext p_220053_4_) { @@ -237,4 +268,27 @@ public class GantryShaftBlock extends DirectionalKineticBlock { && oldState.get(POWERED) == newState.get(POWERED); } + public static class PlacementHelper extends PoleHelper { + + public PlacementHelper() { + super(AllBlocks.GANTRY_SHAFT::has, s -> s.get(FACING) + .getAxis(), FACING); + } + + @Override + public Predicate getItemPredicate() { + return AllBlocks.GANTRY_SHAFT::isIn; + } + + @Override + public PlacementOffset getOffset(World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) { + PlacementOffset offset = super.getOffset(world, state, pos, ray); + if (!offset.isSuccessful()) + return offset; + return PlacementOffset.success(offset.getPos(), offset.getTransform() + .andThen(s -> s.with(POWERED, state.get(POWERED)))); + } + + } + } From f3fd32edd30b9a816d5d4998e87f307373747728 Mon Sep 17 00:00:00 2001 From: Zelophed Date: Thu, 11 Feb 2021 00:28:47 +0100 Subject: [PATCH 4/6] Assisted Placement, Part III - blocks placed by helpers make sounds again - helpers now trigger the proper event and can be cancelled --- .../structureMovement/bearing/SailBlock.java | 13 +---- .../glue/SuperGlueHandler.java | 18 +++--- .../piston/PistonExtensionPoleBlock.java | 25 ++------- .../relays/advanced/GantryShaftBlock.java | 21 ++----- .../relays/advanced/SpeedControllerBlock.java | 21 ++----- .../relays/elementary/CogwheelBlockItem.java | 50 +++++------------ .../relays/elementary/ShaftBlock.java | 23 +------- .../utility/placement/IPlacementHelper.java | 24 ++------ .../utility/placement/PlacementOffset.java | 55 +++++++++++++++---- 9 files changed, 94 insertions(+), 156 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/SailBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/SailBlock.java index 8e12c734a..9c2255629 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/SailBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/SailBlock.java @@ -64,16 +64,9 @@ public class SailBlock extends ProperDirectionalBlock { public ActionResultType onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult ray) { ItemStack heldItem = player.getHeldItem(hand); - if (AllBlocks.SAIL.isIn(heldItem) || AllBlocks.SAIL_FRAME.isIn(heldItem)) { - IPlacementHelper placementHelper = PlacementHelpers.get(placementHelperId); - PlacementOffset offset = placementHelper.getOffset(world, state, pos, ray); - - if (!offset.isReplaceable(world)) - return ActionResultType.PASS; - - offset.placeInWorld(world, ((BlockItem) heldItem.getItem()).getBlock().getDefaultState(), player, heldItem); - return ActionResultType.SUCCESS; - } + IPlacementHelper placementHelper = PlacementHelpers.get(placementHelperId); + if (placementHelper.matchesItem(heldItem)) + return placementHelper.getOffset(world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray); if (heldItem.getItem() instanceof ShearsItem) { if (!world.isRemote) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueHandler.java index 34190f8b8..c9862ba88 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueHandler.java @@ -1,13 +1,9 @@ package com.simibubi.create.content.contraptions.components.structureMovement.glue; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import com.simibubi.create.AllItems; import com.simibubi.create.foundation.networking.AllPackets; +import com.simibubi.create.foundation.utility.placement.IPlacementHelper; import com.simibubi.create.foundation.utility.worldWrappers.RayTraceWorld; - import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -15,12 +11,8 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.RayTraceContext; +import net.minecraft.util.math.*; import net.minecraft.util.math.RayTraceResult.Type; -import net.minecraft.util.math.Vec3d; import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraftforge.event.world.BlockEvent.EntityPlaceEvent; @@ -28,6 +20,10 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.network.PacketDistributor; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + @EventBusSubscriber public class SuperGlueHandler { @@ -65,6 +61,8 @@ public class SuperGlueHandler { return; if (AllItems.WRENCH.isIn(placer.getHeldItemMainhand())) return; + if (event.getPlacedAgainst() == IPlacementHelper.ID) + return; double distance = placer.getAttribute(PlayerEntity.REACH_DISTANCE) .getValue(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonExtensionPoleBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonExtensionPoleBlock.java index 27460381f..b0cb526f2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonExtensionPoleBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonExtensionPoleBlock.java @@ -7,7 +7,6 @@ import com.simibubi.create.content.contraptions.wrench.IWrenchable; import com.simibubi.create.foundation.block.ProperDirectionalBlock; import com.simibubi.create.foundation.utility.placement.IPlacementHelper; import com.simibubi.create.foundation.utility.placement.PlacementHelpers; -import com.simibubi.create.foundation.utility.placement.PlacementOffset; import com.simibubi.create.foundation.utility.placement.util.PoleHelper; import mcp.MethodsReturnNonnullByDefault; import net.minecraft.block.Block; @@ -17,6 +16,7 @@ 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.BlockItem; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.state.StateContainer.Builder; @@ -114,26 +114,9 @@ public class PistonExtensionPoleBlock extends ProperDirectionalBlock implements public ActionResultType onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult ray) { ItemStack heldItem = player.getHeldItem(hand); - if (AllBlocks.PISTON_EXTENSION_POLE.isIn(heldItem) && !player.isSneaking()) { - IPlacementHelper placementHelper = PlacementHelpers.get(placementHelperId); - PlacementOffset offset = placementHelper.getOffset(world, state, pos, ray); - - if (!offset.isReplaceable(world)) - return ActionResultType.PASS; - - offset.placeInWorld(world, AllBlocks.PISTON_EXTENSION_POLE.getDefaultState(), player, heldItem); - - /*BlockPos newPos = new BlockPos(offset.getPos()); - - if (world.isRemote) - return ActionResultType.SUCCESS; - - world.setBlockState(newPos, offset.getTransform().apply(AllBlocks.PISTON_EXTENSION_POLE.getDefaultState())); - if (!player.isCreative()) - heldItem.shrink(1);*/ - - return ActionResultType.SUCCESS; - } + IPlacementHelper placementHelper = PlacementHelpers.get(placementHelperId); + if (placementHelper.matchesItem(heldItem) && !player.isSneaking()) + return placementHelper.getOffset(world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray); return ActionResultType.PASS; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/GantryShaftBlock.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/GantryShaftBlock.java index cca015c0a..05078e359 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/GantryShaftBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/GantryShaftBlock.java @@ -1,9 +1,5 @@ package com.simibubi.create.content.contraptions.relays.advanced; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Predicate; - import com.simibubi.create.AllBlocks; import com.simibubi.create.AllShapes; import com.simibubi.create.AllTileEntities; @@ -15,7 +11,6 @@ import com.simibubi.create.foundation.utility.placement.IPlacementHelper; import com.simibubi.create.foundation.utility.placement.PlacementHelpers; import com.simibubi.create.foundation.utility.placement.PlacementOffset; import com.simibubi.create.foundation.utility.placement.util.PoleHelper; - import net.minecraft.block.Block; import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; @@ -44,6 +39,10 @@ import net.minecraft.world.IWorld; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Predicate; + public class GantryShaftBlock extends DirectionalKineticBlock { public static final IProperty PART = EnumProperty.create("part", Part.class); @@ -66,22 +65,14 @@ public class GantryShaftBlock extends DirectionalKineticBlock { } @Override - public ActionResultType onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, - BlockRayTraceResult ray) { + public ActionResultType onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult ray) { ItemStack heldItem = player.getHeldItem(hand); IPlacementHelper placementHelper = PlacementHelpers.get(placementHelperId); if (!placementHelper.matchesItem(heldItem)) return ActionResultType.PASS; - PlacementOffset offset = placementHelper.getOffset(world, state, pos, ray); - - if (!offset.isReplaceable(world)) - return ActionResultType.PASS; - - offset.placeInWorld(world, ((BlockItem) heldItem.getItem()).getBlock() - .getDefaultState(), player, heldItem); - return ActionResultType.SUCCESS; + return placementHelper.getOffset(world, state, pos, ray).placeInWorld(world, ((BlockItem) heldItem.getItem()), player, hand, ray); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerBlock.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerBlock.java index 5d9071e98..8d15808c4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerBlock.java @@ -1,7 +1,5 @@ package com.simibubi.create.content.contraptions.relays.advanced; -import java.util.function.Predicate; - import com.simibubi.create.AllBlocks; import com.simibubi.create.AllShapes; import com.simibubi.create.AllTileEntities; @@ -13,11 +11,11 @@ import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.placement.IPlacementHelper; import com.simibubi.create.foundation.utility.placement.PlacementHelpers; import com.simibubi.create.foundation.utility.placement.PlacementOffset; - import mcp.MethodsReturnNonnullByDefault; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -32,6 +30,8 @@ import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; +import java.util.function.Predicate; + public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements ITE { private static final int placementHelperId = PlacementHelpers.register(new PlacementHelper()); @@ -67,19 +67,10 @@ public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements public ActionResultType onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult ray) { - IPlacementHelper helper = PlacementHelpers.get(placementHelperId); ItemStack heldItem = player.getHeldItem(hand); - if (helper.matchesItem(heldItem)) { - PlacementOffset offset = helper.getOffset(world, state, pos, ray); - - if (!offset.isReplaceable(world)) - return ActionResultType.PASS; - - offset.placeInWorld(world, AllBlocks.LARGE_COGWHEEL.getDefaultState(), player, heldItem); - - return ActionResultType.SUCCESS; - - } + IPlacementHelper helper = PlacementHelpers.get(placementHelperId); + if (helper.matchesItem(heldItem)) + return helper.getOffset(world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray); return ActionResultType.PASS; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/CogwheelBlockItem.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/CogwheelBlockItem.java index 15ea07c4c..31a886453 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/CogwheelBlockItem.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/CogwheelBlockItem.java @@ -1,10 +1,5 @@ package com.simibubi.create.content.contraptions.relays.elementary; -import static com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock.AXIS; - -import java.util.List; -import java.util.function.Predicate; - import com.simibubi.create.AllBlocks; import com.simibubi.create.AllShapes; import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock; @@ -16,13 +11,13 @@ import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.placement.IPlacementHelper; import com.simibubi.create.foundation.utility.placement.PlacementHelpers; import com.simibubi.create.foundation.utility.placement.PlacementOffset; - import mcp.MethodsReturnNonnullByDefault; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUseContext; import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; @@ -31,6 +26,11 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.World; +import java.util.List; +import java.util.function.Predicate; + +import static com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock.AXIS; + public class CogwheelBlockItem extends BlockItem { boolean large; @@ -47,49 +47,27 @@ public class CogwheelBlockItem extends BlockItem { } @Override - public ActionResultType tryPlace(BlockItemUseContext context) { + public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) { World world = context.getWorld(); - BlockPos pos = context.getPos() - .offset(context.getFace() - .getOpposite()); + BlockPos pos = context.getPos(); BlockState state = world.getBlockState(pos); IPlacementHelper helper = PlacementHelpers.get(placementHelperId); PlayerEntity player = context.getPlayer(); - - if (helper.matchesState(state)) { - PlacementOffset offset = helper.getOffset(world, state, pos, - new BlockRayTraceResult(context.getHitVec(), context.getFace(), pos, true)); - - if (!offset.isReplaceable(world)) - return super.tryPlace(context); - - offset.placeInWorld(world, this, player, context.getItem()); - triggerShiftingGearsAdvancement(world, new BlockPos(offset.getPos()), offset.getTransform() - .apply(getBlock().getDefaultState()), player); - - return ActionResultType.SUCCESS; + BlockRayTraceResult ray = new BlockRayTraceResult(context.getHitVec(), context.getFace(), pos, true); + if (helper.matchesState(state) && player != null && !player.isSneaking()) { + return helper.getOffset(world, state, pos, ray).placeInWorld(world, this, player, context.getHand(), ray); } if (integratedCogHelperId != -1) { helper = PlacementHelpers.get(integratedCogHelperId); - if (helper.matchesState(state)) { - PlacementOffset offset = helper.getOffset(world, state, pos, - new BlockRayTraceResult(context.getHitVec(), context.getFace(), pos, true)); - - if (!offset.isReplaceable(world)) - return super.tryPlace(context); - - offset.placeInWorld(world, this, player, context.getItem()); - triggerShiftingGearsAdvancement(world, new BlockPos(offset.getPos()), offset.getTransform() - .apply(getBlock().getDefaultState()), player); - - return ActionResultType.SUCCESS; + if (helper.matchesState(state) && player != null && !player.isSneaking()) { + return helper.getOffset(world, state, pos, ray).placeInWorld(world, this, player, context.getHand(), ray); } } - return super.tryPlace(context); + return super.onItemUseFirst(stack, context); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/ShaftBlock.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/ShaftBlock.java index f1094dcc0..d68c293f0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/ShaftBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/ShaftBlock.java @@ -7,7 +7,6 @@ import com.simibubi.create.content.contraptions.relays.encased.EncasedShaftBlock import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.utility.placement.IPlacementHelper; import com.simibubi.create.foundation.utility.placement.PlacementHelpers; -import com.simibubi.create.foundation.utility.placement.PlacementOffset; import com.simibubi.create.foundation.utility.placement.util.PoleHelper; import mcp.MethodsReturnNonnullByDefault; import net.minecraft.block.BlockState; @@ -77,26 +76,8 @@ public class ShaftBlock extends AbstractShaftBlock { } IPlacementHelper helper = PlacementHelpers.get(placementHelperId); - if (helper.getItemPredicate().test(heldItem)) { - PlacementOffset offset = helper.getOffset(world, state, pos, ray); - - if (!offset.isReplaceable(world)) - return ActionResultType.PASS; - - offset.placeInWorld(world, (BlockItem) heldItem.getItem(), player, heldItem); - - /*BlockPos newPos = new BlockPos(offset.getPos()); - - if (world.isRemote) - return ActionResultType.SUCCESS; - - Block block = ((BlockItem) heldItem.getItem()).getBlock(); - world.setBlockState(newPos, offset.getTransform().apply(block.getDefaultState())); - if (!player.isCreative()) - heldItem.shrink(1);*/ - - return ActionResultType.SUCCESS; - } + if (helper.matchesItem(heldItem)) + return helper.getOffset(world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray); return ActionResultType.PASS; } diff --git a/src/main/java/com/simibubi/create/foundation/utility/placement/IPlacementHelper.java b/src/main/java/com/simibubi/create/foundation/utility/placement/IPlacementHelper.java index 2cb70be61..082776a7c 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/placement/IPlacementHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/placement/IPlacementHelper.java @@ -6,6 +6,7 @@ import com.simibubi.create.foundation.utility.Pair; import com.simibubi.create.foundation.utility.VecHelper; import mcp.MethodsReturnNonnullByDefault; import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; @@ -22,6 +23,11 @@ import java.util.stream.Collectors; @MethodsReturnNonnullByDefault public interface IPlacementHelper { + /** + * used as an identifier in SuperGlueHandler to skip blocks placed by helpers + */ + BlockState ID = new BlockState(Blocks.AIR, null); + /** * @return a predicate that gets tested with the items held in the players hands, * should return true if this placement helper is active with the given item @@ -61,24 +67,6 @@ public interface IPlacementHelper { CreateClient.outliner.showLine("placementArrowB" + center + target, start.add(offset), endB.add(offset)).lineWidth(1/16f); } - /*@OnlyIn(Dist.CLIENT) - static void renderArrow(Vec3d center, Direction towards, BlockRayTraceResult ray) { - Direction hitFace = ray.getFace(); - - if (hitFace.getAxis() == towards.getAxis()) - return; - - //get the two perpendicular directions to form the arrow - Direction[] directions = Arrays.stream(Direction.Axis.values()).filter(axis -> axis != hitFace.getAxis() && axis != towards.getAxis()).map(Iterate::directionsInAxis).findFirst().orElse(new Direction[]{}); - Vec3d startOffset = new Vec3d(towards.getDirectionVec()); - Vec3d start = center.add(startOffset); - for (Direction dir : directions) { - Vec3d arrowOffset = new Vec3d(dir.getDirectionVec()).scale(.25); - Vec3d target = center.add(startOffset.scale(0.75)).add(arrowOffset); - CreateClient.outliner.showLine("placementArrow" + towards + dir, start, target).lineWidth(1/16f); - } - }*/ - static List orderedByDistanceOnlyAxis(BlockPos pos, Vec3d hit, Direction.Axis axis) { return orderedByDistance(pos, hit, dir -> dir.getAxis() == axis); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/placement/PlacementOffset.java b/src/main/java/com/simibubi/create/foundation/utility/placement/PlacementOffset.java index 8da2b5ce2..e9d50d6d5 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/placement/PlacementOffset.java +++ b/src/main/java/com/simibubi/create/foundation/utility/placement/PlacementOffset.java @@ -1,15 +1,26 @@ package com.simibubi.create.foundation.utility.placement; +import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.block.BlockState; +import net.minecraft.block.SoundType; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.fluid.Fluids; import net.minecraft.fluid.IFluidState; import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUseContext; import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.stats.Stats; +import net.minecraft.util.ActionResultType; +import net.minecraft.util.Hand; +import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.util.BlockSnapshot; +import net.minecraftforge.event.world.BlockEvent; import java.util.function.Function; @@ -55,25 +66,49 @@ public class PlacementOffset { return world.getBlockState(new BlockPos(pos)).getMaterial().isReplaceable(); } - - public void placeInWorld(World world, BlockItem blockItem, PlayerEntity player, ItemStack item) { - placeInWorld(world, blockItem.getBlock().getDefaultState(), player, item); - } - public void placeInWorld(World world, BlockState defaultState, PlayerEntity player, ItemStack item) { - if (world.isRemote) - return; + public ActionResultType placeInWorld(World world, BlockItem blockItem, PlayerEntity player, Hand hand, BlockRayTraceResult ray) { + + ItemUseContext context = new ItemUseContext(player, hand, ray); BlockPos newPos = new BlockPos(pos); - BlockState state = stateTransform.apply(defaultState); + + if (!world.isBlockModifiable(player, newPos)) + return ActionResultType.PASS; + + if (!isReplaceable(world)) + return ActionResultType.PASS; + + BlockState state = stateTransform.apply(blockItem.getBlock().getDefaultState()); if (state.has(BlockStateProperties.WATERLOGGED)) { IFluidState fluidState = world.getFluidState(newPos); state = state.with(BlockStateProperties.WATERLOGGED, fluidState.getFluid() == Fluids.WATER); } + BlockSnapshot snapshot = BlockSnapshot.getBlockSnapshot(world, newPos); world.setBlockState(newPos, state); + BlockEvent.EntityPlaceEvent event = new BlockEvent.EntityPlaceEvent(snapshot, IPlacementHelper.ID, player); + if (MinecraftForge.EVENT_BUS.post(event)) { + snapshot.restore(true, false); + return ActionResultType.FAIL; + } + + BlockState newState = world.getBlockState(newPos); + SoundType soundtype = newState.getSoundType(world, newPos, player); + world.playSound(player, newPos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); + + player.addStat(Stats.ITEM_USED.get(blockItem)); + + if (world.isRemote) + return ActionResultType.SUCCESS; + + if (player instanceof ServerPlayerEntity) + CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayerEntity) player, newPos, context.getItem()); + if (!player.isCreative()) - item.shrink(1); + context.getItem().shrink(1); + + return ActionResultType.SUCCESS; } } From b4c881a6c8eff198f558bec55aa98570e97161eb Mon Sep 17 00:00:00 2001 From: Zelophed Date: Thu, 11 Feb 2021 17:47:55 +0100 Subject: [PATCH 5/6] Player Feedback, Part II --- src/generated/resources/.cache/cache | 24 ++++---- .../resources/assets/create/lang/en_us.json | 6 ++ .../assets/create/lang/unfinished/de_de.json | 8 ++- .../assets/create/lang/unfinished/fr_fr.json | 8 ++- .../assets/create/lang/unfinished/it_it.json | 8 ++- .../assets/create/lang/unfinished/ja_jp.json | 8 ++- .../assets/create/lang/unfinished/ko_kr.json | 8 ++- .../assets/create/lang/unfinished/nl_nl.json | 8 ++- .../assets/create/lang/unfinished/pt_br.json | 8 ++- .../assets/create/lang/unfinished/ru_ru.json | 8 ++- .../assets/create/lang/unfinished/zh_cn.json | 8 ++- .../structureMovement/AssemblyException.java | 41 +++++++++++-- .../structureMovement/Contraption.java | 61 ++++++------------- .../IDisplayAssemblyExceptions.java | 28 +++++++++ .../bearing/ClockworkBearingTileEntity.java | 33 +++++----- .../bearing/ClockworkContraption.java | 16 +++-- .../bearing/MechanicalBearingTileEntity.java | 37 ++++++----- .../mounted/CartAssemblerBlock.java | 11 +++- .../mounted/CartAssemblerTileEntity.java | 41 +++++++++---- .../piston/LinearActuatorTileEntity.java | 35 +++++------ .../piston/PistonContraption.java | 12 ++-- .../pulley/PulleyTileEntity.java | 5 +- .../goggles/GoggleOverlayRenderer.java | 9 +++ .../goggles/IHaveGoggleInformation.java | 6 +- .../assets/create/lang/default/messages.json | 7 +++ 25 files changed, 282 insertions(+), 162 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/IDisplayAssemblyExceptions.java diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 0dfe925ea..2d9d6f52b 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -140,7 +140,7 @@ de8a40b7daf1497d5aecee47a43b3e0b1d030b00 assets/create/blockstates/fancy_scoria_ fc9ac0a7e7191b93516719455a17177fa6524ecc assets/create/blockstates/fancy_weathered_limestone_bricks_slab.json b2a7c321b1795f20e7433f81a55ce4683de081b8 assets/create/blockstates/fancy_weathered_limestone_bricks_stairs.json 6372fe02ba0065acb0758121c45a15a1a8fdc5de assets/create/blockstates/fancy_weathered_limestone_bricks_wall.json -4c3e0500f9382d2e426e823fe876f57f4d7ee3b4 assets/create/blockstates/fluid_pipe.json +6106fc0a0f9d83da89c3e8af98e7c45232602c23 assets/create/blockstates/fluid_pipe.json f0eaab18e16c4f3f65ebf3b55b08f0dc445720fe assets/create/blockstates/fluid_tank.json 5408d92ab02af86539ac42971d4033545970bb3a assets/create/blockstates/fluid_valve.json e9da1794b6ece7f9aa8bcb43d42c23a55446133b assets/create/blockstates/flywheel.json @@ -335,7 +335,7 @@ e8b0a401c10d1ba67ed71ba31bd5f9bc28571b65 assets/create/blockstates/powered_toggl d06cd9a1101b18d306a786320aab12018b1325d6 assets/create/blockstates/purple_sail.json 92957119abd5fbcca36a113b2a80255fd70fc303 assets/create/blockstates/purple_seat.json 61035f8afe75ff7bbd291da5d8690bcbebe679eb assets/create/blockstates/purple_valve_handle.json -bdd56f32ce0a148b6e466a55ab2777f69fc08cfc assets/create/blockstates/radial_chassis.json +143d66a7262ccd29f36784d6b064d4a13ba374b6 assets/create/blockstates/radial_chassis.json 45877c4d90a7185c2f304edbd67379d800920439 assets/create/blockstates/red_sail.json da1b08387af7afa0855ee8d040f620c01f20660a assets/create/blockstates/red_seat.json 722fc77bbf387af8a4016e42cbf9501d2b968881 assets/create/blockstates/red_valve_handle.json @@ -399,16 +399,16 @@ a3a11524cd3515fc01d905767b4b7ea782adaf03 assets/create/blockstates/yellow_seat.j 7f39521b211441f5c3e06d60c5978cebe16cacfb assets/create/blockstates/zinc_block.json b7181bcd8182b2f17088e5aa881f374c9c65470c assets/create/blockstates/zinc_ore.json df67c2c11fa22487d3a0fdc9b008056e593d14e3 assets/create/lang/en_ud.json -3ad443f44eb33fe8c3ac092d1532dcbd27e49c84 assets/create/lang/en_us.json -612a63d73f7f4b8e79dce3f53ddbe3345f0e74d8 assets/create/lang/unfinished/de_de.json -2e37dc718a8dea2af85daba7266c877ce80ff35b assets/create/lang/unfinished/fr_fr.json -f843761728c403276b7a47282f4fdd039b5b6854 assets/create/lang/unfinished/it_it.json -8b90c66fd5974c993e83bfa5733ca03187211d28 assets/create/lang/unfinished/ja_jp.json -59db0a3cff42707ecb828b975ef1fcba2a21a521 assets/create/lang/unfinished/ko_kr.json -b1900a6cce7216a4baa844affa169cfb32ff645c assets/create/lang/unfinished/nl_nl.json -d3f09a37b1f4ec5d53effc2b87efbccf2df2b7c7 assets/create/lang/unfinished/pt_br.json -16c92dab525ba20e85b65ee084f7b760432dcb73 assets/create/lang/unfinished/ru_ru.json -c8b5c2a3a65468950aa713a56bf1c930eef81305 assets/create/lang/unfinished/zh_cn.json +9fa2b840f81a9d61e25af4718a4948ee762ef0a8 assets/create/lang/en_us.json +ebe9ae0de05c542426e1fc9eeb865cad08f7c6a0 assets/create/lang/unfinished/de_de.json +f2525e7139a8e5aaac2fed2a562ad13a295f0e4e assets/create/lang/unfinished/fr_fr.json +30db009b45db33814b43f15d09775de2f9cad091 assets/create/lang/unfinished/it_it.json +25c2d05bfcdd0e64e889ca6ff36377d933f35e87 assets/create/lang/unfinished/ja_jp.json +7a4f40c3a6851714a450173f0c2f1e5689d96025 assets/create/lang/unfinished/ko_kr.json +c2b4070659ce9a0a44cbaa37beef3b0217d15c00 assets/create/lang/unfinished/nl_nl.json +9cfe6a2af979661bbdcc78edc28ab07b9a8f2f43 assets/create/lang/unfinished/pt_br.json +590368f1507e77d67c416299188b2e147e0a9616 assets/create/lang/unfinished/ru_ru.json +719105e25c79198ad76bd1782499545ce0f8a3ce assets/create/lang/unfinished/zh_cn.json 846200eb548d3bfa2e77b41039de159b4b6cfb45 assets/create/models/block/acacia_window.json 1930fa3a3c98d53dd19e4ee7f55bc27fd47aa281 assets/create/models/block/acacia_window_pane_noside.json 1763ea2c9b981d187f5031ba608f3d5d3be3986a assets/create/models/block/acacia_window_pane_noside_alt.json diff --git a/src/generated/resources/assets/create/lang/en_us.json b/src/generated/resources/assets/create/lang/en_us.json index a7b48ea0c..8fa382ee8 100644 --- a/src/generated/resources/assets/create/lang/en_us.json +++ b/src/generated/resources/assets/create/lang/en_us.json @@ -819,6 +819,12 @@ "create.gui.goggles.kinetic_stats": "Kinetic Stats:", "create.gui.goggles.at_current_speed": "at current speed", "create.gui.goggles.pole_length": "Pole Length:", + "create.gui.assembly.exception": "This Contraption was unable to assemble:", + "create.gui.assembly.exception.unmovableBlock": "Unmovable Block (%4$s) at [%1$s %2$s %3$s]", + "create.gui.assembly.exception.chunkNotLoaded": "The Block at [%1$s %2$s %3$s] was not in a loaded chunk", + "create.gui.assembly.exception.structureTooLarge": "There are too many Blocks included in the contraption.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.tooManyPistonPoles": "There are too many extension Poles attached to this Piston.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.noPistonPoles": "The Piston is missing some extension Poles", "create.gui.gauge.info_header": "Gauge Information:", "create.gui.speedometer.title": "Rotation Speed", "create.gui.stressometer.title": "Network Stress", diff --git a/src/generated/resources/assets/create/lang/unfinished/de_de.json b/src/generated/resources/assets/create/lang/unfinished/de_de.json index ab2ac6851..3379876de 100644 --- a/src/generated/resources/assets/create/lang/unfinished/de_de.json +++ b/src/generated/resources/assets/create/lang/unfinished/de_de.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 1211", + "_": "Missing Localizations: 1217", "_": "->------------------------] Game Elements [------------------------<-", @@ -820,6 +820,12 @@ "create.gui.goggles.kinetic_stats": "UNLOCALIZED: Kinetic Stats:", "create.gui.goggles.at_current_speed": "UNLOCALIZED: at current speed", "create.gui.goggles.pole_length": "UNLOCALIZED: Pole Length:", + "create.gui.assembly.exception": "UNLOCALIZED: This Contraption was unable to assemble:", + "create.gui.assembly.exception.unmovableBlock": "UNLOCALIZED: Unmovable Block (%4$s) at [%1$s %2$s %3$s]", + "create.gui.assembly.exception.chunkNotLoaded": "UNLOCALIZED: The Block at [%1$s %2$s %3$s] was not in a loaded chunk", + "create.gui.assembly.exception.structureTooLarge": "UNLOCALIZED: There are too many Blocks included in the contraption.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.tooManyPistonPoles": "UNLOCALIZED: There are too many extension Poles attached to this Piston.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.noPistonPoles": "UNLOCALIZED: The Piston is missing some extension Poles", "create.gui.gauge.info_header": "UNLOCALIZED: Gauge Information:", "create.gui.speedometer.title": "UNLOCALIZED: Rotation Speed", "create.gui.stressometer.title": "UNLOCALIZED: Network Stress", diff --git a/src/generated/resources/assets/create/lang/unfinished/fr_fr.json b/src/generated/resources/assets/create/lang/unfinished/fr_fr.json index 24cd8a5b7..c14ef3c22 100644 --- a/src/generated/resources/assets/create/lang/unfinished/fr_fr.json +++ b/src/generated/resources/assets/create/lang/unfinished/fr_fr.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 862", + "_": "Missing Localizations: 868", "_": "->------------------------] Game Elements [------------------------<-", @@ -820,6 +820,12 @@ "create.gui.goggles.kinetic_stats": "Statistiques cinétiques:", "create.gui.goggles.at_current_speed": "À la vitesse actuelle", "create.gui.goggles.pole_length": "UNLOCALIZED: Pole Length:", + "create.gui.assembly.exception": "UNLOCALIZED: This Contraption was unable to assemble:", + "create.gui.assembly.exception.unmovableBlock": "UNLOCALIZED: Unmovable Block (%4$s) at [%1$s %2$s %3$s]", + "create.gui.assembly.exception.chunkNotLoaded": "UNLOCALIZED: The Block at [%1$s %2$s %3$s] was not in a loaded chunk", + "create.gui.assembly.exception.structureTooLarge": "UNLOCALIZED: There are too many Blocks included in the contraption.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.tooManyPistonPoles": "UNLOCALIZED: There are too many extension Poles attached to this Piston.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.noPistonPoles": "UNLOCALIZED: The Piston is missing some extension Poles", "create.gui.gauge.info_header": "Informations sur la jauge:", "create.gui.speedometer.title": "Vitesse de rotation", "create.gui.stressometer.title": "Stress du réseau", diff --git a/src/generated/resources/assets/create/lang/unfinished/it_it.json b/src/generated/resources/assets/create/lang/unfinished/it_it.json index 7de389b9f..134283a58 100644 --- a/src/generated/resources/assets/create/lang/unfinished/it_it.json +++ b/src/generated/resources/assets/create/lang/unfinished/it_it.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 846", + "_": "Missing Localizations: 852", "_": "->------------------------] Game Elements [------------------------<-", @@ -820,6 +820,12 @@ "create.gui.goggles.kinetic_stats": "Statistiche Cinetiche:", "create.gui.goggles.at_current_speed": "Alla velocità Attuale", "create.gui.goggles.pole_length": "UNLOCALIZED: Pole Length:", + "create.gui.assembly.exception": "UNLOCALIZED: This Contraption was unable to assemble:", + "create.gui.assembly.exception.unmovableBlock": "UNLOCALIZED: Unmovable Block (%4$s) at [%1$s %2$s %3$s]", + "create.gui.assembly.exception.chunkNotLoaded": "UNLOCALIZED: The Block at [%1$s %2$s %3$s] was not in a loaded chunk", + "create.gui.assembly.exception.structureTooLarge": "UNLOCALIZED: There are too many Blocks included in the contraption.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.tooManyPistonPoles": "UNLOCALIZED: There are too many extension Poles attached to this Piston.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.noPistonPoles": "UNLOCALIZED: The Piston is missing some extension Poles", "create.gui.gauge.info_header": "Informazioni sul Calibro:", "create.gui.speedometer.title": "Velocità di Rotazione", "create.gui.stressometer.title": "Stress della Rete", diff --git a/src/generated/resources/assets/create/lang/unfinished/ja_jp.json b/src/generated/resources/assets/create/lang/unfinished/ja_jp.json index 9b31a9385..9318e59cd 100644 --- a/src/generated/resources/assets/create/lang/unfinished/ja_jp.json +++ b/src/generated/resources/assets/create/lang/unfinished/ja_jp.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 845", + "_": "Missing Localizations: 851", "_": "->------------------------] Game Elements [------------------------<-", @@ -820,6 +820,12 @@ "create.gui.goggles.kinetic_stats": "動力の統計:", "create.gui.goggles.at_current_speed": "現在の速度", "create.gui.goggles.pole_length": "UNLOCALIZED: Pole Length:", + "create.gui.assembly.exception": "UNLOCALIZED: This Contraption was unable to assemble:", + "create.gui.assembly.exception.unmovableBlock": "UNLOCALIZED: Unmovable Block (%4$s) at [%1$s %2$s %3$s]", + "create.gui.assembly.exception.chunkNotLoaded": "UNLOCALIZED: The Block at [%1$s %2$s %3$s] was not in a loaded chunk", + "create.gui.assembly.exception.structureTooLarge": "UNLOCALIZED: There are too many Blocks included in the contraption.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.tooManyPistonPoles": "UNLOCALIZED: There are too many extension Poles attached to this Piston.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.noPistonPoles": "UNLOCALIZED: The Piston is missing some extension Poles", "create.gui.gauge.info_header": "計器の情報:", "create.gui.speedometer.title": "回転速度", "create.gui.stressometer.title": "ネットワークの応力", diff --git a/src/generated/resources/assets/create/lang/unfinished/ko_kr.json b/src/generated/resources/assets/create/lang/unfinished/ko_kr.json index bec923df7..e8dd41da1 100644 --- a/src/generated/resources/assets/create/lang/unfinished/ko_kr.json +++ b/src/generated/resources/assets/create/lang/unfinished/ko_kr.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 52", + "_": "Missing Localizations: 58", "_": "->------------------------] Game Elements [------------------------<-", @@ -820,6 +820,12 @@ "create.gui.goggles.kinetic_stats": "가동 상태:", "create.gui.goggles.at_current_speed": "현재 에너지량", "create.gui.goggles.pole_length": "UNLOCALIZED: Pole Length:", + "create.gui.assembly.exception": "UNLOCALIZED: This Contraption was unable to assemble:", + "create.gui.assembly.exception.unmovableBlock": "UNLOCALIZED: Unmovable Block (%4$s) at [%1$s %2$s %3$s]", + "create.gui.assembly.exception.chunkNotLoaded": "UNLOCALIZED: The Block at [%1$s %2$s %3$s] was not in a loaded chunk", + "create.gui.assembly.exception.structureTooLarge": "UNLOCALIZED: There are too many Blocks included in the contraption.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.tooManyPistonPoles": "UNLOCALIZED: There are too many extension Poles attached to this Piston.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.noPistonPoles": "UNLOCALIZED: The Piston is missing some extension Poles", "create.gui.gauge.info_header": "게이지 정보:", "create.gui.speedometer.title": "회전 속도", "create.gui.stressometer.title": "네트워크 부하", diff --git a/src/generated/resources/assets/create/lang/unfinished/nl_nl.json b/src/generated/resources/assets/create/lang/unfinished/nl_nl.json index 0b8b4afb2..067508d5c 100644 --- a/src/generated/resources/assets/create/lang/unfinished/nl_nl.json +++ b/src/generated/resources/assets/create/lang/unfinished/nl_nl.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 1152", + "_": "Missing Localizations: 1158", "_": "->------------------------] Game Elements [------------------------<-", @@ -820,6 +820,12 @@ "create.gui.goggles.kinetic_stats": "UNLOCALIZED: Kinetic Stats:", "create.gui.goggles.at_current_speed": "UNLOCALIZED: at current speed", "create.gui.goggles.pole_length": "UNLOCALIZED: Pole Length:", + "create.gui.assembly.exception": "UNLOCALIZED: This Contraption was unable to assemble:", + "create.gui.assembly.exception.unmovableBlock": "UNLOCALIZED: Unmovable Block (%4$s) at [%1$s %2$s %3$s]", + "create.gui.assembly.exception.chunkNotLoaded": "UNLOCALIZED: The Block at [%1$s %2$s %3$s] was not in a loaded chunk", + "create.gui.assembly.exception.structureTooLarge": "UNLOCALIZED: There are too many Blocks included in the contraption.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.tooManyPistonPoles": "UNLOCALIZED: There are too many extension Poles attached to this Piston.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.noPistonPoles": "UNLOCALIZED: The Piston is missing some extension Poles", "create.gui.gauge.info_header": "UNLOCALIZED: Gauge Information:", "create.gui.speedometer.title": "UNLOCALIZED: Rotation Speed", "create.gui.stressometer.title": "UNLOCALIZED: Network Stress", diff --git a/src/generated/resources/assets/create/lang/unfinished/pt_br.json b/src/generated/resources/assets/create/lang/unfinished/pt_br.json index e0eb5b879..b7397663d 100644 --- a/src/generated/resources/assets/create/lang/unfinished/pt_br.json +++ b/src/generated/resources/assets/create/lang/unfinished/pt_br.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 1218", + "_": "Missing Localizations: 1224", "_": "->------------------------] Game Elements [------------------------<-", @@ -820,6 +820,12 @@ "create.gui.goggles.kinetic_stats": "UNLOCALIZED: Kinetic Stats:", "create.gui.goggles.at_current_speed": "UNLOCALIZED: at current speed", "create.gui.goggles.pole_length": "UNLOCALIZED: Pole Length:", + "create.gui.assembly.exception": "UNLOCALIZED: This Contraption was unable to assemble:", + "create.gui.assembly.exception.unmovableBlock": "UNLOCALIZED: Unmovable Block (%4$s) at [%1$s %2$s %3$s]", + "create.gui.assembly.exception.chunkNotLoaded": "UNLOCALIZED: The Block at [%1$s %2$s %3$s] was not in a loaded chunk", + "create.gui.assembly.exception.structureTooLarge": "UNLOCALIZED: There are too many Blocks included in the contraption.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.tooManyPistonPoles": "UNLOCALIZED: There are too many extension Poles attached to this Piston.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.noPistonPoles": "UNLOCALIZED: The Piston is missing some extension Poles", "create.gui.gauge.info_header": "UNLOCALIZED: Gauge Information:", "create.gui.speedometer.title": "UNLOCALIZED: Rotation Speed", "create.gui.stressometer.title": "UNLOCALIZED: Network Stress", diff --git a/src/generated/resources/assets/create/lang/unfinished/ru_ru.json b/src/generated/resources/assets/create/lang/unfinished/ru_ru.json index 2085aa34a..88dbb7788 100644 --- a/src/generated/resources/assets/create/lang/unfinished/ru_ru.json +++ b/src/generated/resources/assets/create/lang/unfinished/ru_ru.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 2", + "_": "Missing Localizations: 8", "_": "->------------------------] Game Elements [------------------------<-", @@ -820,6 +820,12 @@ "create.gui.goggles.kinetic_stats": "Кинетическая статистика:", "create.gui.goggles.at_current_speed": "На текущей скорости", "create.gui.goggles.pole_length": "Длина поршня", + "create.gui.assembly.exception": "UNLOCALIZED: This Contraption was unable to assemble:", + "create.gui.assembly.exception.unmovableBlock": "UNLOCALIZED: Unmovable Block (%4$s) at [%1$s %2$s %3$s]", + "create.gui.assembly.exception.chunkNotLoaded": "UNLOCALIZED: The Block at [%1$s %2$s %3$s] was not in a loaded chunk", + "create.gui.assembly.exception.structureTooLarge": "UNLOCALIZED: There are too many Blocks included in the contraption.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.tooManyPistonPoles": "UNLOCALIZED: There are too many extension Poles attached to this Piston.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.noPistonPoles": "UNLOCALIZED: The Piston is missing some extension Poles", "create.gui.gauge.info_header": "Калибровочная информация:", "create.gui.speedometer.title": "Скорость вращения", "create.gui.stressometer.title": "Сетевой момент", diff --git a/src/generated/resources/assets/create/lang/unfinished/zh_cn.json b/src/generated/resources/assets/create/lang/unfinished/zh_cn.json index 783cb9fb2..a1e4b7a73 100644 --- a/src/generated/resources/assets/create/lang/unfinished/zh_cn.json +++ b/src/generated/resources/assets/create/lang/unfinished/zh_cn.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 5", + "_": "Missing Localizations: 11", "_": "->------------------------] Game Elements [------------------------<-", @@ -820,6 +820,12 @@ "create.gui.goggles.kinetic_stats": "动力学状态:", "create.gui.goggles.at_current_speed": "当前速度应力值", "create.gui.goggles.pole_length": "UNLOCALIZED: Pole Length:", + "create.gui.assembly.exception": "UNLOCALIZED: This Contraption was unable to assemble:", + "create.gui.assembly.exception.unmovableBlock": "UNLOCALIZED: Unmovable Block (%4$s) at [%1$s %2$s %3$s]", + "create.gui.assembly.exception.chunkNotLoaded": "UNLOCALIZED: The Block at [%1$s %2$s %3$s] was not in a loaded chunk", + "create.gui.assembly.exception.structureTooLarge": "UNLOCALIZED: There are too many Blocks included in the contraption.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.tooManyPistonPoles": "UNLOCALIZED: There are too many extension Poles attached to this Piston.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.noPistonPoles": "UNLOCALIZED: The Piston is missing some extension Poles", "create.gui.gauge.info_header": "仪表信息:", "create.gui.speedometer.title": "旋转速度", "create.gui.stressometer.title": "网络应力", diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java index 67e595602..4beac5ff9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java @@ -1,23 +1,52 @@ package com.simibubi.create.content.contraptions.components.structureMovement; +import com.simibubi.create.foundation.config.AllConfigs; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TranslationTextComponent; -public class AssemblyException extends RuntimeException { - public final ITextComponent message; +public class AssemblyException extends Exception { + public final ITextComponent component; - public AssemblyException(ITextComponent message) { - this.message = message; + public AssemblyException(ITextComponent component) { + this.component = component; } public AssemblyException(String langKey, Object... objects) { - this(new TranslationTextComponent("gui.goggles.contraptions." + langKey, objects)); + this(new TranslationTextComponent("create.gui.assembly.exception." + langKey, objects)); } public static AssemblyException unmovableBlock(BlockPos pos, BlockState state) { - return new AssemblyException("unmovableBlock", pos.getX(), pos.getY(), pos.getZ(), + return new AssemblyException("unmovableBlock", + pos.getX(), + pos.getY(), + pos.getZ(), new TranslationTextComponent(state.getBlock().getTranslationKey())); } + + public static AssemblyException unloadedChunk(BlockPos pos) { + return new AssemblyException("chunkNotLoaded", + pos.getX(), + pos.getY(), + pos.getZ()); + } + + public static AssemblyException structureTooLarge() { + return new AssemblyException("structureTooLarge", + AllConfigs.SERVER.kinetics.maxBlocksMoved.get()); + } + + public static AssemblyException tooManyPistonPoles() { + return new AssemblyException("tooManyPistonPoles", + AllConfigs.SERVER.kinetics.maxPistonPoles.get()); + } + + public static AssemblyException noPistonPoles() { + return new AssemblyException("noPistonPoles"); + } + + public String getFormattedText() { + return component.getFormattedText(); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index e2344c503..eb52b707e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -1,28 +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.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Queue; -import java.util.Set; -import java.util.UUID; -import java.util.function.BiConsumer; -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.AllMovementBehaviours; import com.simibubi.create.content.contraptions.base.KineticTileEntity; @@ -52,15 +29,7 @@ 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.IWaterLoggable; -import net.minecraft.block.PressurePlateBlock; +import net.minecraft.block.*; import net.minecraft.block.material.PushReaction; import net.minecraft.entity.Entity; import net.minecraft.fluid.Fluids; @@ -92,6 +61,16 @@ import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; import net.minecraftforge.fluids.capability.templates.FluidTank; 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.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 { @@ -150,7 +129,7 @@ public abstract class Contraption { } protected boolean addToInitialFrontier(World world, BlockPos pos, Direction forcedDirection, - Queue frontier) { + Queue frontier) throws AssemblyException { return true; } @@ -161,7 +140,7 @@ public abstract class Contraption { return contraption; } - public boolean searchMovedStructure(World world, BlockPos pos, @Nullable Direction forcedDirection) { + public boolean searchMovedStructure(World world, BlockPos pos, @Nullable Direction forcedDirection) throws AssemblyException { initialPassengers.clear(); Queue frontier = new LinkedList<>(); Set visited = new HashSet<>(); @@ -180,7 +159,7 @@ public abstract class Contraption { if (!moveBlock(world, forcedDirection, frontier, visited)) return false; } - throw new AssemblyException("structureTooLarge"); + throw AssemblyException.structureTooLarge(); } public void onEntityCreated(AbstractContraptionEntity entity) { @@ -249,7 +228,7 @@ public abstract class Contraption { /** move the first block in frontier queue */ protected boolean moveBlock(World world, @Nullable Direction forcedDirection, Queue frontier, - Set visited) { + Set visited) throws AssemblyException { BlockPos pos = frontier.poll(); if (pos == null) return false; @@ -258,7 +237,7 @@ public abstract class Contraption { if (World.isOutsideBuildHeight(pos)) return true; if (!world.isBlockPresent(pos)) - throw new AssemblyException("chunkNotLoaded"); + throw AssemblyException.unloadedChunk(pos); if (isAnchoringBlockAt(pos)) return true; BlockState state = world.getBlockState(pos); @@ -348,7 +327,7 @@ public abstract class Contraption { if (blocks.size() <= AllConfigs.SERVER.kinetics.maxBlocksMoved.get()) return true; else - throw new AssemblyException("structureTooLarge"); + throw AssemblyException.structureTooLarge(); } private void moveBearing(BlockPos pos, Queue frontier, Set visited, BlockState state) { @@ -402,7 +381,7 @@ public abstract class Contraption { } private boolean moveMechanicalPiston(World world, BlockPos pos, Queue frontier, Set visited, - BlockState state) { + BlockState state) throws AssemblyException { int limit = AllConfigs.SERVER.kinetics.maxPistonPoles.get(); Direction direction = state.get(MechanicalPistonBlock.FACING); if (state.get(MechanicalPistonBlock.STATE) == PistonState.EXTENDED) { @@ -424,7 +403,7 @@ public abstract class Contraption { break; } if (limit <= -1) - throw new AssemblyException("tooManyPistonPoles"); + throw AssemblyException.tooManyPistonPoles(); } BlockPos searchPos = pos; @@ -443,7 +422,7 @@ public abstract class Contraption { } if (limit <= -1) - throw new AssemblyException("tooManyPistonPoles"); + throw AssemblyException.tooManyPistonPoles(); return true; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/IDisplayAssemblyExceptions.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/IDisplayAssemblyExceptions.java new file mode 100644 index 000000000..33abfc9fb --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/IDisplayAssemblyExceptions.java @@ -0,0 +1,28 @@ +package com.simibubi.create.content.contraptions.components.structureMovement; + +import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation; +import com.simibubi.create.foundation.utility.Lang; +import net.minecraft.util.text.TextFormatting; + +import java.util.Arrays; +import java.util.List; + +public interface IDisplayAssemblyExceptions { + + default boolean addExceptionToTooltip(List tooltip) { + AssemblyException e = getLastAssemblyException(); + if (e == null) + return false; + + if (!tooltip.isEmpty()) + tooltip.add(""); + + tooltip.add(IHaveGoggleInformation.spacing + TextFormatting.GOLD + Lang.translate("gui.assembly.exception")); + String text = e.getFormattedText(); + Arrays.stream(text.split("\n")).forEach(l -> tooltip.add(IHaveGoggleInformation.spacing + TextFormatting.GRAY + l)); + + return true; + } + + AssemblyException getLastAssemblyException(); +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java index 35a036a50..12c65902f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java @@ -1,13 +1,10 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; -import java.util.List; - -import org.apache.commons.lang3.tuple.Pair; - import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity; +import com.simibubi.create.content.contraptions.components.structureMovement.IDisplayAssemblyExceptions; import com.simibubi.create.content.contraptions.components.structureMovement.bearing.ClockworkContraption.HandType; import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.gui.AllIcons; @@ -17,7 +14,6 @@ import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollOpt import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.ServerSpeedProvider; - import net.minecraft.block.BlockState; import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.properties.BlockStateProperties; @@ -27,8 +23,11 @@ import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.text.ITextComponent; +import org.apache.commons.lang3.tuple.Pair; -public class ClockworkBearingTileEntity extends KineticTileEntity implements IBearingTileEntity { +import java.util.List; + +public class ClockworkBearingTileEntity extends KineticTileEntity implements IBearingTileEntity, IDisplayAssemblyExceptions { protected ControlledContraptionEntity hourHand; protected ControlledContraptionEntity minuteHand; @@ -39,7 +38,7 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe protected boolean running; protected boolean assembleNextTick; - protected ITextComponent lastException; + protected AssemblyException lastException; protected ScrollOptionBehaviour operationMode; @@ -108,6 +107,11 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe applyRotations(); } + @Override + public AssemblyException getLastAssemblyException() { + return lastException; + } + protected void applyRotations() { BlockState blockState = getBlockState(); Axis axis = Axis.X; @@ -207,7 +211,8 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe contraption = ClockworkContraption.assembleClockworkAt(world, pos, direction); lastException = null; } catch (AssemblyException e) { - lastException = e.message; + lastException = e; + sendData(); return; } if (contraption == null) @@ -294,7 +299,7 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe compound.putFloat("HourAngle", hourAngle); compound.putFloat("MinuteAngle", minuteAngle); if (lastException != null) - compound.putString("LastException", ITextComponent.Serializer.toJson(lastException)); + compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component)); super.write(compound, clientPacket); } @@ -307,7 +312,7 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe hourAngle = compound.getFloat("HourAngle"); minuteAngle = compound.getFloat("MinuteAngle"); if (compound.contains("LastException")) - lastException = ITextComponent.Serializer.fromJson(compound.getString("LastException")); + lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException"))); else lastException = null; super.read(compound, clientPacket); @@ -408,12 +413,4 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe return pos; } - @Override - public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { - boolean added = super.addToGoggleTooltip(tooltip, isPlayerSneaking); - if (lastException != null) - tooltip.add(lastException.getFormattedText()); - return lastException != null || added; - } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java index be481d66e..ed71bf748 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java @@ -1,21 +1,19 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; -import java.util.HashSet; -import java.util.Queue; -import java.util.Set; - -import org.apache.commons.lang3.tuple.Pair; - import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.foundation.utility.NBTHelper; - import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.HashSet; +import java.util.Queue; +import java.util.Set; public class ClockworkContraption extends Contraption { @@ -88,13 +86,13 @@ public class ClockworkContraption extends Contraption { } @Override - public boolean searchMovedStructure(World world, BlockPos pos, Direction direction) { + public boolean searchMovedStructure(World world, BlockPos pos, Direction direction) throws AssemblyException { return super.searchMovedStructure(world, pos.offset(direction, offset + 1), null); } @Override protected boolean moveBlock(World world, Direction direction, Queue frontier, - Set visited) { + Set visited) throws AssemblyException { if (ignoreBlocks.contains(frontier.peek())) { frontier.poll(); return true; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java index 1bb979484..353e58c17 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java @@ -1,13 +1,10 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; -import static net.minecraft.state.properties.BlockStateProperties.FACING; - -import java.util.List; - import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity; +import com.simibubi.create.content.contraptions.components.structureMovement.IDisplayAssemblyExceptions; import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; @@ -15,7 +12,6 @@ import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollOpt import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.ServerSpeedProvider; - import net.minecraft.block.BlockState; import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.properties.BlockStateProperties; @@ -25,7 +21,11 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.text.ITextComponent; -public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity implements IBearingTileEntity { +import java.util.List; + +import static net.minecraft.state.properties.BlockStateProperties.FACING; + +public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity implements IBearingTileEntity, IDisplayAssemblyExceptions { protected ScrollOptionBehaviour movementMode; protected ControlledContraptionEntity movedContraption; @@ -33,7 +33,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp protected boolean running; protected boolean assembleNextTick; protected float clientAngleDiff; - protected ITextComponent lastException; + protected AssemblyException lastException; public MechanicalBearingTileEntity(TileEntityType type) { super(type); @@ -66,7 +66,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp compound.putBoolean("Running", running); compound.putFloat("Angle", angle); if (lastException != null) - compound.putString("LastException", ITextComponent.Serializer.toJson(lastException)); + compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component)); super.write(compound, clientPacket); } @@ -76,7 +76,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp running = compound.getBoolean("Running"); angle = compound.getFloat("Angle"); if (compound.contains("LastException")) - lastException = ITextComponent.Serializer.fromJson(compound.getString("LastException")); + lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException"))); else lastException = null; super.read(compound, clientPacket); @@ -113,6 +113,11 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp return speed; } + @Override + public AssemblyException getLastAssemblyException() { + return lastException; + } + protected boolean isWindmill() { return false; } @@ -130,11 +135,13 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp Direction direction = getBlockState().get(FACING); BearingContraption contraption = new BearingContraption(isWindmill(), direction); try { - lastException = null; if (!contraption.assemble(world, pos)) return; + + lastException = null; } catch (AssemblyException e) { - lastException = e.message; + lastException = e; + sendData(); return; } @@ -296,12 +303,4 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp TooltipHelper.addHint(tooltip, "hint.empty_bearing"); return true; } - - @Override - public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { - boolean added = super.addToGoggleTooltip(tooltip, isPlayerSneaking); - if (lastException != null) - tooltip.add(lastException.getFormattedText()); - return lastException != null || added; - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java index 5813f6afe..8a50eb7cf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerBlock.java @@ -237,11 +237,18 @@ public class CartAssemblerBlock extends AbstractRailBlock MountedContraption contraption = new MountedContraption(mode); try { - assembler.ifPresent(te -> te.lastException = null); if (!contraption.assemble(world, pos)) return; + + assembler.ifPresent(te -> { + te.lastException = null; + te.sendData(); + }); } catch (AssemblyException e) { - assembler.ifPresent(te -> te.lastException = e.message); + assembler.ifPresent(te -> { + te.lastException = e; + te.sendData(); + }); return; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerTileEntity.java index 6e1c3be7a..4640e7fa9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerTileEntity.java @@ -1,8 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.mounted; -import java.util.List; - -import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; +import com.simibubi.create.content.contraptions.components.structureMovement.IDisplayAssemblyExceptions; import com.simibubi.create.foundation.gui.AllIcons; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; @@ -12,19 +11,21 @@ import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.INamedIco import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollOptionBehaviour; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.VecHelper; - +import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.properties.RailShape; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; -public class CartAssemblerTileEntity extends SmartTileEntity implements IHaveGoggleInformation { +import java.util.List; + +public class CartAssemblerTileEntity extends SmartTileEntity implements IDisplayAssemblyExceptions { private static final int assemblyCooldown = 8; protected ScrollOptionBehaviour movementMode; private int ticksSinceMinecartUpdate; - protected ITextComponent lastException; //TODO + protected AssemblyException lastException; public CartAssemblerTileEntity(TileEntityType type) { super(type); @@ -47,6 +48,27 @@ public class CartAssemblerTileEntity extends SmartTileEntity implements IHaveGog behaviours.add(movementMode); } + @Override + public void write(CompoundNBT compound, boolean clientPacket) { + if (lastException != null) + compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component)); + super.write(compound, clientPacket); + } + + @Override + protected void read(CompoundNBT compound, boolean clientPacket) { + if (compound.contains("LastException")) + lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException"))); + else + lastException = null; + super.read(compound, clientPacket); + } + + @Override + public AssemblyException getLastAssemblyException() { + return lastException; + } + protected ValueBoxTransform getMovementModeSlot() { return new CartAssemblerValueBoxTransform(); } @@ -106,11 +128,4 @@ public class CartAssemblerTileEntity extends SmartTileEntity implements IHaveGog public boolean isMinecartUpdateValid() { return ticksSinceMinecartUpdate >= assemblyCooldown; } - - @Override - public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { - if (lastException != null) - tooltip.add(lastException.getFormattedText()); - return lastException != null; - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java index e92f2d807..9b6454df9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java @@ -1,18 +1,12 @@ package com.simibubi.create.content.contraptions.components.structureMovement.piston; -import java.util.List; - import com.simibubi.create.content.contraptions.base.KineticTileEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; -import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.IControlContraption; +import com.simibubi.create.content.contraptions.components.structureMovement.*; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform; import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollOptionBehaviour; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.ServerSpeedProvider; - import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.math.BlockPos; @@ -20,7 +14,9 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; -public abstract class LinearActuatorTileEntity extends KineticTileEntity implements IControlContraption { +import java.util.List; + +public abstract class LinearActuatorTileEntity extends KineticTileEntity implements IControlContraption, IDisplayAssemblyExceptions { public float offset; public boolean running; @@ -29,7 +25,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme protected boolean forceMove; protected ScrollOptionBehaviour movementMode; protected boolean waitingForSpeedChange; - protected ITextComponent lastException; + protected AssemblyException lastException; // Custom position sync protected float clientOffsetDiff; @@ -87,8 +83,9 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme assemble(); lastException = null; } catch (AssemblyException e) { - lastException = e.message; + lastException = e; } + sendData(); } return; } @@ -162,7 +159,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme compound.putBoolean("Waiting", waitingForSpeedChange); compound.putFloat("Offset", offset); if (lastException != null) - compound.putString("LastException", ITextComponent.Serializer.toJson(lastException)); + compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component)); super.write(compound, clientPacket); if (clientPacket && forceMove) { @@ -180,7 +177,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme waitingForSpeedChange = compound.getBoolean("Waiting"); offset = compound.getFloat("Offset"); if (compound.contains("LastException")) - lastException = ITextComponent.Serializer.fromJson(compound.getString("LastException")); + lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException"))); else lastException = null; super.read(compound, clientPacket); @@ -197,6 +194,11 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme movedContraption = null; } + @Override + public AssemblyException getLastAssemblyException() { + return lastException; + } + public abstract void disassemble(); protected abstract void assemble() throws AssemblyException; @@ -302,13 +304,4 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme public BlockPos getBlockPosition() { return pos; } - - @Override - public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { - boolean added = super.addToGoggleTooltip(tooltip, isPlayerSneaking); - if (lastException != null) - tooltip.add(lastException.getFormattedText()); - return lastException != null || added; - } - } \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java index 39a48d58e..c1cb38c3a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java @@ -68,7 +68,7 @@ public class PistonContraption extends TranslatingContraption { return true; } - private boolean collectExtensions(World world, BlockPos pos, Direction direction) { + private boolean collectExtensions(World world, BlockPos pos, Direction direction) throws AssemblyException { List poles = new ArrayList<>(); BlockPos actualStart = pos; BlockState nextBlock = world.getBlockState(actualStart.offset(direction)); @@ -91,7 +91,7 @@ public class PistonContraption extends TranslatingContraption { nextBlock = world.getBlockState(actualStart.offset(direction)); if (extensionsInFront > MechanicalPistonBlock.maxAllowedPistonPoles()) - throw new AssemblyException("tooManyPistonPoles"); + throw AssemblyException.tooManyPistonPoles(); } } @@ -114,7 +114,7 @@ public class PistonContraption extends TranslatingContraption { nextBlock = world.getBlockState(end.offset(direction.getOpposite())); if (extensionsInFront + extensionsInBack > MechanicalPistonBlock.maxAllowedPistonPoles()) - throw new AssemblyException("tooManyPistonPoles"); + throw AssemblyException.tooManyPistonPoles(); } anchor = pos.offset(direction, initialExtensionProgress + 1); @@ -126,7 +126,7 @@ public class PistonContraption extends TranslatingContraption { 1, 1); if (extensionLength == 0) - throw new AssemblyException("noPistonPoles"); + throw AssemblyException.noPistonPoles(); bounds = new AxisAlignedBB(0, 0, 0, 0, 0, 0); @@ -146,7 +146,7 @@ public class PistonContraption extends TranslatingContraption { } @Override - protected boolean addToInitialFrontier(World world, BlockPos pos, Direction direction, Queue frontier) { + protected boolean addToInitialFrontier(World world, BlockPos pos, Direction direction, Queue frontier) throws AssemblyException { frontier.clear(); boolean sticky = isStickyPiston(world.getBlockState(pos.offset(orientation, -1))); boolean retracting = direction != orientation; @@ -159,7 +159,7 @@ public class PistonContraption extends TranslatingContraption { if (retracting && World.isOutsideBuildHeight(currentPos)) return true; if (!world.isBlockPresent(currentPos)) - throw new AssemblyException("chunkNotLoaded"); + throw AssemblyException.unloadedChunk(currentPos); BlockState state = world.getBlockState(currentPos); if (!BlockMovementTraits.movementNecessary(state, world, currentPos)) return true; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java index b1894d543..5f0bf3469 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java @@ -9,7 +9,6 @@ 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; @@ -192,7 +191,7 @@ public class PulleyTileEntity extends LinearActuatorTileEntity { protected void read(CompoundNBT compound, boolean clientPacket) { initialOffset = compound.getInt("InitialOffset"); if (compound.contains("LastException")) - lastException = ITextComponent.Serializer.fromJson(compound.getString("LastException")); + lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException"))); else lastException = null; super.read(compound, clientPacket); @@ -202,7 +201,7 @@ public class PulleyTileEntity extends LinearActuatorTileEntity { public void write(CompoundNBT compound, boolean clientPacket) { compound.putInt("InitialOffset", initialOffset); if (lastException != null) - compound.putString("LastException", ITextComponent.Serializer.toJson(lastException)); + compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component)); super.write(compound, clientPacket); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java index 07b9dff3a..c61452bb8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import com.simibubi.create.CreateClient; +import com.simibubi.create.content.contraptions.components.structureMovement.IDisplayAssemblyExceptions; import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock; import com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonExtensionPoleBlock; import com.simibubi.create.foundation.config.AllConfigs; @@ -92,6 +93,14 @@ public class GoggleOverlayRenderer { tooltip.remove(tooltip.size() - 1); } + if (te instanceof IDisplayAssemblyExceptions) { + boolean exceptionAdded = ((IDisplayAssemblyExceptions) te).addExceptionToTooltip(tooltip); + if (exceptionAdded) { + hasHoveringInformation = true; + hoverAddedInformation = true; + } + } + // break early if goggle or hover returned false when present if ((hasGoggleInformation && !goggleAddedInformation) && (hasHoveringInformation && !hoverAddedInformation)) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/goggles/IHaveGoggleInformation.java b/src/main/java/com/simibubi/create/content/contraptions/goggles/IHaveGoggleInformation.java index 728f1c631..9a664a92d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/goggles/IHaveGoggleInformation.java +++ b/src/main/java/com/simibubi/create/content/contraptions/goggles/IHaveGoggleInformation.java @@ -9,13 +9,13 @@ import java.util.List; public interface IHaveGoggleInformation { DecimalFormat decimalFormat = new DecimalFormat("#.##"); - public static String spacing = " "; + String spacing = " "; /** * this method will be called when looking at a TileEntity that implemented this interface * - * @return {{@code true}} if the tooltip creation was successful and should be displayed, - * or {{@code false}} if the overlay should not be displayed + * @return {@code true} if the tooltip creation was successful and should be displayed, + * or {@code false} if the overlay should not be displayed * */ default boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking){ return false; diff --git a/src/main/resources/assets/create/lang/default/messages.json b/src/main/resources/assets/create/lang/default/messages.json index 57fbc9b7e..94af8ae4d 100644 --- a/src/main/resources/assets/create/lang/default/messages.json +++ b/src/main/resources/assets/create/lang/default/messages.json @@ -172,6 +172,13 @@ "create.gui.goggles.at_current_speed": "at current speed", "create.gui.goggles.pole_length": "Pole Length:", + "create.gui.assembly.exception": "This Contraption was unable to assemble:", + "create.gui.assembly.exception.unmovableBlock": "Unmovable Block (%4$s) at [%1$s %2$s %3$s]", + "create.gui.assembly.exception.chunkNotLoaded": "The Block at [%1$s %2$s %3$s] was not in a loaded chunk", + "create.gui.assembly.exception.structureTooLarge": "There are too many Blocks included in the contraption.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.tooManyPistonPoles": "There are too many extension Poles attached to this Piston.\nThe configured maximum is: %1$s", + "create.gui.assembly.exception.noPistonPoles": "The Piston is missing some extension Poles", + "create.gui.gauge.info_header": "Gauge Information:", "create.gui.speedometer.title": "Rotation Speed", "create.gui.stressometer.title": "Network Stress", From 34de9a031997f48801392d40b7ebb8b6261e5d9c Mon Sep 17 00:00:00 2001 From: Zelophed Date: Fri, 12 Feb 2021 03:13:19 +0100 Subject: [PATCH 6/6] Player Feedback, Part III --- .../structureMovement/AssemblyException.java | 43 +++++++- .../bearing/ClockworkBearingTileEntity.java | 9 +- .../bearing/MechanicalBearingTileEntity.java | 9 +- .../gantry/GantryContraption.java | 4 +- .../gantry/GantryPinionTileEntity.java | 39 ++++++- .../mounted/CartAssemblerTileEntity.java | 9 +- .../piston/LinearActuatorTileEntity.java | 9 +- .../piston/PistonContraption.java | 2 +- .../pulley/PulleyTileEntity.java | 7 -- .../foundation/command/AllCommands.java | 43 +++++--- .../foundation/command/HighlightCommand.java | 103 ++++++++++++++++++ .../foundation/command/HighlightPacket.java | 55 ++++++++++ .../foundation/networking/AllPackets.java | 25 ++--- .../foundation/utility/outliner/Outliner.java | 23 ++-- 14 files changed, 298 insertions(+), 82 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/command/HighlightCommand.java create mode 100644 src/main/java/com/simibubi/create/foundation/command/HighlightPacket.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java index 4beac5ff9..0db500c6d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AssemblyException.java @@ -2,12 +2,39 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.simibubi.create.foundation.config.AllConfigs; import net.minecraft.block.BlockState; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TranslationTextComponent; public class AssemblyException extends Exception { public final ITextComponent component; + private BlockPos position = null; + + public static void write(CompoundNBT compound, AssemblyException exception) { + if (exception == null) + return; + + CompoundNBT nbt = new CompoundNBT(); + nbt.putString("Component", ITextComponent.Serializer.toJson(exception.component)); + if (exception.hasPosition()) + nbt.putLong("Position", exception.getPosition().toLong()); + + compound.put("LastException", nbt); + } + + public static AssemblyException read(CompoundNBT compound) { + if (!compound.contains("LastException")) + return null; + + CompoundNBT nbt = compound.getCompound("LastException"); + String string = nbt.getString("Component"); + AssemblyException exception = new AssemblyException(ITextComponent.Serializer.fromJson(string)); + if (nbt.contains("Position")) + exception.position = BlockPos.fromLong(nbt.getLong("Position")); + + return exception; + } public AssemblyException(ITextComponent component) { this.component = component; @@ -18,18 +45,22 @@ public class AssemblyException extends Exception { } public static AssemblyException unmovableBlock(BlockPos pos, BlockState state) { - return new AssemblyException("unmovableBlock", + AssemblyException e = new AssemblyException("unmovableBlock", pos.getX(), pos.getY(), pos.getZ(), new TranslationTextComponent(state.getBlock().getTranslationKey())); + e.position = pos; + return e; } public static AssemblyException unloadedChunk(BlockPos pos) { - return new AssemblyException("chunkNotLoaded", + AssemblyException e = new AssemblyException("chunkNotLoaded", pos.getX(), pos.getY(), pos.getZ()); + e.position = pos; + return e; } public static AssemblyException structureTooLarge() { @@ -49,4 +80,12 @@ public class AssemblyException extends Exception { public String getFormattedText() { return component.getFormattedText(); } + + public boolean hasPosition() { + return position != null; + } + + public BlockPos getPosition() { + return position; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java index 12c65902f..69b40f6fd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkBearingTileEntity.java @@ -22,7 +22,6 @@ import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.text.ITextComponent; import org.apache.commons.lang3.tuple.Pair; import java.util.List; @@ -298,8 +297,7 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe compound.putBoolean("Running", running); compound.putFloat("HourAngle", hourAngle); compound.putFloat("MinuteAngle", minuteAngle); - if (lastException != null) - compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component)); + AssemblyException.write(compound, lastException); super.write(compound, clientPacket); } @@ -311,10 +309,7 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe running = compound.getBoolean("Running"); hourAngle = compound.getFloat("HourAngle"); minuteAngle = compound.getFloat("MinuteAngle"); - if (compound.contains("LastException")) - lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException"))); - else - lastException = null; + lastException = AssemblyException.read(compound); super.read(compound, clientPacket); if (!clientPacket) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java index 353e58c17..65573cb35 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/MechanicalBearingTileEntity.java @@ -19,7 +19,6 @@ import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.text.ITextComponent; import java.util.List; @@ -65,8 +64,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp public void write(CompoundNBT compound, boolean clientPacket) { compound.putBoolean("Running", running); compound.putFloat("Angle", angle); - if (lastException != null) - compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component)); + AssemblyException.write(compound, lastException); super.write(compound, clientPacket); } @@ -75,10 +73,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp float angleBefore = angle; running = compound.getBoolean("Running"); angle = compound.getFloat("Angle"); - if (compound.contains("LastException")) - lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException"))); - else - lastException = null; + lastException = AssemblyException.read(compound); super.read(compound, clientPacket); if (!clientPacket) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraption.java index 58ddcadcb..8bc426b3e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryContraption.java @@ -1,9 +1,9 @@ package com.simibubi.create.content.contraptions.components.structureMovement.gantry; import com.simibubi.create.AllBlocks; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionType; import com.simibubi.create.content.contraptions.components.structureMovement.TranslatingContraption; - import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; @@ -21,7 +21,7 @@ public class GantryContraption extends TranslatingContraption { } @Override - public boolean assemble(World world, BlockPos pos) { + public boolean assemble(World world, BlockPos pos) throws AssemblyException { if (!searchMovedStructure(world, pos, null)) return false; startMoving(world); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryPinionTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryPinionTileEntity.java index 3c2b6f437..000a944ba 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryPinionTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryPinionTileEntity.java @@ -1,23 +1,26 @@ package com.simibubi.create.content.contraptions.components.structureMovement.gantry; -import static net.minecraft.state.properties.BlockStateProperties.FACING; - import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionCollider; +import com.simibubi.create.content.contraptions.components.structureMovement.IDisplayAssemblyExceptions; import com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock; import com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity; - import net.minecraft.block.BlockState; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; -public class GantryPinionTileEntity extends KineticTileEntity { +import static net.minecraft.state.properties.BlockStateProperties.FACING; + +public class GantryPinionTileEntity extends KineticTileEntity implements IDisplayAssemblyExceptions { boolean assembleNextTick; + protected AssemblyException lastException; public GantryPinionTileEntity(TileEntityType typeIn) { super(typeIn); @@ -50,6 +53,11 @@ public class GantryPinionTileEntity extends KineticTileEntity { } } + @Override + public AssemblyException getLastAssemblyException() { + return lastException; + } + private void tryAssemble() { BlockState blockState = getBlockState(); if (!(blockState.getBlock() instanceof GantryPinionBlock)) @@ -71,8 +79,17 @@ public class GantryPinionTileEntity extends KineticTileEntity { if (pinionMovementSpeed < 0) movementDirection = movementDirection.getOpposite(); - if (!contraption.assemble(world, pos)) + try { + lastException = null; + if (!contraption.assemble(world, pos)) + return; + + sendData(); + } catch (AssemblyException e) { + lastException = e; + sendData(); return; + } if (ContraptionCollider.isCollidingWithWorld(world, contraption, pos.offset(movementDirection), movementDirection)) return; @@ -85,6 +102,18 @@ public class GantryPinionTileEntity extends KineticTileEntity { world.addEntity(movedContraption); } + @Override + protected void write(CompoundNBT compound, boolean clientPacket) { + AssemblyException.write(compound, lastException); + super.write(compound, clientPacket); + } + + @Override + protected void read(CompoundNBT compound, boolean clientPacket) { + lastException = AssemblyException.read(compound); + super.read(compound, clientPacket); + } + @Override public float propagateRotationTo(KineticTileEntity target, BlockState stateFrom, BlockState stateTo, BlockPos diff, boolean connectedViaAxes, boolean connectedViaCogs) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerTileEntity.java index 4640e7fa9..f94f0bdc7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/CartAssemblerTileEntity.java @@ -16,7 +16,6 @@ import net.minecraft.state.properties.RailShape; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.text.ITextComponent; import java.util.List; @@ -50,17 +49,13 @@ public class CartAssemblerTileEntity extends SmartTileEntity implements IDisplay @Override public void write(CompoundNBT compound, boolean clientPacket) { - if (lastException != null) - compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component)); + AssemblyException.write(compound, lastException); super.write(compound, clientPacket); } @Override protected void read(CompoundNBT compound, boolean clientPacket) { - if (compound.contains("LastException")) - lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException"))); - else - lastException = null; + lastException = AssemblyException.read(compound); super.read(compound, clientPacket); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java index 1adfdb1cd..ce3cb1470 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/LinearActuatorTileEntity.java @@ -12,7 +12,6 @@ import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.text.ITextComponent; import java.util.List; @@ -158,8 +157,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme compound.putBoolean("Running", running); compound.putBoolean("Waiting", waitingForSpeedChange); compound.putFloat("Offset", offset); - if (lastException != null) - compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component)); + AssemblyException.write(compound, lastException); super.write(compound, clientPacket); if (clientPacket && forceMove) { @@ -176,10 +174,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme running = compound.getBoolean("Running"); waitingForSpeedChange = compound.getBoolean("Waiting"); offset = compound.getFloat("Offset"); - if (compound.contains("LastException")) - lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException"))); - else - lastException = null; + lastException = AssemblyException.read(compound); super.read(compound, clientPacket); if (!clientPacket) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java index 09565629a..e0b12b263 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java @@ -1,8 +1,8 @@ package com.simibubi.create.content.contraptions.components.structureMovement.piston; -import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes; import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; import com.simibubi.create.content.contraptions.components.structureMovement.BlockMovementTraits; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionType; import com.simibubi.create.content.contraptions.components.structureMovement.TranslatingContraption; import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.*; import com.simibubi.create.foundation.config.AllConfigs; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java index 5f0bf3469..b20ff7fdc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyTileEntity.java @@ -22,7 +22,6 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.text.ITextComponent; public class PulleyTileEntity extends LinearActuatorTileEntity { @@ -190,18 +189,12 @@ public class PulleyTileEntity extends LinearActuatorTileEntity { @Override protected void read(CompoundNBT compound, boolean clientPacket) { initialOffset = compound.getInt("InitialOffset"); - if (compound.contains("LastException")) - lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException"))); - else - lastException = null; super.read(compound, clientPacket); } @Override public void write(CompoundNBT compound, boolean clientPacket) { compound.putInt("InitialOffset", initialOffset); - if (lastException != null) - compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component)); super.write(compound, clientPacket); } diff --git a/src/main/java/com/simibubi/create/foundation/command/AllCommands.java b/src/main/java/com/simibubi/create/foundation/command/AllCommands.java index fe1ec78cf..cf36c3c7a 100644 --- a/src/main/java/com/simibubi/create/foundation/command/AllCommands.java +++ b/src/main/java/com/simibubi/create/foundation/command/AllCommands.java @@ -1,25 +1,42 @@ package com.simibubi.create.foundation.command; import com.mojang.brigadier.CommandDispatcher; - +import com.mojang.brigadier.tree.CommandNode; +import com.mojang.brigadier.tree.LiteralCommandNode; import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; +import net.minecraft.entity.player.PlayerEntity; + +import java.util.Collections; +import java.util.function.Predicate; public class AllCommands { - public static void register(CommandDispatcher dispatcher) { - dispatcher.register(Commands.literal("create") - //general purpose - .then(ToggleDebugCommand.register()) - .then(OverlayConfigCommand.register()) - .then(FixLightingCommand.register()) - .then(ReplaceInCommandBlocksCommand.register()) + public static Predicate sourceIsPlayer = (cs) -> cs.getEntity() instanceof PlayerEntity; - //dev-util - //Comment out for release - .then(ClearBufferCacheCommand.register()) - .then(ChunkUtilCommand.register()) -// .then(KillTPSCommand.register()) + public static void register(CommandDispatcher dispatcher) { + + LiteralCommandNode createRoot = dispatcher.register(Commands.literal("create") + //general purpose + .then(ToggleDebugCommand.register()) + .then(OverlayConfigCommand.register()) + .then(FixLightingCommand.register()) + .then(ReplaceInCommandBlocksCommand.register()) + .then(HighlightCommand.register()) + + //dev-util + //Comment out for release + .then(ClearBufferCacheCommand.register()) + .then(ChunkUtilCommand.register()) + //.then(KillTPSCommand.register()) + ); + + CommandNode c = dispatcher.findNode(Collections.singleton("c")); + if (c != null) + return; + + dispatcher.register(Commands.literal("c") + .redirect(createRoot) ); } } diff --git a/src/main/java/com/simibubi/create/foundation/command/HighlightCommand.java b/src/main/java/com/simibubi/create/foundation/command/HighlightCommand.java new file mode 100644 index 000000000..6071c14f9 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/command/HighlightCommand.java @@ -0,0 +1,103 @@ +package com.simibubi.create.foundation.command; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException; +import com.simibubi.create.content.contraptions.components.structureMovement.IDisplayAssemblyExceptions; +import com.simibubi.create.foundation.networking.AllPackets; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.command.arguments.BlockPosArgument; +import net.minecraft.command.arguments.EntityArgument; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.*; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.world.World; +import net.minecraftforge.fml.network.PacketDistributor; + +import java.util.Collection; + +public class HighlightCommand { + + public static ArgumentBuilder register() { + return Commands.literal("highlight") + .requires(cs -> cs.hasPermissionLevel(0)) + .requires(AllCommands.sourceIsPlayer) + .then(Commands.argument("pos", BlockPosArgument.blockPos()) + .requires(AllCommands.sourceIsPlayer) + .executes(ctx -> { + BlockPos pos = BlockPosArgument.getLoadedBlockPos(ctx, "pos"); + + AllPackets.channel.send( + PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) ctx.getSource().getEntity()), + new HighlightPacket(pos) + ); + + return Command.SINGLE_SUCCESS; + }) + .then(Commands.argument("players", EntityArgument.players()) + .executes(ctx -> { + Collection players = EntityArgument.getPlayers(ctx, "players"); + BlockPos pos = BlockPosArgument.getBlockPos(ctx, "pos"); + + for (ServerPlayerEntity p : players) { + AllPackets.channel.send( + PacketDistributor.PLAYER.with(() -> p), + new HighlightPacket(pos) + ); + } + + return players.size(); + }) + ) + ) + .executes(ctx -> { + ServerPlayerEntity player = ctx.getSource().asPlayer(); + return highlightAssemblyExceptionFor(player, ctx.getSource()); + }); + + } + + private static void sendMissMessage(CommandSource source) { + source.sendFeedback(new StringTextComponent("Try looking at a Block that has failed to assemble a Contraption and try again."), true); + } + + private static int highlightAssemblyExceptionFor(ServerPlayerEntity player, CommandSource source) { + double distance = player.getAttribute(PlayerEntity.REACH_DISTANCE).getValue(); + Vec3d start = player.getEyePosition(1); + Vec3d look = player.getLook(1); + Vec3d end = start.add(look.x * distance, look.y * distance, look.z * distance); + World world = player.world; + + BlockRayTraceResult ray = world.rayTraceBlocks(new RayTraceContext(start, end, RayTraceContext.BlockMode.OUTLINE, RayTraceContext.FluidMode.NONE, player)); + if (ray.getType() == RayTraceResult.Type.MISS) { + sendMissMessage(source); + return 0; + } + + BlockPos pos = ray.getPos(); + TileEntity te = world.getTileEntity(pos); + if (!(te instanceof IDisplayAssemblyExceptions)) { + sendMissMessage(source); + return 0; + } + + IDisplayAssemblyExceptions display = (IDisplayAssemblyExceptions) te; + AssemblyException exception = display.getLastAssemblyException(); + if (exception == null) { + sendMissMessage(source); + return 0; + } + + if (!exception.hasPosition()) { + source.sendFeedback(new StringTextComponent("Can't highlight a specific position for this issue"), true); + return Command.SINGLE_SUCCESS; + } + + BlockPos p = exception.getPosition(); + String command = "/create highlight " + p.getX() + " " + p.getY() + " " + p.getZ(); + return player.server.getCommandManager().handleCommand(source, command); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/command/HighlightPacket.java b/src/main/java/com/simibubi/create/foundation/command/HighlightPacket.java new file mode 100644 index 000000000..7b4b10a4c --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/command/HighlightPacket.java @@ -0,0 +1,55 @@ +package com.simibubi.create.foundation.command; + +import com.simibubi.create.AllSpecialTextures; +import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.networking.SimplePacketBase; +import net.minecraft.client.Minecraft; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.shapes.VoxelShapes; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.network.NetworkEvent; + +import java.util.function.Supplier; + +public class HighlightPacket extends SimplePacketBase { + + private final BlockPos pos; + + public HighlightPacket(BlockPos pos) { + this.pos = pos; + } + + public HighlightPacket(PacketBuffer buffer) { + this.pos = BlockPos.fromLong(buffer.readLong()); + } + + @Override + public void write(PacketBuffer buffer) { + buffer.writeLong(pos.toLong()); + } + + @Override + public void handle(Supplier ctx) { + ctx.get().enqueueWork(() -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { + performHighlight(pos); + })); + + ctx.get().setPacketHandled(true); + } + + @OnlyIn(Dist.CLIENT) + public static void performHighlight(BlockPos pos) { + if (Minecraft.getInstance().world == null || !Minecraft.getInstance().world.isBlockPresent(pos)) + return; + + CreateClient.outliner.showAABB("highlightCommand", VoxelShapes.fullCube().getBoundingBox().offset(pos), 200) + .lineWidth(1 / 32f) + .colored(0xEeEeEe) + //.colored(0x243B50) + .withFaceTexture(AllSpecialTextures.SELECTION); + + } +} diff --git a/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java b/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java index 6c5342883..2cabdfb0a 100644 --- a/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java +++ b/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java @@ -1,19 +1,11 @@ package com.simibubi.create.foundation.networking; -import java.util.function.BiConsumer; -import java.util.function.Function; -import java.util.function.Supplier; - import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionDisassemblyPacket; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionStallPacket; import com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryContraptionUpdatePacket; import com.simibubi.create.content.contraptions.components.structureMovement.glue.GlueEffectPacket; -import com.simibubi.create.content.contraptions.components.structureMovement.sync.ClientMotionPacket; -import com.simibubi.create.content.contraptions.components.structureMovement.sync.ContraptionFluidPacket; -import com.simibubi.create.content.contraptions.components.structureMovement.sync.ContraptionInteractionPacket; -import com.simibubi.create.content.contraptions.components.structureMovement.sync.ContraptionSeatMappingPacket; -import com.simibubi.create.content.contraptions.components.structureMovement.sync.LimbSwingUpdatePacket; +import com.simibubi.create.content.contraptions.components.structureMovement.sync.*; import com.simibubi.create.content.contraptions.components.structureMovement.train.CouplingCreationPacket; import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartControllerUpdatePacket; import com.simibubi.create.content.contraptions.fluids.actors.FluidSplashPacket; @@ -25,16 +17,12 @@ import com.simibubi.create.content.logistics.block.mechanicalArm.ArmPlacementPac import com.simibubi.create.content.logistics.item.filter.FilterScreenPacket; import com.simibubi.create.content.logistics.packet.ConfigureFlexcratePacket; import com.simibubi.create.content.logistics.packet.ConfigureStockswitchPacket; -import com.simibubi.create.content.schematics.packet.ConfigureSchematicannonPacket; -import com.simibubi.create.content.schematics.packet.InstantSchematicPacket; -import com.simibubi.create.content.schematics.packet.SchematicPlacePacket; -import com.simibubi.create.content.schematics.packet.SchematicSyncPacket; -import com.simibubi.create.content.schematics.packet.SchematicUploadPacket; +import com.simibubi.create.content.schematics.packet.*; import com.simibubi.create.foundation.command.ConfigureConfigPacket; +import com.simibubi.create.foundation.command.HighlightPacket; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringCountUpdatePacket; import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueUpdatePacket; import com.simibubi.create.foundation.utility.ServerSpeedProvider; - import net.minecraft.network.PacketBuffer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; @@ -46,8 +34,12 @@ import net.minecraftforge.fml.network.PacketDistributor; import net.minecraftforge.fml.network.PacketDistributor.TargetPoint; import net.minecraftforge.fml.network.simple.SimpleChannel; -import static net.minecraftforge.fml.network.NetworkDirection.PLAY_TO_SERVER; +import java.util.function.BiConsumer; +import java.util.function.Function; +import java.util.function.Supplier; + import static net.minecraftforge.fml.network.NetworkDirection.PLAY_TO_CLIENT; +import static net.minecraftforge.fml.network.NetworkDirection.PLAY_TO_SERVER; public enum AllPackets { @@ -85,6 +77,7 @@ public enum AllPackets { FLUID_SPLASH(FluidSplashPacket.class, FluidSplashPacket::new, PLAY_TO_CLIENT), CONTRAPTION_FLUID(ContraptionFluidPacket.class, ContraptionFluidPacket::new, PLAY_TO_CLIENT), GANTRY_UPDATE(GantryContraptionUpdatePacket.class, GantryContraptionUpdatePacket::new, PLAY_TO_CLIENT), + BLOCK_HIGHLIGHT(HighlightPacket.class, HighlightPacket::new, PLAY_TO_CLIENT) ; diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/Outliner.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/Outliner.java index 39a019c65..9c442b89d 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/outliner/Outliner.java +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/Outliner.java @@ -1,24 +1,18 @@ package com.simibubi.create.foundation.utility.outliner; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.tileEntity.behaviour.ValueBox; import com.simibubi.create.foundation.utility.outliner.LineOutline.EndChasingLineOutline; import com.simibubi.create.foundation.utility.outliner.Outline.OutlineParams; - import net.minecraft.client.Minecraft; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; +import java.util.*; + public class Outliner { final Map outlines; @@ -57,6 +51,13 @@ public class Outliner { return entry.outline.getParams(); } + public OutlineParams showAABB(Object slot, AxisAlignedBB bb, int ttl) { + createAABBOutlineIfMissing(slot, bb); + ChasingAABBOutline outline = getAndRefreshAABB(slot, ttl); + outline.prevBB = outline.targetBB = bb; + return outline.getParams(); + } + public OutlineParams showAABB(Object slot, AxisAlignedBB bb) { createAABBOutlineIfMissing(slot, bb); ChasingAABBOutline outline = getAndRefreshAABB(slot); @@ -112,6 +113,12 @@ public class Outliner { return (ChasingAABBOutline) entry.getOutline(); } + private ChasingAABBOutline getAndRefreshAABB(Object slot, int ttl) { + OutlineEntry entry = outlines.get(slot); + entry.ticksTillRemoval = ttl; + return (ChasingAABBOutline) entry.getOutline(); + } + // Maintenance public Outliner() {