Make biome indicator non-static
This commit is contained in:
@@ -11,77 +11,85 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.world.biome.Biome;
|
import net.minecraft.world.biome.Biome;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public class BiomeIndicator
|
public class BiomeIndicator
|
||||||
{
|
{
|
||||||
private static final Set<String> BIOMES;
|
private final Set<String> biomes = new HashSet<String>();
|
||||||
private static String CURRENT_BIOME;
|
private String currentBiome;
|
||||||
private static int TICKS;
|
private int ticksRemaining;
|
||||||
|
|
||||||
static
|
public BiomeIndicator()
|
||||||
{
|
{
|
||||||
Set<String> pool = new HashSet<String>();
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init()
|
||||||
|
{
|
||||||
|
Set<String> biomes = new HashSet<String>();
|
||||||
|
|
||||||
for(ResourceLocation location : Biome.REGISTRY.getKeys())
|
for(ResourceLocation location : Biome.REGISTRY.getKeys())
|
||||||
{
|
{
|
||||||
pool.add(filterName(Biome.REGISTRY.getObject(location).getBiomeName()));
|
biomes.add(this.filterName(Biome.REGISTRY.getObject(location).getBiomeName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
BIOMES = new HashSet<String>(pool);
|
this.biomes.addAll(biomes);
|
||||||
|
|
||||||
for(String biome : pool)
|
for(String biome : biomes)
|
||||||
{
|
{
|
||||||
for(String index : pool)
|
for(String index : biomes)
|
||||||
{
|
{
|
||||||
if(index.matches(biome + "([A-Za-z ])+") || index.matches("([A-Za-z ])+ " + biome))
|
if(index.matches(biome + "([A-Za-z ])+") || index.matches("([A-Za-z ])+ " + biome))
|
||||||
{
|
{
|
||||||
BIOMES.remove(index);
|
this.biomes.remove(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BIOMES.remove("River");
|
this.biomes.remove("River");
|
||||||
BIOMES.remove("Beach");
|
this.biomes.remove("Beach");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void tick()
|
public void tick()
|
||||||
{
|
{
|
||||||
int posX = MathHelper.floor(Minecraft.getMinecraft().player.posX);
|
int posX = MathHelper.floor(Minecraft.getMinecraft().player.posX);
|
||||||
int posY = MathHelper.floor(Minecraft.getMinecraft().player.posY);
|
int posY = MathHelper.floor(Minecraft.getMinecraft().player.posY);
|
||||||
int posZ = MathHelper.floor(Minecraft.getMinecraft().player.posZ);
|
int posZ = MathHelper.floor(Minecraft.getMinecraft().player.posZ);
|
||||||
|
|
||||||
BlockPos pos = new BlockPos(posX, posY, posZ);
|
BlockPos pos = new BlockPos(posX, posY, posZ);
|
||||||
|
|
||||||
if(Minecraft.getMinecraft().world != null && Minecraft.getMinecraft().world.isBlockLoaded(pos))
|
if(Minecraft.getMinecraft().world != null && Minecraft.getMinecraft().world.isBlockLoaded(pos))
|
||||||
{
|
{
|
||||||
Chunk chunk = Minecraft.getMinecraft().world.getChunkFromBlockCoords(pos);
|
Chunk chunk = Minecraft.getMinecraft().world.getChunkFromBlockCoords(pos);
|
||||||
String biome = getBaseBiome(filterName(chunk.getBiome(pos, Minecraft.getMinecraft().world.getBiomeProvider()).getBiomeName()));
|
String biome = this.getBaseBiome(this.filterName(chunk.getBiome(pos, Minecraft.getMinecraft().world.getBiomeProvider()).getBiomeName()));
|
||||||
|
|
||||||
if(TICKS == 0 && biome != null)
|
if(this.ticksRemaining == 0 && biome != null)
|
||||||
{
|
{
|
||||||
if(CURRENT_BIOME == null || !CURRENT_BIOME.equals(biome))
|
if(this.currentBiome == null || !this.currentBiome.equals(biome))
|
||||||
{
|
{
|
||||||
Minecraft.getMinecraft().ingameGUI.displayTitle(biome, null, 20, 60, 20);
|
Minecraft.getMinecraft().ingameGUI.displayTitle(biome, null, 20, 60, 20);
|
||||||
TICKS = 100;
|
this.ticksRemaining = 100;
|
||||||
CURRENT_BIOME = biome;
|
this.currentBiome = biome;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(TICKS > 0)
|
else if(this.ticksRemaining > 0)
|
||||||
{
|
{
|
||||||
TICKS--;
|
this.ticksRemaining--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String filterName(String biome)
|
private String filterName(String biome)
|
||||||
{
|
{
|
||||||
return biome.replaceAll("([a-z])([A-Z])", "$1 $2").replaceAll("[^A-Za-z ]", "").replaceAll("( [A-Z])$", "");
|
return biome.replaceAll("([a-z])([A-Z])", "$1 $2").replaceAll("[^A-Za-z ]", "").replaceAll("( [A-Z])$", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static String getBaseBiome(String input)
|
private String getBaseBiome(String input)
|
||||||
{
|
{
|
||||||
for(String biome : BIOMES)
|
for(String biome : this.biomes)
|
||||||
{
|
{
|
||||||
if(input.matches("([A-Za-z ])*" + biome + "([A-Za-z ])*"))
|
if(input.matches("([A-Za-z ])*" + biome + "([A-Za-z ])*"))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user