use of net.tropicraft.core.common.entity.placeable.EntityBeachFloat in project Tropicraft by Tropicraft.
the class ScubaHandler method onRenderPlayer.
@SubscribeEvent
public void onRenderPlayer(RenderPlayerEvent.Pre event) {
if (inGUI) {
return;
}
EntityPlayer p = event.getEntityPlayer();
PlayerSwimData d = getData(p);
if (p.isElytraFlying() || p.getRidingEntity() instanceof EntityBeachFloat) {
return;
}
updateSwimRenderAngles(p);
boolean inLiquid = isInWater(p) && isInWater(p, 0, 0.4D, 0);
if (inLiquid) {
if (!p.onGround && isPlayerWearingFlippers(p)) {
p.limbSwingAmount = 0.2f + (d.currentSwimSpeed / 20);
}
} else {
if (d.currentRotationPitch == 0f && d.currentRotationRoll == 0f) {
return;
}
}
GlStateManager.pushMatrix();
boolean isSelf = d.playerUUID.equals(Minecraft.getMinecraft().player.getUniqueID());
GlStateManager.translate(0, 1.5f, 0f);
if (p.isRiding() && p.getRidingEntity() instanceof EntityTropicraftWaterBase) {
d.currentRotationYaw = 0f;
d.currentRotationRoll = 0f;
d.currentHeadPitchOffset = 0f;
d.currentRotationPitch = 0f;
d.rotationYawHead = 90f;
}
if (isSelf) {
GlStateManager.rotate(d.currentRotationYaw, 0f, -1f, 0f);
GlStateManager.rotate(d.currentRotationPitch, 1f, 0f, 0f);
GlStateManager.rotate(d.currentRotationRoll, 0f, 0f, -1f);
} else {
GlStateManager.translate(event.getX(), event.getY(), event.getZ());
GlStateManager.rotate(d.currentRotationYaw, 0f, -1f, 0f);
GlStateManager.rotate(d.currentRotationPitch, 1f, 0f, 0f);
GlStateManager.rotate(d.currentRotationRoll, 0f, 0f, -1f);
GlStateManager.translate(-event.getX(), -event.getY(), -event.getZ());
}
GlStateManager.translate(0, -1.5f, 0f);
updateSwimDataAngles(p);
clearPlayerRenderAngles(p);
}
use of net.tropicraft.core.common.entity.placeable.EntityBeachFloat in project Tropicraft by Tropicraft.
the class ScubaHandler method onRenderPlayer.
@SubscribeEvent
public void onRenderPlayer(RenderPlayerEvent.Post event) {
if (inGUI) {
return;
}
if (event.getEntityPlayer().isElytraFlying() || event.getEntityPlayer().getRidingEntity() instanceof EntityBeachFloat) {
return;
}
EntityPlayer p = event.getEntityPlayer();
boolean inLiquid = isInWater(p) && isInWater(p, 0, 0.4D, 0);
if (!inLiquid) {
if (getData(p).currentRotationPitch == 0f && getData(p).currentRotationRoll == 0f) {
return;
}
}
restorePlayerRenderAngles(p);
GlStateManager.popMatrix();
}
use of net.tropicraft.core.common.entity.placeable.EntityBeachFloat in project Tropicraft by Tropicraft.
the class RenderBeachFloat method onRenderPlayerPost.
@SubscribeEvent
public void onRenderPlayerPost(RenderPlayerEvent.Post event) {
EntityPlayer p = event.getEntityPlayer();
if (p.getRidingEntity() instanceof EntityBeachFloat) {
GlStateManager.popMatrix();
p.rotationPitch = rotationPitch;
p.prevRotationPitch = prevRotationPitch;
}
}
use of net.tropicraft.core.common.entity.placeable.EntityBeachFloat in project Tropicraft by Tropicraft.
the class RenderBeachFloat method onRenderPlayer.
@SubscribeEvent
public void onRenderPlayer(RenderPlayerEvent.Pre event) {
EntityPlayer p = event.getEntityPlayer();
Entity riding = p.getRidingEntity();
if (riding instanceof EntityBeachFloat) {
EntityBeachFloat floaty = (EntityBeachFloat) riding;
GlStateManager.pushMatrix();
if (p != Minecraft.getMinecraft().getRenderViewEntity()) {
GlStateManager.translate(event.getX(), event.getY(), event.getZ());
}
GlStateManager.rotate(-(floaty.prevRotationYaw + (event.getPartialRenderTick() * (floaty.rotationYaw - floaty.prevRotationYaw))), 0, 1, 0);
GlStateManager.translate(0, 1.55, 1.55);
GlStateManager.rotate(-90, 1, 0, 0);
// Cancel out player camera rotation
float f = p.renderYawOffset - p.prevRenderYawOffset;
while (f < -180) f += 360;
while (f >= 180) f -= 360;
f = p.prevRenderYawOffset + (event.getPartialRenderTick() * f);
GlStateManager.rotate(f, 0, 1, 0);
// Lock in head
p.rotationYawHead = p.renderYawOffset;
p.prevRotationYawHead = p.prevRenderYawOffset;
rotationPitch = p.rotationPitch;
prevRotationPitch = p.prevRotationPitch;
p.rotationPitch = 10f;
p.prevRotationPitch = 10f;
if (p != Minecraft.getMinecraft().getRenderViewEntity()) {
GlStateManager.translate(-event.getX(), -event.getY(), -event.getZ());
}
}
}
use of net.tropicraft.core.common.entity.placeable.EntityBeachFloat in project Tropicraft by Tropicraft.
the class ItemBeachFloat method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
ItemStack stack = playerIn.getHeldItem(hand);
float f = 1.0F;
float f1 = playerIn.prevRotationPitch + (playerIn.rotationPitch - playerIn.prevRotationPitch) * f;
float f2 = playerIn.prevRotationYaw + (playerIn.rotationYaw - playerIn.prevRotationYaw) * f;
double d0 = playerIn.prevPosX + (playerIn.posX - playerIn.prevPosX) * (double) f;
double d1 = playerIn.prevPosY + (playerIn.posY - playerIn.prevPosY) * (double) f + (double) playerIn.getEyeHeight();
double d2 = playerIn.prevPosZ + (playerIn.posZ - playerIn.prevPosZ) * (double) f;
Vec3d vec3d = new Vec3d(d0, d1, d2);
float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI);
float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI);
float f5 = -MathHelper.cos(-f1 * 0.017453292F);
float f6 = MathHelper.sin(-f1 * 0.017453292F);
float f7 = f4 * f5;
float f8 = f3 * f5;
double d3 = 5.0D;
Vec3d vec3d1 = vec3d.addVector((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
RayTraceResult raytraceresult = worldIn.rayTraceBlocks(vec3d, vec3d1, true);
if (raytraceresult == null) {
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
} else {
Vec3d vec3d2 = playerIn.getLook(f);
boolean flag = false;
List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity(playerIn, playerIn.getEntityBoundingBox().expand(vec3d2.x * d3, vec3d2.y * d3, vec3d2.z * d3).grow(1.0D));
for (int i = 0; i < list.size(); ++i) {
Entity entity = (Entity) list.get(i);
if (entity.canBeCollidedWith()) {
AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().grow((double) entity.getCollisionBorderSize());
if (axisalignedbb.contains(vec3d)) {
flag = true;
}
}
}
if (flag) {
return new ActionResult<>(EnumActionResult.PASS, stack);
} else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK) {
return new ActionResult<>(EnumActionResult.PASS, stack);
} else {
Block block = worldIn.getBlockState(raytraceresult.getBlockPos()).getBlock();
boolean flag1 = block == Blocks.WATER || block == Blocks.FLOWING_WATER;
double x = raytraceresult.hitVec.x;
double y = flag1 ? raytraceresult.hitVec.y - 0.12D : raytraceresult.hitVec.y;
double z = raytraceresult.hitVec.z;
int color = ColorHelper.getColorFromDamage(stack.getItemDamage());
EntityBeachFloat beachFloat = new EntityBeachFloat(worldIn, x, y, z, color, playerIn);
if (!worldIn.getCollisionBoxes(beachFloat, beachFloat.getEntityBoundingBox().grow(-0.1D)).isEmpty()) {
return new ActionResult<>(EnumActionResult.FAIL, stack);
} else {
if (!worldIn.isRemote) {
worldIn.spawnEntity(beachFloat);
}
if (!playerIn.capabilities.isCreativeMode) {
stack.shrink(1);
}
playerIn.addStat(StatList.getObjectUseStats(this));
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
}
}
}
Aggregations