fix (also remove thread because apparently bad boo bad bad blablabla

threads are now worse
This commit is contained in:
ayunami2000 2022-01-18 13:22:52 -05:00
parent eeb90a315a
commit d0c582c524
4 changed files with 19692 additions and 19739 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -54,28 +54,27 @@ public class GuiScreenModules extends GuiScreen {
NoteblockPlayer.thr=null; NoteblockPlayer.thr=null;
mc.thePlayer.sendChatToPlayer("Stopped notebot!"); mc.thePlayer.sendChatToPlayer("Stopped notebot!");
}else { }else {
NoteblockPlayer.thr = new Thread(new Runnable() {
@Override
public void run() {
EaglerAdapter.openFileChooser("nbs", ".nbs,.mid,.midi"); EaglerAdapter.openFileChooser("nbs", ".nbs,.mid,.midi");
try { NoteblockPlayer.zleep(1000);
Thread.sleep(1000);
while(!EaglerAdapter.isFocused()){ while(!EaglerAdapter.isFocused()){
Thread.sleep(100); NoteblockPlayer.zleep(100);
} }
Thread.sleep(500); NoteblockPlayer.zleep(500);
} catch (InterruptedException e) {}
byte[] b; byte[] b;
if ((b = EaglerAdapter.getFileChooserResult()) != null && b.length > 0) { if ((b = EaglerAdapter.getFileChooserResult()) != null && b.length > 0) {
String name = EaglerAdapter.getFileChooserResultName(); String name = EaglerAdapter.getFileChooserResultName();
NoteblockPlayer.songdata = b; NoteblockPlayer.songdata = b;
mc.thePlayer.sendChatToPlayer("Playing \""+name+"\" on notebot!"); mc.thePlayer.sendChatToPlayer("Playing \""+name+"\" on notebot!");
NoteblockPlayer.play((name.toLowerCase().endsWith(".nbs")?NoteblockPlayer.loadSong():MidiConverter.midiToTxt()).split("\n")); String[] songLines=(name.toLowerCase().endsWith(".nbs")?NoteblockPlayer.loadSong():MidiConverter.midiToTxt()).split("\n");
} NoteblockPlayer.thr = new Thread(new Runnable() {
@Override
public void run() {
NoteblockPlayer.play(songLines);
} }
}); });
NoteblockPlayer.thr.start(); NoteblockPlayer.thr.start();
} }
}
}else if(par1GuiButton.id == 3){ }else if(par1GuiButton.id == 3){
NoteblockPlayer.legit=!NoteblockPlayer.legit; NoteblockPlayer.legit=!NoteblockPlayer.legit;
}else if(par1GuiButton.id == 4){ }else if(par1GuiButton.id == 4){

View File

@ -116,13 +116,20 @@ public class NoteblockPlayer {
} }
} }
public static void zleep(int ms){
long startTime=System.currentTimeMillis();
try {
while(System.currentTimeMillis()-startTime<ms){
Thread.sleep(0);
}
} catch (InterruptedException e) {}
}
public static boolean building=false; public static boolean building=false;
public static void placeAndTuneNoteblocks(HashMap<Integer, HashMap<Integer, Vec3>> instrNoteToBlock){ public static void placeAndTuneNoteblocks(HashMap<Integer, HashMap<Integer, Vec3>> instrNoteToBlock){
if(!playing)return; if(!playing)return;
building=true; building=true;
try { zleep(100);
Thread.sleep(100);
} catch (InterruptedException e) {}
for(Map.Entry<Integer, HashMap<Integer, Vec3>> entry : instrNoteToBlock.entrySet()) { for(Map.Entry<Integer, HashMap<Integer, Vec3>> entry : instrNoteToBlock.entrySet()) {
Integer instr = entry.getKey(); Integer instr = entry.getKey();
HashMap<Integer, Vec3> noteBlockPos = entry.getValue(); HashMap<Integer, Vec3> noteBlockPos = entry.getValue();
@ -154,9 +161,7 @@ public class NoteblockPlayer {
mc.thePlayer.inventory.mainInventory[0] = item; mc.thePlayer.inventory.mainInventory[0] = item;
mc.playerController.sendSlotPacket(item, mc.thePlayer.inventoryContainer.inventorySlots.size() - 9); mc.playerController.sendSlotPacket(item, mc.thePlayer.inventoryContainer.inventorySlots.size() - 9);
mc.getNetHandler().addToSendQueue(new Packet16BlockItemSwitch(0)); mc.getNetHandler().addToSendQueue(new Packet16BlockItemSwitch(0));
try{ zleep(50);
Thread.sleep(50);
} catch (InterruptedException e) {}
} }
rotateToBlock(blockPos.addVector(0,-1,0)); rotateToBlock(blockPos.addVector(0,-1,0));
if(id1!=0) { if(id1!=0) {
@ -165,9 +170,7 @@ public class NoteblockPlayer {
mc.getNetHandler().addToSendQueue(new Packet14BlockDig(1, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1)); mc.getNetHandler().addToSendQueue(new Packet14BlockDig(1, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1));
mc.getNetHandler().addToSendQueue(new Packet14BlockDig(2, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1)); mc.getNetHandler().addToSendQueue(new Packet14BlockDig(2, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1));
PlayerControllerMP.clickBlockCreative(mc, mc.playerController, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1); PlayerControllerMP.clickBlockCreative(mc, mc.playerController, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1);
try{ zleep(50);
Thread.sleep(50);
} catch (InterruptedException e) {}
} }
/* /*
//attempt to place //attempt to place
@ -182,9 +185,7 @@ public class NoteblockPlayer {
mc.thePlayer.inventory.mainInventory[0] = item; mc.thePlayer.inventory.mainInventory[0] = item;
mc.playerController.sendSlotPacket(item, mc.thePlayer.inventoryContainer.inventorySlots.size() - 9); mc.playerController.sendSlotPacket(item, mc.thePlayer.inventoryContainer.inventorySlots.size() - 9);
mc.getNetHandler().addToSendQueue(new Packet16BlockItemSwitch(0)); mc.getNetHandler().addToSendQueue(new Packet16BlockItemSwitch(0));
try{ zleep(50);
Thread.sleep(50);
} catch (InterruptedException e) {}
} }
rotateToBlock(blockPos.addVector(0,-2,0)); rotateToBlock(blockPos.addVector(0,-2,0));
if(id1!=0) { if(id1!=0) {
@ -193,9 +194,7 @@ public class NoteblockPlayer {
mc.getNetHandler().addToSendQueue(new Packet14BlockDig(1, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1)); mc.getNetHandler().addToSendQueue(new Packet14BlockDig(1, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1));
mc.getNetHandler().addToSendQueue(new Packet14BlockDig(2, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1)); mc.getNetHandler().addToSendQueue(new Packet14BlockDig(2, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1));
PlayerControllerMP.clickBlockCreative(mc, mc.playerController, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1); PlayerControllerMP.clickBlockCreative(mc, mc.playerController, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1);
try{ zleep(50);
Thread.sleep(50);
} catch (InterruptedException e) {}
} }
if(id2!=0) { if(id2!=0) {
//attempt to break //attempt to break
@ -203,9 +202,7 @@ public class NoteblockPlayer {
mc.getNetHandler().addToSendQueue(new Packet14BlockDig(1, (int) blockPos.xCoord, (int) (blockPos.yCoord - 2), (int) blockPos.zCoord, 1)); mc.getNetHandler().addToSendQueue(new Packet14BlockDig(1, (int) blockPos.xCoord, (int) (blockPos.yCoord - 2), (int) blockPos.zCoord, 1));
mc.getNetHandler().addToSendQueue(new Packet14BlockDig(2, (int) blockPos.xCoord, (int) (blockPos.yCoord - 2), (int) blockPos.zCoord, 1)); mc.getNetHandler().addToSendQueue(new Packet14BlockDig(2, (int) blockPos.xCoord, (int) (blockPos.yCoord - 2), (int) blockPos.zCoord, 1));
PlayerControllerMP.clickBlockCreative(mc, mc.playerController, (int) blockPos.xCoord, (int) (blockPos.yCoord - 2), (int) blockPos.zCoord, 1); PlayerControllerMP.clickBlockCreative(mc, mc.playerController, (int) blockPos.xCoord, (int) (blockPos.yCoord - 2), (int) blockPos.zCoord, 1);
try{ zleep(50);
Thread.sleep(50);
} catch (InterruptedException e) {}
} }
/* /*
//attempt to place //attempt to place
@ -237,9 +234,7 @@ public class NoteblockPlayer {
currentNote=-1; currentNote=-1;
hasBeenPlaced=false; hasBeenPlaced=false;
} }
try { zleep(50);
Thread.sleep(50);
} catch (InterruptedException e) {}
currPos=mc.thePlayer.getPosition(1); currPos=mc.thePlayer.getPosition(1);
//rangeBlockDist=currPos.addVector(0,mc.thePlayer.getEyeHeight(),0).distanceTo(blockPosVec3d); //rangeBlockDist=currPos.addVector(0,mc.thePlayer.getEyeHeight(),0).distanceTo(blockPosVec3d);
blockDist=currPos.distanceTo(blockPos); blockDist=currPos.distanceTo(blockPos);
@ -250,9 +245,7 @@ public class NoteblockPlayer {
} }
if(playing) { if(playing) {
mc.thePlayer.sendChatMessage("/gamemode 0"); mc.thePlayer.sendChatMessage("/gamemode 0");
try { zleep(500);
Thread.sleep(500);
} catch (InterruptedException e) {}
} }
building = false; building = false;
} }
@ -358,11 +351,13 @@ public class NoteblockPlayer {
//keep notes within 2-octave range //keep notes within 2-octave range
Integer notePitch=Math.max(33,Math.min(57,noteInfo.getPitch()))-33; Integer notePitch=Math.max(33,Math.min(57,noteInfo.getPitch()))-33;
int instrId=noteInfo.getInstrument().getID(); int instrId=noteInfo.getInstrument().getID();
if(instrId!=-1)instrId=in2old[nb2in[instrId]]; if(instrId!=-1){
instrId=in2old[nb2in[instrId]];
tickLines.add(noteKey + ":" + notePitch + ":" + instrId + "\n"); tickLines.add(noteKey + ":" + notePitch + ":" + instrId + "\n");
songLines.put(noteKey,tickLines); songLines.put(noteKey,tickLines);
} }
} }
}
SortedSet<Integer> ticks = new TreeSet<>(songLines.keySet()); SortedSet<Integer> ticks = new TreeSet<>(songLines.keySet());
for (Integer tick : ticks) { for (Integer tick : ticks) {
ArrayList<String> tickLines = songLines.get(tick); ArrayList<String> tickLines = songLines.get(tick);