火炮指示器确认时会发送一次射击诸元

This commit is contained in:
Atsuishio 2025-07-12 11:53:11 +08:00 committed by Light_Quanta
parent 970aa5ac86
commit 4ca89c305f
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -2,17 +2,29 @@ package com.atsuishio.superbwarfare.network.message.send;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.component.ModDataComponents;
import com.atsuishio.superbwarfare.entity.vehicle.Mk42Entity;
import com.atsuishio.superbwarfare.entity.vehicle.Mle1934Entity;
import com.atsuishio.superbwarfare.entity.vehicle.MortarEntity;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.item.FiringParameters;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.NBTTool;
import io.netty.buffer.ByteBuf;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.network.handling.IPayloadContext;
import org.jetbrains.annotations.NotNull;
import static com.atsuishio.superbwarfare.item.ArtilleryIndicator.TAG_CANNON;
public record FiringParametersEditMessage(
int x, int y, int z,
int radius, boolean isDepressed, boolean mainHand
@ -37,6 +49,27 @@ public record FiringParametersEditMessage(
var parameters = new FiringParameters.Parameters(new BlockPos(message.x, message.y, message.z), message.radius, message.isDepressed);
stack.set(ModDataComponents.FIRING_PARAMETERS, parameters);
ListTag tags = NBTTool.getTag(stack).getList(TAG_CANNON, Tag.TAG_COMPOUND);
for (int i = 0; i < tags.size(); i++) {
var tag = tags.getCompound(i);
Entity entity = EntityFindUtil.findEntity(player.level(), tag.getString("UUID"));
if (entity instanceof MortarEntity mortarEntity) {
if (!mortarEntity.setTarget(stack)) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.warn").withStyle(ChatFormatting.RED), true);
}
}
if (entity instanceof Mk42Entity mk42Entity) {
if (!mk42Entity.setTarget(stack)) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.mk_42.warn").withStyle(ChatFormatting.RED), true);
}
}
if (entity instanceof Mle1934Entity mle1934Entity) {
if (!mle1934Entity.setTarget(stack)) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.mle_1934.warn").withStyle(ChatFormatting.RED), true);
}
}
}
}
@Override