Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.manusoftar.minefinder.serverproxy;
- import java.awt.Point;
- import java.util.List;
- import java.util.Random;
- import java.util.Stack;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.entity.EntityPlayerSP;
- import net.minecraft.command.CommandBase;
- import net.minecraft.command.CommandException;
- import net.minecraft.command.ICommand;
- import net.minecraft.command.ICommandSender;
- import net.minecraft.util.BlockPos;
- import net.minecraft.util.ChatComponentText;
- public class MineFinderCommand implements ICommand {
- private static boolean hasMineshaftStartingPoint(long mapSeed, int chunkX, int chunkZ){
- Random rand = new Random();
- // *** MapGenBase->generate() / MapGenStructure->getNeareastInstance()
- rand.setSeed(mapSeed);
- long seedMod1 = rand.nextLong();
- long seedMod2 = rand.nextLong();
- long seedMod3 = (long)chunkX * seedMod1;
- long seedMod4 = (long)chunkZ * seedMod2;
- rand.setSeed(seedMod3 ^ seedMod4 ^ mapSeed);
- rand.nextInt();
- // *** MapGenMineshaft->canSpawnStructureAtCoords
- if(rand.nextDouble() < 0.01D && rand.nextInt(80) < Math.max(Math.abs(chunkX), Math.abs(chunkZ))){
- return true;
- }
- return false;
- }
- @Override
- public int compareTo(Object o) {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public String getName() {
- // TODO Auto-generated method stub
- return "findMine";
- }
- @Override
- public String getCommandUsage(ICommandSender sender) {
- // TODO Auto-generated method stub
- return "findMine radius";
- }
- @Override
- public List getAliases() {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public void execute(ICommandSender sender, String[] args) throws CommandException {
- // TODO Auto-generated method stub
- // El comando es /findMine o /findMine
- int range = 150;
- if (args.length>0){
- try {
- range = Integer.parseInt(args[0]);
- EntityPlayerSP p1 = Minecraft.getMinecraft().thePlayer;
- int chunkx, chunkz;
- chunkx = p1.chunkCoordX;
- chunkz = p1.chunkCoordZ;
- Stack<Point> chunks = new Stack<Point>();
- //Semilla de creación del mundo actual
- long seed = sender.getEntityWorld().getSeed();
- for (int offx = 0; offx<range; offx++){
- for (int offz = 0; offz<range; offz++){
- if (hasMineshaftStartingPoint(seed, chunkx+offx, chunkz+offz)){
- chunks.push(new Point(chunkx+offx,chunkz+offz));
- }
- if (hasMineshaftStartingPoint(seed, chunkx+offx, chunkz-offz)){
- chunks.push(new Point(chunkx+offx,chunkz-offz));
- }
- if (hasMineshaftStartingPoint(seed, chunkx-offx, chunkz+offz)){
- chunks.push(new Point(chunkx-offx,chunkz+offz));
- }
- if (hasMineshaftStartingPoint(seed, chunkx-offx, chunkz-offz)){
- chunks.push(new Point(chunkx-offx,chunkz-offz));
- }
- }
- }
- int distance=99999999;
- int min = -1;
- for ( int n = 0; n<chunks.size(); n++ ) {
- Point chunk = chunks.get(n);
- int dis = (int)(Math.sqrt(Math.pow(chunkx-chunk.x, 2)+Math.pow(chunkz-chunk.y,2)));
- if (dis < distance) {
- distance = dis;
- min = n;
- }
- }
- sender.addChatMessage(new ChatComponentText("Mina encontrada: " + chunks.get(min).toString()));
- } catch(Exception ex){
- }
- }
- }
- @Override
- public boolean canCommandSenderUse(ICommandSender sender) {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public boolean isUsernameIndex(String[] args, int index) {
- // TODO Auto-generated method stub
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement