Separate "launch" into another SourceSet

This commit is contained in:
Brady 2018-09-04 18:48:00 -05:00
parent a45f291d67
commit bba2458f8e
No known key found for this signature in database
GPG Key ID: 73A788379A197567
20 changed files with 578 additions and 534 deletions

View File

@ -46,6 +46,12 @@ compileJava {
sourceCompatibility = targetCompatibility = '1.8' sourceCompatibility = targetCompatibility = '1.8'
} }
sourceSets {
launch {
compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output
}
}
minecraft { minecraft {
version = '1.12.2' version = '1.12.2'
mappings = 'snapshot_20180731' mappings = 'snapshot_20180731'
@ -64,7 +70,7 @@ repositories {
} }
dependencies { dependencies {
runtime implementation('org.spongepowered:mixin:0.7.11-SNAPSHOT') { runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
// Mixin includes a lot of dependencies that are too up-to-date // Mixin includes a lot of dependencies that are too up-to-date
exclude module: 'launchwrapper' exclude module: 'launchwrapper'
exclude module: 'guava' exclude module: 'guava'
@ -79,3 +85,7 @@ mixin {
defaultObfuscationEnv notch defaultObfuscationEnv notch
add sourceSets.main, 'mixins.baritone.refmap.json' add sourceSets.main, 'mixins.baritone.refmap.json'
} }
jar {
from sourceSets.launch.output
}

View File

@ -1,71 +1,71 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.launch; package baritone.launch;
import net.minecraft.launchwrapper.ITweaker; import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.LaunchClassLoader; import net.minecraft.launchwrapper.LaunchClassLoader;
import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.launch.MixinBootstrap;
import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.Mixins; import org.spongepowered.asm.mixin.Mixins;
import org.spongepowered.tools.obfuscation.mcp.ObfuscationServiceMCP; import org.spongepowered.tools.obfuscation.mcp.ObfuscationServiceMCP;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* @author Brady * @author Brady
* @since 7/31/2018 9:59 PM * @since 7/31/2018 9:59 PM
*/ */
public class BaritoneTweaker implements ITweaker { public class BaritoneTweaker implements ITweaker {
List<String> args; List<String> args;
@Override @Override
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) { public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
this.args = new ArrayList<>(args); this.args = new ArrayList<>(args);
if (gameDir != null) addArg("gameDir", gameDir.getAbsolutePath()); if (gameDir != null) addArg("gameDir", gameDir.getAbsolutePath());
if (assetsDir != null) addArg("assetsDir", assetsDir.getAbsolutePath()); if (assetsDir != null) addArg("assetsDir", assetsDir.getAbsolutePath());
if (profile != null) addArg("version", profile); if (profile != null) addArg("version", profile);
} }
@Override @Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) { public void injectIntoClassLoader(LaunchClassLoader classLoader) {
MixinBootstrap.init(); MixinBootstrap.init();
MixinEnvironment.getDefaultEnvironment().setSide(MixinEnvironment.Side.CLIENT); MixinEnvironment.getDefaultEnvironment().setSide(MixinEnvironment.Side.CLIENT);
MixinEnvironment.getDefaultEnvironment().setObfuscationContext(ObfuscationServiceMCP.NOTCH); MixinEnvironment.getDefaultEnvironment().setObfuscationContext(ObfuscationServiceMCP.NOTCH);
Mixins.addConfiguration("mixins.baritone.json"); Mixins.addConfiguration("mixins.baritone.json");
} }
@Override @Override
public final String getLaunchTarget() { public final String getLaunchTarget() {
return "net.minecraft.client.main.Main"; return "net.minecraft.client.main.Main";
} }
@Override @Override
public final String[] getLaunchArguments() { public final String[] getLaunchArguments() {
return this.args.toArray(new String[0]); return this.args.toArray(new String[0]);
} }
private void addArg(String label, String value) { private void addArg(String label, String value) {
if (!args.contains("--" + label) && value != null) { if (!args.contains("--" + label) && value != null) {
this.args.add("--" + label); this.args.add("--" + label);
this.args.add(value); this.args.add(value);
} }
} }
} }

View File

@ -1,44 +1,44 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.launch; package baritone.launch;
import net.minecraft.launchwrapper.LaunchClassLoader; import net.minecraft.launchwrapper.LaunchClassLoader;
import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.tools.obfuscation.mcp.ObfuscationServiceMCP; import org.spongepowered.tools.obfuscation.mcp.ObfuscationServiceMCP;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* @author Brady * @author Brady
* @since 7/31/2018 10:09 PM * @since 7/31/2018 10:09 PM
*/ */
public class BaritoneTweakerForge extends BaritoneTweaker { public class BaritoneTweakerForge extends BaritoneTweaker {
@Override @Override
public final void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) { public final void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
this.args = new ArrayList<>(); this.args = new ArrayList<>();
} }
@Override @Override
public final void injectIntoClassLoader(LaunchClassLoader classLoader) { public final void injectIntoClassLoader(LaunchClassLoader classLoader) {
super.injectIntoClassLoader(classLoader); super.injectIntoClassLoader(classLoader);
MixinEnvironment.getDefaultEnvironment().setObfuscationContext(ObfuscationServiceMCP.SEARGE); MixinEnvironment.getDefaultEnvironment().setObfuscationContext(ObfuscationServiceMCP.SEARGE);
} }
} }

View File

@ -1,34 +1,34 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.launch; package baritone.launch;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* @author Brady * @author Brady
* @since 7/31/2018 10:10 PM * @since 7/31/2018 10:10 PM
*/ */
public class BaritoneTweakerOptifine extends BaritoneTweaker { public class BaritoneTweakerOptifine extends BaritoneTweaker {
@Override @Override
public final void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) { public final void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
this.args = new ArrayList<>(); this.args = new ArrayList<>();
} }
} }

View File

@ -15,6 +15,23 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.utils.accessor.IAnvilChunkLoader; import baritone.utils.accessor.IAnvilChunkLoader;

View File

@ -15,6 +15,23 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.utils.accessor.IChunkProviderServer; import baritone.utils.accessor.IChunkProviderServer;

View File

@ -1,44 +1,44 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.Baritone; import baritone.Baritone;
import net.minecraft.client.settings.GameSettings; import net.minecraft.client.settings.GameSettings;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
/** /**
* @author Brady * @author Brady
* @since 8/1/2018 12:28 AM * @since 8/1/2018 12:28 AM
*/ */
@Mixin(GameSettings.class) @Mixin(GameSettings.class)
public class MixinGameSettings { public class MixinGameSettings {
@Redirect( @Redirect(
method = "isKeyDown", method = "isKeyDown",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z", target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z",
remap = false remap = false
) )
) )
private static boolean isKeyDown(int keyCode) { private static boolean isKeyDown(int keyCode) {
return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode); return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode);
} }
} }

View File

@ -1,47 +1,47 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.Baritone; import baritone.Baritone;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiContainer;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
/** /**
* @author Brady * @author Brady
* @since 7/31/2018 10:47 PM * @since 7/31/2018 10:47 PM
*/ */
@Mixin(GuiContainer.class) @Mixin(GuiContainer.class)
public class MixinGuiContainer { public class MixinGuiContainer {
@Redirect( @Redirect(
method = { method = {
"mouseClicked", "mouseClicked",
"mouseReleased" "mouseReleased"
}, },
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z", target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z",
remap = false remap = false
) )
) )
private boolean isKeyDown(int keyCode) { private boolean isKeyDown(int keyCode) {
return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode); return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode);
} }
} }

View File

@ -1,48 +1,48 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.Baritone; import baritone.Baritone;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
/** /**
* @author Brady * @author Brady
* @since 7/31/2018 10:38 PM * @since 7/31/2018 10:38 PM
*/ */
@Mixin(GuiScreen.class) @Mixin(GuiScreen.class)
public class MixinGuiScreen { public class MixinGuiScreen {
@Redirect( @Redirect(
method = { method = {
"isCtrlKeyDown", "isCtrlKeyDown",
"isShiftKeyDown", "isShiftKeyDown",
"isAltKeyDown" "isAltKeyDown"
}, },
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z", target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z",
remap = false remap = false
) )
) )
private static boolean isKeyDown(int keyCode) { private static boolean isKeyDown(int keyCode) {
return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode); return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode);
} }
} }

View File

@ -1,43 +1,43 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.Baritone; import baritone.Baritone;
import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.settings.KeyBinding;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
/** /**
* @author Brady * @author Brady
* @since 7/31/2018 11:44 PM * @since 7/31/2018 11:44 PM
*/ */
@Mixin(KeyBinding.class) @Mixin(KeyBinding.class)
public class MixinKeyBinding { public class MixinKeyBinding {
@Inject( @Inject(
method = "isKeyDown", method = "isKeyDown",
at = @At("HEAD"), at = @At("HEAD"),
cancellable = true cancellable = true
) )
private void isKeyDown(CallbackInfoReturnable<Boolean> cir) { private void isKeyDown(CallbackInfoReturnable<Boolean> cir) {
if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this)) if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this))
cir.setReturnValue(true); cir.setReturnValue(true);
} }
} }

View File

@ -1,176 +1,176 @@
/* /*
* This file is part of Baritone. * This file is part of Baritone.
* *
* Baritone is free software: you can redistribute it and/or modify * Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Baritone is distributed in the hope that it will be useful, * Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.event.events.BlockInteractEvent; import baritone.api.event.events.BlockInteractEvent;
import baritone.api.event.events.TickEvent; import baritone.api.event.events.TickEvent;
import baritone.api.event.events.WorldEvent; import baritone.api.event.events.WorldEvent;
import baritone.api.event.events.type.EventState; import baritone.api.event.events.type.EventState;
import baritone.behavior.impl.PathingBehavior; import baritone.behavior.impl.PathingBehavior;
import baritone.utils.ExampleBaritoneControl; import baritone.utils.ExampleBaritoneControl;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.lib.Opcodes; import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
/** /**
* @author Brady * @author Brady
* @since 7/31/2018 10:51 PM * @since 7/31/2018 10:51 PM
*/ */
@Mixin(Minecraft.class) @Mixin(Minecraft.class)
public class MixinMinecraft { public class MixinMinecraft {
@Shadow @Shadow
private int leftClickCounter; private int leftClickCounter;
@Shadow @Shadow
public EntityPlayerSP player; public EntityPlayerSP player;
@Shadow @Shadow
public WorldClient world; public WorldClient world;
@Inject( @Inject(
method = "init", method = "init",
at = @At("RETURN") at = @At("RETURN")
) )
private void init(CallbackInfo ci) { private void init(CallbackInfo ci) {
Baritone.INSTANCE.init(); Baritone.INSTANCE.init();
ExampleBaritoneControl.INSTANCE.initAndRegister(); ExampleBaritoneControl.INSTANCE.initAndRegister();
} }
@Inject( @Inject(
method = "runTick", method = "runTick",
at = @At( at = @At(
value = "FIELD", value = "FIELD",
opcode = Opcodes.GETFIELD, opcode = Opcodes.GETFIELD,
target = "net/minecraft/client/Minecraft.currentScreen:Lnet/minecraft/client/gui/GuiScreen;", target = "net/minecraft/client/Minecraft.currentScreen:Lnet/minecraft/client/gui/GuiScreen;",
ordinal = 5, ordinal = 5,
shift = At.Shift.BY, shift = At.Shift.BY,
by = -3 by = -3
) )
) )
private void runTick(CallbackInfo ci) { private void runTick(CallbackInfo ci) {
Minecraft mc = (Minecraft) (Object) this; Minecraft mc = (Minecraft) (Object) this;
Baritone.INSTANCE.getGameEventHandler().onTick(new TickEvent( Baritone.INSTANCE.getGameEventHandler().onTick(new TickEvent(
EventState.PRE, EventState.PRE,
(mc.player != null && mc.world != null) (mc.player != null && mc.world != null)
? TickEvent.Type.IN ? TickEvent.Type.IN
: TickEvent.Type.OUT : TickEvent.Type.OUT
)); ));
} }
@Redirect( @Redirect(
method = "runTickKeyboard", method = "runTickKeyboard",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z", target = "org/lwjgl/input/Keyboard.isKeyDown(I)Z",
remap = false remap = false
) )
) )
private boolean Keyboard$isKeyDown(int keyCode) { private boolean Keyboard$isKeyDown(int keyCode) {
return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode); return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode);
} }
@Inject( @Inject(
method = "processKeyBinds", method = "processKeyBinds",
at = @At("HEAD") at = @At("HEAD")
) )
private void runTickKeyboard(CallbackInfo ci) { private void runTickKeyboard(CallbackInfo ci) {
Baritone.INSTANCE.getGameEventHandler().onProcessKeyBinds(); Baritone.INSTANCE.getGameEventHandler().onProcessKeyBinds();
} }
@Inject( @Inject(
method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V",
at = @At("HEAD") at = @At("HEAD")
) )
private void preLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) { private void preLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) {
// If we're unloading the world but one doesn't exist, ignore it // If we're unloading the world but one doesn't exist, ignore it
if (this.world == null && world == null) { if (this.world == null && world == null) {
return; return;
} }
Baritone.INSTANCE.getGameEventHandler().onWorldEvent( Baritone.INSTANCE.getGameEventHandler().onWorldEvent(
new WorldEvent( new WorldEvent(
world, world,
EventState.PRE EventState.PRE
) )
); );
} }
@Inject( @Inject(
method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V",
at = @At("RETURN") at = @At("RETURN")
) )
private void postLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) { private void postLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) {
// still fire event for both null, as that means we've just finished exiting a world // still fire event for both null, as that means we've just finished exiting a world
Baritone.INSTANCE.getGameEventHandler().onWorldEvent( Baritone.INSTANCE.getGameEventHandler().onWorldEvent(
new WorldEvent( new WorldEvent(
world, world,
EventState.POST EventState.POST
) )
); );
} }
@Redirect( @Redirect(
method = "runTick", method = "runTick",
at = @At( at = @At(
value = "FIELD", value = "FIELD",
opcode = Opcodes.GETFIELD, opcode = Opcodes.GETFIELD,
target = "net/minecraft/client/gui/GuiScreen.allowUserInput:Z" target = "net/minecraft/client/gui/GuiScreen.allowUserInput:Z"
) )
) )
private boolean isAllowUserInput(GuiScreen screen) { private boolean isAllowUserInput(GuiScreen screen) {
return (PathingBehavior.INSTANCE.getCurrent() != null && player != null) || screen.allowUserInput; return (PathingBehavior.INSTANCE.getCurrent() != null && player != null) || screen.allowUserInput;
} }
@Inject( @Inject(
method = "clickMouse", method = "clickMouse",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "net/minecraft/client/multiplayer/PlayerControllerMP.clickBlock(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;)Z" target = "net/minecraft/client/multiplayer/PlayerControllerMP.clickBlock(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;)Z"
), ),
locals = LocalCapture.CAPTURE_FAILHARD locals = LocalCapture.CAPTURE_FAILHARD
) )
private void onBlockBreak(CallbackInfo ci, BlockPos pos) { private void onBlockBreak(CallbackInfo ci, BlockPos pos) {
Baritone.INSTANCE.getGameEventHandler().onBlockInteract(new BlockInteractEvent(pos, BlockInteractEvent.Type.BREAK)); Baritone.INSTANCE.getGameEventHandler().onBlockInteract(new BlockInteractEvent(pos, BlockInteractEvent.Type.BREAK));
} }
@Inject( @Inject(
method = "rightClickMouse", method = "rightClickMouse",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "net/minecraft/client/entity/EntityPlayerSP.swingArm(Lnet/minecraft/util/EnumHand;)V" target = "net/minecraft/client/entity/EntityPlayerSP.swingArm(Lnet/minecraft/util/EnumHand;)V"
), ),
locals = LocalCapture.CAPTURE_FAILHARD locals = LocalCapture.CAPTURE_FAILHARD
) )
private void onBlockUse(CallbackInfo ci, EnumHand var1[], int var2, int var3, EnumHand enumhand, ItemStack itemstack, BlockPos blockpos, int i, EnumActionResult enumactionresult) { private void onBlockUse(CallbackInfo ci, EnumHand var1[], int var2, int var3, EnumHand enumhand, ItemStack itemstack, BlockPos blockpos, int i, EnumActionResult enumactionresult) {
Baritone.INSTANCE.getGameEventHandler().onBlockInteract(new BlockInteractEvent(blockpos, BlockInteractEvent.Type.USE)); Baritone.INSTANCE.getGameEventHandler().onBlockInteract(new BlockInteractEvent(blockpos, BlockInteractEvent.Type.USE));
} }
} }

View File

@ -1,27 +1,27 @@
{ {
"required": true, "required": true,
"package": "baritone.launch.mixins", "package": "baritone.launch.mixins",
"refmap": "mixins.baritone.refmap.json", "refmap": "mixins.baritone.refmap.json",
"compatibilityLevel": "JAVA_8", "compatibilityLevel": "JAVA_8",
"verbose": false, "verbose": false,
"injectors": { "injectors": {
"maxShiftBy": 2 "maxShiftBy": 2
}, },
"client": [ "client": [
"MixinAnvilChunkLoader", "MixinAnvilChunkLoader",
"MixinBlockPos", "MixinBlockPos",
"MixinChunkProviderServer", "MixinChunkProviderServer",
"MixinEntity", "MixinEntity",
"MixinEntityPlayerSP", "MixinEntityPlayerSP",
"MixinEntityRenderer", "MixinEntityRenderer",
"MixinGameSettings", "MixinGameSettings",
"MixinGuiContainer", "MixinGuiContainer",
"MixinGuiScreen", "MixinGuiScreen",
"MixinInventoryPlayer", "MixinInventoryPlayer",
"MixinKeyBinding", "MixinKeyBinding",
"MixinMinecraft", "MixinMinecraft",
"MixinNetHandlerPlayClient", "MixinNetHandlerPlayClient",
"MixinNetworkManager", "MixinNetworkManager",
"MixinWorldClient" "MixinWorldClient"
] ]
} }