Improve biome finder code
This commit is contained in:
parent
d9c2cb4291
commit
620d101668
1 changed files with 50 additions and 16 deletions
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
package biomesoplenty.common.item;
|
package biomesoplenty.common.item;
|
||||||
|
|
||||||
import biomesoplenty.api.biome.BOPBiomes;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -64,36 +63,71 @@ public class ItemBiomeFinder extends Item
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||||
{
|
{
|
||||||
if (world.isRemote) {return stack;} // TODO: can we make it client only and skip this?
|
// carry out the search on the server, not the client
|
||||||
|
if (world.isRemote) {return stack;}
|
||||||
|
|
||||||
if (!stack.hasTagCompound()) {stack.setTagCompound(new NBTTagCompound());}
|
if (!stack.hasTagCompound()) {stack.setTagCompound(new NBTTagCompound());}
|
||||||
int biomeIDToFind = stack.getTagCompound().getInteger("biomeIDToFind");
|
NBTTagCompound nbt = stack.getTagCompound();
|
||||||
BiomeGenBase biomeToFind = BiomeGenBase.getBiome(biomeIDToFind); // returns ocean if biomeIDToFind is out of bounds
|
|
||||||
System.out.println("Using biome finder looking for "+biomeToFind.biomeName);
|
if (nbt.getBoolean("found"))
|
||||||
if (stack.getTagCompound().getBoolean("foundBiome"))
|
|
||||||
{
|
{
|
||||||
System.out.println("Already found, returning");
|
System.out.println("Already found, returning");
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
biomeToFind = BOPBiomes.originValley.get();
|
if (nbt.hasKey("searchStarted") && (world.getWorldTime() - nbt.getLong("searchStarted") < 200))
|
||||||
// search for biomeToFind, maximum distace 5000 blocks, 64 blocks between samples
|
{
|
||||||
BlockPos pos = this.spiralOutwardsLookingForBiome(world, biomeToFind, player.posX, player.posZ, 5000, 64);
|
System.out.println("Still searching, returning");
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
if (!nbt.hasKey("biomeIDToFind"))
|
||||||
|
{
|
||||||
|
System.out.println("No biome to find, returning");
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
BiomeGenBase biomeToFind = BiomeGenBase.getBiome(nbt.getInteger("biomeIDToFind")); // returns ocean if biomeIDToFind is out of bounds
|
||||||
|
System.out.println("Biome finder looking for "+biomeToFind.biomeName);
|
||||||
|
writeNBTSearching(nbt, world);
|
||||||
|
|
||||||
|
// search for biomeToFind, maximum distance 5000 blocks, 64 blocks between samples
|
||||||
|
BlockPos pos = this.spiralOutwardsLookingForBiome(world, biomeToFind, player.posX, player.posZ, 5000, 64);
|
||||||
if (pos == null)
|
if (pos == null)
|
||||||
{
|
{
|
||||||
//System.out.println("Didn't find it");
|
writeNBTNotFound(nbt);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stack.getTagCompound().setInteger("posX", pos.getX());
|
writeNBTFound(nbt, pos);
|
||||||
stack.getTagCompound().setInteger("posY", pos.getY());
|
|
||||||
stack.getTagCompound().setBoolean("foundBiome", true);
|
|
||||||
// TODO: BOPPacketHandler.instance.sendTo(new MessageBiomePosition(pos), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void writeNBTSearching(NBTTagCompound nbt, World world)
|
||||||
|
{
|
||||||
|
nbt.setBoolean("found",false);
|
||||||
|
nbt.setLong("searchStarted", world.getWorldTime());
|
||||||
|
nbt.removeTag("posX");
|
||||||
|
nbt.removeTag("posZ");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeNBTFound(NBTTagCompound nbt, BlockPos pos)
|
||||||
|
{
|
||||||
|
nbt.setBoolean("found",true);
|
||||||
|
nbt.removeTag("searchStarted");
|
||||||
|
nbt.setInteger("posX", pos.getX());
|
||||||
|
nbt.setInteger("posZ", pos.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeNBTNotFound(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
|
nbt.setBoolean("found",false);
|
||||||
|
nbt.removeTag("searchStarted");
|
||||||
|
nbt.removeTag("posX");
|
||||||
|
nbt.removeTag("posZ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* TODO: all the rendering stuff... not sure how it's going to work
|
/* TODO: all the rendering stuff... not sure how it's going to work
|
||||||
public class TextureBiomeFinder extends TextureAtlasSprite
|
public class TextureBiomeFinder extends TextureAtlasSprite
|
||||||
|
|
Loading…
Reference in a new issue