mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 13:43:42 +01:00
small command adjustments
This commit is contained in:
parent
753d5d2fa9
commit
46bbdc70c9
2 changed files with 74 additions and 28 deletions
|
@ -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<Template.BlockInfo> blocks = Lists.newArrayList();
|
||||
List<Template.BlockInfo> 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<SuperGlueEntity> glue = world.getEntitiesWithinAABB(SuperGlueEntity.class, AxisAlignedBB.func_216363_a(sourceArea));
|
||||
List<Pair<BlockPos, Direction>> 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<BlockPos, Direction> 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<Template.BlockInfo> blocks = Lists.newArrayList();
|
||||
List<Template.BlockInfo> 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<SuperGlueEntity> glue = world.getEntitiesWithinAABB(SuperGlueEntity.class, AxisAlignedBB.func_216363_a(sourceArea));
|
||||
List<Pair<BlockPos, Direction>> 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<Template.BlockInfo> 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<BlockPos, Direction> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<CommandSource, ?> register() {
|
||||
|
||||
|
@ -50,6 +55,31 @@ public class CouplingCommand {
|
|||
})
|
||||
)
|
||||
)
|
||||
.then(Commands.argument("carts", EntityArgument.entities())
|
||||
.executes(ctx -> {
|
||||
Collection<? extends Entity> entities = EntityArgument.getEntities(ctx, "carts");
|
||||
if (entities.size() != 2)
|
||||
throw TWO_CARTS.create(entities.size());
|
||||
|
||||
ArrayList<? extends Entity> 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())
|
||||
|
|
Loading…
Reference in a new issue