Advertisement
manusoftar

Minecraft mod part 2

Jul 28th, 2015
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.08 KB | None | 0 0
  1. package com.manusoftar.minefinder.serverproxy;
  2.  
  3. import java.awt.Point;
  4. import java.util.List;
  5. import java.util.Random;
  6. import java.util.Stack;
  7.  
  8. import net.minecraft.client.Minecraft;
  9. import net.minecraft.client.entity.EntityPlayerSP;
  10. import net.minecraft.command.CommandBase;
  11. import net.minecraft.command.CommandException;
  12. import net.minecraft.command.ICommand;
  13. import net.minecraft.command.ICommandSender;
  14. import net.minecraft.util.BlockPos;
  15. import net.minecraft.util.ChatComponentText;
  16.  
  17. public class MineFinderCommand implements ICommand {
  18.  
  19. private static boolean hasMineshaftStartingPoint(long mapSeed, int chunkX, int chunkZ){
  20.        
  21.         Random rand = new Random();
  22.        
  23.         // *** MapGenBase->generate() / MapGenStructure->getNeareastInstance()
  24.         rand.setSeed(mapSeed);
  25.         long seedMod1 = rand.nextLong();
  26.         long seedMod2 = rand.nextLong();
  27.        
  28.         long seedMod3 = (long)chunkX * seedMod1;
  29.         long seedMod4 = (long)chunkZ * seedMod2;
  30.        
  31.         rand.setSeed(seedMod3 ^ seedMod4 ^ mapSeed);
  32.        
  33.         rand.nextInt();
  34.        
  35.         // *** MapGenMineshaft->canSpawnStructureAtCoords
  36.         if(rand.nextDouble() < 0.01D && rand.nextInt(80) < Math.max(Math.abs(chunkX), Math.abs(chunkZ))){
  37.             return true;
  38.         }
  39.        
  40.         return false;
  41.     }
  42.  
  43.  
  44.     @Override
  45.     public int compareTo(Object o) {
  46.         // TODO Auto-generated method stub
  47.         return 0;
  48.     }
  49.  
  50.  
  51.     @Override
  52.     public String getName() {
  53.         // TODO Auto-generated method stub
  54.         return "findMine";
  55.     }
  56.  
  57.  
  58.     @Override
  59.     public String getCommandUsage(ICommandSender sender) {
  60.         // TODO Auto-generated method stub
  61.         return "findMine radius";
  62.     }
  63.  
  64.  
  65.     @Override
  66.     public List getAliases() {
  67.         // TODO Auto-generated method stub
  68.         return null;
  69.     }
  70.  
  71.  
  72.     @Override
  73.     public void execute(ICommandSender sender, String[] args) throws CommandException {
  74.         // TODO Auto-generated method stub
  75.         // El comando es /findMine o /findMine 
  76.            
  77.         int range = 150;
  78.           if (args.length>0){
  79.                try {
  80.                    range = Integer.parseInt(args[0]);
  81.                    
  82.                    EntityPlayerSP p1 = Minecraft.getMinecraft().thePlayer;
  83.                    int chunkx, chunkz;
  84.                    chunkx = p1.chunkCoordX;
  85.                    chunkz = p1.chunkCoordZ;
  86.                    
  87.                    Stack<Point> chunks = new Stack<Point>();
  88.                    
  89.                    //Semilla de creación del mundo actual
  90.                    long seed = sender.getEntityWorld().getSeed();
  91.                    
  92.                    for (int offx = 0; offx<range; offx++){
  93.                        for (int offz = 0; offz<range; offz++){
  94.                             if (hasMineshaftStartingPoint(seed, chunkx+offx, chunkz+offz)){
  95.                                 chunks.push(new Point(chunkx+offx,chunkz+offz));
  96.                             }
  97.                             if (hasMineshaftStartingPoint(seed, chunkx+offx, chunkz-offz)){
  98.                                 chunks.push(new Point(chunkx+offx,chunkz-offz));
  99.                             }
  100.                             if (hasMineshaftStartingPoint(seed, chunkx-offx, chunkz+offz)){
  101.                                 chunks.push(new Point(chunkx-offx,chunkz+offz));
  102.                             }
  103.                             if (hasMineshaftStartingPoint(seed, chunkx-offx, chunkz-offz)){
  104.                                 chunks.push(new Point(chunkx-offx,chunkz-offz));
  105.                             }
  106.                        }
  107.                    }
  108.                    
  109.                    int distance=99999999;
  110.                    int min = -1;
  111.                    for ( int n = 0; n<chunks.size(); n++ ) {
  112.                        Point chunk = chunks.get(n);
  113.                        int dis = (int)(Math.sqrt(Math.pow(chunkx-chunk.x, 2)+Math.pow(chunkz-chunk.y,2)));
  114.                        if (dis < distance) {
  115.                            distance = dis;
  116.                            min = n;
  117.                        }
  118.                    }
  119.                    
  120.                    
  121.                    
  122.                    
  123.                    sender.addChatMessage(new ChatComponentText("Mina encontrada: " + chunks.get(min).toString()));
  124.                    
  125.                    
  126.                } catch(Exception ex){
  127.                    
  128.                }
  129.            }
  130.        
  131.        
  132.     }
  133.  
  134.  
  135.     @Override
  136.     public boolean canCommandSenderUse(ICommandSender sender) {
  137.         // TODO Auto-generated method stub
  138.         return false;
  139.     }
  140.  
  141.  
  142.     @Override
  143.     public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) {
  144.         // TODO Auto-generated method stub
  145.         return null;
  146.     }
  147.  
  148.  
  149.     @Override
  150.     public boolean isUsernameIndex(String[] args, int index) {
  151.         // TODO Auto-generated method stub
  152.         return false;
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement