Search in sources :

Example 1 with Upgrade

use of xyz.przemyk.simpleplanes.upgrades.Upgrade in project simple-planes by przemykomo.

the class CommonEventHandler method interact.

@SubscribeEvent
public static void interact(PlayerInteractEvent.RightClickItem event) {
    Player player = event.getPlayer();
    Entity entity = player.getRootVehicle();
    if (entity instanceof PlaneEntity) {
        ItemStack itemStack = player.getItemInHand(event.getHand());
        if (!itemStack.isEmpty()) {
            if (itemStack.getItem() == Items.TNT && entity instanceof LargePlaneEntity && ((LargePlaneEntity) entity).tryToAddTNT(player, itemStack)) {
                return;
            }
            PlaneEntity planeEntity = (PlaneEntity) entity;
            for (Upgrade upgrade : planeEntity.upgrades.values()) {
                upgrade.onItemRightClick(event);
            }
        }
    }
}
Also used : Entity(net.minecraft.world.entity.Entity) LargePlaneEntity(xyz.przemyk.simpleplanes.entities.LargePlaneEntity) PlaneEntity(xyz.przemyk.simpleplanes.entities.PlaneEntity) Player(net.minecraft.world.entity.player.Player) LargePlaneEntity(xyz.przemyk.simpleplanes.entities.LargePlaneEntity) PlaneEntity(xyz.przemyk.simpleplanes.entities.PlaneEntity) LargePlaneEntity(xyz.przemyk.simpleplanes.entities.LargePlaneEntity) ItemStack(net.minecraft.world.item.ItemStack) Upgrade(xyz.przemyk.simpleplanes.upgrades.Upgrade) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with Upgrade

use of xyz.przemyk.simpleplanes.upgrades.Upgrade in project simple-planes by przemykomo.

the class PlaneRenderer method render.

@Override
public void render(T planeEntity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) {
    poseStack.pushPose();
    poseStack.translate(0.0D, 0.375D, 0.0D);
    poseStack.scale(-1.0F, -1.0F, 1.0F);
    poseStack.translate(0, -0.5, 0);
    poseStack.mulPose(Vector3f.YP.rotationDegrees(180));
    double firstPersonYOffset = -0.7D;
    boolean isPlayerRidingInFirstPersonView = Minecraft.getInstance().player != null && planeEntity.hasPassenger(Minecraft.getInstance().player) && (Minecraft.getInstance()).options.cameraType == CameraType.FIRST_PERSON;
    if (isPlayerRidingInFirstPersonView) {
        poseStack.translate(0.0D, firstPersonYOffset, 0.0D);
    }
    Quaternion q = MathUtil.lerpQ(partialTicks, planeEntity.getQ_Prev(), planeEntity.getQ_Client());
    poseStack.mulPose(q);
    float rockingAngle = planeEntity.getRockingAngle(partialTicks);
    if (!Mth.equal(rockingAngle, 0.0F)) {
        poseStack.mulPose(new Quaternion(new Vector3f(1.0F, 0.0F, 1.0F), rockingAngle, true));
    }
    float f = (float) planeEntity.getTimeSinceHit() - partialTicks;
    float f1 = planeEntity.getDamageTaken() - partialTicks;
    if (f1 < 0.1F) {
        f1 = 0.1F;
    }
    if (f > 0.0F) {
        float angle = Mth.clamp(f * f1 / 200.0F, -30, 30);
        f = planeEntity.tickCount + partialTicks;
        poseStack.mulPose(Vector3f.ZP.rotationDegrees(Mth.sin(f) * angle));
    }
    poseStack.translate(0, -0.6, 0);
    if (isPlayerRidingInFirstPersonView) {
        poseStack.translate(0.0D, -firstPersonYOffset, 0.0D);
    }
    VertexConsumer vertexConsumer = buffer.getBuffer(planeEntityModel.renderType(getMaterialTexture(planeEntity)));
    planeEntityModel.setupAnim(planeEntity, partialTicks, 0, 0, 0, 0);
    planeEntityModel.renderToBuffer(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
    for (Upgrade upgrade : planeEntity.upgrades.values()) {
        upgrade.render(poseStack, buffer, packedLight, partialTicks);
    }
    vertexConsumer = ItemRenderer.getArmorFoilBuffer(buffer, planeEntityModel.renderType(PROPELLER_TEXTURE), false, planeEntity.isNoGravity());
    propellerModel.setupAnim(planeEntity, partialTicks, 0, 0, 0, 0);
    propellerModel.renderToBuffer(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
    poseStack.pushPose();
    poseStack.popPose();
    poseStack.popPose();
    super.render(planeEntity, 0, partialTicks, poseStack, buffer, packedLight);
}
Also used : Quaternion(com.mojang.math.Quaternion) Vector3f(com.mojang.math.Vector3f) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) Upgrade(xyz.przemyk.simpleplanes.upgrades.Upgrade)

Aggregations

Upgrade (xyz.przemyk.simpleplanes.upgrades.Upgrade)2 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)1 Quaternion (com.mojang.math.Quaternion)1 Vector3f (com.mojang.math.Vector3f)1 Entity (net.minecraft.world.entity.Entity)1 Player (net.minecraft.world.entity.player.Player)1 ItemStack (net.minecraft.world.item.ItemStack)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 LargePlaneEntity (xyz.przemyk.simpleplanes.entities.LargePlaneEntity)1 PlaneEntity (xyz.przemyk.simpleplanes.entities.PlaneEntity)1