Merge pull request #712 from IronException/master

dimensional coords extension
This commit is contained in:
Leijurv 2019-08-08 21:47:19 -10:00
commit 7b21b0401d
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A

View File

@ -44,11 +44,14 @@ import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.world.DimensionType;
import net.minecraft.world.chunk.Chunk;
import java.nio.file.Path;
import java.util.*;
import static org.apache.commons.lang3.StringUtils.isNumeric;
public class ExampleBaritoneControl implements Helper, AbstractGameEventListener {
private static final String COMMAND_PREFIX = "#";
@ -260,7 +263,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
try {
String[] coords = msg.substring("build".length()).trim().split(" ");
file = coords[0] + ".schematic";
origin = new BlockPos(parseOrDefault(coords[1], ctx.playerFeet().x), parseOrDefault(coords[2], ctx.playerFeet().y), parseOrDefault(coords[3], ctx.playerFeet().z));
origin = new BlockPos(parseOrDefault(coords[1], ctx.playerFeet().x, 1), parseOrDefault(coords[2], ctx.playerFeet().y, 1), parseOrDefault(coords[3], ctx.playerFeet().z, 1));
} catch (Exception ex) {
file = msg.substring(5).trim() + ".schematic";
origin = ctx.playerFeet();
@ -673,8 +676,8 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
return false;
}
private int parseOrDefault(String str, int i) {
return str.equals("~") ? i : str.startsWith("~") ? Integer.parseInt(str.substring(1)) + i : Integer.parseInt(str);
private int parseOrDefault(String str, int i, double dimensionFactor) {
return str.equals("~") ? i : str.startsWith("~") ? (int) (Integer.parseInt(str.substring(1)) * dimensionFactor) + i : (int) (Integer.parseInt(str) * dimensionFactor);
}
private void log(List<ItemStack> stacks) {
@ -689,18 +692,23 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
Goal goal;
try {
BetterBlockPos playerFeet = ctx.playerFeet();
switch (params.length) {
int length = params.length - 1; // length has to be smaller when a dimension parameter is added
if (params.length < 1 || (isNumeric(params[params.length - 1]) || params[params.length - 1].startsWith("~"))) {
length = params.length;
}
switch (length) {
case 0:
goal = new GoalBlock(playerFeet);
break;
case 1:
goal = new GoalYLevel(parseOrDefault(params[0], playerFeet.y));
goal = new GoalYLevel(parseOrDefault(params[0], playerFeet.y, 1));
break;
case 2:
goal = new GoalXZ(parseOrDefault(params[0], playerFeet.x), parseOrDefault(params[1], playerFeet.z));
goal = new GoalXZ(parseOrDefault(params[0], playerFeet.x, calculateDimensionFactor(params[params.length - 1])), parseOrDefault(params[1], playerFeet.z, calculateDimensionFactor(params[params.length - 1])));
break;
case 3:
goal = new GoalBlock(new BlockPos(parseOrDefault(params[0], playerFeet.x), parseOrDefault(params[1], playerFeet.y), parseOrDefault(params[2], playerFeet.z)));
goal = new GoalBlock(new BlockPos(parseOrDefault(params[0], playerFeet.x, calculateDimensionFactor(params[params.length - 1])), parseOrDefault(params[1], playerFeet.y, 1), parseOrDefault(params[2], playerFeet.z, calculateDimensionFactor(params[params.length - 1]))));
break;
default:
logDirect("unable to understand lol");
@ -712,4 +720,24 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
}
return goal;
}
private double calculateDimensionFactor(String to) {
return Math.pow(8, ctx.world().provider.getDimensionType().getId() - getDimensionByName(to.toLowerCase()).getId());
}
private DimensionType getDimensionByName(String name) {
if ("the_end".contains(name)) {
return DimensionType.THE_END;
}
if ("the_overworld".contains(name) || "surface".contains(name)) {
return DimensionType.OVERWORLD;
}
if ("the_nether".contains(name) || "hell".contains(name)) {
return DimensionType.NETHER;
}
return ctx.world().provider.getDimensionType();
}
}