优化载具HUD
This commit is contained in:
parent
fed3dcca79
commit
527c38d751
10 changed files with 91 additions and 64 deletions
|
@ -2,7 +2,6 @@ package com.atsuishio.superbwarfare.client.screens;
|
|||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.client.RenderHelper;
|
||||
import com.atsuishio.superbwarfare.config.server.CannonConfig;
|
||||
import com.atsuishio.superbwarfare.entity.AnnihilatorEntity;
|
||||
import com.atsuishio.superbwarfare.entity.ICannonEntity;
|
||||
import com.atsuishio.superbwarfare.entity.Mk42Entity;
|
||||
|
@ -12,10 +11,8 @@ import com.atsuishio.superbwarfare.tools.TraceTool;
|
|||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
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.LivingEntity;
|
||||
|
@ -32,19 +29,8 @@ import java.text.DecimalFormat;
|
|||
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||
public class CannonHudOverlay {
|
||||
|
||||
public static float health = 0;
|
||||
public static float maxHealth = 0;
|
||||
public static float indicatorPosH = 0;
|
||||
|
||||
public static float energy = 0;
|
||||
public static float maxEnergy = 0;
|
||||
|
||||
private static final ResourceLocation ARMOR = ModUtils.loc("textures/screens/armor.png");
|
||||
private static final ResourceLocation ENERGY = ModUtils.loc("textures/screens/energy.png");
|
||||
private static final ResourceLocation HEALTH = ModUtils.loc("textures/screens/armor_value.png");
|
||||
private static final ResourceLocation HEALTH_FRAME = ModUtils.loc("textures/screens/armor_value_frame.png");
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
public static void eventHandler(RenderGuiEvent.Pre event) {
|
||||
int w = event.getWindow().getGuiScaledWidth();
|
||||
|
@ -62,40 +48,19 @@ public class CannonHudOverlay {
|
|||
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);
|
||||
GuiGraphics guiGraphics = event.getGuiGraphics();
|
||||
|
||||
if (cannon instanceof Mk42Entity) {
|
||||
health = cannon.getEntityData().get(Mk42Entity.HEALTH);
|
||||
maxHealth = CannonConfig.MK42_HP.get();
|
||||
indicatorPosH = 1.3f;
|
||||
}
|
||||
|
||||
if (cannon instanceof Mle1934Entity) {
|
||||
health = cannon.getEntityData().get(Mle1934Entity.HEALTH);
|
||||
maxHealth = CannonConfig.MLE1934_HP.get();
|
||||
indicatorPosH = 1.2f;
|
||||
}
|
||||
|
||||
if (cannon instanceof AnnihilatorEntity) {
|
||||
health = cannon.getEntityData().get(AnnihilatorEntity.HEALTH);
|
||||
maxHealth = CannonConfig.ANNIHILATOR_HP.get();
|
||||
energy = cannon.getEntityData().get(AnnihilatorEntity.ENERGY);
|
||||
maxEnergy = CannonConfig.ANNIHILATOR_MAX_ENERGY.get().floatValue();
|
||||
indicatorPosH = cannon.getEntityData().get(AnnihilatorEntity.OFFSET_ANGLE);
|
||||
|
||||
guiGraphics.pose().pushPose();
|
||||
guiGraphics.blit(ENERGY, w - 96, h - 28, 0, 0, 12, 12, 12, 12);
|
||||
guiGraphics.blit(HEALTH_FRAME, w - 83, h - 26, 0, 0, 80, 8, 80, 8);
|
||||
guiGraphics.blit(HEALTH, w - 83, h - 26, 0, 0, (int) (80 * energy / maxEnergy), 8, 80, 8);
|
||||
guiGraphics.pose().popPose();
|
||||
}
|
||||
|
||||
guiGraphics.pose().pushPose();
|
||||
guiGraphics.blit(ARMOR, w - 96, h - 14, 0, 0, 12, 12, 12, 12);
|
||||
guiGraphics.blit(HEALTH_FRAME, w - 83, h - 12, 0, 0, 80, 8, 80, 8);
|
||||
guiGraphics.blit(HEALTH, w - 83, h - 12, 0, 0, (int) (80 * health / maxHealth), 8, 80, 8);
|
||||
guiGraphics.pose().popPose();
|
||||
|
||||
float yRotOffset = Mth.lerp(event.getPartialTick(), player.yRotO, player.getYRot());
|
||||
float xRotOffset = Mth.lerp(event.getPartialTick(), player.xRotO, player.getXRot());
|
||||
float diffY = cannon.getViewYRot(event.getPartialTick()) - yRotOffset;
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package com.atsuishio.superbwarfare.client.screens;
|
||||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.config.server.CannonConfig;
|
||||
import com.atsuishio.superbwarfare.entity.ICannonEntity;
|
||||
import com.atsuishio.superbwarfare.entity.IChargeEntity;
|
||||
import com.atsuishio.superbwarfare.entity.IVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.entity.SpeedboatEntity;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -52,20 +50,22 @@ public class VehicleHudOverlay {
|
|||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
GuiGraphics guiGraphics = event.getGuiGraphics();
|
||||
|
||||
if (vehicle instanceof SpeedboatEntity) {
|
||||
health = vehicle.getEntityData().get(SpeedboatEntity.HEALTH);
|
||||
maxHealth = CannonConfig.SPEEDBOAT_HP.get();
|
||||
energy = vehicle.getEntityData().get(SpeedboatEntity.ENERGY);
|
||||
maxEnergy = CannonConfig.SPEEDBOAT_MAX_ENERGY.get().floatValue();
|
||||
guiGraphics.pose().pushPose();
|
||||
if (vehicle instanceof IChargeEntity iCharge) {
|
||||
energy = iCharge.getEnergy();
|
||||
maxEnergy = iCharge.getMaxEnergy();
|
||||
guiGraphics.blit(ENERGY, w - 96, h - 28, 0, 0, 12, 12, 12, 12);
|
||||
guiGraphics.blit(HEALTH_FRAME, w - 83, h - 26, 0, 0, 80, 8, 80, 8);
|
||||
guiGraphics.blit(HEALTH, w - 83, h - 26, 0, 0, (int) (80 * energy / maxEnergy), 8, 80, 8);
|
||||
}
|
||||
|
||||
guiGraphics.pose().pushPose();
|
||||
guiGraphics.blit(ENERGY, w - 96, h - 28, 0, 0, 12, 12, 12, 12);
|
||||
guiGraphics.blit(HEALTH_FRAME, w - 83, h - 26, 0, 0, 80, 8, 80, 8);
|
||||
guiGraphics.blit(HEALTH, w - 83, h - 26, 0, 0, (int) (80 * energy / maxEnergy), 8, 80, 8);
|
||||
guiGraphics.blit(ARMOR, w - 96, h - 14, 0, 0, 12, 12, 12, 12);
|
||||
guiGraphics.blit(HEALTH_FRAME, w - 83, h - 12, 0, 0, 80, 8, 80, 8);
|
||||
guiGraphics.blit(HEALTH, w - 83, h - 12, 0, 0, (int) (80 * health / maxHealth), 8, 80, 8);
|
||||
if (vehicle instanceof IVehicleEntity iVehicle) {
|
||||
health = iVehicle.getHealth();
|
||||
maxHealth = iVehicle.getMaxHealth();
|
||||
guiGraphics.blit(ARMOR, w - 96, h - 14, 0, 0, 12, 12, 12, 12);
|
||||
guiGraphics.blit(HEALTH_FRAME, w - 83, h - 12, 0, 0, 80, 8, 80, 8);
|
||||
guiGraphics.blit(HEALTH, w - 83, h - 12, 0, 0, (int) (80 * health / maxHealth), 8, 80, 8);
|
||||
}
|
||||
guiGraphics.pose().popPose();
|
||||
|
||||
}
|
||||
|
@ -73,6 +73,6 @@ public class VehicleHudOverlay {
|
|||
private static boolean shouldRenderCrossHair(Player player) {
|
||||
if (player == null) return false;
|
||||
return !player.isSpectator()
|
||||
&& (player.getVehicle() != null && player.getVehicle() instanceof IVehicleEntity && !(player.getVehicle() instanceof ICannonEntity));
|
||||
&& (player.getVehicle() != null && player.getVehicle() instanceof IVehicleEntity);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
|
|||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
||||
public static final float MAX_HEALTH = CannonConfig.ANNIHILATOR_HP.get();
|
||||
public static final float MAX_ENERGY = CannonConfig.ANNIHILATOR_MAX_ENERGY.get().floatValue();
|
||||
public static final float SHOOT_COST = CannonConfig.ANNIHILATOR_SHOOT_COST.get().floatValue();
|
||||
|
||||
protected int interpolationSteps;
|
||||
|
@ -527,6 +528,26 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
|
|||
|
||||
@Override
|
||||
public boolean canCharge() {
|
||||
return this.entityData.get(ENERGY) < CannonConfig.ANNIHILATOR_MAX_ENERGY.get().floatValue();
|
||||
return this.entityData.get(ENERGY) < MAX_ENERGY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergy() {
|
||||
return this.entityData.get(ENERGY).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergy() {
|
||||
return (int)MAX_ENERGY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHealth() {
|
||||
return this.entityData.get(HEALTH).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxHealth() {
|
||||
return (int)MAX_HEALTH;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity;
|
|||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public interface ICannonEntity extends IVehicleEntity {
|
||||
|
||||
void cannonShoot(Player player);
|
||||
float getHealth();
|
||||
float getMaxHealth();
|
||||
}
|
||||
|
|
|
@ -5,4 +5,6 @@ public interface IChargeEntity {
|
|||
void charge(int amount);
|
||||
|
||||
boolean canCharge();
|
||||
int getEnergy();
|
||||
int getMaxEnergy();
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
package com.atsuishio.superbwarfare.entity;
|
||||
public interface IVehicleEntity {
|
||||
float getHealth();
|
||||
float getMaxHealth();
|
||||
}
|
||||
|
|
|
@ -421,4 +421,14 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
|
|||
return this.cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHealth() {
|
||||
return this.entityData.get(HEALTH).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxHealth() {
|
||||
return (int)MAX_HEALTH;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -516,4 +516,14 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
|
|||
return this.cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHealth() {
|
||||
return this.entityData.get(HEALTH).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxHealth() {
|
||||
return (int)MAX_HEALTH;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -300,6 +300,9 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
|||
cannotFire = false;
|
||||
}
|
||||
|
||||
turretYRotO = this.getTurretYRot();
|
||||
turretXRotO = this.getTurretXRot();
|
||||
|
||||
Entity driver = this.getFirstPassenger();
|
||||
if (driver instanceof Player player) {
|
||||
if (heat > 100) {
|
||||
|
@ -364,12 +367,11 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
|||
*/
|
||||
private void gunnerFire() {
|
||||
if (this.entityData.get(COOL_DOWN) != 0 || this.cannotFire) return;
|
||||
if (this.getItemStacks().stream().noneMatch(stack -> stack.is(ModItems.HEAVY_AMMO.get()))) return;
|
||||
|
||||
Entity driver = this.getFirstPassenger();
|
||||
if (driver == null) return;
|
||||
|
||||
if (driver instanceof Player player && !(player.getMainHandItem().is(ModTags.Items.GUN))) {
|
||||
if (this.getItemStacks().stream().noneMatch(stack -> stack.is(ModItems.HEAVY_AMMO.get())) && !player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) return;
|
||||
if (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).holdFire) {
|
||||
ProjectileEntity projectile = new ProjectileEntity(driver.level())
|
||||
.shooter(player)
|
||||
|
@ -393,7 +395,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
|||
}
|
||||
|
||||
Level level = player.level();
|
||||
|
||||
final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ());
|
||||
|
||||
for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(4), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) {
|
||||
|
@ -401,12 +402,10 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
|||
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(6, 5, 7, this.getX(), this.getEyeY(), this.getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
if (level instanceof ServerLevel) {
|
||||
this.entityData.set(COOL_DOWN, 3);
|
||||
heat += 4;
|
||||
}
|
||||
|
||||
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
||||
}
|
||||
}
|
||||
|
@ -513,9 +512,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
|||
|
||||
float gunAngle = -Math.clamp(-140f, 140f, Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot()));
|
||||
|
||||
turretYRotO = this.getTurretYRot();
|
||||
turretXRotO = this.getTurretXRot();
|
||||
|
||||
this.setTurretYRot(gunAngle);
|
||||
this.setTurretXRot(driver.getXRot() - this.getXRot());
|
||||
}
|
||||
|
@ -846,4 +842,24 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
|||
public void stopOpen(Player pPlayer) {
|
||||
this.level().gameEvent(GameEvent.CONTAINER_CLOSE, this.position(), GameEvent.Context.of(pPlayer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergy() {
|
||||
return this.entityData.get(ENERGY).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergy() {
|
||||
return (int)MAX_ENERGY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHealth() {
|
||||
return this.entityData.get(HEALTH).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxHealth() {
|
||||
return (int)MAX_HEALTH;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.network.message;
|
||||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.entity.ICannonEntity;
|
||||
import com.atsuishio.superbwarfare.entity.IVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.network.ModVariables;
|
||||
|
@ -52,7 +52,7 @@ public class ZoomMessage {
|
|||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
|
||||
if (player.isPassenger() && player.getVehicle() instanceof ICannonEntity) {
|
||||
if (player.isPassenger() && player.getVehicle() instanceof IVehicleEntity) {
|
||||
SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1);
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class ZoomMessage {
|
|||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
|
||||
if (player.isPassenger() && player.getVehicle() instanceof ICannonEntity) {
|
||||
if (player.isPassenger() && player.getVehicle() instanceof IVehicleEntity) {
|
||||
SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_OUT.get(), 2, 1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue