diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java new file mode 100644 index 000000000..e876ccfd3 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java @@ -0,0 +1,99 @@ +package com.atsuishio.superbwarfare.client.overlay; + +import com.atsuishio.superbwarfare.ModUtils; +import com.atsuishio.superbwarfare.entity.IHelicopterEntity; +import com.atsuishio.superbwarfare.entity.MobileVehicleEntity; +import com.atsuishio.superbwarfare.network.ModVariables; +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Axis; +import net.minecraft.client.Camera; +import net.minecraft.client.CameraType; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.Vec3; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.RenderGuiEvent; +import net.minecraftforge.eventbus.api.EventPriority; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +import java.text.DecimalFormat; + +import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; + +@Mod.EventBusSubscriber(value = Dist.CLIENT) +public class HelicopterHudOverlay { + + private static float scopeScale = 1; + private static float lerpVy = 1; + private static float lerpPower = 1; + + @SubscribeEvent(priority = EventPriority.LOWEST) + public static void eventHandler(RenderGuiEvent.Pre event) { + int w = event.getWindow().getGuiScaledWidth(); + int h = event.getWindow().getGuiScaledHeight(); + Player player = Minecraft.getInstance().player; + Minecraft mc = Minecraft.getInstance(); + Camera camera = mc.gameRenderer.getMainCamera(); + Vec3 cameraPos = camera.getPosition(); + PoseStack poseStack = event.getGuiGraphics().pose(); + + if (player != null) { + + if (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).edit) + return; + + if (player.getVehicle() instanceof IHelicopterEntity iHelicopterEntity && player.getVehicle() instanceof MobileVehicleEntity mobileVehicle && iHelicopterEntity.isDriver(player) && Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) { + RenderSystem.disableDepthTest(); + RenderSystem.depthMask(false); + RenderSystem.enableBlend(); + RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + RenderSystem.setShaderColor(1, 1, 1, 1); + scopeScale = Mth.lerp(event.getPartialTick(), scopeScale, 1F); + float f = (float) Math.min(w, h); + float f1 = Math.min((float) w / f, (float) h / f) * scopeScale; + float i = Mth.floor(f * f1); + float j = Mth.floor(f * f1); + float k = ((w - i) / 2); + float l = ((h - j) / 2); + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/helicopter/heli_base.png"), k, l, 0, 0.0F, i, j, i, j); + + poseStack.pushPose(); + poseStack.rotateAround(Axis.ZP.rotationDegrees(-iHelicopterEntity.getRotZ(event.getPartialTick())),w / 2f, h / 2f, 0); + float pitch = iHelicopterEntity.getRotX(event.getPartialTick()); +// player.displayClientMessage(Component.literal("Angle:" + new java.text.DecimalFormat("##").format(pitch)), true); + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/helicopter/heli_line.png"), (float) w / 2 - 128, (float) h / 2 - 512 - 5.475f * pitch, 0, 0, 256, 1024, 256, 1024); + poseStack.popPose(); + poseStack.pushPose(); + poseStack.rotateAround(Axis.ZP.rotationDegrees(-iHelicopterEntity.getRotZ(event.getPartialTick())),w / 2f, h / 2f - 56, 0); + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/helicopter/roll_ind.png"), (float) w / 2 - 8, (float) h / 2 - 88, 0, 0, 16, 16, 16, 16); + poseStack.popPose(); + + event.getGuiGraphics().blit(ModUtils.loc("textures/screens/helicopter/heli_power_ruler.png"), w / 2 + 100, h / 2 - 64, 0, 0, 64, 128, 64, 128); + + float power = iHelicopterEntity.getPower(); + lerpPower = Mth.lerp(0.001f * event.getPartialTick(), lerpPower, power); + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/helicopter/heli_power.png"), (float) w / 2 + 130f, ((float) h / 2 - 64 + 124 - power * 900), 0, 0, 4, power * 900, 4, power * 900); + lerpVy = (float) Mth.lerp(0.021f * event.getPartialTick(), lerpVy, mobileVehicle.getDeltaMovement().y() + 0.06f); + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/helicopter/heli_vy_move.png"), (float) w / 2 + 100, ((float) h / 2 - 64 - Math.max(lerpVy, 0) * 100f), 0, 0, 64, 128, 64, 128); + event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##").format(mobileVehicle.getY())), + w / 2 + 104, h / 2, 0x66FF00, false); + preciseBlit(event.getGuiGraphics(), ModUtils.loc("textures/screens/helicopter/speed_frame.png"), (float) w / 2 - 144, (float) h / 2 - 6, 0, 0, 50, 18, 50, 18); + event.getGuiGraphics().drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##").format(length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y + 0.06, mobileVehicle.getDeltaMovement().z) * 72) + "KM/H"), + w / 2 - 140, h / 2, 0x66FF00, false); + } else { + scopeScale = 0.7f; + } + } + } + + public static double length(double x, double y,double z) { + return Math.sqrt(x * x + y * y + z * z); + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/Ah6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/Ah6Entity.java index 8b2b3b8ce..2190504d6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/Ah6Entity.java @@ -37,7 +37,7 @@ import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache import software.bernie.geckolib.core.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; -public class Ah6Entity extends MobileVehicleEntity implements GeoEntity { +public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelicopterEntity { private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public static final float MAX_HEALTH = 200; @@ -89,11 +89,11 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity { this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.06, 0.0)); if (this.onGround()) { this.setDeltaMovement(this.getDeltaMovement().multiply(0.6, 0.95, 0.6)); - this.setZRot(this.roll * 0.4f); - this.setXRot(this.getXRot() * 0.4f); + this.setZRot(this.roll * 0.7f); + this.setXRot(this.getXRot() * 0.7f); } else { - float f = (float) Mth.clamp(0.93f + 0.03f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90, 0.01, 0.99); - this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).scale(0.03 * this.getDeltaMovement().length()))); + float f = (float) Mth.clamp(0.945f + 0.02f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90, 0.01, 0.99); + this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).scale(0.032 * this.getDeltaMovement().length()))); this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.95, f)); } this.refreshDimensions(); @@ -110,48 +110,55 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity { this.rightInputDown = false; this.forwardInputDown = false; this.backInputDown = false; + this.setZRot(this.roll * 0.8f); + this.setXRot(this.getXRot() * 0.8f); + this.entityData.set(POWER, this.entityData.get(POWER) * 0.98f); } else if (passenger instanceof Player player) { if (level().isClientSide && this.getEnergy() > 0) { level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), this.getEngineSound(), this.getSoundSource(), Math.min((this.forwardInputDown || this.backInputDown ? 7.5f : 5f) * 2 * Mth.abs(this.entityData.get(POWER)), 0.25f), (random.nextFloat() * 0.1f + 1f), false); } - if (!this.onGround()) { - diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot())); - diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot())); + diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot())); + diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot())); - if (rightInputDown) { - this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) - 0.8f); - } else if (this.leftInputDown) { - this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) + 0.8f); - } - - this.setYRot(this.getYRot() + 0.75f * diffY); - this.setXRot(Mth.clamp(this.getXRot() + 0.5f * diffX, -85, 85)); - this.setZRot(Mth.clamp(this.getRoll() - this.entityData.get(DELTA_ROT) + 0.2f * diffY, -85, 85)); + if (rightInputDown) { + this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) - 0.15f); + } else if (this.leftInputDown) { + this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) + 0.15f); } + this.setYRot(this.getYRot() + Mth.clamp((this.onGround() ? 0.1f : 1.2f) * diffY * this.entityData.get(POWER) + 0.5f * this.entityData.get(DELTA_ROT), -3f, 3f)); + this.setXRot(Mth.clamp(this.getXRot() + (this.onGround() ? 0 : 1.2f) * diffX * this.entityData.get(POWER), -80, 80)); + this.setZRot(Mth.clamp(this.getRoll() - this.entityData.get(DELTA_ROT) + (this.onGround() ? 0 : 0.75f) * diffY * this.entityData.get(POWER), -50, 50)); + if (this.upInputDown || this.forwardInputDown) { - this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.005f, 0.12f)); + this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.002f, 0.12f)); } if (this.downInputDown || this.backInputDown) { - this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.005f, 0)); + this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0015f, 0)); } -// player.displayClientMessage(Component.literal("Power:" + new java.text.DecimalFormat("##.####").format(this.entityData.get(POWER))), true); +// player.displayClientMessage(Component.literal("Angle:" + new java.text.DecimalFormat("##.##").format(this.getDeltaMovement().y())), true); + + if(!(this.upInputDown || this.forwardInputDown || this.downInputDown || this.backInputDown)) { + if (this.getDeltaMovement().y() + 0.06 < 0) { + this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0005f, 0.12f)); + } else { + this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0005f, 0)); + } + } } - this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.9f); - this.entityData.set(POWER, this.entityData.get(POWER) * 0.9998f); + this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.95f); - - setDeltaMovement(getDeltaMovement().add(0.0f, Math.sin((90 - this.getXRot()) * Mth.DEG_TO_RAD) * this.entityData.get(POWER), 0.0f)); + setDeltaMovement(getDeltaMovement().add(0.0f, Math.min(Math.sin((90 - this.getXRot()) * Mth.DEG_TO_RAD), Math.sin((90 + this.getRoll()) * Mth.DEG_TO_RAD)) * this.entityData.get(POWER), 0.0f)); Vector3f direction = getRightDirection().mul(Math.cos((this.getRoll() + 90) * Mth.DEG_TO_RAD) * this.entityData.get(POWER)); - setDeltaMovement(getDeltaMovement().add(new Vec3(direction.x, direction.y, direction.z).scale(0.8))); + setDeltaMovement(getDeltaMovement().add(new Vec3(direction.x, direction.y, direction.z).scale(0.4))); Vector3f directionZ = getForwardDirection().mul(-Math.cos((this.getXRot() + 90) * Mth.DEG_TO_RAD) * this.entityData.get(POWER)); - setDeltaMovement(getDeltaMovement().add(new Vec3(directionZ.x, directionZ.y, directionZ.z).scale(0.5))); + setDeltaMovement(getDeltaMovement().add(new Vec3(directionZ.x, directionZ.y, directionZ.z).scale(0.35))); } @Override @@ -167,7 +174,7 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity { entity.setYBodyRot(this.getYRot()); float f2 = Mth.wrapDegrees(entity.getYRot() - this.getYRot()); - float f3 = Mth.clamp(f2, -10.0F, 10.0F); + float f3 = Mth.clamp(f2, -60.0F, 60.0F); entity.yRotO += f3 - f2; entity.setYRot(entity.getYRot() + f3 - f2); entity.setYHeadRot(entity.getYRot()); @@ -248,4 +255,49 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity { public int getMaxEnergy() { return MAX_ENERGY; } + + @Override + public void vehicleShoot(Player player) { + } + + @Override + public boolean isDriver(Player player) { + return player == this.getFirstPassenger(); + } + + @Override + public int mainGunRpm() { + return 360; + } + + @Override + public boolean canShoot(Player player) { + return false; + } + + @Override + public int getAmmoCount(Player player) { + return -1; + } + + + @Override + public float getRotX(float tickDelta) { + return this.getPitch(tickDelta); + } + + @Override + public float getRotY(float tickDelta) { + return this.getYaw(tickDelta); + } + + @Override + public float getRotZ(float tickDelta) { + return this.getRoll(tickDelta); + } + + @Override + public float getPower() { + return this.entityData.get(POWER); + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/IHelicopterEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/IHelicopterEntity.java new file mode 100644 index 000000000..5479e90a2 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/entity/IHelicopterEntity.java @@ -0,0 +1,8 @@ +package com.atsuishio.superbwarfare.entity; + +public interface IHelicopterEntity extends IArmedVehicleEntity { + float getRotX(float tickDelta); + float getRotY(float tickDelta); + float getRotZ(float tickDelta); + float getPower(); +} diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/VehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/VehicleEntity.java index ac4668db0..299a262aa 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/VehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/VehicleEntity.java @@ -46,6 +46,14 @@ public class VehicleEntity extends Entity { return Mth.lerp(0.6f * tickDelta, prevRoll, getRoll()); } + public float getYaw(float tickDelta) { + return Mth.lerp(0.6f * tickDelta, yRotO, getYRot()); + } + + public float getPitch(float tickDelta) { + return Mth.lerp(0.6f * tickDelta, xRotO, getXRot()); + } + public void setZRot(float rot) { roll = rot; } @@ -190,7 +198,7 @@ public class VehicleEntity extends Entity { super.baseTick(); prevRoll = this.getRoll(); - setZRot(roll * 0.8f); + setZRot(roll * 0.9f); float delta = Math.abs(getYRot() - yRotO); while (getYRot() > 180F) { diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index 24bf0f71f..607b7b42a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -3,10 +3,7 @@ package com.atsuishio.superbwarfare.event; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.config.client.DisplayConfig; -import com.atsuishio.superbwarfare.entity.DroneEntity; -import com.atsuishio.superbwarfare.entity.IArmedVehicleEntity; -import com.atsuishio.superbwarfare.entity.ICannonEntity; -import com.atsuishio.superbwarfare.entity.SpeedboatEntity; +import com.atsuishio.superbwarfare.entity.*; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.network.ModVariables; @@ -1287,6 +1284,10 @@ public class ClientEventHandler { ItemStack stack = mc.player.getMainHandItem(); + if (mc.player.getVehicle() instanceof Ah6Entity && mc.player.getVehicle() instanceof IHelicopterEntity iHelicopterEntity && iHelicopterEntity .isDriver(mc.player)) { + event.setCanceled(true); + } + if (mc.player.getVehicle() instanceof SpeedboatEntity && zoom) { event.setCanceled(true); } diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/MouseHandlerMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/MouseHandlerMixin.java index 32e5be714..16249ccba 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/MouseHandlerMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/MouseHandlerMixin.java @@ -50,8 +50,8 @@ public class MouseHandlerMixin { } } - if (player.getVehicle() instanceof Ah6Entity) { - return 0.25; + if (player.getVehicle() instanceof Ah6Entity ah6Entity && !ah6Entity.onGround()) { + return 0.24; } if (stack.is(ModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) { diff --git a/src/main/resources/assets/superbwarfare/textures/screens/helicopter/drone_fov_move.png b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/drone_fov_move.png new file mode 100644 index 000000000..03236ac0e Binary files /dev/null and b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/drone_fov_move.png differ diff --git a/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_base.png b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_base.png new file mode 100644 index 000000000..bb30277fa Binary files /dev/null and b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_base.png differ diff --git a/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_line.png b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_line.png new file mode 100644 index 000000000..8c076246f Binary files /dev/null and b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_line.png differ diff --git a/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_power.png b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_power.png new file mode 100644 index 000000000..0b8e16616 Binary files /dev/null and b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_power.png differ diff --git a/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_power_ruler.png b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_power_ruler.png new file mode 100644 index 000000000..11f049c1c Binary files /dev/null and b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_power_ruler.png differ diff --git a/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_vy_move.png b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_vy_move.png new file mode 100644 index 000000000..148c60fb0 Binary files /dev/null and b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/heli_vy_move.png differ diff --git a/src/main/resources/assets/superbwarfare/textures/screens/helicopter/roll_ind.png b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/roll_ind.png new file mode 100644 index 000000000..e666deb8d Binary files /dev/null and b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/roll_ind.png differ diff --git a/src/main/resources/assets/superbwarfare/textures/screens/helicopter/speed_frame.png b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/speed_frame.png new file mode 100644 index 000000000..4fb8ec4f6 Binary files /dev/null and b/src/main/resources/assets/superbwarfare/textures/screens/helicopter/speed_frame.png differ