sync fard
xd
53961
javascript/classes.js
BIN
javascript/ran_windows_amd64.exe
Normal file
2
javascript/start.bat
Normal file
|
@ -0,0 +1,2 @@
|
|||
@echo off
|
||||
ran_windows_amd64.exe --port 80
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 585 B After Width: | Height: | Size: 521 B |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 1006 B After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 856 B After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 895 B After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 991 B After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 654 B After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 836 B After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 8.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 926 B After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 16 KiB |
|
@ -1,2 +1,2 @@
|
|||
The default look of Minecraft
|
||||
|
||||
Dark theme pack ported by ayunami2000
|
||||
Resources by nebulr and rickenzino
|
||||
|
|
Before Width: | Height: | Size: 151 B After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 157 B After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 153 B After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 142 B After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 86 KiB After Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 68 KiB |
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 89 KiB |
99
src/main/java/me/ayunami2000/ayuncraft/GuiScreenModules.java
Normal file
|
@ -0,0 +1,99 @@
|
|||
package me.ayunami2000.ayuncraft;
|
||||
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.minecraft.src.*;
|
||||
|
||||
public class GuiScreenModules extends GuiScreen {
|
||||
|
||||
public GuiScreenModules(GuiScreen parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
protected String screenTitle = "ayuncraft";
|
||||
private GuiScreen parent;
|
||||
private GuiTextField iteminfo;
|
||||
|
||||
public void initGui() {
|
||||
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 148, "Close"));
|
||||
this.iteminfo = new GuiTextField(this.fontRenderer, this.width / 2 - 98, this.height / 6 + 24, 195, 20);
|
||||
this.iteminfo.setFocused(true);
|
||||
this.iteminfo.setText("383");
|
||||
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 6 + 124, "Give"));
|
||||
this.buttonList.add(new GuiButton(2, this.width / 2 - 100, this.height / 6 + 100, "Toggle Notebot"));
|
||||
this.buttonList.add(new GuiButton(3, this.width / 2 - 100, this.height / 6 + 76, "Toggle Legit mode"));
|
||||
}
|
||||
|
||||
public void onGuiClosed() {
|
||||
EaglerAdapter.enableRepeatEvents(false);
|
||||
}
|
||||
|
||||
public void drawScreen(int mx, int my, float par3) {
|
||||
this.drawDefaultBackground();
|
||||
this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 15, 16777215);
|
||||
super.drawScreen(mx, my, par3);
|
||||
this.iteminfo.drawTextBox();
|
||||
}
|
||||
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if(par1GuiButton.id == 200) {
|
||||
this.mc.displayGuiScreen(parent);
|
||||
}else if(par1GuiButton.id == 1) {
|
||||
try{
|
||||
String[] pieces=iteminfo.getText().split(":",2);
|
||||
int itemid=Integer.parseInt(pieces[0]);
|
||||
int dmg=pieces.length==1?0:Integer.parseInt(pieces[1]);
|
||||
ItemStack theitem=new ItemStack(itemid, 64, dmg);
|
||||
mc.thePlayer.inventory.addItemStackToInventory(theitem);
|
||||
//mc.thePlayer.inventoryContainer.detectAndSendChanges();
|
||||
//mc.thePlayer.dropPlayerItem(theitem);
|
||||
}catch(NumberFormatException e){}
|
||||
}else if(par1GuiButton.id == 2) {
|
||||
if(NoteblockPlayer.playing){
|
||||
NoteblockPlayer.playing=false;
|
||||
NoteblockPlayer.thr=null;
|
||||
mc.thePlayer.sendChatToPlayer("Stopped notebot!");
|
||||
}else {
|
||||
NoteblockPlayer.thr = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
EaglerAdapter.openFileChooser("nbs", "application/nbs");
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
while(!EaglerAdapter.isFocused()){
|
||||
Thread.sleep(100);
|
||||
}
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {}
|
||||
byte[] b;
|
||||
if ((b = EaglerAdapter.getFileChooserResult()) != null && b.length > 0) {
|
||||
String name = EaglerAdapter.getFileChooserResultName();
|
||||
NoteblockPlayer.songdata = b;
|
||||
mc.thePlayer.sendChatToPlayer("Playing \""+name+"\" on notebot!");
|
||||
NoteblockPlayer.play();
|
||||
}
|
||||
}
|
||||
});
|
||||
NoteblockPlayer.thr.start();
|
||||
}
|
||||
}else if(par1GuiButton.id == 3){
|
||||
NoteblockPlayer.legit=!NoteblockPlayer.legit;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
this.iteminfo.updateCursorCounter();
|
||||
}
|
||||
|
||||
protected void keyTyped(char par1, int par2) {
|
||||
this.iteminfo.textboxKeyTyped(par1, par2);
|
||||
}
|
||||
|
||||
protected void mouseClicked(int par1, int par2, int par3) {
|
||||
super.mouseClicked(par1, par2, par3);
|
||||
this.iteminfo.mouseClicked(par1, par2, par3);
|
||||
}
|
||||
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
}
|
453
src/main/java/me/ayunami2000/ayuncraft/NoteblockPlayer.java
Normal file
|
@ -0,0 +1,453 @@
|
|||
package me.ayunami2000.ayuncraft;
|
||||
|
||||
import me.ayunami2000.ayuncraft.nbsapi.Layer;
|
||||
import me.ayunami2000.ayuncraft.nbsapi.Note;
|
||||
import me.ayunami2000.ayuncraft.nbsapi.Song;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.src.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class NoteblockPlayer {
|
||||
public static boolean playing=false;
|
||||
public static byte[] songdata=null;
|
||||
public static Song song=null;
|
||||
public static Thread thr=null;
|
||||
private static final int[] nb2in=new int[]{0,4,1,2,3,7,5,6,8,9,10,11,12,13,14,15};
|
||||
private static int[] in2old=new int[]{0,1,2,3,4,0,0,4,0,0,0,0,4,0,4,0};
|
||||
private static Block[] instruments=new Block[]{Block.dirt,Block.stone,Block.sand,Block.glass,Block.planks};
|
||||
private static Vec3 startingPos = null;
|
||||
private static Minecraft mc=Minecraft.getMinecraft();
|
||||
public static boolean legit=false;
|
||||
|
||||
private static boolean playingSong=false;
|
||||
private static String[] songLiness=null;
|
||||
private static HashMap<Integer,HashMap<Integer,Vec3>> instrNoteToBlocks=null;
|
||||
private static int tickPassed=0;
|
||||
public static void tick(){
|
||||
if(playing&&playingSong){
|
||||
int linesPlayed=0;
|
||||
for (String songLine : songLiness) {
|
||||
String[] songInfo = songLine.split(":");
|
||||
int tick = Integer.parseInt(songInfo[0])-tickPassed;
|
||||
int note = Integer.parseInt(songInfo[1]);
|
||||
int instr = Integer.parseInt(songInfo[2]);
|
||||
if(tick<=0) {
|
||||
Vec3 blockPos=instrNoteToBlocks.get(instr).get(note);
|
||||
try {
|
||||
mc.playerController.clickBlock((int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1);
|
||||
if(legit)rotateToBlock(blockPos.addVector(0,-1,0));
|
||||
}catch(NullPointerException e){}
|
||||
//mc.getNetHandler().addToSendQueue(new Packet14BlockDig(0, (int) blockPos.xCoord, (int) blockPos.yCoord, (int) blockPos.zCoord,1));
|
||||
//mc.thePlayer.swingItem();
|
||||
linesPlayed++;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
tickPassed++;
|
||||
if(linesPlayed!=0)songLiness=Arrays.copyOfRange(songLiness,linesPlayed,songLiness.length);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private static void playSong(String[] songLines,HashMap<Integer,HashMap<Integer,Vec3>> instrNoteToBlock) throws InterruptedException {
|
||||
int ticks=0;
|
||||
for (String songLine : songLines) {
|
||||
if(playing) {
|
||||
String[] songInfo = songLine.split(":");
|
||||
int tick = Integer.parseInt(songInfo[0]);
|
||||
int note = Integer.parseInt(songInfo[1]);
|
||||
int instr = Integer.parseInt(songInfo[2]);
|
||||
if(instr!=-1) {
|
||||
Vec3 blockPos=instrNoteToBlock.get(instr).get(note);
|
||||
try {
|
||||
mc.playerController.clickBlock((int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1);
|
||||
rotateToBlock(blockPos.addVector(0,-1,0));
|
||||
}catch(NullPointerException e){}
|
||||
Thread.sleep((tick - ticks) * 50L);
|
||||
ticks=tick;
|
||||
//mc.getNetHandler().addToSendQueue(new Packet14BlockDig(0, (int) blockPos.xCoord, (int) blockPos.yCoord, (int) blockPos.zCoord,1));
|
||||
//mc.thePlayer.swingItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public static void rotateToBlock(Vec3 block){
|
||||
block=block.addVector(0.5,0.5,0.5);
|
||||
|
||||
Vec3 eyesPos = mc.thePlayer.getPosition(1).addVector(0,mc.thePlayer.getEyeHeight(),0);
|
||||
|
||||
double diffX = block.xCoord - eyesPos.xCoord;
|
||||
double diffY = block.yCoord - eyesPos.yCoord;
|
||||
double diffZ = block.zCoord - eyesPos.zCoord;
|
||||
|
||||
double diffXZ = Math.sqrt(diffX * diffX + diffZ * diffZ);
|
||||
|
||||
float yaw = (float)Math.toDegrees(Math.atan2(diffZ, diffX)) - 90F;
|
||||
float pitch = (float)-Math.toDegrees(Math.atan2(diffY, diffXZ));
|
||||
|
||||
mc.thePlayer.prevRotationYaw = mc.thePlayer.rotationYaw;
|
||||
mc.thePlayer.prevRotationPitch = mc.thePlayer.rotationPitch;
|
||||
mc.thePlayer.rotationYaw=yaw%360.0F;
|
||||
mc.thePlayer.rotationPitch=pitch%360.0F;
|
||||
}
|
||||
|
||||
public static void play(){
|
||||
playingSong=false;
|
||||
playing=true;
|
||||
String[] songLines=loadSong().split("\n");
|
||||
HashMap<Integer, HashMap<Integer, Vec3>> songBlocks=songLinesToBlocks(songLines);
|
||||
if(playing)placeAndTuneNoteblocks(songBlocks);
|
||||
if(playing) {
|
||||
songLiness=songLines;
|
||||
instrNoteToBlocks=songBlocks;
|
||||
tickPassed=0;
|
||||
playingSong=true;
|
||||
/*
|
||||
try {
|
||||
playSong(songLines,songBlocks);
|
||||
} catch (InterruptedException e) {}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
public static Vec3 notePos=null;
|
||||
public static int targetNote=-1;
|
||||
public static boolean correctNote=false;
|
||||
public static int currentNote=-1;
|
||||
public static int theoreticalNote=-1;
|
||||
public static void notePlayed(int x,int y,int z,int note){
|
||||
if(!playing){
|
||||
correctNote=false;
|
||||
notePos=null;
|
||||
targetNote=-1;
|
||||
currentNote=-1;
|
||||
theoreticalNote=-1;
|
||||
}
|
||||
if(notePos!=null&&targetNote!=-1){
|
||||
if((int)notePos.xCoord==x&&(int)notePos.yCoord==y+1&&(int)notePos.zCoord==z){
|
||||
currentNote=note;
|
||||
if(theoreticalNote<0)theoreticalNote=currentNote;
|
||||
mc.thePlayer.sendChatToPlayer("Tuning: "+note+"/"+targetNote);
|
||||
if(targetNote==note) {
|
||||
notePos = null;
|
||||
targetNote = -1;
|
||||
currentNote = -1;
|
||||
theoreticalNote = -1;
|
||||
correctNote = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean building=false;
|
||||
public static void placeAndTuneNoteblocks(HashMap<Integer, HashMap<Integer, Vec3>> instrNoteToBlock){
|
||||
if(!playing)return;
|
||||
building=true;
|
||||
//mc.thePlayer.sendChatMessage("/gamemode 1");
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {}
|
||||
for(Map.Entry<Integer, HashMap<Integer, Vec3>> entry : instrNoteToBlock.entrySet()) {
|
||||
Integer instr = entry.getKey();
|
||||
HashMap<Integer, Vec3> noteBlockPos = entry.getValue();
|
||||
for(Map.Entry<Integer, Vec3> entryy : noteBlockPos.entrySet()) {
|
||||
Integer note = entryy.getKey();
|
||||
Vec3 blockPos = entryy.getValue();
|
||||
if(playing) {
|
||||
Vec3 currPos=mc.thePlayer.getPosition(1);
|
||||
//double rangeBlockDist=currPos.addVector(0,mc.thePlayer.getEyeHeight(),0).distanceTo(blockPosVec3d);
|
||||
double blockDist=currPos.distanceTo(blockPos);
|
||||
double oldBlockDist=32767;
|
||||
boolean hasBeenPlaced=false;
|
||||
correctNote=false;
|
||||
while (playing&&((!hasBeenPlaced)||(!correctNote))/*!(rangeBlockDist <= mc.playerController.getBlockReachDistance()+1.0F && (blockDist >= 1.25F))*/) {
|
||||
if(Math.abs(oldBlockDist-blockDist)>0.1){
|
||||
mc.thePlayer.sendChatToPlayer("Need noteblock with instrument "+instruments[instr].getLocalizedName()+" and tuning "+note+". Distance: "+blockDist+". XYZ: "+blockPos);
|
||||
}
|
||||
oldBlockDist=blockDist;
|
||||
int id1=mc.theWorld.getBlockId((int)blockPos.xCoord,(int)(blockPos.yCoord-1),(int)blockPos.zCoord);
|
||||
int id2=mc.theWorld.getBlockId((int)blockPos.xCoord,(int)(blockPos.yCoord-2),(int)blockPos.zCoord);
|
||||
boolean check1=id1==Block.music.blockID;
|
||||
boolean check2=id2==instruments[instr].blockID;
|
||||
int slot1id=mc.thePlayer.inventory.mainInventory[0]==null?-1:mc.thePlayer.inventory.mainInventory[0].itemID;
|
||||
if(mc.playerController.isInCreativeMode()) {
|
||||
if (check2 && (!check1)) {
|
||||
if(slot1id != Block.music.blockID) {
|
||||
//give block
|
||||
ItemStack item = new ItemStack(Block.music);
|
||||
mc.thePlayer.inventory.mainInventory[0] = item;
|
||||
mc.playerController.sendSlotPacket(item, mc.thePlayer.inventoryContainer.inventorySlots.size() - 9);
|
||||
mc.getNetHandler().addToSendQueue(new Packet16BlockItemSwitch(0));
|
||||
try{
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
rotateToBlock(blockPos.addVector(0,-1,0));
|
||||
if(id1!=0) {
|
||||
//attempt to break
|
||||
mc.getNetHandler().addToSendQueue(new Packet14BlockDig(0, (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));
|
||||
PlayerControllerMP.clickBlockCreative(mc, mc.playerController, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1);
|
||||
try{
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
/*
|
||||
//attempt to place
|
||||
if(legit)rotateToBlock(blockPos.addVector(0,-1,0));
|
||||
mc.thePlayer.inventory.currentItem=0;
|
||||
mc.getNetHandler().addToSendQueue(new Packet15Place((int) blockPos.xCoord, (int) (blockPos.yCoord-1), (int) blockPos.zCoord,1,mc.thePlayer.inventory.getCurrentItem(),0,1,0));
|
||||
*/
|
||||
}else if ((!check2) && (!check1)) {
|
||||
if(slot1id != instruments[instr].blockID) {
|
||||
//give block
|
||||
ItemStack item = new ItemStack(instruments[instr]);
|
||||
mc.thePlayer.inventory.mainInventory[0] = item;
|
||||
mc.playerController.sendSlotPacket(item, mc.thePlayer.inventoryContainer.inventorySlots.size() - 9);
|
||||
mc.getNetHandler().addToSendQueue(new Packet16BlockItemSwitch(0));
|
||||
try{
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
rotateToBlock(blockPos.addVector(0,-2,0));
|
||||
if(id1!=0) {
|
||||
//attempt to break block above
|
||||
mc.getNetHandler().addToSendQueue(new Packet14BlockDig(0, (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));
|
||||
PlayerControllerMP.clickBlockCreative(mc, mc.playerController, (int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1);
|
||||
try{
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
if(id2!=0) {
|
||||
//attempt to break
|
||||
mc.getNetHandler().addToSendQueue(new Packet14BlockDig(0, (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));
|
||||
PlayerControllerMP.clickBlockCreative(mc, mc.playerController, (int) blockPos.xCoord, (int) (blockPos.yCoord - 2), (int) blockPos.zCoord, 1);
|
||||
try{
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
/*
|
||||
//attempt to place
|
||||
if(legit)rotateToBlock(blockPos.addVector(0,-2,0));
|
||||
mc.thePlayer.inventory.currentItem=0;
|
||||
mc.getNetHandler().addToSendQueue(new Packet15Place((int) blockPos.xCoord, (int) (blockPos.yCoord-2), (int) blockPos.zCoord,1,mc.thePlayer.inventory.getCurrentItem(),0,1,0));
|
||||
*/
|
||||
}
|
||||
}
|
||||
if(check1&&check2){
|
||||
hasBeenPlaced=true;
|
||||
notePos=blockPos;
|
||||
targetNote=note;
|
||||
if(theoreticalNote==-1){
|
||||
theoreticalNote=-2;
|
||||
//find out the note
|
||||
if(mc.playerController.isInCreativeMode()) {
|
||||
mc.getNetHandler().addToSendQueue(new Packet15Place((int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1, mc.thePlayer.inventory.getCurrentItem(), 0, 1, 0));
|
||||
}else{
|
||||
mc.playerController.clickBlock((int) blockPos.xCoord, (int) blockPos.yCoord-1, (int) blockPos.zCoord,1);
|
||||
}
|
||||
}else if(theoreticalNote>=0&&theoreticalNote!=targetNote) {
|
||||
theoreticalNote=(theoreticalNote+1)%25;
|
||||
mc.getNetHandler().addToSendQueue(new Packet15Place((int) blockPos.xCoord, (int) (blockPos.yCoord - 1), (int) blockPos.zCoord, 1, mc.thePlayer.inventory.getCurrentItem(), 0, 1, 0));
|
||||
}
|
||||
}else{
|
||||
notePos=null;
|
||||
targetNote=-1;
|
||||
currentNote=-1;
|
||||
hasBeenPlaced=false;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {}
|
||||
currPos=mc.thePlayer.getPosition(1);
|
||||
//rangeBlockDist=currPos.addVector(0,mc.thePlayer.getEyeHeight(),0).distanceTo(blockPosVec3d);
|
||||
blockDist=currPos.distanceTo(blockPos);
|
||||
}
|
||||
correctNote=false;
|
||||
/*
|
||||
if(playing) {
|
||||
ItemStack noteblocks = new ItemStack(instruments[instr]);
|
||||
mc.thePlayer.inventory.clearInventory(-1,-1);
|
||||
mc.thePlayer.inventory.currentItem=0;
|
||||
mc.thePlayer.inventory.mainInventory[mc.thePlayer.inventory.currentItem]=noteblocks;
|
||||
mc.playerController.sendSlotPacket(noteblocks,0);
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
//mc.thePlayer.inventoryContainer.detectAndSendChanges();
|
||||
}catch(InterruptedException e){}
|
||||
PlayerControllerMP.clickBlockCreative(mc,mc.playerController, (int) blockPos.xCoord, (int) (blockPos.yCoord-2), (int) blockPos.zCoord,1);
|
||||
mc.thePlayer.swingItem();
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
mc.getNetHandler().addToSendQueue(new Packet15Place((int) blockPos.xCoord, (int) (blockPos.yCoord-1), (int) blockPos.zCoord,1,mc.thePlayer.inventory.getCurrentItem(),0,1,0));
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
noteblocks = new ItemStack(Block.music);
|
||||
mc.thePlayer.inventory.clearInventory(-1,-1);
|
||||
mc.thePlayer.inventory.currentItem=0;
|
||||
mc.thePlayer.inventory.mainInventory[mc.thePlayer.inventory.currentItem]=noteblocks;
|
||||
mc.getNetHandler().addToSendQueue(new Packet16BlockItemSwitch(0));
|
||||
mc.playerController.sendSlotPacket(noteblocks,0);
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
//mc.thePlayer.inventoryContainer.detectAndSendChanges();
|
||||
}catch(InterruptedException e){}
|
||||
PlayerControllerMP.clickBlockCreative(mc,mc.playerController, (int) blockPos.xCoord, (int) (blockPos.yCoord-1), (int) blockPos.zCoord,1);
|
||||
mc.thePlayer.swingItem();
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
mc.getNetHandler().addToSendQueue(new Packet15Place((int) blockPos.xCoord, (int) blockPos.yCoord, (int) blockPos.zCoord,1,mc.thePlayer.inventory.getCurrentItem(),0,1,0));
|
||||
Thread.sleep(50);
|
||||
for(int i=0;i<note;i++){
|
||||
Thread.sleep(50);
|
||||
mc.getNetHandler().addToSendQueue(new Packet15Place((int) blockPos.xCoord, (int) blockPos.yCoord, (int) blockPos.zCoord,1,mc.thePlayer.inventory.getCurrentItem(),0,1,0));
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
if(playing) {
|
||||
mc.thePlayer.sendChatMessage("/gamemode 0");
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
building = false;
|
||||
}
|
||||
|
||||
public static List<int[]> spiral(int size){
|
||||
List<int[]> result=new ArrayList<int[]>();
|
||||
int x = 0; // current position; x
|
||||
int y = 0; // current position; y
|
||||
int d = 0; // current direction; 0=RIGHT, 1=DOWN, 2=LEFT, 3=UP
|
||||
int c = 0; // counter
|
||||
int s = 1; // chain size
|
||||
|
||||
// starting point
|
||||
x = ((int)Math.floor(size/2.0))-1;
|
||||
y = ((int)Math.floor(size/2.0))-1;
|
||||
|
||||
for (int k=1; k<=(size-1); k++)
|
||||
{
|
||||
for (int j=0; j<(k<(size-1)?2:3); j++)
|
||||
{
|
||||
for (int i=0; i<s; i++)
|
||||
{
|
||||
result.add(new int[]{x,y});
|
||||
c++;
|
||||
|
||||
switch (d)
|
||||
{
|
||||
case 0: y = y + 1; break;
|
||||
case 1: x = x + 1; break;
|
||||
case 2: y = y - 1; break;
|
||||
case 3: x = x - 1; break;
|
||||
}
|
||||
}
|
||||
d = (d+1)%4;
|
||||
}
|
||||
s = s + 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, HashMap<Integer, Vec3>> songLinesToBlocks(String[] songLines){
|
||||
HashMap<Integer,HashMap<Integer,Vec3>> instrNoteToBlock=new HashMap<>();
|
||||
int uniqueNotes=0;
|
||||
startingPos=Vec3.createVectorHelper(Math.floor(mc.thePlayer.posX),Math.floor(mc.thePlayer.posY),Math.floor(mc.thePlayer.posZ));
|
||||
Vec3 centerPos=startingPos.addVector(0,-1,0);
|
||||
for (String songLine : songLines) {
|
||||
String[] songInfo = songLine.split(":");
|
||||
int tick = Integer.parseInt(songInfo[0]);
|
||||
int note = Integer.parseInt(songInfo[1]);
|
||||
int instr = Integer.parseInt(songInfo[2]);
|
||||
if(!(instrNoteToBlock.containsKey(instr)&&instrNoteToBlock.get(instr).containsKey(note))){
|
||||
HashMap<Integer,Vec3> theVal=instrNoteToBlock.containsKey(instr)?instrNoteToBlock.get(instr):new HashMap<Integer,Vec3>();
|
||||
theVal.put(note,centerPos);
|
||||
instrNoteToBlock.put(instr,theVal);
|
||||
uniqueNotes++;
|
||||
}
|
||||
}
|
||||
AtomicInteger counter= new AtomicInteger();
|
||||
//fuck you, add 1 to spiral size. excess is already disposed of, so does it really matter if it only runs once?
|
||||
List<int[]> spiralCoords=spiral(1+Math.min(9,(int)Math.ceil(Math.sqrt(uniqueNotes))));
|
||||
List<int[]> spiralCoordsTwo=uniqueNotes>81?spiral(1+(int)Math.ceil(Math.sqrt(uniqueNotes-81))):new ArrayList<int[]>();
|
||||
|
||||
for(Map.Entry<Integer, HashMap<Integer, Vec3>> entry : instrNoteToBlock.entrySet()) {
|
||||
Integer instr = entry.getKey();
|
||||
HashMap<Integer, Vec3> noteBlockPos = entry.getValue();
|
||||
HashMap<Integer, Vec3> noteBlockPosOrig = (HashMap<Integer, Vec3>) noteBlockPos.clone();
|
||||
for(Map.Entry<Integer, Vec3> entryy : noteBlockPos.entrySet()) {
|
||||
Integer note = entryy.getKey();
|
||||
Vec3 blockPos = entryy.getValue();
|
||||
int currNum=counter.getAndIncrement();
|
||||
Vec3 theBlock=Vec3.createVectorHelper(blockPos.xCoord,blockPos.yCoord,blockPos.zCoord);
|
||||
if(currNum>=81){
|
||||
theBlock=theBlock.addVector(spiralCoordsTwo.get(currNum-81)[0]-spiralCoordsTwo.get(0)[0],4,spiralCoordsTwo.get(currNum-81)[1]-spiralCoordsTwo.get(0)[1]);
|
||||
}else{
|
||||
//todo: fix corners
|
||||
theBlock=theBlock.addVector(spiralCoords.get(currNum)[0]-spiralCoords.get(0)[0],0,spiralCoords.get(currNum)[1]-spiralCoords.get(0)[1]);
|
||||
Vec3 offset=theBlock.subtract(blockPos);
|
||||
if(Math.abs(offset.xCoord)==4&&Math.abs(offset.zCoord)==4){
|
||||
theBlock=theBlock.addVector(0,1,0);
|
||||
}
|
||||
}
|
||||
noteBlockPos.replace(note,blockPos,theBlock);
|
||||
}
|
||||
instrNoteToBlock.replace(instr,noteBlockPosOrig,noteBlockPos);
|
||||
}
|
||||
return instrNoteToBlock;
|
||||
}
|
||||
|
||||
public static String loadSong(){
|
||||
try{
|
||||
String resSongFile="";
|
||||
Map<Integer, ArrayList<String>> songLines=new HashMap<>();
|
||||
Song nbsSong = new Song(songdata);
|
||||
List<Layer> nbsSongBoard = nbsSong.getSongBoard();
|
||||
for (int i = 0; i < nbsSongBoard.size(); i++) {
|
||||
Layer layer=nbsSongBoard.get(i);
|
||||
HashMap<Integer, Note> noteList = layer.getNoteList();
|
||||
for (Map.Entry note : noteList.entrySet()) {
|
||||
Note noteInfo = (Note) note.getValue();
|
||||
Integer noteKey=(int)((double)(int)note.getKey()/(5.0*((double)nbsSong.getTempo()/10000.0)));
|
||||
if(!songLines.containsKey(noteKey))songLines.put(noteKey,new ArrayList<String>());
|
||||
ArrayList<String> tickLines=songLines.get(noteKey);
|
||||
//keep notes within 2-octave range
|
||||
Integer notePitch=Math.max(33,Math.min(57,noteInfo.getPitch()))-33;
|
||||
int instrId=noteInfo.getInstrument().getID();
|
||||
if(instrId!=-1)instrId=in2old[nb2in[instrId]];
|
||||
tickLines.add(noteKey + ":" + notePitch + ":" + instrId + "\n");
|
||||
songLines.put(noteKey,tickLines);
|
||||
}
|
||||
}
|
||||
SortedSet<Integer> ticks = new TreeSet<>(songLines.keySet());
|
||||
for (Integer tick : ticks) {
|
||||
ArrayList<String> tickLines = songLines.get(tick);
|
||||
for(int i=0;i<tickLines.size();i++){
|
||||
resSongFile+=tickLines.get(i);
|
||||
}
|
||||
}
|
||||
if(resSongFile.endsWith("\n"))resSongFile=resSongFile.substring(0,resSongFile.length()-1);
|
||||
return resSongFile;
|
||||
}catch(Exception e){
|
||||
//e.printStackTrace();
|
||||
playing=false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package me.ayunami2000.ayuncraft.nbsapi;
|
||||
|
||||
/**
|
||||
* Note block's instrument.
|
||||
* @author Le Duy Quang
|
||||
*
|
||||
*/
|
||||
public enum Instrument {
|
||||
HARP (0),
|
||||
BASS (1),
|
||||
DRUM (2),
|
||||
SNARE (3),
|
||||
CLICK (4),
|
||||
GUITAR (5),
|
||||
FLUTE (6),
|
||||
BELL (7),
|
||||
CHIME (8),
|
||||
XYLOPHONE (9);
|
||||
|
||||
private final int ID;
|
||||
private Instrument(int ID) {
|
||||
this.ID = ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ID of the instrument to be written in NBS files.
|
||||
* @return The ID.
|
||||
*/
|
||||
public int getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the instrument from its NBS file ID.
|
||||
* @param ID The instrument ID (0-9).
|
||||
* @return The corresponding instrument.
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public static Instrument fromID(int ID) throws IllegalArgumentException {
|
||||
switch (ID) {
|
||||
case 0: return HARP;
|
||||
case 1: return BASS;
|
||||
case 2: return DRUM;
|
||||
case 3: return SNARE;
|
||||
case 4: return CLICK;
|
||||
case 5: return GUITAR;
|
||||
case 6: return FLUTE;
|
||||
case 7: return BELL;
|
||||
case 8: return CHIME;
|
||||
case 9: return XYLOPHONE;
|
||||
default: throw new IllegalArgumentException("ID must be from 1 to 9.");
|
||||
}
|
||||
}
|
||||
}
|
61
src/main/java/me/ayunami2000/ayuncraft/nbsapi/Layer.java
Normal file
|
@ -0,0 +1,61 @@
|
|||
package me.ayunami2000.ayuncraft.nbsapi;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* A layer of a song.
|
||||
* @author Le Duy Quang
|
||||
*
|
||||
*/
|
||||
public class Layer {
|
||||
private HashMap<Integer, Note> notes = new HashMap<Integer, Note>();
|
||||
private String name;
|
||||
private byte volume;
|
||||
|
||||
/**
|
||||
* Creates an empty layer with name and volume.
|
||||
* @param name The layer's name.
|
||||
* @param volume The layer's volume (0-100).
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public Layer(String name, byte volume) throws IllegalArgumentException {
|
||||
setName(name);
|
||||
setVolume(volume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the note list of the layer.
|
||||
* @return The list.
|
||||
*/
|
||||
public HashMap<Integer, Note> getNoteList() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the note at a tick on the layer.
|
||||
* @param pos The tick where the note is on.
|
||||
* @param note The note's properties.
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public void setNote(int pos, Note note) throws IllegalArgumentException {
|
||||
if (pos < 0) throw new IllegalArgumentException("Note position must not be negative.");
|
||||
notes.put(pos, note);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public byte getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setVolume(byte volume) throws IllegalArgumentException {
|
||||
if (volume < 0 || volume > 100) throw new IllegalArgumentException("Volume must be from 0 to 100.");
|
||||
this.volume = volume;
|
||||
}
|
||||
}
|
40
src/main/java/me/ayunami2000/ayuncraft/nbsapi/Note.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package me.ayunami2000.ayuncraft.nbsapi;
|
||||
|
||||
/**
|
||||
* A note in a song.
|
||||
* @author Le Duy Quang
|
||||
*
|
||||
*/
|
||||
public class Note {
|
||||
private Instrument instrument;
|
||||
private byte pitch;
|
||||
|
||||
/**
|
||||
* A note in a song.
|
||||
* @param instrument The instrument of the note.
|
||||
* @param pitch The pitch of the note (0-87).
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public Note(Instrument instrument, byte pitch) throws IllegalArgumentException {
|
||||
if (pitch < 0 || pitch > 87) throw new IllegalArgumentException("Pitch must be from 0 to 87.");
|
||||
setInstrument(instrument);
|
||||
setPitch(pitch);
|
||||
}
|
||||
|
||||
public Instrument getInstrument() {
|
||||
return instrument;
|
||||
}
|
||||
|
||||
public void setInstrument(Instrument instrument) {
|
||||
this.instrument = instrument;
|
||||
}
|
||||
|
||||
public byte getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public void setPitch(byte pitch) throws IllegalArgumentException {
|
||||
if (pitch < 0 || pitch > 87) throw new IllegalArgumentException("Pitch must be from 0 to 87.");
|
||||
this.pitch = pitch;
|
||||
}
|
||||
}
|
367
src/main/java/me/ayunami2000/ayuncraft/nbsapi/Song.java
Normal file
|
@ -0,0 +1,367 @@
|
|||
package me.ayunami2000.ayuncraft.nbsapi;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* A note block song.
|
||||
* @author Le Duy Quang
|
||||
*
|
||||
*/
|
||||
public class Song {
|
||||
private short length;
|
||||
private short height;
|
||||
private String name;
|
||||
private String author;
|
||||
private String originalAuthor;
|
||||
private String description;
|
||||
private short tempo;
|
||||
private boolean autoSave;
|
||||
private byte autoSaveDuration;
|
||||
private byte timeSignature;
|
||||
private int minutesSpent;
|
||||
private int leftClicks;
|
||||
private int rightClicks;
|
||||
private int blocksAdded;
|
||||
private int blocksRemoved;
|
||||
private String MidiSchematicFile;
|
||||
private List<Layer> songBoard;
|
||||
|
||||
private ByteArrayInputStream instream;
|
||||
private DataInputStream in;
|
||||
private FileOutputStream outstream;
|
||||
private DataOutputStream out;
|
||||
|
||||
/**
|
||||
* Builds a new song with the given information.
|
||||
* @param length
|
||||
* @param name
|
||||
* @param author
|
||||
* @param originalAuthor
|
||||
* @param description
|
||||
* @param tempo
|
||||
* @param autoSave
|
||||
* @param autoSaveDuration
|
||||
* @param timeSignature
|
||||
* @param minutesSpent
|
||||
* @param leftClicks
|
||||
* @param rightClicks
|
||||
* @param blocksAdded
|
||||
* @param blocksRemoved
|
||||
* @param MidiSchematicFile
|
||||
* @param songBoard
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public Song(
|
||||
short length,
|
||||
String name,
|
||||
String author,
|
||||
String originalAuthor,
|
||||
String description,
|
||||
short tempo,
|
||||
boolean autoSave,
|
||||
byte autoSaveDuration,
|
||||
byte timeSignature,
|
||||
int minutesSpent,
|
||||
int leftClicks,
|
||||
int rightClicks,
|
||||
int blocksAdded,
|
||||
int blocksRemoved,
|
||||
String MidiSchematicFile,
|
||||
List<Layer> songBoard) throws IllegalArgumentException {
|
||||
setLength(length);
|
||||
setName(name);
|
||||
setAuthor(author);
|
||||
setOriginalAuthor(originalAuthor);
|
||||
setDescription(description);
|
||||
setTempo(tempo);
|
||||
setAutoSave(autoSave);
|
||||
setAutoSaveDuration(autoSaveDuration);
|
||||
setTimeSignature(timeSignature);
|
||||
setLeftClicks(leftClicks);
|
||||
setRightClicks(rightClicks);
|
||||
setBlocksAdded(blocksAdded);
|
||||
setBlocksRemoved(blocksRemoved);
|
||||
setMidiSchematicFile(MidiSchematicFile);
|
||||
changeSongBoardTo(songBoard);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a song from a byte array.
|
||||
* @param fromBytes The byte array that should be read.
|
||||
* @throws IOException
|
||||
*/
|
||||
public Song(byte[] fromBytes) throws IOException {
|
||||
instream = new ByteArrayInputStream(fromBytes);
|
||||
in = new DataInputStream(instream);
|
||||
setLength(readShort());
|
||||
setHeight(readShort());
|
||||
setName(readString());
|
||||
setAuthor(readString());
|
||||
setOriginalAuthor(readString());
|
||||
setDescription(readString());
|
||||
setTempo(readShort());
|
||||
setAutoSave(in.readBoolean());
|
||||
setAutoSaveDuration(in.readByte());
|
||||
setTimeSignature(in.readByte());
|
||||
setMinutesSpent(readInt());
|
||||
setLeftClicks(readInt());
|
||||
setRightClicks(readInt());
|
||||
setBlocksAdded(readInt());
|
||||
setBlocksRemoved(readInt());
|
||||
setMidiSchematicFile(readString());
|
||||
|
||||
songBoard = new ArrayList<Layer>();
|
||||
for (int i = 0; i < height; i++) songBoard.add(new Layer("",(byte) 100));
|
||||
int tick = -1;
|
||||
while (true) {
|
||||
short jumpDistance = readShort();
|
||||
if (jumpDistance == 0) break;
|
||||
tick += jumpDistance;
|
||||
short layer = -1;
|
||||
while (true) {
|
||||
short jumpLayers = readShort();
|
||||
if (jumpLayers == 0) break;
|
||||
layer += jumpLayers;
|
||||
while (songBoard.size() < layer+1) {
|
||||
songBoard.add(new Layer("",(byte) 100));
|
||||
}
|
||||
songBoard.get(layer).setNote(tick, new Note(Instrument.fromID(in.readByte()), in.readByte()));
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < getHeight(); i++) {
|
||||
songBoard.get(i).setName(readString());
|
||||
songBoard.get(i).setVolume(in.readByte());
|
||||
}
|
||||
in.close();
|
||||
instream.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the song to the specific file.
|
||||
* @param toFile The file to write to.
|
||||
* @throws IOException
|
||||
*/
|
||||
public void writeSong(File toFile) throws IOException {
|
||||
short maxLength = -1;
|
||||
for (Layer l : songBoard) {
|
||||
short maxPos = -1;
|
||||
for (int i : l.getNoteList().keySet()) {
|
||||
if (i > maxPos) maxPos = (short) i;
|
||||
}
|
||||
if (maxPos > maxLength) maxLength = maxPos;
|
||||
}
|
||||
setLength((short) Math.max(1, maxLength));
|
||||
setHeight((short) songBoard.size());
|
||||
|
||||
outstream = new FileOutputStream(toFile);
|
||||
out = new DataOutputStream(outstream);
|
||||
writeShort(length);
|
||||
writeShort(height);
|
||||
writeString(name);
|
||||
writeString(author);
|
||||
writeString(originalAuthor);
|
||||
writeString(description);
|
||||
writeShort(tempo);
|
||||
out.writeByte(autoSave ? 1 : 0);
|
||||
out.writeByte(autoSaveDuration);
|
||||
out.writeByte(timeSignature);
|
||||
writeInt(minutesSpent);
|
||||
writeInt(leftClicks);
|
||||
writeInt(rightClicks);
|
||||
writeInt(blocksAdded);
|
||||
writeInt(blocksRemoved);
|
||||
writeString(MidiSchematicFile);
|
||||
|
||||
List<WritableNote> noteList = Utils.convertToWritable(songBoard);
|
||||
int oldTick = -1;
|
||||
int oldLayer = -1;
|
||||
for (WritableNote i : noteList) {
|
||||
if (i.getLocation() > oldTick) {
|
||||
if (oldTick != -1) writeShort((short)0);
|
||||
writeShort((short) (i.getLocation() - oldTick));
|
||||
oldTick = i.getLocation();
|
||||
oldLayer = -1;
|
||||
}
|
||||
writeShort((short)(i.getLayer() - oldLayer));
|
||||
oldLayer = i.getLayer();
|
||||
out.writeByte(i.getInstrument().getID());
|
||||
out.writeByte(i.getPitch());
|
||||
}
|
||||
writeShort((short)0);
|
||||
writeShort((short)0);
|
||||
|
||||
for (Layer l : songBoard) {
|
||||
writeString(l.getName());
|
||||
out.writeByte(l.getVolume() |