修复可开火判定,添加载具弹药显示HUD
This commit is contained in:
parent
6ebd1be672
commit
6803841b67
8 changed files with 95 additions and 24 deletions
|
@ -1,16 +1,22 @@
|
|||
package com.atsuishio.superbwarfare.client.screens;
|
||||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
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.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
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.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderGuiEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
|
@ -68,6 +74,51 @@ public class VehicleHudOverlay {
|
|||
}
|
||||
guiGraphics.pose().popPose();
|
||||
|
||||
PoseStack poseStack = event.getGuiGraphics().pose();
|
||||
|
||||
if (vehicle instanceof IVehicleEntity iVehicle && iVehicle.getAmmoCount(player) != -1) {
|
||||
|
||||
boolean iCharge = iVehicle instanceof IChargeEntity;
|
||||
|
||||
// 渲染当前弹药量
|
||||
poseStack.pushPose();
|
||||
poseStack.scale(1.5f, 1.5f, 1f);
|
||||
|
||||
float v = h / 1.5f - (iCharge ? 42 : 29) / 1.5f;
|
||||
|
||||
if (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) && !(iVehicle instanceof ICannonEntity)) {
|
||||
event.getGuiGraphics().drawString(
|
||||
Minecraft.getInstance().font,
|
||||
"∞",
|
||||
w / 1.5f - 41 / 1.5f,
|
||||
v,
|
||||
0xFFFFFF,
|
||||
true
|
||||
);
|
||||
} else {
|
||||
event.getGuiGraphics().drawString(
|
||||
Minecraft.getInstance().font,
|
||||
iVehicle.getAmmoCount(player) + "",
|
||||
w / 1.5f - 41 / 1.5f,
|
||||
v,
|
||||
0xFFFFFF,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
poseStack.popPose();
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
// 渲染弹药类型
|
||||
event.getGuiGraphics().drawString(
|
||||
Minecraft.getInstance().font,
|
||||
getVehicleAmmoType(stack, iVehicle),
|
||||
w - 90,
|
||||
h - (iCharge ? 38 : 26),
|
||||
0xFFFFFF,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldRenderCrossHair(Player player) {
|
||||
|
@ -75,4 +126,17 @@ public class VehicleHudOverlay {
|
|||
return !player.isSpectator()
|
||||
&& (player.getVehicle() != null && player.getVehicle() instanceof IVehicleEntity);
|
||||
}
|
||||
|
||||
private static String getVehicleAmmoType(ItemStack stack, IVehicleEntity iVehicle) {
|
||||
if (stack.getItem() == ModItems.AP_5_INCHES.get() && iVehicle instanceof ICannonEntity) {
|
||||
return Component.translatable("ammotype.superbwarfare.ap").getString();
|
||||
}
|
||||
if (stack.getItem() == ModItems.HE_5_INCHES.get() && iVehicle instanceof ICannonEntity) {
|
||||
return Component.translatable("ammotype.superbwarfare.he").getString();
|
||||
}
|
||||
if (iVehicle instanceof SpeedboatEntity) {
|
||||
return Component.translatable("ammotype.superbwarfare.cal50").getString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -567,7 +567,7 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getAmmoCount() {
|
||||
return 0;
|
||||
public int getAmmoCount(Player player) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,5 +16,5 @@ public interface IVehicleEntity {
|
|||
|
||||
boolean canShoot(Player player);
|
||||
|
||||
int getAmmoCount();
|
||||
int getAmmoCount(Player player);
|
||||
}
|
||||
|
|
|
@ -447,7 +447,11 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getAmmoCount() {
|
||||
return 0;
|
||||
public int getAmmoCount(Player player) {
|
||||
if (player.getMainHandItem().getItem() instanceof CannonShellItem) {
|
||||
return player.getMainHandItem().getCount();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -542,7 +542,11 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getAmmoCount() {
|
||||
return 0;
|
||||
public int getAmmoCount(Player player) {
|
||||
if (player.getMainHandItem().getItem() instanceof CannonShellItem) {
|
||||
return player.getMainHandItem().getCount();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -311,7 +311,9 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
|||
cannotFire = false;
|
||||
}
|
||||
|
||||
if (this.level() instanceof ServerLevel) {
|
||||
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).mapToInt(ItemStack::getCount).sum());
|
||||
}
|
||||
|
||||
turretYRotO = this.getTurretYRot();
|
||||
turretXRotO = this.getTurretXRot();
|
||||
|
@ -344,9 +346,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
|||
this.entityData.set(ROT_Y, this.getYRot());
|
||||
}
|
||||
|
||||
handleClientSync();
|
||||
this.tickLerp();
|
||||
this.controlBoat();
|
||||
this.entityData.set(HEALTH, java.lang.Math.min(this.entityData.get(HEALTH) + 0.05f, MAX_HEALTH));
|
||||
|
||||
if (this.entityData.get(HEALTH) <= 0) {
|
||||
this.ejectPassengers();
|
||||
|
@ -357,6 +357,9 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
|||
crushEntities(this.getDeltaMovement());
|
||||
}
|
||||
|
||||
handleClientSync();
|
||||
tickLerp();
|
||||
controlBoat();
|
||||
collideBlock();
|
||||
gunnerAngle();
|
||||
pickUpItem();
|
||||
|
@ -921,13 +924,13 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
|
|||
|
||||
@Override
|
||||
public boolean canShoot(Player player) {
|
||||
return (this.getItemStacks().stream().anyMatch(stack -> stack.is(ModItems.HEAVY_AMMO.get())) || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())))
|
||||
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())))
|
||||
&& !player.getMainHandItem().is(ModTags.Items.GUN)
|
||||
&& !cannotFire;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmmoCount() {
|
||||
return 0;
|
||||
public int getAmmoCount(Player player) {
|
||||
return this.entityData.get(AMMO);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import net.minecraft.client.multiplayer.ClientLevel;
|
|||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.util.Mth;
|
||||
|
@ -552,8 +551,8 @@ public class ClientEventHandler {
|
|||
if (player == null) return;
|
||||
if (level == null) return;
|
||||
|
||||
if (player.getVehicle() instanceof IVehicleEntity iVehicle && iVehicle.isDriver(player)) {
|
||||
player.displayClientMessage(Component.literal("canShoot: " + iVehicle.canShoot(player)), true);
|
||||
if (notInGame()) {
|
||||
clientTimerVehicle.stop();
|
||||
}
|
||||
|
||||
if (player.getVehicle() instanceof IVehicleEntity iVehicle && iVehicle.isDriver(player) && iVehicle.canShoot(player)) {
|
||||
|
@ -580,15 +579,9 @@ public class ClientEventHandler {
|
|||
playVehicleClientSounds(player, iVehicle);
|
||||
clientTimerVehicle.setProgress((clientTimerVehicle.getProgress() - cooldown));
|
||||
}
|
||||
|
||||
if (notInGame()) {
|
||||
clientTimerVehicle.stop();
|
||||
}
|
||||
|
||||
} else {
|
||||
clientTimerVehicle.stop();
|
||||
}
|
||||
|
||||
} else {
|
||||
clientTimerVehicle.stop();
|
||||
}
|
||||
|
|
|
@ -460,5 +460,8 @@
|
|||
"des.superbwarfare.tips.edit": "Press %1$s key to edit this weapon",
|
||||
"commands.ammo.no_permission": "Permission denied",
|
||||
"des.superbwarfare.revolver.da": "DA",
|
||||
"des.superbwarfare.revolver.sa": "SA"
|
||||
"des.superbwarfare.revolver.sa": "SA",
|
||||
"ammotype.superbwarfare.ap": "AP SHELL",
|
||||
"ammotype.superbwarfare.he": "HE SHELL",
|
||||
"ammotype.superbwarfare.cal50": ".50 BMG"
|
||||
}
|
Loading…
Add table
Reference in a new issue