Search in sources :

Example 1 with EntityBeachFloat

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);
}
Also used : MessagePlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData) PlayerSwimData(net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData) EntityBeachFloat(net.tropicraft.core.common.entity.placeable.EntityBeachFloat) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityTropicraftWaterBase(net.tropicraft.core.common.entity.underdasea.atlantoku.EntityTropicraftWaterBase) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with EntityBeachFloat

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();
}
Also used : EntityBeachFloat(net.tropicraft.core.common.entity.placeable.EntityBeachFloat) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with EntityBeachFloat

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;
    }
}
Also used : EntityBeachFloat(net.tropicraft.core.common.entity.placeable.EntityBeachFloat) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with EntityBeachFloat

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());
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityBeachFloat(net.tropicraft.core.common.entity.placeable.EntityBeachFloat) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with EntityBeachFloat

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);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityBeachFloat(net.tropicraft.core.common.entity.placeable.EntityBeachFloat) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EntityBeachFloat (net.tropicraft.core.common.entity.placeable.EntityBeachFloat)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 Entity (net.minecraft.entity.Entity)2 Block (net.minecraft.block.Block)1 ItemStack (net.minecraft.item.ItemStack)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1 EntityTropicraftWaterBase (net.tropicraft.core.common.entity.underdasea.atlantoku.EntityTropicraftWaterBase)1 MessagePlayerSwimData (net.tropicraft.core.common.network.MessagePlayerSwimData)1 PlayerSwimData (net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData)1