Skip to content
This repository was archived by the owner on Jul 25, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/TraverseTeam/Traverse
Browse files Browse the repository at this point in the history
  • Loading branch information
ProfessorProspector committed Apr 29, 2018
2 parents 65e018a + ac0bfbb commit f8209ce
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
74 changes: 50 additions & 24 deletions src/main/java/prospector/traverse/commands/CommandFindBiome.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
Expand All @@ -15,6 +16,7 @@

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CommandFindBiome extends CommandBase {
Expand All @@ -28,6 +30,9 @@ public static BlockPos spiralOutwardsLookingForBiome(ICommandSender sender, Worl
double dist = 0;
int n;
long start = System.currentTimeMillis();
BlockPos.PooledMutableBlockPos pos = BlockPos.PooledMutableBlockPos.retain();
int previous = 0;
int i = 0;
for (n = 0; dist < Integer.MAX_VALUE; ++n) {
if ((System.currentTimeMillis() - start) > timeout) {
return null;
Expand All @@ -36,7 +41,22 @@ public static BlockPos spiralOutwardsLookingForBiome(ICommandSender sender, Worl
dist = a * rootN;
x = startX + (dist * Math.sin(b * rootN));
z = startZ + (dist * Math.cos(b * rootN));
if (world.getBiome(new BlockPos(x, 0, z)).equals(biomeToFind)) {
pos.setPos(x, 0, z);
if (sender instanceof EntityPlayer) {
if (previous == 3)
previous = 0;
String s = (previous == 0 ? "." : previous == 1 ? ".." : "...");
((EntityPlayer) sender).sendStatusMessage(new TextComponentString("Scanning" + s), true);
if (i == 1501) {
previous++;
i = 0;
}
i++;
}
if (world.getBiome(pos).equals(biomeToFind)) {
pos.release();
if (sender instanceof EntityPlayer)
((EntityPlayer) sender).sendStatusMessage(new TextComponentString("Found Biome"), true);
return new BlockPos((int) x, 0, (int) z);
}
}
Expand All @@ -54,18 +74,18 @@ public String getUsage(ICommandSender sender) {
}

@Override
public List<String> getTabCompletions(MinecraftServer server,
ICommandSender sender,
String[] args,
@Nullable
BlockPos targetPos) {
List<String> strings = new ArrayList<>();
for (Biome b : ForgeRegistries.BIOMES.getValues()) {
String s = b.getRegistryName().toString();
if (s.toLowerCase().contains(args[0].toLowerCase()))
strings.add(s);
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
if(args.length==1) {
List<String> strings = new ArrayList<>();
for (Biome b : ForgeRegistries.BIOMES.getValues()) {
String s = b.getRegistryName().toString();
if (s.toLowerCase().contains(args[0].toLowerCase()))
strings.add(s);
}

return strings;
}
return strings;
return Collections.emptyList();
}

@Override
Expand All @@ -86,16 +106,22 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
return;
}
long start = System.currentTimeMillis();
BlockPos pos = spiralOutwardsLookingForBiome(sender, sender.getEntityWorld(), biome, sender.getPosition().getX(), sender.getPosition().getZ(), TraverseConfig.findBiomeCommandTimeout);
if (pos == null) {
sender.sendMessage(new TextComponentString(TextFormatting.RED + "Error! Biome '" + args[0] + "' could not be found after " + TextFormatting.GRAY + TraverseConfig.findBiomeCommandTimeout + "ms" + TextFormatting.RED + "."));
return;
}
if (sender instanceof EntityPlayerMP) {
EntityPlayerMP playerMP = (EntityPlayerMP) sender;
playerMP.connection.setPlayerLocation(pos.getX(), 150, pos.getZ(), 0, 0);
}

sender.sendMessage(new TextComponentString(TextFormatting.WHITE + "Found '" + biome.getRegistryName().toString() + "' Biome! " + TextFormatting.GRAY + "(" + (System.currentTimeMillis() - start) + "ms)"));
final Biome finalBiome = biome;
new Thread(() -> {
BlockPos pos = spiralOutwardsLookingForBiome(sender, sender.getEntityWorld(), finalBiome, sender.getPosition().getX(), sender.getPosition().getZ(), TraverseConfig.findBiomeCommandTimeout);
if (pos == null) {
server.addScheduledTask(() -> sender.sendMessage(new TextComponentString(TextFormatting.RED + "Error! Biome '" + args[0] + "' could not be found after " + TextFormatting.GRAY + TraverseConfig.findBiomeCommandTimeout + "ms" + TextFormatting.RED + ".")));
return;
}
if (sender instanceof EntityPlayerMP) {
server.addScheduledTask(() -> {
EntityPlayerMP playerMP = (EntityPlayerMP) sender;
playerMP.connection.setPlayerLocation(pos.getX(), 150, pos.getZ(), 0, 0);
sender.sendMessage(new TextComponentString(TextFormatting.WHITE + "Found '" + finalBiome.getRegistryName().toString() + "' Biome! " + TextFormatting.GRAY + "(" + (System.currentTimeMillis() - start) + "ms)"));
});
return;
}
server.addScheduledTask(() -> sender.sendMessage(new TextComponentString(TextFormatting.RED + "Error! An unknown error occurred.")));
}, "Biome Finder - Traverse").start();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TraverseConfig {
public static boolean registerBiomesRegardless = false;
public static boolean disableCustomSkies = false;
public static boolean vanillaCanyonBlocks = false;
public static int findBiomeCommandTimeout = 20_000;
public static int findBiomeCommandTimeout = 30_000;
public static boolean disallowVillages = false;
public static boolean disallowBoulders = false;

Expand Down

0 comments on commit f8209ce

Please sign in to comment.