blob: 091d660252294ffe2058bfcb4ec5b37f346b1932 [file] [log] [blame] [raw]
package com.legacy.aether.client;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.legacy.aether.common.entities.passive.mountable.EntityAerbunny;
import com.legacy.aether.common.player.PlayerAether;
public class AetherEntityRenderer extends EntityRenderer
{
private Entity pointedEntity;
private Minecraft mc;
public AetherEntityRenderer(Minecraft mc, IResourceManager resources)
{
super(mc, resources);
this.mc = mc;
}
@Override
public void getMouseOver(float partialTick)
{
EntityPlayer entityPlayer = this.mc.thePlayer;
if (this.mc.thePlayer != null && entityPlayer.inventory.getCurrentItem() != null && PlayerAether.get(entityPlayer) != null && PlayerAether.get(entityPlayer).getReach() == 10.0D)
{
this.getExtendedReach(partialTick);
}
else if (this.mc.thePlayer != null && !this.mc.thePlayer.getPassengers().isEmpty() && this.mc.thePlayer.getPassengers().get(0) instanceof EntityAerbunny)
{
this.getMountRightClick(partialTick);
}
else
{
super.getMouseOver(partialTick);
}
}
private void getMountRightClick(float partialTick)
{
Entity entity = this.mc.getRenderViewEntity();
if (entity != null)
{
if (this.mc.theWorld != null)
{
this.mc.mcProfiler.startSection("pick");
this.mc.pointedEntity = null;
double d0 = (double)this.mc.playerController.getBlockReachDistance();
this.mc.objectMouseOver = entity.rayTrace(d0, partialTick);
double d1 = d0;
Vec3d vec3d = entity.getPositionEyes(partialTick);
boolean flag = false;
if (this.mc.playerController.extendedReach())
{
d0 = 6.0D;
d1 = 6.0D;
}
else
{
if (d0 > 3.0D)
{
flag = true;
}
}
if (this.mc.objectMouseOver != null)
{
d1 = this.mc.objectMouseOver.hitVec.distanceTo(vec3d);
}
Vec3d vec3d1 = entity.getLook(partialTick);
Vec3d vec3d2 = vec3d.addVector(vec3d1.xCoord * d0, vec3d1.yCoord * d0, vec3d1.zCoord * d0);
this.pointedEntity = null;
Vec3d vec3d3 = null;
float f = 1.0F;
List<Entity> list = this.mc.theWorld.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().addCoord(vec3d1.xCoord * d0, vec3d1.yCoord * d0, vec3d1.zCoord * d0).expand((double)f, (double)f, (double)f), Predicates.and(EntitySelectors.NOT_SPECTATING, new Predicate<Entity>()
{
public boolean apply(@Nullable Entity p_apply_1_)
{
return p_apply_1_ != null;
}
}));
double d2 = d1;
for (int j = 0; j < list.size(); ++j)
{
Entity entity1 = (Entity)list.get(j);
AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expandXyz((double)entity1.getCollisionBorderSize());
RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(vec3d, vec3d2);
if (axisalignedbb.isVecInside(vec3d))
{
if (d2 >= 0.0D)
{
this.pointedEntity = entity1;
vec3d3 = raytraceresult == null ? vec3d : raytraceresult.hitVec;
d2 = 0.0D;
}
}
else if (raytraceresult != null)
{
double d3 = vec3d.distanceTo(raytraceresult.hitVec);
if (d3 < d2 || d2 == 0.0D)
{
if (d2 == 0.0D)
{
this.pointedEntity = entity1;
vec3d3 = raytraceresult.hitVec;
}
else
{
this.pointedEntity = entity1;
vec3d3 = raytraceresult.hitVec;
d2 = d3;
}
}
}
}
if (this.pointedEntity != null && flag && vec3d.distanceTo(vec3d3) > 3.0D)
{
this.pointedEntity = null;
this.mc.objectMouseOver = new RayTraceResult(RayTraceResult.Type.MISS, vec3d3, (EnumFacing)null, new BlockPos(vec3d3));
}
if (this.pointedEntity != null && (d2 < d1 || this.mc.objectMouseOver == null))
{
this.mc.objectMouseOver = new RayTraceResult(this.pointedEntity, vec3d3);
if (this.pointedEntity instanceof EntityLivingBase || this.pointedEntity instanceof EntityItemFrame)
{
this.mc.pointedEntity = this.pointedEntity;
}
}
this.mc.mcProfiler.endSection();
}
}
}
private void getExtendedReach(float partialTicks)
{
Entity entity = this.mc.getRenderViewEntity();
if (entity != null)
{
if (this.mc.theWorld != null)
{
this.mc.mcProfiler.startSection("pick");
this.mc.pointedEntity = null;
double d0 = 10.0D;
this.mc.objectMouseOver = entity.rayTrace(d0, partialTicks);
double d1 = d0;
Vec3d vec3d = entity.getPositionEyes(partialTicks);
boolean flag = false;
if (this.mc.objectMouseOver != null)
{
d1 = this.mc.objectMouseOver.hitVec.distanceTo(vec3d);
}
Vec3d vec3d1 = entity.getLook(partialTicks);
Vec3d vec3d2 = vec3d.addVector(vec3d1.xCoord * d0, vec3d1.yCoord * d0, vec3d1.zCoord * d0);
this.pointedEntity = null;
Vec3d vec3d3 = null;
float f = 1.0F;
List<Entity> list = this.mc.theWorld.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().addCoord(vec3d1.xCoord * d0, vec3d1.yCoord * d0, vec3d1.zCoord * d0).expand((double)f, (double)f, (double)f), Predicates.and(EntitySelectors.NOT_SPECTATING, new Predicate<Entity>()
{
public boolean apply(@Nullable Entity p_apply_1_)
{
return p_apply_1_ != null;
}
}));
double d2 = d1;
for (int j = 0; j < list.size(); ++j)
{
Entity entity1 = (Entity)list.get(j);
AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expandXyz((double)entity1.getCollisionBorderSize());
RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(vec3d, vec3d2);
if (axisalignedbb.isVecInside(vec3d))
{
if (d2 >= 0.0D)
{
this.pointedEntity = entity1;
vec3d3 = raytraceresult == null ? vec3d : raytraceresult.hitVec;
d2 = 0.0D;
}
}
else if (raytraceresult != null)
{
double d3 = vec3d.distanceTo(raytraceresult.hitVec);
if (d3 < d2 || d2 == 0.0D)
{
if (d2 == 0.0D)
{
this.pointedEntity = entity1;
vec3d3 = raytraceresult.hitVec;
}
else
{
this.pointedEntity = entity1;
vec3d3 = raytraceresult.hitVec;
d2 = d3;
}
}
}
}
if (this.pointedEntity != null && flag && vec3d.distanceTo(vec3d3) > 3.0D)
{
this.pointedEntity = null;
this.mc.objectMouseOver = new RayTraceResult(RayTraceResult.Type.MISS, vec3d3, (EnumFacing)null, new BlockPos(vec3d3));
}
if (this.pointedEntity != null && (d2 < d1 || this.mc.objectMouseOver == null))
{
this.mc.objectMouseOver = new RayTraceResult(this.pointedEntity, vec3d3);
if (this.pointedEntity instanceof EntityLivingBase || this.pointedEntity instanceof EntityItemFrame)
{
this.mc.pointedEntity = this.pointedEntity;
}
}
this.mc.mcProfiler.endSection();
}
}
}
}