diff --git a/src/main/java/com/simibubi/create/foundation/command/CloneCommand.java b/src/main/java/com/simibubi/create/foundation/command/CloneCommand.java index 83bc8b4a8..d5a07c8fc 100644 --- a/src/main/java/com/simibubi/create/foundation/command/CloneCommand.java +++ b/src/main/java/com/simibubi/create/foundation/command/CloneCommand.java @@ -37,7 +37,10 @@ public class CloneCommand { .then(Commands.argument("begin", BlockPosArgument.blockPos()) .then(Commands.argument("end", BlockPosArgument.blockPos()) .then(Commands.argument("destination", BlockPosArgument.blockPos()) - .executes(ctx -> doClone(ctx.getSource(), BlockPosArgument.getLoadedBlockPos(ctx, "begin"), BlockPosArgument.getLoadedBlockPos(ctx, "end"), BlockPosArgument.getLoadedBlockPos(ctx, "destination"))) + .then(Commands.literal("skipBlocks") + .executes(ctx -> doClone(ctx.getSource(), BlockPosArgument.getLoadedBlockPos(ctx, "begin"), BlockPosArgument.getLoadedBlockPos(ctx, "end"), BlockPosArgument.getLoadedBlockPos(ctx, "destination"), false)) + ) + .executes(ctx -> doClone(ctx.getSource(), BlockPosArgument.getLoadedBlockPos(ctx, "begin"), BlockPosArgument.getLoadedBlockPos(ctx, "end"), BlockPosArgument.getLoadedBlockPos(ctx, "destination"), true)) ) ) ) @@ -50,7 +53,7 @@ public class CloneCommand { } - private static int doClone(CommandSource source, BlockPos begin, BlockPos end, BlockPos destination) throws CommandSyntaxException { + private static int doClone(CommandSource source, BlockPos begin, BlockPos end, BlockPos destination, boolean cloneBlocks) throws CommandSyntaxException { MutableBoundingBox sourceArea = new MutableBoundingBox(begin, end); BlockPos destinationEnd = destination.add(sourceArea.getLength()); MutableBoundingBox destinationArea = new MutableBoundingBox(destination, destinationEnd); @@ -64,12 +67,47 @@ public class CloneCommand { if (!world.isAreaLoaded(begin, end) || !world.isAreaLoaded(destination, destinationEnd)) throw BlockPosArgument.POS_UNLOADED.create(); - List blocks = Lists.newArrayList(); - List tileBlocks = Lists.newArrayList(); BlockPos diffToTarget = new BlockPos(destinationArea.minX - sourceArea.minX, destinationArea.minY - sourceArea.minY, destinationArea.minZ - sourceArea.minZ); + int blockPastes = cloneBlocks ? cloneBlocks(sourceArea, world, diffToTarget) : 0; + int gluePastes = cloneGlue(sourceArea, world, diffToTarget); + + if (cloneBlocks) + source.sendFeedback(new StringTextComponent("Successfully cloned " + blockPastes + " Blocks"), true); + + source.sendFeedback(new StringTextComponent("Successfully applied glue " + gluePastes + " times"), true); + return blockPastes + gluePastes; + + } + + private static int cloneGlue(MutableBoundingBox sourceArea, ServerWorld world, BlockPos diffToTarget) { + int gluePastes = 0; + + List glue = world.getEntitiesWithinAABB(SuperGlueEntity.class, AxisAlignedBB.func_216363_a(sourceArea)); + List> newGlue = Lists.newArrayList(); + + for (SuperGlueEntity g : glue) { + BlockPos pos = g.getHangingPosition(); + Direction direction = g.getFacingDirection(); + newGlue.add(Pair.of(pos.add(diffToTarget), direction)); + } + + for (Pair p : newGlue) { + SuperGlueEntity g = new SuperGlueEntity(world, p.getFirst(), p.getSecond()); + if (g.onValidSurface()){ + world.addEntity(g); + gluePastes++; + } + } + return gluePastes; + } + + private static int cloneBlocks(MutableBoundingBox sourceArea, ServerWorld world, BlockPos diffToTarget) { + int blockPastes = 0; + + List blocks = Lists.newArrayList(); + List tileBlocks = Lists.newArrayList(); - //gather info for (int z = sourceArea.minZ; z <= sourceArea.maxZ; ++z) { for (int y = sourceArea.minY; y <= sourceArea.maxY; ++y) { for (int x = sourceArea.minX; x <= sourceArea.maxX; ++x) { @@ -88,16 +126,6 @@ public class CloneCommand { } } - List glue = world.getEntitiesWithinAABB(SuperGlueEntity.class, AxisAlignedBB.func_216363_a(sourceArea)); - List> newGlue = Lists.newArrayList(); - - for (SuperGlueEntity g : glue) { - BlockPos pos = g.getHangingPosition(); - Direction direction = g.getFacingDirection(); - newGlue.add(Pair.of(pos.add(diffToTarget), direction)); - } - - //paste List allBlocks = Lists.newArrayList(); allBlocks.addAll(blocks); allBlocks.addAll(tileBlocks); @@ -110,9 +138,6 @@ public class CloneCommand { world.setBlockState(info.pos, Blocks.BARRIER.getDefaultState(), 2); } - int blockPastes = 0; - int gluePastes = 0; - for (Template.BlockInfo info : allBlocks) { if (world.setBlockState(info.pos, info.state, 2)) blockPastes++; @@ -136,19 +161,10 @@ public class CloneCommand { world.notifyNeighbors(info.pos, info.state.getBlock()); } - for (Pair p : newGlue) { - SuperGlueEntity g = new SuperGlueEntity(world, p.getFirst(), p.getSecond()); - if (g.onValidSurface()){ - world.addEntity(g); - gluePastes++; - } - } world.getPendingBlockTicks().copyTicks(sourceArea, diffToTarget); - source.sendFeedback(new StringTextComponent("Successfully cloned " + blockPastes + " Blocks and applied Glue " + gluePastes + " times"), true); - return blockPastes + gluePastes; - + return blockPastes; } } diff --git a/src/main/java/com/simibubi/create/foundation/command/CouplingCommand.java b/src/main/java/com/simibubi/create/foundation/command/CouplingCommand.java index 8e4512956..62cb360f1 100644 --- a/src/main/java/com/simibubi/create/foundation/command/CouplingCommand.java +++ b/src/main/java/com/simibubi/create/foundation/command/CouplingCommand.java @@ -1,7 +1,9 @@ package com.simibubi.create.foundation.command; +import com.google.common.collect.Lists; import com.mojang.brigadier.Command; import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.simibubi.create.content.contraptions.components.structureMovement.train.CouplingHandler; import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController; @@ -16,12 +18,15 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.text.StringTextComponent; import net.minecraftforge.common.util.LazyOptional; +import java.util.ArrayList; +import java.util.Collection; import java.util.UUID; public class CouplingCommand { public static final SimpleCommandExceptionType ONLY_MINECARTS_ALLOWED = new SimpleCommandExceptionType(new StringTextComponent("Only Minecarts can be coupled")); public static final SimpleCommandExceptionType SAME_DIMENSION = new SimpleCommandExceptionType(new StringTextComponent("Minecarts have to be in the same Dimension")); + public static final DynamicCommandExceptionType TWO_CARTS = new DynamicCommandExceptionType(a -> new StringTextComponent("Your selector targeted " + a + " entities. You can only couple 2 Minecarts at a time.")); public static ArgumentBuilder register() { @@ -50,6 +55,31 @@ public class CouplingCommand { }) ) ) + .then(Commands.argument("carts", EntityArgument.entities()) + .executes(ctx -> { + Collection entities = EntityArgument.getEntities(ctx, "carts"); + if (entities.size() != 2) + throw TWO_CARTS.create(entities.size()); + + ArrayList eList = Lists.newArrayList(entities); + Entity cart1 = eList.get(0); + if (!(cart1 instanceof AbstractMinecartEntity)) + throw ONLY_MINECARTS_ALLOWED.create(); + + Entity cart2 = eList.get(1); + if (!(cart2 instanceof AbstractMinecartEntity)) + throw ONLY_MINECARTS_ALLOWED.create(); + + if (!cart1.getEntityWorld().equals(cart2.getEntityWorld())) + throw SAME_DIMENSION.create(); + + Entity source = ctx.getSource().getEntity(); + + CouplingHandler.tryToCoupleCarts(source instanceof PlayerEntity ? (PlayerEntity) source : null, cart1.getEntityWorld(), cart1.getEntityId(), cart2.getEntityId()); + + return Command.SINGLE_SUCCESS; + }) + ) ) .then(Commands.literal("remove") .then(Commands.argument("cart1", EntityArgument.entity())