Advertisement
manusoftar

Minecraft mod another attempt

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