Search in sources :

Example 1 with MultiBufferSource

use of net.minecraft.client.renderer.MultiBufferSource in project Tropicraft by Tropicraft.

the class PlayerRotationHandler method onRenderPlayer.

@SubscribeEvent
public static void onRenderPlayer(RenderPlayerEvent.Pre event) {
    PoseStack stack = event.getMatrixStack();
    MultiBufferSource buffers = event.getBuffers();
    Player p = event.getPlayer();
    Entity riding = p.getVehicle();
    if (riding instanceof BeachFloatEntity) {
        FurnitureEntity floaty = (FurnitureEntity) riding;
        stack.pushPose();
        stack.mulPose(Vector3f.YP.rotationDegrees(-(floaty.yRotO + (event.getPartialRenderTick() * (floaty.getYRot() - floaty.yRotO)))));
        stack.translate(0, 1.55, 1.55);
        stack.mulPose(Vector3f.XN.rotationDegrees(90));
        // Cancel out player camera rotation
        float f = interpolateAndWrap(p.yBodyRot, p.yBodyRotO, event.getPartialRenderTick());
        stack.mulPose(Vector3f.YP.rotationDegrees(f));
        // Lock in head
        rotationYawHead = p.yHeadRot;
        prevRotationYawHead = p.yHeadRotO;
        p.yHeadRot = p.yBodyRot;
        p.yHeadRotO = p.yBodyRotO;
        rotationPitch = p.getXRot();
        prevRotationPitch = p.xRotO;
        p.setXRot(10f);
        p.xRotO = 10f;
        // Cancel limb swing
        p.animationPosition = 0;
        p.animationSpeed = 0;
        p.animationSpeedOld = 0;
    }
    if (riding instanceof SeaTurtleEntity) {
        SeaTurtleEntity turtle = (SeaTurtleEntity) riding;
        stack.pushPose();
        // Cancel out player camera rotation
        float pitch = interpolateAndWrap(turtle.getXRot(), turtle.xRotO, event.getPartialRenderTick());
        float yaw = interpolateAndWrap(turtle.yHeadRot, turtle.yHeadRotO, event.getPartialRenderTick());
        stack.translate(0, turtle.getPassengersRidingOffset() - p.getMyRidingOffset(), 0);
        stack.mulPose(Vector3f.YN.rotationDegrees(yaw));
        // TODO figure out why this budging is needed
        stack.translate(0, -0.1, 0);
        stack.mulPose(Vector3f.XP.rotationDegrees(pitch));
        stack.translate(0, 0.1, 0);
        stack.mulPose(Vector3f.YP.rotationDegrees(yaw));
        stack.translate(0, -turtle.getPassengersRidingOffset() + p.getMyRidingOffset(), 0);
        Vec3 passengerOffset = (new Vec3(-0.25f, 0.0D, 0.0D)).yRot((float) (-Math.toRadians(yaw) - (Math.PI / 2)));
        stack.translate(passengerOffset.x(), 0, passengerOffset.z());
        // Lock in head
        rotationPitch = p.getXRot();
        prevRotationPitch = p.xRotO;
        p.setXRot(10f);
        p.xRotO = 10f;
    }
}
Also used : BeachFloatEntity(net.tropicraft.core.common.entity.placeable.BeachFloatEntity) Entity(net.minecraft.world.entity.Entity) FurnitureEntity(net.tropicraft.core.common.entity.placeable.FurnitureEntity) SeaTurtleEntity(net.tropicraft.core.common.entity.SeaTurtleEntity) Player(net.minecraft.world.entity.player.Player) PoseStack(com.mojang.blaze3d.vertex.PoseStack) FurnitureEntity(net.tropicraft.core.common.entity.placeable.FurnitureEntity) Vec3(net.minecraft.world.phys.Vec3) MultiBufferSource(net.minecraft.client.renderer.MultiBufferSource) BeachFloatEntity(net.tropicraft.core.common.entity.placeable.BeachFloatEntity) SeaTurtleEntity(net.tropicraft.core.common.entity.SeaTurtleEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 MultiBufferSource (net.minecraft.client.renderer.MultiBufferSource)1 Entity (net.minecraft.world.entity.Entity)1 Player (net.minecraft.world.entity.player.Player)1 Vec3 (net.minecraft.world.phys.Vec3)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 SeaTurtleEntity (net.tropicraft.core.common.entity.SeaTurtleEntity)1 BeachFloatEntity (net.tropicraft.core.common.entity.placeable.BeachFloatEntity)1 FurnitureEntity (net.tropicraft.core.common.entity.placeable.FurnitureEntity)1