Added Notebot, Updated AutoWither, Added PlayCommand
This commit is contained in:
parent
494a616f35
commit
ca9de92aa5
|
@ -0,0 +1,56 @@
|
|||
package me.rigamortis.seppuku.api.module.notebot;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
* @author noil
|
||||
*/
|
||||
public class Note {
|
||||
|
||||
private int index;
|
||||
|
||||
private BlockPos position;
|
||||
|
||||
private int instrument;
|
||||
|
||||
private int pitch;
|
||||
|
||||
public Note(int index, BlockPos position, int instrument, int pitch) {
|
||||
this.index = index;
|
||||
this.position = position;
|
||||
this.instrument = instrument;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public void setPosition(BlockPos position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void setInstrument(int instrument) {
|
||||
this.instrument = instrument;
|
||||
}
|
||||
|
||||
public void setPitch(int pitch) {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
public BlockPos getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public int getInstrument() {
|
||||
return this.instrument;
|
||||
}
|
||||
|
||||
public int getPitch() {
|
||||
return this.pitch;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package me.rigamortis.seppuku.api.module.notebot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author noil
|
||||
*/
|
||||
public class NotePlayer {
|
||||
|
||||
private final List<Integer> notesToPlay = new ArrayList<>();
|
||||
|
||||
public void play(int index) {
|
||||
this.notesToPlay.add(index);
|
||||
}
|
||||
|
||||
public void rest(int index) {
|
||||
for (int i = 0; i < index; i++)
|
||||
this.notesToPlay.add(-1);
|
||||
}
|
||||
|
||||
public void chord(int index) {
|
||||
switch (index) {
|
||||
case 1:
|
||||
play(1);
|
||||
play(5);
|
||||
play(8);
|
||||
break;
|
||||
case 2:
|
||||
play(2);
|
||||
play(6);
|
||||
play(9);
|
||||
break;
|
||||
case 3:
|
||||
play(3);
|
||||
play(6);
|
||||
play(10);
|
||||
break;
|
||||
case 4:
|
||||
play(4);
|
||||
play(6);
|
||||
play(10);
|
||||
break;
|
||||
case 5:
|
||||
play(5);
|
||||
play(7);
|
||||
play(12);
|
||||
break;
|
||||
case 6:
|
||||
play(6);
|
||||
play(10);
|
||||
play(13);
|
||||
break;
|
||||
case 7:
|
||||
play(7);
|
||||
play(10);
|
||||
play(14);
|
||||
break;
|
||||
case 8:
|
||||
play(8);
|
||||
play(12);
|
||||
play(15);
|
||||
break;
|
||||
case 9:
|
||||
play(9);
|
||||
play(13);
|
||||
play(16);
|
||||
break;
|
||||
case 10:
|
||||
play(10);
|
||||
play(13);
|
||||
play(17);
|
||||
break;
|
||||
case 11:
|
||||
play(11);
|
||||
play(15);
|
||||
play(18);
|
||||
break;
|
||||
case 12:
|
||||
play(12);
|
||||
play(16);
|
||||
play(19);
|
||||
break;
|
||||
case 13:
|
||||
play(13);
|
||||
play(17);
|
||||
play(20);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Integer> getNotesToPlay() {
|
||||
return this.notesToPlay;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package me.rigamortis.seppuku.api.util;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -42,4 +43,12 @@ public class BlockUtil {
|
|||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static boolean rayTrace(Vec3d to) {
|
||||
return (mc.world.rayTraceBlocks(new Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight(), mc.player.posZ), to, false, true, false) == null);
|
||||
}
|
||||
|
||||
public static boolean rayTrace(BlockPos to) {
|
||||
return (mc.world.rayTraceBlocks(new Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight(), mc.player.posZ), new Vec3d(to.getX(), to.getY(), to.getZ()), false, true, false) == null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package me.rigamortis.seppuku.api.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author noil
|
||||
*/
|
||||
public class RegexUtil {
|
||||
|
||||
// thanks @wine for the regex pattern
|
||||
public static final Pattern BY_CAPITAL = Pattern.compile("(?=\\p{Lu})");
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package me.rigamortis.seppuku.impl.command;
|
||||
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import me.rigamortis.seppuku.Seppuku;
|
||||
import me.rigamortis.seppuku.api.command.Command;
|
||||
import me.rigamortis.seppuku.impl.module.world.NotebotModule;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
/**
|
||||
* @author noil
|
||||
*/
|
||||
public final class PlayCommand extends Command {
|
||||
|
||||
private final ScriptEngineManager scriptFactory = new ScriptEngineManager();
|
||||
private final ScriptEngine scriptEngine = this.scriptFactory.getEngineByName("JavaScript");
|
||||
|
||||
private File directory = null;
|
||||
|
||||
public PlayCommand() {
|
||||
super("Play", new String[]{"playsong", "begin"}, "Plays a song file from your /Seppuku/Songs/ directory.", ".play <song file name>");
|
||||
|
||||
this.directory = new File(Seppuku.INSTANCE.getConfigManager().getConfigDir(), "Songs");
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec(String input) {
|
||||
if (!this.clamp(input, 2, 2)) {
|
||||
this.printUsage();
|
||||
return;
|
||||
}
|
||||
|
||||
final String[] split = input.split(" ");
|
||||
|
||||
final NotebotModule notebotModule = (NotebotModule) Seppuku.INSTANCE.getModuleManager().find(NotebotModule.class);
|
||||
if (notebotModule != null) {
|
||||
try {
|
||||
File file = new File(directory, split[1] + ".js");
|
||||
if (file.exists()) {
|
||||
this.scriptEngine.getBindings(100).put("bot", notebotModule.getNotePlayer());
|
||||
notebotModule.getNotePlayer().getNotesToPlay().clear();
|
||||
notebotModule.setCurrentNote(0);
|
||||
notebotModule.getState().setEnumValue("PLAYING");
|
||||
this.scriptEngine.eval(new FileReader(file.getAbsolutePath()));
|
||||
Seppuku.INSTANCE.logChat("Playing '" + ChatFormatting.YELLOW + file.getName().replaceAll(".js", "") + ChatFormatting.GRAY + "'");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -71,6 +71,7 @@ public final class CommandManager {
|
|||
this.commandList.add(new CalcStrongholdCommand());
|
||||
this.commandList.add(new LastInvCommand());
|
||||
this.commandList.add(new SearchCommand());
|
||||
this.commandList.add(new PlayCommand());
|
||||
|
||||
//create commands for every value within every module
|
||||
loadValueCommands();
|
||||
|
@ -78,7 +79,7 @@ public final class CommandManager {
|
|||
//load our external commands
|
||||
loadExternalCommands();
|
||||
|
||||
Collections.sort(commandList, Comparator.comparing(Command::getDisplayName));
|
||||
commandList.sort(Comparator.comparing(Command::getDisplayName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -166,6 +166,7 @@ public final class ModuleManager {
|
|||
add(new DonkeyAlertModule());
|
||||
add(new ReachModule());
|
||||
add(new AutoWitherModule());
|
||||
add(new NotebotModule());
|
||||
|
||||
// p2w experience
|
||||
if (Seppuku.INSTANCE.getCapeManager().hasCape())
|
||||
|
@ -173,7 +174,7 @@ public final class ModuleManager {
|
|||
|
||||
this.loadExternalModules();
|
||||
|
||||
Collections.sort(moduleList, Comparator.comparing(Module::getDisplayName));
|
||||
moduleList.sort(Comparator.comparing(Module::getDisplayName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -200,13 +201,11 @@ public final class ModuleManager {
|
|||
//create a new instance of the class
|
||||
final Module module = (Module) clazz.newInstance();
|
||||
|
||||
if (module != null) {
|
||||
//add the class to our list of modules
|
||||
add(module);
|
||||
//add the class to our list of modules
|
||||
add(module);
|
||||
|
||||
Seppuku.INSTANCE.getEventManager().dispatchEvent(new EventModuleLoad(module));
|
||||
Seppuku.INSTANCE.getLogger().log(Level.INFO, "Found external module " + module.getDisplayName());
|
||||
}
|
||||
Seppuku.INSTANCE.getEventManager().dispatchEvent(new EventModuleLoad(module));
|
||||
Seppuku.INSTANCE.getLogger().log(Level.INFO, "Found external module " + module.getDisplayName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ public final class NoCrystalModule extends Module {
|
|||
public final Value<Boolean> extended = new Value<Boolean>("Extended", new String[]{"extend", "e", "big"}, "Enlarges the size of the fortress.", false);
|
||||
public final Value<Boolean> disable = new Value<Boolean>("Disable", new String[]{"dis", "autodisable", "autodis", "d"}, "Automatically disable after obsidian is placed.", false);
|
||||
public final Value<Boolean> sneak = new Value<Boolean>("PlaceOnSneak", new String[]{"sneak", "s", "pos", "sneakPlace"}, "When true, NoCrystal will only place while the player is sneaking.", false);
|
||||
public final Value<Float> range = new Value<Float>("Range", new String[]{"MaxRange", "MaximumRange"}, "The maximum block reaching range to continue building in.", 6.0f, 1.0f, 10.0f, 0.5f);
|
||||
public final Value<Float> placeDelay = new Value<Float>("Delay", new String[]{"PlaceDelay", "PlaceDel"}, "The delay(ms) between obsidian blocks being placed.", 100.0f, 0.0f, 500.0f, 1.0f);
|
||||
|
||||
private final Timer placeTimer = new Timer();
|
||||
|
@ -198,7 +199,7 @@ public final class NoCrystalModule extends Module {
|
|||
return false;
|
||||
|
||||
// Player is too far from distance
|
||||
if (mc.player.getDistance(pos.getX(), pos.getY(), pos.getZ()) > 6.0f)
|
||||
if (mc.player.getDistance(pos.getX(), pos.getY(), pos.getZ()) > this.range.getValue())
|
||||
return false;
|
||||
|
||||
// Check if the block is replaceable
|
||||
|
|
|
@ -97,7 +97,7 @@ public final class ElytraFlyModule extends Module {
|
|||
if (this.stayAirborneDisable.getValue() && this.stayAirborne.getValue()) {
|
||||
if (mc.player.onGround) {
|
||||
this.stayAirborne.setValue(false);
|
||||
Seppuku.INSTANCE.logChat("\247rToggled \2477ElytraFly " + this.stayAirborne.getName() + "\247r off as you've touched the ground.");
|
||||
Seppuku.INSTANCE.logChat("\247rToggled\2477 ElytraFly " + this.stayAirborne.getName() + " \247coff\247r, as you've touched the ground.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
|
|||
public final class BrightnessModule extends Module {
|
||||
|
||||
public final Value<Mode> mode = new Value<Mode>("Mode", new String[]{"Mode", "M"}, "The brightness mode to use.", Mode.GAMMA);
|
||||
public final Value<Boolean> disablePotion = new Value<Boolean>("DisablePotion", new String[]{"AutoDisablePotion", "dp", "adp"}, "Automatically remove the night vision effect if using a different mode.", false);
|
||||
|
||||
private enum Mode {
|
||||
GAMMA, POTION, TABLE
|
||||
|
@ -56,7 +57,7 @@ public final class BrightnessModule extends Module {
|
|||
|
||||
for (int i = 0; i <= 15; ++i) {
|
||||
float f1 = 1.0F - (float) i / 15.0F;
|
||||
Minecraft.getMinecraft().world.provider.getLightBrightnessTable()[i] = (1.0F - f1) / (f1 * 3.0F + 1.0F) * 1.0F + 0.0F;
|
||||
Minecraft.getMinecraft().world.provider.getLightBrightnessTable()[i] = (1.0F - f1) / (f1 * 3.0F + 1.0F) + 0.0F;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +71,9 @@ public final class BrightnessModule extends Module {
|
|||
@Listener
|
||||
public void onUpdate(EventPlayerUpdate event) {
|
||||
if (event.getStage() == EventStageable.EventStage.PRE) {
|
||||
if (!this.mode.getValue().equals(Mode.POTION) && this.disablePotion.getValue())
|
||||
Minecraft.getMinecraft().player.removePotionEffect(MobEffects.NIGHT_VISION);
|
||||
|
||||
switch (this.mode.getValue()) {
|
||||
case GAMMA:
|
||||
Minecraft.getMinecraft().gameSettings.gammaSetting = 1000;
|
||||
|
|
|
@ -45,10 +45,14 @@ public final class AutoWitherModule extends Module {
|
|||
|
||||
public final Value<Boolean> rotate = new Value<Boolean>("Rotate", new String[]{"rotation", "r", "rotate"}, "Rotate to place blocks.", true);
|
||||
public final Value<Boolean> disable = new Value<Boolean>("Disable", new String[]{"dis", "autodisable", "autodis", "d"}, "Automatically disable after wither is placed.", false);
|
||||
public final Value<Boolean> sneak = new Value<Boolean>("PlaceOnSneak", new String[]{"sneak", "s", "pos", "sneakPlace"}, "When true, AutoWitherModule will only place while the player is sneaking.", false);
|
||||
public final Value<Boolean> sneak = new Value<Boolean>("PlaceOnSneak", new String[]{"sneak", "s", "pos", "sneakPlace"}, "When true, AutoWither will only place while the player is sneaking.", false);
|
||||
public final Value<Boolean> noSkulls = new Value<Boolean>("NoSkulls", new String[]{"skulls", "ns", "noheads", "nowitherskulls", "noskull", "nowitherskull"}, "When true, AutoWither will only place the soul sand.", false);
|
||||
public final Value<Float> range = new Value<Float>("Range", new String[]{"MaxRange", "MaximumRange"}, "The maximum block reaching range to continue building in.", 6.0f, 1.0f, 10.0f, 0.5f);
|
||||
public final Value<Float> placeDelay = new Value<Float>("Delay", new String[]{"PlaceDelay", "PlaceDel"}, "The delay(ms) between blocks being placed.", 100.0f, 0.0f, 500.0f, 1.0f);
|
||||
public final Value<Float> waitDelay = new Value<Float>("WaitDelay", new String[]{"RightClickDelay", "wd"}, "The delay(ms) between withers being created on right click.", 750.0f, 0.0f, 1000.0f, 1.0f);
|
||||
|
||||
private final Timer placeTimer = new Timer();
|
||||
private final Timer waitTimer = new Timer();
|
||||
private final RotationTask rotationTask = new RotationTask("AutoWitherTask", 2);
|
||||
|
||||
private FreeCamModule freeCamModule = null;
|
||||
|
@ -75,7 +79,14 @@ public final class AutoWitherModule extends Module {
|
|||
if (this.rotationTask.isOnline())
|
||||
Seppuku.INSTANCE.getRotationManager().finishTask(this.rotationTask);
|
||||
|
||||
this.beginBuildingPos = event.getPos();
|
||||
if (this.waitDelay.getValue() <= 0) {
|
||||
this.beginBuildingPos = event.getPos();
|
||||
} else {
|
||||
if (this.waitTimer.passed(this.waitDelay.getValue())) {
|
||||
this.beginBuildingPos = event.getPos();
|
||||
this.waitTimer.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,12 +128,14 @@ public final class AutoWitherModule extends Module {
|
|||
}
|
||||
|
||||
// find missing skulls
|
||||
for (int j = 0; j < skullBlocks.length; j++) {
|
||||
BlockPos blockPos = skullBlocks[j];
|
||||
if (!this.valid(blockPos, true))
|
||||
continue;
|
||||
if (!this.noSkulls.getValue()) {
|
||||
for (int j = 0; j < skullBlocks.length; j++) {
|
||||
BlockPos blockPos = skullBlocks[j];
|
||||
if (!this.valid(blockPos, true))
|
||||
continue;
|
||||
|
||||
skullsToPlace.add(blockPos);
|
||||
skullsToPlace.add(blockPos);
|
||||
}
|
||||
}
|
||||
|
||||
if (soulSandToPlace.size() != 0) { // we have soul sand to place
|
||||
|
@ -276,7 +289,7 @@ public final class AutoWitherModule extends Module {
|
|||
return false;
|
||||
|
||||
// Player is too far from distance
|
||||
if (mc.player.getDistance(pos.getX(), pos.getY(), pos.getZ()) > 6.0f)
|
||||
if (mc.player.getDistance(pos.getX(), pos.getY(), pos.getZ()) > this.range.getValue())
|
||||
return false;
|
||||
|
||||
// Check if the block is replaceable
|
||||
|
@ -316,17 +329,6 @@ public final class AutoWitherModule extends Module {
|
|||
mc.player.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(sideOffset, otherSide, EnumHand.MAIN_HAND, 0.5F, 0.5F, 0.5F));
|
||||
mc.player.connection.sendPacket(new CPacketAnimation(EnumHand.MAIN_HAND));
|
||||
|
||||
//mc.playerController.processRightClickBlock(mc.player, mc.world, sideOffset, otherSide, new Vec3d(0.5F, 0.5F, 0.5F), EnumHand.MAIN_HAND);
|
||||
//mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||
|
||||
/*if (!visible.getValue()) {
|
||||
mc.player.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(sideOffset, otherSide, EnumHand.MAIN_HAND, 0.5F, 0.5F, 0.5F));
|
||||
mc.player.connection.sendPacket(new CPacketAnimation(EnumHand.MAIN_HAND));
|
||||
} else {
|
||||
mc.playerController.processRightClickBlock(mc.player, mc.world, sideOffset, otherSide, new Vec3d(0.5F, 0.5F, 0.5F), EnumHand.MAIN_HAND);
|
||||
mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||
}*/
|
||||
|
||||
if (activated)
|
||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,323 @@
|
|||
package me.rigamortis.seppuku.impl.module.world;
|
||||
|
||||
import me.rigamortis.seppuku.Seppuku;
|
||||
import me.rigamortis.seppuku.api.event.EventStageable;
|
||||
import me.rigamortis.seppuku.api.event.network.EventReceivePacket;
|
||||
import me.rigamortis.seppuku.api.event.player.EventUpdateWalkingPlayer;
|
||||
import me.rigamortis.seppuku.api.event.world.EventLoadWorld;
|
||||
import me.rigamortis.seppuku.api.module.Module;
|
||||
import me.rigamortis.seppuku.api.module.notebot.Note;
|
||||
import me.rigamortis.seppuku.api.module.notebot.NotePlayer;
|
||||
import me.rigamortis.seppuku.api.task.rotation.RotationTask;
|
||||
import me.rigamortis.seppuku.api.util.MathUtil;
|
||||
import me.rigamortis.seppuku.api.util.Timer;
|
||||
import me.rigamortis.seppuku.api.value.Value;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.play.client.CPacketPlayerDigging;
|
||||
import net.minecraft.network.play.server.SPacketBlockAction;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* @author noil
|
||||
*/
|
||||
public final class NotebotModule extends Module {
|
||||
|
||||
private final Value<BotState> state = new Value<BotState>("State", new String[]{"State", "s"}, "Current state of the note-bot.", BotState.IDLE);
|
||||
private final Value<Mode> mode = new Value<Mode>("Mode", new String[]{"mod", "m"}, "Current mode of the note-bot.", Mode.AUTOMATIC);
|
||||
private final Value<Boolean> rotate = new Value<Boolean>("Rotate", new String[]{"rot", "r"}, "Rotate the player's head & body for each note-bot function.", true);
|
||||
private final Value<Boolean> swing = new Value<Boolean>("Swing", new String[]{"swingarm", "armswing", "sa"}, "Swing the player's hand for each note-bot function.", true);
|
||||
private final Value<Float> clickDelay = new Value<Float>("ClickDelay", new String[]{"Click Delay", "click-delay", "delay", "del", "cd", "d"}, "Delay(ms) to wait between clicks.", 200.0f, 0.0f, 1000.0f, 1.0f);
|
||||
|
||||
private final RotationTask rotationTask = new RotationTask("NoteBot", 2);
|
||||
|
||||
private BlockPos currentBlock;
|
||||
private int currentNote;
|
||||
|
||||
private final int[] positionOffsets = new int[]{2, 1, 2};
|
||||
|
||||
private final NotePlayer notePlayer = new NotePlayer();
|
||||
private final Timer timer = new Timer();
|
||||
|
||||
private final List<BlockPos> blocks = new ArrayList<>();
|
||||
private final List<BlockPos> tunedBlocks = new ArrayList<>();
|
||||
private final Map<BlockPos, Note> discoveredBlocks = new HashMap<>();
|
||||
|
||||
private final int BLOCK_AREA = 25;
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
public NotebotModule() {
|
||||
super("Notebot", new String[]{"Notebot+", "MusicBot", "MusicPlayer", "MidiPlayer", "MidiBot"}, "Play .midi files on a 5x5 grid of note-blocks.", "NONE", -1, ModuleType.WORLD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
|
||||
if (mc.world == null)
|
||||
return;
|
||||
|
||||
IntStream.range(0, 25).forEach(note -> {
|
||||
int[] area = this.blockArea(note);
|
||||
this.blocks.add(new BlockPos(area[0], area[1], area[2]));
|
||||
});
|
||||
|
||||
if (this.mode.getValue().equals(Mode.AUTOMATIC)) {
|
||||
this.state.setEnumValue("DISCOVERING");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
super.onDisable();
|
||||
|
||||
if (mc.world == null)
|
||||
return;
|
||||
|
||||
this.clearData();
|
||||
Seppuku.INSTANCE.getRotationManager().finishTask(this.rotationTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMetaData() {
|
||||
return this.state.getValue().name();
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onLoadWorld(EventLoadWorld event) {
|
||||
if (event.getWorld() != null) {
|
||||
this.toggle(); // toggle off
|
||||
Seppuku.INSTANCE.logChat("\247rToggled\2477 " + this.getDisplayName() + " \247coff\247r, as you've loaded into a new world.");
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onReceivePacket(EventReceivePacket event) {
|
||||
if (event.getStage() != EventStageable.EventStage.POST)
|
||||
return;
|
||||
|
||||
if (!(event.getPacket() instanceof SPacketBlockAction))
|
||||
return;
|
||||
|
||||
SPacketBlockAction packetBlockAction = (SPacketBlockAction) event.getPacket();
|
||||
BlockPos position = packetBlockAction.getBlockPosition();
|
||||
this.blocks.stream().filter(blockPos -> this.correctPosition(position, this.blocks.indexOf(blockPos))).forEach(blockPos -> {
|
||||
final Note note = new Note(this.blocks.indexOf(blockPos), position, packetBlockAction.getData1(), packetBlockAction.getData2());
|
||||
if (!this.discoveredBlocks.containsKey(blockPos)) {
|
||||
this.discoveredBlocks.put(blockPos, note);
|
||||
} else {
|
||||
if (!this.tunedBlocks.contains(blockPos) && this.blocks.indexOf(blockPos) == packetBlockAction.getData2()) {
|
||||
this.tunedBlocks.add(blockPos);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onMotionUpdate(EventUpdateWalkingPlayer event) {
|
||||
if (mc.world == null || mc.player == null)
|
||||
return;
|
||||
|
||||
if (mc.player.capabilities.isCreativeMode) {
|
||||
if (this.rotationTask.isOnline())
|
||||
Seppuku.INSTANCE.getRotationManager().finishTask(this.rotationTask);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.getStage()) {
|
||||
case PRE:
|
||||
if (this.state.getValue() == BotState.PLAYING && this.notePlayer.getNotesToPlay().size() > 0) {
|
||||
int playingNote = this.notePlayer.getNotesToPlay().get(this.currentNote) % 24;
|
||||
if (playingNote != -1) {
|
||||
this.currentBlock = new BlockPos(this.getPosition(playingNote));
|
||||
this.lookAtPosition(this.currentBlock);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mode.getValue().equals(Mode.AUTOMATIC)) {
|
||||
if ((this.discoveredBlocks.size() == BLOCK_AREA && this.tunedBlocks.size() == BLOCK_AREA)) {
|
||||
this.state.setEnumValue("IDLE");
|
||||
}
|
||||
}
|
||||
|
||||
if (this.currentBlock == null) {
|
||||
this.blocks.stream().filter(blockPos -> (!this.discoveredBlocks.containsKey(blockPos) || !this.tunedBlocks.contains(blockPos))).forEach(blockPos -> {
|
||||
final BlockPos workPos = new BlockPos(this.getPosition(this.blocks.indexOf(blockPos)));
|
||||
|
||||
if (!this.discoveredBlocks.containsKey(blockPos)) {
|
||||
if (this.mode.getValue().equals(Mode.AUTOMATIC)) {
|
||||
this.state.setEnumValue("DISCOVERING");
|
||||
}
|
||||
this.currentBlock = new BlockPos(workPos);
|
||||
if (this.rotate.getValue()) {
|
||||
this.lookAtPosition(workPos);
|
||||
}
|
||||
} else if (this.discoveredBlocks.size() == BLOCK_AREA) {
|
||||
if (this.mode.getValue().equals(Mode.AUTOMATIC)) {
|
||||
this.state.setEnumValue("TUNING");
|
||||
}
|
||||
this.currentBlock = new BlockPos(workPos);
|
||||
if (this.rotate.getValue()) {
|
||||
this.lookAtPosition(workPos);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
case POST:
|
||||
if (this.rotationTask.isOnline() || !this.rotate.getValue()) {
|
||||
final EnumFacing direction = EnumFacing.UP;
|
||||
|
||||
switch (this.state.getValue()) {
|
||||
case IDLE:
|
||||
if (this.rotationTask.isOnline()) {
|
||||
Seppuku.INSTANCE.getRotationManager().finishTask(this.rotationTask);
|
||||
}
|
||||
return;
|
||||
case DISCOVERING:
|
||||
if (this.discoveredBlocks.size() != BLOCK_AREA) {
|
||||
mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, this.currentBlock, direction));
|
||||
if (this.swing.getValue()) {
|
||||
mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||
}
|
||||
mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, direction));
|
||||
this.currentBlock = null;
|
||||
}
|
||||
break;
|
||||
case TUNING:
|
||||
if (this.tunedBlocks.size() != BLOCK_AREA && !this.tunedBlocks.contains(this.currentBlock)) {
|
||||
if (this.timer.passed(this.clickDelay.getValue())) {
|
||||
mc.playerController.processRightClickBlock(mc.player, mc.world, this.currentBlock, direction, new Vec3d(0.5F, 0.5F, 0.5F), EnumHand.MAIN_HAND);
|
||||
if (this.swing.getValue()) {
|
||||
mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||
}
|
||||
this.currentBlock = null;
|
||||
this.timer.reset();
|
||||
}
|
||||
} else {
|
||||
this.currentBlock = null;
|
||||
}
|
||||
break;
|
||||
case PLAYING:
|
||||
if (this.currentNote >= this.notePlayer.getNotesToPlay().size()) {
|
||||
this.currentNote = 0;
|
||||
return;
|
||||
}
|
||||
this.currentNote++;
|
||||
if (this.currentNote != -1) {
|
||||
mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, this.currentBlock, direction));
|
||||
if (this.swing.getValue()) {
|
||||
mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||
}
|
||||
mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, direction));
|
||||
this.currentBlock = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private int[] blockArea(int index) {
|
||||
int[] positions = {(int) Math.floor(mc.player.posX) - this.positionOffsets[0], (int) Math.floor(mc.player.posY) - this.positionOffsets[1], (int) Math.floor(mc.player.posZ) - this.positionOffsets[2]};
|
||||
return new int[]{positions[0] + index % 5, positions[1], positions[2] + index / 5};
|
||||
}
|
||||
|
||||
private void lookAtPosition(BlockPos position) {
|
||||
Seppuku.INSTANCE.getRotationManager().startTask(this.rotationTask);
|
||||
if (this.rotationTask.isOnline()) {
|
||||
final float[] angle = MathUtil.calcAngle(mc.player.getPositionEyes(mc.getRenderPartialTicks()), new Vec3d(position.getX() + 0.5f, position.getY() + 0.5f, position.getZ() + 0.5f));
|
||||
Seppuku.INSTANCE.getRotationManager().setPlayerRotations(angle[0], angle[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private BlockPos getPosition(int note) {
|
||||
int[] blocks = this.blockArea(note);
|
||||
return new BlockPos(blocks[0], blocks[1], blocks[2]);
|
||||
}
|
||||
|
||||
private boolean correctPosition(BlockPos blockPos, int index) {
|
||||
int[] blocks = this.blockArea(index);
|
||||
return (blockPos.getX() == blocks[0] && blockPos
|
||||
.getY() == blocks[1] && blockPos
|
||||
.getZ() == blocks[2]);
|
||||
}
|
||||
|
||||
private String getNote(int note) {
|
||||
int octaveNote = note % 12;
|
||||
switch (octaveNote) {
|
||||
case 0:
|
||||
return "F#";
|
||||
case 1:
|
||||
return "G";
|
||||
case 2:
|
||||
return "G#";
|
||||
case 3:
|
||||
return "A";
|
||||
case 4:
|
||||
return "A#";
|
||||
case 5:
|
||||
return "B";
|
||||
case 6:
|
||||
return "C";
|
||||
case 7:
|
||||
return "C#";
|
||||
case 8:
|
||||
return "D";
|
||||
case 9:
|
||||
return "D#";
|
||||
case 10:
|
||||
return "E";
|
||||
case 11:
|
||||
return "F";
|
||||
case 12:
|
||||
return "Gb";
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
|
||||
private void clearData() {
|
||||
this.discoveredBlocks.clear();
|
||||
if (!this.mode.getValue().equals(Mode.DEBUG)) { // is not debug, so let's wipe our previously tuned blocks data
|
||||
this.tunedBlocks.clear();
|
||||
}
|
||||
this.blocks.clear();
|
||||
this.notePlayer.getNotesToPlay().clear();
|
||||
this.currentBlock = null;
|
||||
}
|
||||
|
||||
public enum BotState {
|
||||
IDLE, DISCOVERING, TUNING, PLAYING;
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
AUTOMATIC, MANUAL, DEBUG
|
||||
}
|
||||
|
||||
public Value<BotState> getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public NotePlayer getNotePlayer() {
|
||||
return notePlayer;
|
||||
}
|
||||
|
||||
public int getCurrentNote() {
|
||||
return currentNote;
|
||||
}
|
||||
|
||||
public void setCurrentNote(int currentNote) {
|
||||
this.currentNote = currentNote;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue