优化lavHUD
This commit is contained in:
parent
c4aa45fb32
commit
7017edf4c1
6 changed files with 96 additions and 25 deletions
|
@ -49,7 +49,7 @@ public class DragonTeethBlock extends Block {
|
|||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
|
||||
return Shapes.or(box(2, 0, 2, 14, 24, 14));
|
||||
return Shapes.or(box(2, 0, 2, 14, 25, 14));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,10 +3,13 @@ package com.atsuishio.superbwarfare.client.overlay;
|
|||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.tools.SeekTool;
|
||||
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.gui.GuiGraphics;
|
||||
|
@ -14,7 +17,10 @@ import net.minecraft.client.renderer.GameRenderer;
|
|||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderGuiEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
|
@ -25,6 +31,7 @@ import org.joml.Math;
|
|||
import java.text.DecimalFormat;
|
||||
|
||||
import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
|
||||
import static com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity.HEAT;
|
||||
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||
public class LandArmorHudOverlay {
|
||||
|
@ -41,12 +48,14 @@ public class LandArmorHudOverlay {
|
|||
Player player = mc.player;
|
||||
GuiGraphics guiGraphics = event.getGuiGraphics();
|
||||
PoseStack poseStack = guiGraphics.pose();
|
||||
Camera camera = mc.gameRenderer.getMainCamera();
|
||||
Vec3 cameraPos = camera.getPosition();
|
||||
|
||||
if (player == null) return;
|
||||
if (player.getVehicle() instanceof Lav150Entity lav150 && lav150.isDriver(player)) {
|
||||
poseStack.pushPose();
|
||||
|
||||
poseStack.translate(-6 * ClientEventHandler.turnRot[1], -6 * ClientEventHandler.turnRot[0], 0);
|
||||
poseStack.translate(-8 * ClientEventHandler.turnRot[1], -8 * ClientEventHandler.turnRot[0], 0);
|
||||
RenderSystem.disableDepthTest();
|
||||
RenderSystem.depthMask(false);
|
||||
RenderSystem.enableBlend();
|
||||
|
@ -67,25 +76,74 @@ public class LandArmorHudOverlay {
|
|||
int addH = (w / h) * 27;
|
||||
preciseBlit(guiGraphics, FRAME, (float) -addW / 2, (float) -addH / 2, 10, 0, 0.0F, w + addW, h + addH, w + addW, h + addH);
|
||||
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_cross.png"), k, l, 0, 0.0F, i, j, i, j);
|
||||
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/compass.png"), (float) w / 2 - 128, (float) 10, 128 + ((float) 64 / 45 * player.getYRot()), 0, 256, 16, 512, 16);
|
||||
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/helicopter/roll_ind.png"), w / 2 - 8, 30, 0, 0.0F, 16, 16, 16, 16);
|
||||
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2 - 64, h - 56, 0, 0.0F, 128, 1, 128, 1);
|
||||
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2 + 112, h - 71, 0, 0.0F, 1, 16, 1, 16);
|
||||
|
||||
//指南针
|
||||
|
||||
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/compass.png"), (float) w / 2 - 128, (float) 10, 128 + ((float) 64 / 45 * player.getYRot()), 0, 256, 16, 512, 16);
|
||||
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/helicopter/roll_ind.png"), w / 2 - 8, 30, 0, 0.0F, 16, 16, 16, 16);
|
||||
|
||||
//炮塔方向
|
||||
|
||||
poseStack.pushPose();
|
||||
poseStack.rotateAround(Axis.ZP.rotationDegrees(Mth.lerp(event.getPartialTick(), lav150.turretYRotO, lav150.getTurretYRot())),w / 2 + 112, h - 56, 0);
|
||||
preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/body.png"), w / 2 + 96, h - 72, 0, 0.0F, 32, 32, 32, 32);
|
||||
poseStack.popPose();
|
||||
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##").format(lav150.getDeltaMovement().length() * 72) + " KM/H"),
|
||||
//时速
|
||||
|
||||
guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("##").format(lav150.getDeltaMovement().length() * 72) + " KM/H"),
|
||||
w / 2 + 160, h / 2 - 48, 0x66FF00, false);
|
||||
|
||||
//低电量警告
|
||||
|
||||
if (lav150.getEnergy() < 0.02 * lav150.getMaxEnergy()) {
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("NO POWER!"),
|
||||
guiGraphics.drawString(mc.font, Component.literal("NO POWER!"),
|
||||
w / 2 - 144, h / 2 + 14, -65536, false);
|
||||
} else if (lav150.getEnergy() < 0.2 * lav150.getMaxEnergy()) {
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("LOW POWER"),
|
||||
guiGraphics.drawString(mc.font, Component.literal("LOW POWER"),
|
||||
w / 2 - 144, h / 2 + 14, 0xFF6B00, false);
|
||||
}
|
||||
|
||||
//测距
|
||||
|
||||
boolean lookAtEntity = false;
|
||||
double blockRange = cameraPos.distanceTo((Vec3.atLowerCornerOf(player.level().clip(
|
||||
new ClipContext(player.getEyePosition(), player.getEyePosition().add(lav150.getBarrelVector(1).scale(520)),
|
||||
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos())));
|
||||
|
||||
double entityRange = 0;
|
||||
|
||||
Entity lookingEntity = SeekTool.seekLivingEntity(player, player.level(), 512, 1);
|
||||
if (lookingEntity != null) {
|
||||
lookAtEntity = true;
|
||||
entityRange = player.distanceTo(lookingEntity);
|
||||
}
|
||||
|
||||
if (lookAtEntity) {
|
||||
guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("##").format(entityRange)),
|
||||
w / 2 - 6, h - 53, 0x66FF00, false);
|
||||
} else {
|
||||
if (blockRange > 512) {
|
||||
guiGraphics.drawString(mc.font, Component.literal("---"), w / 2 - 6, h - 53, 0x66FF00, false);
|
||||
} else {
|
||||
guiGraphics.drawString(mc.font, Component.literal(new DecimalFormat("##").format(blockRange)),
|
||||
w / 2 - 6, h - 53, 0x66FF00, false);
|
||||
}
|
||||
}
|
||||
|
||||
//武器名称
|
||||
|
||||
if (player.getVehicle() instanceof Lav150Entity lav) {
|
||||
double heat = 1 - lav.getEntityData().get(HEAT) / 100.0F;
|
||||
guiGraphics.drawString(mc.font, Component.literal("20MM CANNON " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : lav.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false);
|
||||
}
|
||||
|
||||
//血量
|
||||
|
||||
double heal = lav150.getHealth() / lav150.getMaxHealth();
|
||||
guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##").format(100 * lav150.getHealth() / lav150.getMaxHealth())), w / 2 - 165, h / 2 - 46, Mth.hsvToRgb((float) heal / 3.745318352059925F, 1.0F, 1.0F), false);
|
||||
}
|
||||
|
||||
poseStack.popPose();
|
||||
|
|
|
@ -133,7 +133,7 @@ public class VehicleConfig {
|
|||
AH_6_MAX_ENERGY = builder.defineInRange("ah_6_max_energy", 4000000, 0, 2147483647);
|
||||
|
||||
builder.comment("The cannon damage of AH-6");
|
||||
AH_6_CANNON_DAMAGE = builder.defineInRange("ah_6_cannon_damage", 15, 1, 10000000);
|
||||
AH_6_CANNON_DAMAGE = builder.defineInRange("ah_6_cannon_damage", 25, 1, 10000000);
|
||||
|
||||
builder.comment("The rocket damage of AH-6");
|
||||
AH_6_ROCKET_DAMAGE = builder.defineInRange("ah_6_rocket_damage", 75, 1, 10000000);
|
||||
|
|
|
@ -66,7 +66,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
|||
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
|
||||
|
||||
public static final float MAX_HEALTH = 850;
|
||||
public static final int MAX_ENERGY = VehicleConfig.SPEEDBOAT_MAX_ENERGY.get();
|
||||
public static final int MAX_ENERGY = 2000000;
|
||||
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
public float turretYRot;
|
||||
|
@ -133,7 +133,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
|||
amount *= 0.7f;
|
||||
}
|
||||
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
|
||||
this.hurt(0.5f * Math.max(amount - 25, 0));
|
||||
this.hurt(0.5f * Math.max(amount - 15, 0));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
|||
this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0));
|
||||
|
||||
if (this.onGround()) {
|
||||
float f0 = 0.44f + 0.25f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90 - 0.02f * Mth.abs(this.getRudderRot());
|
||||
float f0 = 0.54f + 0.25f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90 - 0.02f * Mth.abs(this.getRudderRot());
|
||||
this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).normalize().scale(0.05 * this.getDeltaMovement().horizontalDistance())));
|
||||
this.setDeltaMovement(this.getDeltaMovement().multiply(f0, 0.85, f0));
|
||||
} else if (this.isInWater()) {
|
||||
|
@ -243,13 +243,13 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
|||
|
||||
float x = -0.0234375f;
|
||||
float y = 0f;
|
||||
float z = 3f;
|
||||
float z = 4f;
|
||||
|
||||
Vector4f worldPosition = transformPosition(transform, x, y, z);
|
||||
SmallCannonShellEntity smallCannonShell = new SmallCannonShellEntity(player, this.level(),
|
||||
58,
|
||||
36,
|
||||
22,
|
||||
3.5f);
|
||||
3f);
|
||||
|
||||
smallCannonShell.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z);
|
||||
smallCannonShell.shoot(getBarrelVector(1).x, getBarrelVector(1).y + 0.005f, getBarrelVector(1).z, 22,
|
||||
|
@ -277,7 +277,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
|||
}
|
||||
}
|
||||
|
||||
this.entityData.set(HEAT, this.entityData.get(HEAT) + 10);
|
||||
this.entityData.set(HEAT, this.entityData.get(HEAT) + 7);
|
||||
this.entityData.set(FIRE_ANIM, 3);
|
||||
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
||||
}
|
||||
|
@ -302,7 +302,17 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
|||
AABB aabb = AABB.ofSize(new Vec3(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ()), 3.6, 2.6, 3.6);
|
||||
BlockPos.betweenClosedStream(aabb).forEach((pos) -> {
|
||||
BlockState blockstate = this.level().getBlockState(pos);
|
||||
if (blockstate.is(Blocks.LILY_PAD) || blockstate.is(Blocks.ICE) || blockstate.is(Blocks.FROSTED_ICE)) {
|
||||
if (blockstate.is(Blocks.LILY_PAD) || blockstate.is(Blocks.ICE) || blockstate.is(Blocks.FROSTED_ICE)
|
||||
// || blockstate.is(Blocks.BAMBOO)
|
||||
// || blockstate.is(Blocks.GLASS_PANE)
|
||||
// || blockstate.getBlock() instanceof FenceBlock
|
||||
// || blockstate.getBlock() instanceof DoorBlock
|
||||
// || blockstate.getBlock() instanceof LeavesBlock
|
||||
// || blockstate.getBlock() instanceof FenceGateBlock
|
||||
// || blockstate.getBlock() instanceof BambooSaplingBlock
|
||||
// || blockstate.getBlock() instanceof GlassBlock
|
||||
// || blockstate.getBlock() instanceof StainedGlassPaneBlock
|
||||
) {
|
||||
this.level().destroyBlock(pos, true);
|
||||
}
|
||||
});
|
||||
|
@ -319,6 +329,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
|||
this.rightInputDown = false;
|
||||
this.forwardInputDown = false;
|
||||
this.backInputDown = false;
|
||||
this.entityData.set(POWER, 0f);
|
||||
}
|
||||
|
||||
if (forwardInputDown) {
|
||||
|
@ -545,7 +556,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
|||
|
||||
@Override
|
||||
public int mainGunRpm() {
|
||||
return 180;
|
||||
return 300;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -776,14 +776,16 @@ public class ClientEventHandler {
|
|||
if (player != null && shakeTime > 0) {
|
||||
float shakeRadiusAmplitude = (float) Mth.clamp(1 - player.position().distanceTo(new Vec3(shakePos[0], shakePos[1], shakePos[2])) / shakeRadius, 0, 1);
|
||||
|
||||
boolean onVehicle = player.getVehicle() != null;
|
||||
|
||||
if (shakeType > 0) {
|
||||
event.setYaw((float) (yaw + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType)));
|
||||
event.setPitch((float) (pitch - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType)));
|
||||
event.setRoll((float) (roll - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude)));
|
||||
event.setYaw((float) (yaw + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType * (onVehicle ? 0.15 : 1))));
|
||||
event.setPitch((float) (pitch - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType * (onVehicle ? 0.15 : 1))));
|
||||
event.setRoll((float) (roll - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * (onVehicle ? 0.15 : 1))));
|
||||
} else {
|
||||
event.setYaw((float) (yaw - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType)));
|
||||
event.setPitch((float) (pitch + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType)));
|
||||
event.setRoll((float) (roll + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude)));
|
||||
event.setYaw((float) (yaw - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType * (onVehicle ? 0.15 : 1))));
|
||||
event.setPitch((float) (pitch + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType * (onVehicle ? 0.15 : 1))));
|
||||
event.setRoll((float) (roll + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * (onVehicle ? 0.15 : 1))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,11 +74,11 @@ public class ParticleTool {
|
|||
}
|
||||
|
||||
if (level instanceof ServerLevel serverLevel) {
|
||||
sendParticle(serverLevel, ParticleTypes.EXPLOSION, x, y + 1, z, 4, 0.25, 0.25, 0.25, 1, true);
|
||||
sendParticle(serverLevel, ParticleTypes.EXPLOSION, x, y, z, 2, 0.05, 0.05, 0.05, 1, true);
|
||||
sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y, z, 3, 0.1, 0.1, 0.1, 0.02, true);
|
||||
sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, x, y, z, 4, 0.2, 0.2, 0.2, 0.02, true);
|
||||
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), x, y, z, 20, 0, 0, 0, 0.6, true);
|
||||
sendParticle(serverLevel, ParticleTypes.FLASH, x, y + 0.2, z, 20, 0.1, 0.1, 0.1, 20, true);
|
||||
sendParticle(serverLevel, ParticleTypes.FLASH, x, y, z, 5, 0.1, 0.1, 0.1, 20, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue