Instantly share code, notes, and snippets.
Created
August 8, 2021 10:28
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save Death-123/91f70822b76df997f28e4dcd1209babe to your computer and use it in GitHub Desktop.
qemenu_script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Thread = Java.type('java.lang.Thread'); | |
var Minecraft = Java.type("net.minecraft.client.Minecraft"); | |
var EnumHand = Java.type("net.minecraft.util.EnumHand"); | |
var ClickType = Java.type("net.minecraft.inventory.ClickType"); | |
var NBTTagCompound = Java.type("net.minecraft.nbt.NBTTagCompound"); | |
var Item = Java.type("net.minecraft.item.Item"); | |
var ItemStack = Java.type("net.minecraft.item.ItemStack"); | |
var BlockPos = Java.type("net.minecraft.util.math.BlockPos"); | |
var Vec3d = Java.type("net.minecraft.util.math.Vec3d"); | |
var CapabilityManager = Java.type("net.minecraftforge.common.capabilities.CapabilityManager"); | |
var qemenu = Java.type("net.saralab.qemenu.common.QEMenu") | |
var ConfigManager = Java.type("net.saralab.qemenu.common.config.ConfigManager"); | |
var CPacketPlayerDigging = Java.type("net.minecraft.network.play.client.CPacketPlayerDigging"); | |
var EnumFacing = Java.type("net.minecraft.util.EnumFacing"); | |
var ConfigManager = Java.type("net.saralab.qemenu.common.config.ConfigManager"); | |
var File = Java.type("java.io.File"); | |
var Gson = new com.google.gson.Gson; | |
var AnvilGranite = Java.type("com.codetaylor.mc.pyrotech.modules.tech.basic.tile.spi.TileAnvilBase"); | |
var TileEntityCrop = Java.type("com.infinityraider.agricraft.tiles.TileEntityCrop"); | |
var ItemCrop = Java.type("com.infinityraider.agricraft.items.ItemCrop"); | |
var ItemRake = Java.type("com.infinityraider.agricraft.items.ItemRake"); | |
var BlockEnergionCrystal = Java.type("lykrast.prodigytech.common.block.BlockEnergionCrystal"); | |
var mc = Minecraft.func_71410_x(); | |
var connection = mc.func_147114_u(); | |
var player = mc.field_71439_g; | |
var getPosition = function() {return player.func_180425_c();} | |
var getFoodLevel = function() {return player.func_71024_bL().func_75116_a();} | |
var world = mc.field_71441_e; | |
var playerController = mc.field_71442_b; | |
var getObjectMouseOver = function() {return mc.field_71476_x;} | |
var getTileentity = function(blockPos) {return world.func_175625_s(blockPos);} | |
var inventory = new Object(); | |
Object.bindProperties(inventory, player.field_71071_by); | |
inventory.getStackInSlot = inventory.func_70301_a; | |
inventory.getHotbarSelect = function() {return inventory.field_70461_c;} | |
inventory.setHotbarSelect = function(id) {inventory.field_70461_c = id;} | |
//var inventory = player.field_71071_by; | |
var inventorySize = inventory.func_70302_i_(); | |
var inventoryContainer = player.field_71069_bz; | |
var currentItem = inventory.field_70461_c; | |
var getWindowId = function(container) {return container.field_75152_c;} | |
var areItemsEqual = function(A, B) {return ItemStack.func_185132_d(A, B);} | |
//var getBlockPos = getObjectMouseOver().func_178782_a; | |
//var sideHit = getObjectMouseOver().field_178784_b; | |
var leftClickBlock = function(blockPos, sideHit) {playerController.func_180511_b(blockPos, sideHit);} | |
var rightClickBlock = function(BlockPos, sideHit, hitVec, EnumHand) {playerController.func_187099_a(player, world, BlockPos, sideHit, hitVec, EnumHand);} | |
var slotClick = function(container, slotId, mouseButton, clickType, player) {playerController.func_187098_a(getWindowId(container), slotId, mouseButton, clickType, player);} | |
var face = function(face) {return EnumFacing.func_176739_a(face)}; | |
var getItem = function(slot) {return inventory.func_70301_a(slot).func_77973_b()}; | |
var getItemName = function(slot) {return inventory.func_70301_a(inventory.getHotbarSelect()).func_77973_b().func_77658_a()}; | |
var timerThread = new Thread(function(){ | |
var temp = world.func_82737_E(); | |
while(true){ | |
if(!world.func_82737_E().equals(temp)){ | |
if(cycleThread != null){ | |
cycleThread.resume(); | |
} | |
temp = world.func_82737_E(); | |
} | |
Thread.sleep(10); | |
} | |
}, "timerThread"); | |
timerThread.start(); | |
function waitTick(tick){ | |
for(var i = 0; i < tick; i++){ | |
Thread.currentThread().suspend(); | |
} | |
} | |
function stopTimer(task, arg){timerThread.interrupt();} | |
function refresh(task , arg){ | |
if(timerThread != null){timerThread.interrupt();} | |
if(cycleThread != null){cycleThread.interrupt();} | |
logger.info("refreshing"); | |
qemenu.proxy.getActionManager().loadScripts(); | |
ConfigManager.loadAllActions(); | |
printChatMessage("refresh complete") | |
} | |
function test1(task, arg){ | |
var blockPos = getObjectMouseOver().func_178782_a(); | |
var playerPos = getPosition(); | |
var itemStack = inventory.func_70301_a(inventory.getHotbarSelect()); | |
var eachPos = BlockPos.func_177975_b(playerPos.func_177982_a(3, 1, 3), playerPos.func_177982_a(-3, -1, -3)); | |
//logger.info(inventory.func_70301_a(inventory.getHotbarSelect())); | |
var dataFile = new File(ConfigManager.getConfigDir(), "data.txt"); | |
var itemA = new ItemStack(Item.func_111206_d("agricraft:rake")); | |
printChatMessage(areItemsEqual(itemA, itemStack)) | |
printChatMessage(itemA); | |
printChatMessage(itemStack); | |
//printChatMessage(Gson.toJson({a:"itemStack"})); | |
} | |
function test(task , arg){ | |
var blockPos = getObjectMouseOver().func_178782_a(); | |
//var threadGroup = Thread.currentThread().getThreadGroup(); | |
//var total = Thread.activeCount() | |
//var threads = new ThreadArray(total); | |
//threadGroup["enumerate(Thread[])"](threads); | |
//for each(var thread in threads){ | |
// if(thread.getName() == "Thread-388"){thread.interrupt()} | |
//} | |
//logger.info(inventory.getStackInSlot(inventory.getHotbarSelect()).func_77973_b().class); | |
//printChatMessage(world.func_180495_p(blockPos).func_185903_a(player, world, blockPos)); //硬度 | |
//connection.func_147297_a(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockPos, EnumFacing.func_176739_a("up"))) | |
//connection.func_147297_a(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockPos, EnumFacing.func_176739_a("up"))) | |
//while(playerController.func_180512_c(getObjectMouseOver().func_178782_a().func_177982_a(3,0,0), getObjectMouseOver().field_178784_b)){ | |
//} | |
var objectMouseOver = getObjectMouseOver(); | |
var blockPos = objectMouseOver.func_178782_a(); | |
var sideHit = objectMouseOver.field_178784_b; | |
var hitVec = objectMouseOver.field_72307_f; | |
var tileentity = world.func_175625_s(blockPos); | |
//for each(var el in world.func_180495_p(blockPos).class.getMethods()){ | |
// logger.info(el); | |
//} | |
logger.info(world.func_180495_p(blockPos).func_177230_c().class); | |
//printChatMessage(world.func_180495_p(blockPos).func_177229_b(world.func_180495_p(blockPos).func_185920_a("age"))); | |
if(tileentity != null){ | |
var nbt = tileentity.func_189515_b(new NBTTagCompound); | |
logger.info(tileentity.class); | |
var keySet = nbt.func_150296_c(); | |
printChatMessage(nbt); | |
logger.info(keySet); | |
} | |
//printChatMessage(blockPos); | |
//printChatMessage(sideHit); | |
//printChatMessage(hitVec); | |
//printChatMessage(nbt.func_74781_a("agri_seed").func_150285_a_() == "vanilla:weed_plant"); | |
} | |
function slotTrans(slot, type){ | |
if(type == 0){ | |
if(slot < 9){ | |
slot = slot + 36; | |
} | |
}else{ | |
if(slot > 35){ | |
slot = slot - 36; | |
} | |
} | |
return slot; | |
} | |
function moveItemTo(item, slotTo){ | |
for(var i = 0; i < 36; i++) { | |
if(areItemsEqual(inventory.func_70301_a(i), item)){ | |
printChatMessage("found at " + i) | |
var slot = slotTrans(i, 0); | |
if(!areItemsEqual(inventory.func_70301_a(slotTrans(slotTo, 1)), item)){ | |
slotClick(inventoryContainer, slot, 0, ClickType.PICKUP, player); | |
slotClick(inventoryContainer, slotTo, 0, ClickType.PICKUP, player); | |
slotClick(inventoryContainer, slot, 0, ClickType.PICKUP, player); | |
} | |
return true; | |
} | |
} | |
return false; | |
} | |
var cycleThread; | |
function start(task , arg){ | |
if(cycleThread != null){cycleThread.interrupt();} | |
cycleThread = new Thread(function() { | |
var target = inventory.func_70301_a(4); | |
var tool = inventory.func_70301_a(3); | |
var objectMouseOver = getObjectMouseOver(); | |
var blockPos = objectMouseOver.func_178782_a(); | |
var sideHit = objectMouseOver.field_178784_b; | |
var hitVec = objectMouseOver.field_72307_f; | |
if(arg == "anvil"){ | |
var flag = true; | |
var ii = 0 | |
while(flag){ | |
var i = 0 | |
while(areItemsEqual(inventory.func_70301_a(4), target) && areItemsEqual(inventory.func_70301_a(3), tool)) { | |
blockPos = getObjectMouseOver().func_178782_a(); | |
if(!(getTileentity(blockPos) instanceof AnvilGranite) || getFoodLevel() < 4){ | |
flag = false; | |
break; | |
} | |
inventory.setHotbarSelect(4); | |
rightClickBlock(blockPos, sideHit, hitVec, EnumHand.MAIN_HAND); | |
waitTick(1); | |
inventory.setHotbarSelect(3); | |
for(var j = 0; j < 10 ; j++){ | |
rightClickBlock(blockPos, sideHit, hitVec, EnumHand.MAIN_HAND); | |
} | |
waitTick(1); | |
i++; | |
if(i>64)break; | |
} | |
if(!areItemsEqual(inventory.func_70301_a(4), target)){ | |
printChatMessage("searching target"); | |
flag = moveItemTo(target, slotTrans(4, 0)); | |
}else if(!areItemsEqual(inventory.func_70301_a(3), tool)){ | |
printChatMessage("searching tool"); | |
flag = moveItemTo(tool, slotTrans(3, 0)); | |
} | |
if(!flag){ | |
printChatMessage("exit") | |
} | |
waitTick(1); | |
ii++; | |
if(ii > 10) flag = false; | |
} | |
}else if(arg == "agri"){ | |
var cropSticks = inventory.func_70301_a(3); | |
var playerPos = getPosition(); | |
var eachPos = BlockPos.func_177975_b(playerPos.func_177982_a(5, 1, 5), playerPos.func_177982_a(-5, -1, -5)); | |
for each (var pos in eachPos){ | |
if(getTileentity(pos) != null && getTileentity(pos) instanceof TileEntityCrop){ | |
var hitVec = new Vec3d(pos).func_178787_e(new Vec3d(0.5, 0.5, 0.5)); | |
var nbt = getTileentity(pos).func_189515_b(new NBTTagCompound); | |
if(nbt.func_74764_b("agri_seed")){ | |
var seed = nbt.func_74781_a("agri_seed").func_150285_a_(); | |
if(seed == "vanilla:weed_plant"){ | |
inventory.setHotbarSelect(4); | |
rightClickBlock(pos, face("up"), hitVec, EnumHand.MAIN_HAND); | |
waitTick(1); | |
inventory.setHotbarSelect(3); | |
if(!areItemsEqual(inventory.func_70301_a(3), cropSticks)){ | |
flag = moveItemTo(tool, slotTrans(3, 0)); | |
waitTick(1); | |
} | |
rightClickBlock(pos, face("up"), hitVec, EnumHand.MAIN_HAND); | |
waitTick(1); | |
} | |
} | |
} | |
} | |
}else if(arg == "energySeed"){ | |
var playerPos = getPosition(); | |
var eachPos = BlockPos.func_177975_b(playerPos.func_177982_a(5, 1, 5), playerPos.func_177982_a(-5, -1, -5)); | |
for each (var pos in eachPos){ | |
if(world.func_180495_p(pos).func_177230_c() instanceof BlockEnergionCrystal){ | |
var age = world.func_180495_p(pos).getMetadata(); | |
for(var i = 0; i < age; i++){ | |
rightClickBlock(pos, face("up"), hitVec, EnumHand.MAIN_HAND); | |
} | |
waitTick(1); | |
} | |
} | |
}else if(arg == "test"){ | |
var objectMouseOver = getObjectMouseOver(); | |
var blockPos = objectMouseOver.func_178782_a(); | |
var speed = world.func_180495_p(blockPos).func_185903_a(player, world, blockPos); | |
var tick = Math.floor(0.7/speed); | |
connection.func_147297_a(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockPos, EnumFacing.func_176739_a("up"))); | |
waitTick(tick); | |
connection.func_147297_a(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockPos, EnumFacing.func_176739_a("up"))); | |
printChatMessage("done") | |
} | |
}, "cycleThread"); | |
cycleThread.start(); | |
} | |
function end(task, arg){ | |
if(cycleThread != null){ | |
if(!cycleThread.isInterrupted()){ | |
printChatMessage("not interrupted"); | |
cycleThread.interrupt(); | |
}else{ | |
printChatMessage("interrupted"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment