添加目标锁定和目标信息显示
This commit is contained in:
parent
89b712d77b
commit
cb0f593ae8
6 changed files with 127 additions and 7 deletions
|
@ -161,6 +161,7 @@ public class ModUtils {
|
||||||
addNetworkMessage(LungeMineAttackMessage.class, LungeMineAttackMessage::encode, LungeMineAttackMessage::decode, LungeMineAttackMessage::handler);
|
addNetworkMessage(LungeMineAttackMessage.class, LungeMineAttackMessage::encode, LungeMineAttackMessage::decode, LungeMineAttackMessage::handler);
|
||||||
addNetworkMessage(RadarMenuOpenMessage.class, RadarMenuOpenMessage::encode, RadarMenuOpenMessage::decode, RadarMenuOpenMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
addNetworkMessage(RadarMenuOpenMessage.class, RadarMenuOpenMessage::encode, RadarMenuOpenMessage::decode, RadarMenuOpenMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||||
addNetworkMessage(RadarMenuCloseMessage.class, RadarMenuCloseMessage::encode, RadarMenuCloseMessage::decode, RadarMenuCloseMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
addNetworkMessage(RadarMenuCloseMessage.class, RadarMenuCloseMessage::encode, RadarMenuCloseMessage::decode, RadarMenuCloseMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||||
|
addNetworkMessage(RadarSetPosMessage.class, RadarSetPosMessage::encode, RadarSetPosMessage::decode, RadarSetPosMessage::handler);
|
||||||
|
|
||||||
event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)),
|
event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)),
|
||||||
Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), ModPotion.SHOCK.get())));
|
Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), ModPotion.SHOCK.get())));
|
||||||
|
|
|
@ -3,9 +3,11 @@ package com.atsuishio.superbwarfare.client.screens;
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
import com.atsuishio.superbwarfare.block.entity.FuMO25BlockEntity;
|
import com.atsuishio.superbwarfare.block.entity.FuMO25BlockEntity;
|
||||||
import com.atsuishio.superbwarfare.client.RenderHelper;
|
import com.atsuishio.superbwarfare.client.RenderHelper;
|
||||||
|
import com.atsuishio.superbwarfare.entity.VehicleEntity;
|
||||||
import com.atsuishio.superbwarfare.menu.FuMO25Menu;
|
import com.atsuishio.superbwarfare.menu.FuMO25Menu;
|
||||||
import com.atsuishio.superbwarfare.network.message.RadarChangeModeMessage;
|
import com.atsuishio.superbwarfare.network.message.RadarChangeModeMessage;
|
||||||
import com.atsuishio.superbwarfare.network.message.RadarSetParametersMessage;
|
import com.atsuishio.superbwarfare.network.message.RadarSetParametersMessage;
|
||||||
|
import com.atsuishio.superbwarfare.network.message.RadarSetPosMessage;
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.math.Axis;
|
import com.mojang.math.Axis;
|
||||||
|
@ -14,12 +16,16 @@ import net.minecraft.client.gui.components.AbstractButton;
|
||||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -30,6 +36,9 @@ public class FuMO25Screen extends AbstractContainerScreen<FuMO25Menu> {
|
||||||
private static final ResourceLocation TEXTURE = ModUtils.loc("textures/gui/radar.png");
|
private static final ResourceLocation TEXTURE = ModUtils.loc("textures/gui/radar.png");
|
||||||
private static final ResourceLocation SCAN = ModUtils.loc("textures/gui/radar_scan.png");
|
private static final ResourceLocation SCAN = ModUtils.loc("textures/gui/radar_scan.png");
|
||||||
|
|
||||||
|
private BlockPos currentPos = null;
|
||||||
|
private Entity currentTarget = null;
|
||||||
|
|
||||||
public FuMO25Screen(FuMO25Menu pMenu, Inventory pPlayerInventory, Component pTitle) {
|
public FuMO25Screen(FuMO25Menu pMenu, Inventory pPlayerInventory, Component pTitle) {
|
||||||
super(pMenu, pPlayerInventory, pTitle);
|
super(pMenu, pPlayerInventory, pTitle);
|
||||||
imageWidth = 340;
|
imageWidth = 340;
|
||||||
|
@ -51,16 +60,13 @@ public class FuMO25Screen extends AbstractContainerScreen<FuMO25Menu> {
|
||||||
// 网格线
|
// 网格线
|
||||||
renderXLine(pGuiGraphics, pPartialTick, i, j);
|
renderXLine(pGuiGraphics, pPartialTick, i, j);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
// FE
|
// FE
|
||||||
long energy = FuMO25Screen.this.menu.getEnergy();
|
long energy = FuMO25Screen.this.menu.getEnergy();
|
||||||
float energyRate = (float) energy / (float) FuMO25BlockEntity.MAX_ENERGY;
|
float energyRate = (float) energy / (float) FuMO25BlockEntity.MAX_ENERGY;
|
||||||
pGuiGraphics.blit(TEXTURE, i + 278, j + 39, 178, 167, (int) (54 * energyRate), 16, 358, 328);
|
pGuiGraphics.blit(TEXTURE, i + 278, j + 39, 178, 167, (int) (54 * energyRate), 16, 358, 328);
|
||||||
|
|
||||||
|
// 信息显示
|
||||||
|
renderInfo(pGuiGraphics);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderXLine(GuiGraphics guiGraphics, float partialTick, int i, int j) {
|
private void renderXLine(GuiGraphics guiGraphics, float partialTick, int i, int j) {
|
||||||
|
@ -75,6 +81,12 @@ public class FuMO25Screen extends AbstractContainerScreen<FuMO25Menu> {
|
||||||
|
|
||||||
guiGraphics.blit(TEXTURE, i + 8, j + 11, 0, 167, 147, 147, 358, 328);
|
guiGraphics.blit(TEXTURE, i + 8, j + 11, 0, 167, 147, 147, 358, 328);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
poseStack.popPose();
|
poseStack.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +135,63 @@ public class FuMO25Screen extends AbstractContainerScreen<FuMO25Menu> {
|
||||||
poseStack.popPose();
|
poseStack.popPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void renderInfo(GuiGraphics guiGraphics) {
|
||||||
|
int i = (this.width - this.imageWidth) / 2;
|
||||||
|
int j = (this.height - this.imageHeight) / 2;
|
||||||
|
|
||||||
|
if (this.currentPos != null) {
|
||||||
|
guiGraphics.drawString(this.font, Component.translatable("des.superbwarfare.fumo_25.current_pos",
|
||||||
|
"[" + currentPos.getX() + ", " + currentPos.getY() + ", " + currentPos.getZ() + "]"), i + 173, j + 13, 0xffffff);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.currentTarget != null) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(currentTarget.getDisplayName().getString());
|
||||||
|
if (currentTarget instanceof LivingEntity living) {
|
||||||
|
sb.append(" (HP: ").append(new DecimalFormat("##.#").format(living.getHealth()))
|
||||||
|
.append("/").append(new DecimalFormat("##.#").format(living.getMaxHealth())).append(")");
|
||||||
|
} else if (currentTarget instanceof VehicleEntity vehicle) {
|
||||||
|
sb.append(" (HP: ").append(new DecimalFormat("##.#").format(vehicle.getHealth()))
|
||||||
|
.append("/").append(new DecimalFormat("##.#").format(vehicle.getMaxHealth())).append(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
guiGraphics.drawString(this.font, Component.translatable("des.superbwarfare.fumo_25.current_target", sb),
|
||||||
|
i + 173, j + 24, 0xffffff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseClicked(double pMouseX, double pMouseY, int pButton) {
|
||||||
|
var entities = FuMO25ScreenHelper.entities;
|
||||||
|
if (entities == null || entities.isEmpty()) return super.mouseClicked(pMouseX, pMouseY, pButton);
|
||||||
|
var pos = FuMO25ScreenHelper.pos;
|
||||||
|
if (pos == null) return super.mouseClicked(pMouseX, pMouseY, pButton);
|
||||||
|
if (pButton != 0) return super.mouseClicked(pMouseX, pMouseY, pButton);
|
||||||
|
|
||||||
|
int type = (int) FuMO25Screen.this.menu.getFuncType();
|
||||||
|
int range = type == 1 ? FuMO25BlockEntity.MAX_RANGE : FuMO25BlockEntity.DEFAULT_RANGE;
|
||||||
|
|
||||||
|
int i = (this.width - this.imageWidth) / 2;
|
||||||
|
int j = (this.height - this.imageHeight) / 2;
|
||||||
|
|
||||||
|
int centerX = i + 81;
|
||||||
|
int centerY = j + 84;
|
||||||
|
|
||||||
|
for (var entity : entities) {
|
||||||
|
double moveX = (entity.getX() - pos.getX()) / range * 74;
|
||||||
|
double moveZ = (entity.getZ() - pos.getZ()) / range * 74;
|
||||||
|
|
||||||
|
if (pMouseX >= centerX + moveX && pMouseX <= centerX + moveX + 4 && pMouseY >= centerY + moveZ && pMouseY <= centerY + moveZ + 4) {
|
||||||
|
ModUtils.PACKET_HANDLER.sendToServer(new RadarSetPosMessage(entity.getOnPos()));
|
||||||
|
this.currentPos = entity.getOnPos();
|
||||||
|
this.currentTarget = entity;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.mouseClicked(pMouseX, pMouseY, pButton);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
||||||
this.renderBackground(pGuiGraphics);
|
this.renderBackground(pGuiGraphics);
|
||||||
|
@ -159,6 +228,9 @@ public class FuMO25Screen extends AbstractContainerScreen<FuMO25Menu> {
|
||||||
this.inventoryLabelX = 105;
|
this.inventoryLabelX = 105;
|
||||||
this.inventoryLabelY = 128;
|
this.inventoryLabelY = 128;
|
||||||
|
|
||||||
|
this.currentPos = null;
|
||||||
|
this.currentTarget = null;
|
||||||
|
|
||||||
int i = (this.width - this.imageWidth) / 2;
|
int i = (this.width - this.imageWidth) / 2;
|
||||||
int j = (this.height - this.imageHeight) / 2;
|
int j = (this.height - this.imageHeight) / 2;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.atsuishio.superbwarfare.network.message;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.menu.FuMO25Menu;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class RadarSetPosMessage {
|
||||||
|
|
||||||
|
private final BlockPos pos;
|
||||||
|
|
||||||
|
public RadarSetPosMessage(BlockPos pos) {
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void encode(RadarSetPosMessage message, FriendlyByteBuf buffer) {
|
||||||
|
buffer.writeBlockPos(message.pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RadarSetPosMessage decode(FriendlyByteBuf buffer) {
|
||||||
|
return new RadarSetPosMessage(buffer.readBlockPos());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handler(RadarSetPosMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
|
ctx.get().enqueueWork(() -> {
|
||||||
|
ServerPlayer player = ctx.get().getSender();
|
||||||
|
if (player == null) return;
|
||||||
|
|
||||||
|
AbstractContainerMenu menu = player.containerMenu;
|
||||||
|
if (menu instanceof FuMO25Menu fuMO25Menu) {
|
||||||
|
if (!player.containerMenu.stillValid(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fuMO25Menu.setPos(message.pos.getX(), message.pos.getY(), message.pos.getZ());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ctx.get().setPacketHandled(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -79,7 +79,7 @@ public class SeekTool {
|
||||||
&& e.isAlive()
|
&& e.isAlive()
|
||||||
&& !(e instanceof ItemEntity || e instanceof ExperienceOrb || e instanceof HangingEntity || e instanceof ProjectileEntity || e instanceof Projectile || e instanceof ArmorStand)
|
&& !(e instanceof ItemEntity || e instanceof ExperienceOrb || e instanceof HangingEntity || e instanceof ProjectileEntity || e instanceof Projectile || e instanceof ArmorStand)
|
||||||
&& (e instanceof LivingEntity || e instanceof VehicleEntity)
|
&& (e instanceof LivingEntity || e instanceof VehicleEntity)
|
||||||
&& !(e instanceof Player player && (player.isCreative() || player.isSpectator())))
|
&& !(e instanceof Player player && player.isSpectator()))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -216,6 +216,8 @@
|
||||||
"block.superbwarfare.charging_station": "Charging Station",
|
"block.superbwarfare.charging_station": "Charging Station",
|
||||||
"des.superbwarfare.charging_station.energy": "Energy: %1$s / %2$s FE",
|
"des.superbwarfare.charging_station.energy": "Energy: %1$s / %2$s FE",
|
||||||
"block.superbwarfare.fumo_25": "FuMO25 Fire Control Radar",
|
"block.superbwarfare.fumo_25": "FuMO25 Fire Control Radar",
|
||||||
|
"des.superbwarfare.fumo_25.current_pos": "Current Pos: %1$s",
|
||||||
|
"des.superbwarfare.fumo_25.current_target": "Target: %1$s",
|
||||||
|
|
||||||
"item.superbwarfare.high_energy_explosives": "High Energy Explosives",
|
"item.superbwarfare.high_energy_explosives": "High Energy Explosives",
|
||||||
"item.superbwarfare.grain": "Grain",
|
"item.superbwarfare.grain": "Grain",
|
||||||
|
|
|
@ -216,6 +216,8 @@
|
||||||
"block.superbwarfare.charging_station": "充电站",
|
"block.superbwarfare.charging_station": "充电站",
|
||||||
"des.superbwarfare.charging_station.energy": "能量:%1$s / %2$s FE",
|
"des.superbwarfare.charging_station.energy": "能量:%1$s / %2$s FE",
|
||||||
"block.superbwarfare.fumo_25": "FuMO25火控雷达",
|
"block.superbwarfare.fumo_25": "FuMO25火控雷达",
|
||||||
|
"des.superbwarfare.fumo_25.current_pos": "当前坐标:%1$s",
|
||||||
|
"des.superbwarfare.fumo_25.current_target": "目标:%1$s",
|
||||||
|
|
||||||
"item.superbwarfare.high_energy_explosives": "高能炸药",
|
"item.superbwarfare.high_energy_explosives": "高能炸药",
|
||||||
"item.superbwarfare.grain": "推进药柱",
|
"item.superbwarfare.grain": "推进药柱",
|
||||||
|
|
Loading…
Add table
Reference in a new issue