Biome Finder complete.

This commit is contained in:
Adubbz 2014-01-29 14:27:02 +11:00
parent ce8e333252
commit 3d85b36a46
4 changed files with 79 additions and 254 deletions

View File

@ -9,7 +9,6 @@ import net.minecraft.client.particle.EntityBreakingFX;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraft.util.MathHelper;
import net.minecraftforge.client.MinecraftForgeClient;
import biomesoplenty.api.BOPItemHelper;
import biomesoplenty.client.particles.EntityDandelionFX;
import biomesoplenty.client.particles.EntityMagicTreeFX;
@ -29,7 +28,6 @@ import biomesoplenty.client.render.entities.RenderPixie;
import biomesoplenty.client.render.entities.RenderRosester;
import biomesoplenty.client.render.entities.RenderWasp;
import biomesoplenty.client.render.entities.projectiles.RenderDart;
import biomesoplenty.client.render.items.BiomeFinderRenderer;
import biomesoplenty.common.configuration.BOPConfigurationIDs;
import biomesoplenty.common.entities.EntityBird;
import biomesoplenty.common.entities.EntityGlob;
@ -93,8 +91,6 @@ public class ClientProxy extends CommonProxy
{
RenderingRegistry.registerEntityRenderingHandler(EntityPixie.class, new RenderPixie());
}
MinecraftForgeClient.registerItemRenderer(BOPItemHelper.get("biomeFinder"), new BiomeFinderRenderer());
RenderingRegistry.registerBlockHandler(new FoliageRenderer());
RenderingRegistry.registerBlockHandler(new PlantsRenderer());

View File

@ -1,149 +0,0 @@
package biomesoplenty.client.render.items;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.IItemRenderer;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import biomesoplenty.api.BOPItemHelper;
import biomesoplenty.client.render.RenderUtils;
import biomesoplenty.common.items.ItemBiomeFinder;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BiomeFinderRenderer implements IItemRenderer
{
private static ResourceLocation radarLocation = new ResourceLocation("biomesoplenty:textures/items/biomeradarstatic.png");
private double[] currentAngles = new double[BiomeGenBase.func_150565_n().length];
private double[] angleDeltas = new double[BiomeGenBase.func_150565_n().length];
@Override
@SideOnly(Side.CLIENT)
public boolean handleRenderType(ItemStack item, ItemRenderType type)
{
return (type.equals(IItemRenderer.ItemRenderType.EQUIPPED_FIRST_PERSON)) || (type.equals(IItemRenderer.ItemRenderType.INVENTORY)) || (type.equals(IItemRenderer.ItemRenderType.EQUIPPED)) || (type.equals(IItemRenderer.ItemRenderType.ENTITY));
}
@Override
@SideOnly(Side.CLIENT)
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper)
{
return type == IItemRenderer.ItemRenderType.ENTITY;
}
@Override
@SideOnly(Side.CLIENT)
public void renderItem(ItemRenderType type, ItemStack item, Object... data)
{
GL11.glPushMatrix();
Tessellator tessellator = Tessellator.instance;
NBTTagCompound stackCompound = item != null ? item.getTagCompound() : null;
int biomeID = stackCompound != null ? stackCompound.getInteger("biomeIDToFind") : 0;
boolean foundBiome = stackCompound != null ? stackCompound.getBoolean("foundBiome") : false;
NBTTagCompound biomePositionCompound = stackCompound != null ? stackCompound.getCompoundTag("biomePosition") : null;
ItemBiomeFinder biomeFinder = ((ItemBiomeFinder)BOPItemHelper.get("biomeFinder"));
IIcon radarIcon = foundBiome ? biomeFinder.biomeRadarIcons[getIconIndexFacingBiome(biomeID, biomePositionCompound)] : biomeFinder.getIconFromDamage(0);
if (type.equals(IItemRenderer.ItemRenderType.ENTITY))
{
GL11.glTranslated(-0.5D, -0.1D, 0.0D);
}
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
texturemanager.bindTexture(texturemanager.getResourceLocation(item.getItemSpriteNumber()));
GL11.glBlendFunc(770, 771);
if (type.equals(IItemRenderer.ItemRenderType.INVENTORY))
{
RenderUtils.renderIcon(radarIcon, 16.0D, 0.001D, 0.0F, 0.0F, -1.0F);
}
else
{
ItemRenderer.renderItemIn2D(tessellator, radarIcon.getMaxU(), radarIcon.getMinV(), radarIcon.getMinU(), radarIcon.getMaxV(), radarIcon.getIconWidth(), radarIcon.getIconHeight(), 0.0625F);
}
GL11.glPopMatrix();
}
@SideOnly(Side.CLIENT)
private int getIconIndexFacingBiome(int biomeID, NBTTagCompound biomePositionCompound)
{
Minecraft minecraft = Minecraft.getMinecraft();
World world = minecraft.theWorld;
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (biomePositionCompound != null)
{
double playerPosX = player.posX;
double playerPosZ = player.posZ;
int biomePosX = biomePositionCompound.getInteger("x");
int biomePosZ = biomePositionCompound.getInteger("z");
System.out.println(biomePosX);
double d3 = 0.0D;
if (world != null)
{
double d4 = (double)biomePosX - playerPosX;
double d5 = (double)biomePosZ - playerPosZ;
player.rotationYaw %= 360.0D;
d3 = -((player.rotationYaw - 90.0D) * Math.PI / 180.0D - Math.atan2(d5, d4));
}
double d6;
for (d6 = d3 - this.currentAngles[biomeID]; 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.angleDeltas[biomeID] += d6 * 0.1D;
this.angleDeltas[biomeID] *= 0.8D;
this.currentAngles[biomeID] += this.angleDeltas[biomeID];
int i;
for (i = (int)((this.currentAngles[biomeID] / (Math.PI * 2D) + 1.0D) * (double)32) % 32; i < 0; i = (i + 32) % 32)
{
;
}
return i;
}
return 0;
}
}

View File

@ -1,95 +0,0 @@
package biomesoplenty.client.textures;
import biomesoplenty.common.helpers.BOPReflectionHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class TextureBiomeFinder extends TextureAtlasSprite
{
public double currentAngle;
public double angleDelta;
public TextureBiomeFinder(String path)
{
super(path);
}
@Override
public void updateAnimation()
{
Minecraft minecraft = Minecraft.getMinecraft();
NBTTagCompound playerData = minecraft.thePlayer != null ? minecraft.thePlayer.getEntityData() : null;
boolean foundBiome = playerData != null ? playerData.getBoolean("foundBiome") : false;
NBTTagCompound biomePositionCompound = playerData != null ? playerData.getCompoundTag("biomePosition") : null;
if (minecraft.theWorld != null && minecraft.thePlayer != null && foundBiome && biomePositionCompound != null)
{
this.updateFinder(minecraft.theWorld, biomePositionCompound.getInteger("x"), biomePositionCompound.getInteger("z"), minecraft.thePlayer.posX, minecraft.thePlayer.posZ, (double)minecraft.thePlayer.rotationYaw, false);
}
else
{
super.updateAnimation();
}
}
public void updateFinder(World world, int biomePosX, int biomePosZ, double playerPosX, double playerPosZ, double par6, boolean par8)
{
if (!this.framesTextureData.isEmpty())
{
double d3 = 0.0D;
if (world != null && !par8)
{
double d4 = (double)biomePosX - playerPosX;
double d5 = (double)biomePosZ - playerPosZ;
par6 %= 360.0D;
d3 = -((par6 - 90.0D) * Math.PI / 180.0D - Math.atan2(d5, d4));
}
double d6;
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)
{
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

@ -26,11 +26,8 @@ public class ItemBiomeFinder extends Item
{
public IIcon[] biomeRadarIcons = new IIcon[32];
private int tickCount = 0;
private int loopIndex = 0;
public double currentAngle;
public double angleDelta;
private double[] currentAngles = new double[BiomeGenBase.func_150565_n().length];
private double[] angleDeltas = new double[BiomeGenBase.func_150565_n().length];
public ItemBiomeFinder()
{
@ -118,7 +115,7 @@ public class ItemBiomeFinder extends Item
if (biomePosition != null)
{
System.out.println(biomePosition.field_151329_a + " " + biomePosition.field_151328_c);
//System.out.println(biomePosition.field_151329_a + " " + biomePosition.field_151328_c);
NBTTagCompound biomeCompound = new NBTTagCompound();
@ -149,6 +146,34 @@ public class ItemBiomeFinder extends Item
itemIcon = iconRegister.registerIcon("biomesoplenty:biomefinder");
}
@Override
public boolean requiresMultipleRenderPasses()
{
return true;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(ItemStack itemStack, int renderPass)
{
Minecraft minecraft = Minecraft.getMinecraft();
World world = minecraft.theWorld;
EntityPlayer player = minecraft.thePlayer;
NBTTagCompound stackCompound = itemStack != null ? itemStack.getTagCompound() : null;
if (world != null && player != null && stackCompound != null && stackCompound.hasKey("biomeIDToFind") && stackCompound.hasKey("foundBiome"))
{
int biomeID = stackCompound.getInteger("biomeIDToFind");
boolean foundBiome = stackCompound.getBoolean("foundBiome");
NBTTagCompound biomePositionCompound = stackCompound.getCompoundTag("biomePosition");
if (foundBiome) return this.biomeRadarIcons[getIconIndexFacingBiome(world, player, biomePositionCompound.getInteger("x"), biomePositionCompound.getInteger("z"), biomeID)];
}
return itemIcon;
}
@Override
public void addInformation(ItemStack itemStack, EntityPlayer player, List infoList, boolean advancedItemTooltips)
{
@ -173,4 +198,52 @@ public class ItemBiomeFinder extends Item
}
}
}
public int getIconIndexFacingBiome(World world, EntityPlayer player, int biomePosX, int biomePosZ, int biomeID)
{
double d3 = 0.0D;
if (world != null)
{
double d4 = (double)biomePosX - player.posX;
double d5 = (double)biomePosZ - player.posZ;
player.rotationYaw %= 360.0D;
d3 = -((player.rotationYaw - 90.0D) * Math.PI / 180.0D - Math.atan2(d5, d4));
}
double d6;
for (d6 = d3 - this.currentAngles[biomeID]; 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.angleDeltas[biomeID] += d6 * 0.1D;
this.angleDeltas[biomeID] *= 0.8D;
this.currentAngles[biomeID] += this.angleDeltas[biomeID];
int i;
for (i = (int)((this.currentAngles[biomeID] / (Math.PI * 2D) + 1.0D) * (double)32) % 32; i < 0; i = (i + 32) % 32)
{
;
}
return i;
}
}