Removed Reflection for the TemptEventHandler, Added a "No biome found" state for the biome finder and prevented it from being used multiple times (until the biome on it has been changed)

This commit is contained in:
Adubbz 2014-01-25 23:03:45 +11:00
parent 82d5eb3657
commit 79d1f90628
6 changed files with 137 additions and 134 deletions

View File

@ -1,5 +1,6 @@
package biomesoplenty.client.textures; package biomesoplenty.client.textures;
import biomesoplenty.common.helpers.BOPReflectionHelper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureUtil; import net.minecraft.client.renderer.texture.TextureUtil;
@ -23,29 +24,26 @@ public class TextureBiomeFinder extends TextureAtlasSprite
Minecraft minecraft = Minecraft.getMinecraft(); Minecraft minecraft = Minecraft.getMinecraft();
NBTTagCompound playerData = minecraft.thePlayer != null ? minecraft.thePlayer.getEntityData() : null; NBTTagCompound playerData = minecraft.thePlayer != null ? minecraft.thePlayer.getEntityData() : null;
NBTTagCompound biomePositionsCompound = null; boolean foundBiome = playerData != null ? playerData.getBoolean("foundBiome") : false;
NBTTagCompound biomeCompound = null; NBTTagCompound biomePositionCompound = playerData != null ? playerData.getCompoundTag("biomePosition") : null;
if (playerData != null) biomePositionsCompound = playerData.getCompoundTag("biomePositions");
if (biomePositionsCompound != null) biomeCompound = biomePositionsCompound.getCompoundTag("Lavender Fields");
if (minecraft.theWorld != null && minecraft.thePlayer != null && biomeCompound != null) if (minecraft.theWorld != null && minecraft.thePlayer != null && foundBiome && biomePositionCompound != null)
{ {
this.updateFinder(minecraft.theWorld, biomeCompound.getInteger("x"), biomeCompound.getInteger("z"), minecraft.thePlayer.posX, minecraft.thePlayer.posZ, (double)minecraft.thePlayer.rotationYaw, false, false); this.updateFinder(minecraft.theWorld, biomePositionCompound.getInteger("x"), biomePositionCompound.getInteger("z"), minecraft.thePlayer.posX, minecraft.thePlayer.posZ, (double)minecraft.thePlayer.rotationYaw, false);
} }
else else
{ {
this.updateFinder((World)null, 0, 0, 0.0D, 0.0D, 0.0D, true, false); super.updateAnimation();
} }
} }
public void updateFinder(World par1World, int biomePosX, int biomePosZ, double playerPosX, double playerPosZ, double par6, boolean par8, boolean par9) public void updateFinder(World world, int biomePosX, int biomePosZ, double playerPosX, double playerPosZ, double par6, boolean par8)
{ {
if (!this.framesTextureData.isEmpty()) if (!this.framesTextureData.isEmpty())
{ {
double d3 = 0.0D; double d3 = 0.0D;
if (par1World != null && !par8) if (world != null && !par8)
{ {
double d4 = (double)biomePosX - playerPosX; double d4 = (double)biomePosX - playerPosX;
double d5 = (double)biomePosZ - playerPosZ; double d5 = (double)biomePosZ - playerPosZ;
@ -53,51 +51,45 @@ public class TextureBiomeFinder extends TextureAtlasSprite
d3 = -((par6 - 90.0D) * Math.PI / 180.0D - Math.atan2(d5, d4)); d3 = -((par6 - 90.0D) * Math.PI / 180.0D - Math.atan2(d5, d4));
} }
if (par9) double d6;
{
this.currentAngle = d3;
}
else
{
double d6;
for (d6 = d3 - this.currentAngle; d6 < -Math.PI; d6 += (Math.PI * 2D)) for (d6 = d3 - this.currentAngle; d6 < -Math.PI; d6 += (Math.PI * 2D))
{
;
}
while (d6 >= Math.PI)
{
d6 -= (Math.PI * 2D);
}
if (d6 < -1.0D)
{
d6 = -1.0D;
}
if (d6 > 1.0D)
{
d6 = 1.0D;
}
this.angleDelta += d6 * 0.1D;
this.angleDelta *= 0.8D;
this.currentAngle += this.angleDelta;
}
int i;
for (i = (int)((this.currentAngle / (Math.PI * 2D) + 1.0D) * (double)this.framesTextureData.size()) % this.framesTextureData.size(); i < 0; i = (i + this.framesTextureData.size()) % this.framesTextureData.size())
{ {
; ;
} }
if (i != this.frameCounter) while (d6 >= Math.PI)
{ {
this.frameCounter = i; d6 -= (Math.PI * 2D);
TextureUtil.func_147955_a((int[][])this.framesTextureData.get(this.frameCounter), this.width, this.height, this.originX, this.originY, false, false);
} }
if (d6 < -1.0D)
{
d6 = -1.0D;
}
if (d6 > 1.0D)
{
d6 = 1.0D;
}
this.angleDelta += d6 * 0.1D;
this.angleDelta *= 0.8D;
this.currentAngle += this.angleDelta;
}
int i;
for (i = (int)((this.currentAngle / (Math.PI * 2D) + 1.0D) * (double)this.framesTextureData.size()) % this.framesTextureData.size(); i < 0; i = (i + this.framesTextureData.size()) % this.framesTextureData.size())
{
;
}
if (i != this.frameCounter)
{
this.frameCounter = i;
//TODO: uploadTextureMipmap
TextureUtil.func_147955_a((int[][])this.framesTextureData.get(this.frameCounter), this.width, this.height, this.originX, this.originY, false, false);
} }
} }
} }

View File

@ -24,8 +24,7 @@ public class TemptEventHandler
if (!(entity instanceof EntityLiving)) if (!(entity instanceof EntityLiving))
return; return;
//TODO: FEATURE Remove Reflection EntityAITasks tasks = ((EntityLiving)entity).tasks;
EntityAITasks tasks = BOPReflectionHelper.getPrivateValue(EntityLiving.class, ((EntityLiving)entity), "tasks", "field_70714_bg");
if (entity instanceof EntityChicken) if (entity instanceof EntityChicken)
{ {

View File

@ -16,11 +16,12 @@ public class ConnectionEventHandler
{ {
EntityPlayer player = (EntityPlayer)event.player; EntityPlayer player = (EntityPlayer)event.player;
NBTTagCompound biomeToFindCompound = player.getEntityData().getCompoundTag("biomePositions").getCompoundTag("Lavender Fields"); NBTTagCompound biomeToFindCompound = player.getEntityData().getCompoundTag("biomePosition");
boolean foundBiome = player.getEntityData().getBoolean("foundBiome");
if (biomeToFindCompound != null) if (biomeToFindCompound != null)
{ {
BiomesOPlenty.packetPipeline.sendTo(new PacketBiomePosition("Lavender Fields", biomeToFindCompound.getInteger("x"), biomeToFindCompound.getInteger("z")), (EntityPlayerMP)player); BiomesOPlenty.packetPipeline.sendTo(new PacketBiomePosition(biomeToFindCompound.getInteger("x"), biomeToFindCompound.getInteger("z"), foundBiome), (EntityPlayerMP)player);
} }
} }
} }

View File

@ -12,6 +12,7 @@ import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemRecord; import net.minecraft.item.ItemRecord;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
import net.minecraft.world.World; import net.minecraft.world.World;
import biomesoplenty.BiomesOPlenty; import biomesoplenty.BiomesOPlenty;
@ -85,4 +86,10 @@ public class ItemBOPRecord extends ItemRecord
{ {
return (ItemBOPRecord)records.get(par0Str); return (ItemBOPRecord)records.get(par0Str);
} }
@Override
public ResourceLocation getRecordResource(String name)
{
return new ResourceLocation("biomesoplenty:records/" + name.replace("records.", "") + ".ogg");
}
} }

View File

@ -30,94 +30,100 @@ public class ItemBiomeFinder extends Item
@Override @Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
{ {
if (!world.isRemote) if (!itemStack.hasTagCompound()) itemStack.setTagCompound(new NBTTagCompound());
itemStack.getTagCompound().setInteger("biomeIdToFind", BOPBiomeHelper.getBOPBiome("lavenderFields").biomeID);
int biomeIdToFind = itemStack.getTagCompound().getInteger("biomeIdToFind");
if (!world.isRemote && !player.getEntityData().getBoolean("foundBiome"))
{ {
if (!itemStack.hasTagCompound()) itemStack.setTagCompound(new NBTTagCompound()); //TODO: getBiomeGenArray()
BiomeGenBase biomeToFind = BiomeGenBase.func_150565_n()[biomeIdToFind];
BiomeGenBase biomeToFind = BOPBiomeHelper.getBOPBiome("lavenderFields"); if (biomeToFind != null)
int radius = 256;
WorldChunkManager chunkManager = world.getWorldChunkManager();
ChunkPosition finalFoundPosition1 = null;
int playerX = MathHelper.floor_double(player.posX);
int playerZ = MathHelper.floor_double(player.posZ);
for (int x = 10; x <= 10; x++)
{ {
for (int z = -10; z <= 10; z++) int radius = 256;
WorldChunkManager chunkManager = world.getWorldChunkManager();
ChunkPosition finalFoundPosition1 = null;
int playerX = MathHelper.floor_double(player.posX);
int playerZ = MathHelper.floor_double(player.posZ);
for (int x = 10; x <= 10; x++)
{ {
ChunkPosition foundPosition = chunkManager.func_150795_a(playerX + (x * 1024), playerZ + (z * 1024), radius, Arrays.asList(biomeToFind), world.rand); for (int z = -10; z <= 10; z++)
if (foundPosition != null && world.getBiomeGenForCoords(foundPosition.field_151329_a, foundPosition.field_151328_c) == biomeToFind)
{ {
finalFoundPosition1 = foundPosition; ChunkPosition foundPosition = chunkManager.func_150795_a(playerX + (x * 1024), playerZ + (z * 1024), radius, Arrays.asList(biomeToFind), world.rand);
break;
if (foundPosition != null && world.getBiomeGenForCoords(foundPosition.field_151329_a, foundPosition.field_151328_c) == biomeToFind)
{
finalFoundPosition1 = foundPosition;
break;
}
} }
} }
}
ChunkPosition finalFoundPosition2 = null;
ChunkPosition finalFoundPosition2 = null;
for (int x = -10; x <= 10; x++)
for (int x = -10; x <= 10; x++)
{
for (int z = 10; z >= -10; z--)
{ {
ChunkPosition foundPosition = chunkManager.func_150795_a(playerX + (x * 1024), playerZ + (z * 1024), radius, Arrays.asList(biomeToFind), world.rand); for (int z = 10; z >= -10; z--)
if (foundPosition != null && world.getBiomeGenForCoords(foundPosition.field_151329_a, foundPosition.field_151328_c) == biomeToFind)
{ {
finalFoundPosition2 = foundPosition; ChunkPosition foundPosition = chunkManager.func_150795_a(playerX + (x * 1024), playerZ + (z * 1024), radius, Arrays.asList(biomeToFind), world.rand);
break;
if (foundPosition != null && world.getBiomeGenForCoords(foundPosition.field_151329_a, foundPosition.field_151328_c) == biomeToFind)
{
finalFoundPosition2 = foundPosition;
break;
}
} }
} }
}
ChunkPosition biomePosition = null;
System.out.println((finalFoundPosition1 == null) + " " + (finalFoundPosition2 == null));
if (finalFoundPosition1 != null && finalFoundPosition2 != null)
{
int f1X = finalFoundPosition1.field_151329_a;
int f1Z = finalFoundPosition1.field_151328_c;
int f2X = finalFoundPosition2.field_151329_a; ChunkPosition biomePosition = null;
int f2Z = finalFoundPosition2.field_151328_c;
System.out.println(f1X + " " + f1Z);
System.out.println(f2X + " " + f2Z);
if (Math.sqrt((f1X * f1X) + (f1Z * f1Z)) > Math.sqrt((f2X * f2X) + (f2Z * f2Z))) biomePosition = finalFoundPosition2; System.out.println((finalFoundPosition1 == null) + " " + (finalFoundPosition2 == null));
else biomePosition = finalFoundPosition1;
}
else
{
if (finalFoundPosition1 == null) biomePosition = finalFoundPosition2;
else if (finalFoundPosition2 == null) biomePosition = finalFoundPosition1;
}
if (biomePosition != null) if (finalFoundPosition1 != null && finalFoundPosition2 != null)
{ {
System.out.println(biomePosition.field_151329_a + " " + biomePosition.field_151328_c); int f1X = finalFoundPosition1.field_151329_a;
int f1Z = finalFoundPosition1.field_151328_c;
NBTTagCompound biomeCompound = new NBTTagCompound();
int f2X = finalFoundPosition2.field_151329_a;
biomeCompound.setInteger("x", biomePosition.field_151329_a); int f2Z = finalFoundPosition2.field_151328_c;
biomeCompound.setInteger("z", biomePosition.field_151328_c);
System.out.println(f1X + " " + f1Z);
if (!player.getEntityData().hasKey("biomePositions")) player.getEntityData().setTag("biomePositions", new NBTTagCompound()); System.out.println(f2X + " " + f2Z);
NBTTagCompound biomePositions = player.getEntityData().getCompoundTag("biomePositions"); if (Math.sqrt((f1X * f1X) + (f1Z * f1Z)) > Math.sqrt((f2X * f2X) + (f2Z * f2Z))) biomePosition = finalFoundPosition2;
else biomePosition = finalFoundPosition1;
if (!biomePositions.hasKey(biomeToFind.biomeName)) biomePositions.setTag(biomeToFind.biomeName, biomeCompound); }
else
BiomesOPlenty.packetPipeline.sendTo(new PacketBiomePosition(biomeToFind.biomeName, biomePosition.field_151329_a, biomePosition.field_151328_c), (EntityPlayerMP)player); {
if (finalFoundPosition1 == null) biomePosition = finalFoundPosition2;
else if (finalFoundPosition2 == null) biomePosition = finalFoundPosition1;
}
if (biomePosition != null)
{
System.out.println(biomePosition.field_151329_a + " " + biomePosition.field_151328_c);
NBTTagCompound biomeCompound = new NBTTagCompound();
biomeCompound.setInteger("x", biomePosition.field_151329_a);
biomeCompound.setInteger("z", biomePosition.field_151328_c);
if (!player.getEntityData().hasKey("biomePosition")) player.getEntityData().setTag("biomePosition", biomeCompound);
player.getEntityData().setBoolean("foundBiome", true);
BiomesOPlenty.packetPipeline.sendTo(new PacketBiomePosition(biomePosition.field_151329_a, biomePosition.field_151328_c, true), (EntityPlayerMP)player);
}
System.out.println("Done looking");
} }
System.out.println("Done looking");
} }
return itemStack; return itemStack;

View File

@ -9,33 +9,33 @@ import biomesoplenty.common.network.AbstractPacket;
public class PacketBiomePosition extends AbstractPacket public class PacketBiomePosition extends AbstractPacket
{ {
private String biomeName;
private int x; private int x;
private int z; private int z;
private boolean foundBiome;
public PacketBiomePosition() {} public PacketBiomePosition() {}
public PacketBiomePosition(String biomeName, int x, int z) public PacketBiomePosition(int x, int z, boolean foundBiome)
{ {
this.biomeName = biomeName;
this.x = x; this.x = x;
this.z = z; this.z = z;
this.foundBiome = foundBiome;
} }
@Override @Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
{ {
ByteBufUtils.writeUTF8String(buffer, biomeName);
buffer.writeInt(x); buffer.writeInt(x);
buffer.writeInt(z); buffer.writeInt(z);
buffer.writeBoolean(foundBiome);
} }
@Override @Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
{ {
biomeName = ByteBufUtils.readUTF8String(buffer);
x = buffer.readInt(); x = buffer.readInt();
z = buffer.readInt(); z = buffer.readInt();
foundBiome = buffer.readBoolean();
} }
@Override @Override
@ -46,11 +46,9 @@ public class PacketBiomePosition extends AbstractPacket
biomeCompound.setInteger("x", x); biomeCompound.setInteger("x", x);
biomeCompound.setInteger("z", z); biomeCompound.setInteger("z", z);
if (!player.getEntityData().hasKey("biomePositions")) player.getEntityData().setTag("biomePositions", new NBTTagCompound()); if (!player.getEntityData().hasKey("biomePosition")) player.getEntityData().setTag("biomePosition", biomeCompound);
NBTTagCompound biomePositions = player.getEntityData().getCompoundTag("biomePositions"); player.getEntityData().setBoolean("foundBiome", foundBiome);
if (!biomePositions.hasKey(biomeName)) biomePositions.setTag(biomeName, biomeCompound);
} }
@Override @Override