From d505ec4f9f031a982d2c93ef40d675e396be75d9 Mon Sep 17 00:00:00 2001 From: Babbaj Date: Sun, 21 Jul 2019 20:54:02 -0400 Subject: [PATCH] build the schematic schematica has open --- build.gradle | 8 +++ scripts/proguard.pro | 5 ++ .../baritone/api/process/IBuilderProcess.java | 2 + .../api/utils/ExampleBaritoneControl.java | 4 ++ .../java/baritone/process/BuilderProcess.java | 15 ++++++ .../schematica/SchematicAdapter.java | 54 +++++++++++++++++++ .../schematica/SchematicaHelper.java | 50 +++++++++++++++++ .../lunatrius/core/util/math/MBlockPos.java | 30 +++++++++++ .../lunatrius/schematica/Schematica.java | 24 +++++++++ .../lunatrius/schematica/api/ISchematic.java | 31 +++++++++++ .../client/world/SchematicWorld.java | 32 +++++++++++ .../schematica/proxy/ClientProxy.java | 29 ++++++++++ .../schematica/proxy/CommonProxy.java | 20 +++++++ 13 files changed, 304 insertions(+) create mode 100644 src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java create mode 100644 src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java create mode 100644 src/schematica_api/java/com/github/lunatrius/core/util/math/MBlockPos.java create mode 100644 src/schematica_api/java/com/github/lunatrius/schematica/Schematica.java create mode 100644 src/schematica_api/java/com/github/lunatrius/schematica/api/ISchematic.java create mode 100644 src/schematica_api/java/com/github/lunatrius/schematica/client/world/SchematicWorld.java create mode 100644 src/schematica_api/java/com/github/lunatrius/schematica/proxy/ClientProxy.java create mode 100644 src/schematica_api/java/com/github/lunatrius/schematica/proxy/CommonProxy.java diff --git a/build.gradle b/build.gradle index 00e35617..1264f0fe 100755 --- a/build.gradle +++ b/build.gradle @@ -55,6 +55,14 @@ sourceSets { launch { compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output } + + schematica_api { + compileClasspath += main.compileClasspath + } + + main { + compileClasspath += schematica_api.output + } } minecraft { diff --git a/scripts/proguard.pro b/scripts/proguard.pro index bb8df2ae..2e10986d 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -31,6 +31,11 @@ # need to keep mixin names -keep class baritone.launch.** { *; } +#try to keep usage of schematica in separate classes +-keep class baritone.utils.schematic.schematica.* +#proguard doesnt like it when it cant find our fake schematica classes +-dontwarn baritone.utils.schematic.schematica.* + # copy all necessary libraries into tempLibraries to build # The correct jar will be copied from the forgegradle cache based on the mapping type being compiled with diff --git a/src/api/java/baritone/api/process/IBuilderProcess.java b/src/api/java/baritone/api/process/IBuilderProcess.java index d9397786..f73f0e74 100644 --- a/src/api/java/baritone/api/process/IBuilderProcess.java +++ b/src/api/java/baritone/api/process/IBuilderProcess.java @@ -54,6 +54,8 @@ public interface IBuilderProcess extends IBaritoneProcess { return build(schematicFile, file, origin); } + void buildOpenSchematic(); + void pause(); void resume(); diff --git a/src/api/java/baritone/api/utils/ExampleBaritoneControl.java b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java index 96d6ad2f..46300150 100644 --- a/src/api/java/baritone/api/utils/ExampleBaritoneControl.java +++ b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java @@ -295,6 +295,10 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener logDirect(success ? "Loaded" : "Unable to load"); return true; } + if (msg.startsWith("schematica")) { + baritone.getBuilderProcess().buildOpenSchematic(); + return true; + } if (msg.equals("come")) { customGoalProcess.setGoalAndPath(new GoalBlock(new BlockPos(Helper.mc.getRenderViewEntity()))); logDirect("Coming"); diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 52f21b76..5317c39a 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -35,6 +35,7 @@ import baritone.utils.BlockStateInterface; import baritone.utils.PathingCommandContext; import baritone.utils.schematic.AirSchematic; import baritone.utils.schematic.Schematic; +import baritone.utils.schematic.schematica.SchematicaHelper; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import net.minecraft.block.BlockAir; import net.minecraft.block.BlockLiquid; @@ -106,6 +107,20 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil return true; } + @Override + public void buildOpenSchematic() { + if (SchematicaHelper.isSchematicaPresent()) { + Optional> schematic = SchematicaHelper.getOpenSchematic(); + if (schematic.isPresent()) { + this.build(schematic.get().getFirst().toString(), schematic.get().getFirst(), schematic.get().getSecond()); + } else { + logDirect("No schematic currently open"); + } + } else { + logDirect("Schematica is not present"); + } + } + public void clearArea(BlockPos corner1, BlockPos corner2) { BlockPos origin = new BlockPos(Math.min(corner1.getX(), corner2.getX()), Math.min(corner1.getY(), corner2.getY()), Math.min(corner1.getZ(), corner2.getZ())); int widthX = Math.abs(corner1.getX() - corner2.getX()) + 1; diff --git a/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java b/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java new file mode 100644 index 00000000..4e399348 --- /dev/null +++ b/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java @@ -0,0 +1,54 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils.schematic.schematica; + +import baritone.api.utils.ISchematic; + +import com.github.lunatrius.schematica.client.world.SchematicWorld; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; + +// TODO: this only works for the default rotation +public final class SchematicAdapter implements ISchematic { + private final SchematicWorld schematic; + + + public SchematicAdapter(SchematicWorld schematicWorld) { + this.schematic = schematicWorld; + } + + @Override + public IBlockState desiredState(int x, int y, int z) { + return schematic.getSchematic().getBlockState(new BlockPos(x, y, z)); + } + + @Override + public int widthX() { + return schematic.getSchematic().getWidth(); + } + + @Override + public int heightY() { + return schematic.getSchematic().getHeight(); + } + + @Override + public int lengthZ() { + return schematic.getSchematic().getLength(); + } +} diff --git a/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java b/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java new file mode 100644 index 00000000..bf5d4678 --- /dev/null +++ b/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java @@ -0,0 +1,50 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils.schematic.schematica; + +import baritone.api.utils.ISchematic; +import com.github.lunatrius.core.util.math.MBlockPos; +import com.github.lunatrius.schematica.Schematica; +import com.github.lunatrius.schematica.proxy.ClientProxy; +import net.minecraft.util.Tuple; +import net.minecraft.util.math.BlockPos; + +import java.util.Optional; + +public enum SchematicaHelper { + ; + + public static boolean isSchematicaPresent() { + try { + Class.forName(Schematica.class.getName()); + return true; + } catch (ClassNotFoundException ex) { + return false; + } + } + + public static Optional> getOpenSchematic() { + return Optional.ofNullable(ClientProxy.schematic) + .map(world -> { + MBlockPos poz = world.position; + return new Tuple<>(new SchematicAdapter(world), new BlockPos(poz.field_177962_a, poz.field_177960_b, poz.field_177961_c)); + }); + } + + private static void meme(Class clazz) throws ClassNotFoundException {} +} diff --git a/src/schematica_api/java/com/github/lunatrius/core/util/math/MBlockPos.java b/src/schematica_api/java/com/github/lunatrius/core/util/math/MBlockPos.java new file mode 100644 index 00000000..60cf6fae --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/core/util/math/MBlockPos.java @@ -0,0 +1,30 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package com.github.lunatrius.core.util.math; + +import net.minecraft.util.math.BlockPos; + +public class MBlockPos extends BlockPos { + public int field_177962_a; // x + public int field_177960_b; // y + public int field_177961_c; // z + + private MBlockPos() { + super(6, 6, 6); + } +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/Schematica.java b/src/schematica_api/java/com/github/lunatrius/schematica/Schematica.java new file mode 100644 index 00000000..7d786dbd --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/Schematica.java @@ -0,0 +1,24 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package com.github.lunatrius.schematica; + +import com.github.lunatrius.schematica.proxy.CommonProxy; + +public class Schematica { + public static CommonProxy proxy; +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/api/ISchematic.java b/src/schematica_api/java/com/github/lunatrius/schematica/api/ISchematic.java new file mode 100644 index 00000000..6430dbfc --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/api/ISchematic.java @@ -0,0 +1,31 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package com.github.lunatrius.schematica.api; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; + +public interface ISchematic { + IBlockState getBlockState(BlockPos var1); + + int getWidth(); + + int getHeight(); + + int getLength(); +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/client/world/SchematicWorld.java b/src/schematica_api/java/com/github/lunatrius/schematica/client/world/SchematicWorld.java new file mode 100644 index 00000000..fc4b89f9 --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/client/world/SchematicWorld.java @@ -0,0 +1,32 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package com.github.lunatrius.schematica.client.world; + +import com.github.lunatrius.core.util.math.MBlockPos; +import com.github.lunatrius.schematica.api.ISchematic; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; + +public class SchematicWorld { + private ISchematic schematic; + public final MBlockPos position = (MBlockPos)(Object)"cringe"; + + public ISchematic getSchematic() { + throw new LinkageError("LOL"); + } +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/proxy/ClientProxy.java b/src/schematica_api/java/com/github/lunatrius/schematica/proxy/ClientProxy.java new file mode 100644 index 00000000..e58e76b5 --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/proxy/ClientProxy.java @@ -0,0 +1,29 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package com.github.lunatrius.schematica.proxy; + +import com.github.lunatrius.schematica.client.world.SchematicWorld; +import net.minecraft.util.EnumFacing; + +public class ClientProxy extends CommonProxy { + public static SchematicWorld schematic; + + public static EnumFacing orientation; + public static EnumFacing axisFlip; + public static EnumFacing axisRotation; +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/proxy/CommonProxy.java b/src/schematica_api/java/com/github/lunatrius/schematica/proxy/CommonProxy.java new file mode 100644 index 00000000..eb3c034e --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/proxy/CommonProxy.java @@ -0,0 +1,20 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package com.github.lunatrius.schematica.proxy; + +public abstract class CommonProxy {}