优化绑定方式

This commit is contained in:
17146 2025-07-12 20:17:11 +08:00 committed by Light_Quanta
parent 168178e96d
commit e115a06969
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
6 changed files with 47 additions and 61 deletions

View file

@ -30,7 +30,6 @@ import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.Container;
@ -161,23 +160,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
ItemStack stack = player.getMainHandItem();
if (stack.getItem() instanceof ArtilleryIndicator indicator) {
if (indicator.addCannon(stack, getStringUUID())) {
if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1);
}
player.displayClientMessage(Component.translatable("des.superbwarfare.artillery_indicator.add", this.getDisplayName())
.withStyle(ChatFormatting.GREEN), true);
return InteractionResult.SUCCESS;
} else if (indicator.removeCannon(stack, getStringUUID())) {
if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1);
}
player.displayClientMessage(Component.translatable("des.superbwarfare.artillery_indicator.remove", this.getDisplayName())
.withStyle(ChatFormatting.RED), true);
return InteractionResult.SUCCESS;
} else {
return InteractionResult.FAIL;
}
return indicator.bind(stack, player, this);
}
if (stack.is(ModTags.Items.CROWBAR) && !player.isShiftKeyDown()) {

View file

@ -30,7 +30,6 @@ import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.Container;
@ -167,23 +166,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
ItemStack stack = player.getMainHandItem();
if (stack.getItem() instanceof ArtilleryIndicator indicator) {
if (indicator.addCannon(stack, getStringUUID())) {
if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1);
}
player.displayClientMessage(Component.translatable("des.superbwarfare.artillery_indicator.add", this.getDisplayName())
.withStyle(ChatFormatting.GREEN), true);
return InteractionResult.SUCCESS;
} else if (indicator.removeCannon(stack, getStringUUID())) {
if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1);
}
player.displayClientMessage(Component.translatable("des.superbwarfare.artillery_indicator.remove", this.getDisplayName())
.withStyle(ChatFormatting.RED), true);
return InteractionResult.SUCCESS;
} else {
return InteractionResult.FAIL;
}
return indicator.bind(stack, player, this);
}
if (stack.is(ModTags.Items.CROWBAR) && !player.isShiftKeyDown()) {

View file

@ -155,24 +155,8 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container,
public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) {
ItemStack mainHandItem = player.getMainHandItem();
if (mainHandItem.getItem() instanceof ArtilleryIndicator indicator && this.entityData.get(INTELLIGENT)) {
if (indicator.addCannon(mainHandItem, getStringUUID())) {
if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1);
}
player.displayClientMessage(Component.translatable("des.superbwarfare.artillery_indicator.add", this.getDisplayName())
.withStyle(ChatFormatting.GREEN), true);
return InteractionResult.SUCCESS;
} else if (indicator.removeCannon(mainHandItem, getStringUUID())) {
if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1);
}
player.displayClientMessage(Component.translatable("des.superbwarfare.artillery_indicator.remove", this.getDisplayName())
.withStyle(ChatFormatting.RED), true);
return InteractionResult.SUCCESS;
} else {
return InteractionResult.FAIL;
}
if (mainHandItem.getItem() instanceof ArtilleryIndicator indicator) {
return indicator.bind(mainHandItem, player, this);
}
if (mainHandItem.getItem() instanceof Monitor && player.isShiftKeyDown() && !this.entityData.get(INTELLIGENT)) {

View file

@ -11,8 +11,11 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
@ -137,16 +140,49 @@ public class ArtilleryIndicator extends Item implements ItemScreenProvider {
}
public void setTarget(ItemStack stack, Player player) {
ListTag tags = NBTTool.getTag(stack).getList(TAG_CANNON, Tag.TAG_COMPOUND);
var mainTag = NBTTool.getTag(stack);
ListTag tags = mainTag.getList(TAG_CANNON, Tag.TAG_COMPOUND);
List<CompoundTag> list = new ArrayList<>();
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 LockTargetEntity lockTargetEntity) {
list.add(tag);
if (!lockTargetEntity.setTarget(stack)) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.warn", entity.getDisplayName())
.withStyle(ChatFormatting.RED), true);
}
}
}
if (list.size() != tags.size()) {
ListTag listTag = new ListTag();
listTag.addAll(list);
mainTag.put(TAG_CANNON, listTag);
NBTTool.saveTag(stack, mainTag);
}
}
public InteractionResult bind(ItemStack stack, Player player, Entity entity) {
if (this.addCannon(stack, entity.getStringUUID())) {
if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1);
}
player.displayClientMessage(Component.translatable("des.superbwarfare.artillery_indicator.add", entity.getDisplayName())
.withStyle(ChatFormatting.GREEN), true);
return InteractionResult.SUCCESS;
} else if (this.removeCannon(stack, entity.getStringUUID())) {
if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.5F, 1);
}
player.displayClientMessage(Component.translatable("des.superbwarfare.artillery_indicator.remove", entity.getDisplayName())
.withStyle(ChatFormatting.RED), true);
return InteractionResult.SUCCESS;
} else {
return InteractionResult.FAIL;
}
}
}

View file

@ -255,8 +255,8 @@
"item.superbwarfare.heavy_armament_module": "Heavy Armament Module",
"item.superbwarfare.artillery_indicator": "Artillery Indicator",
"des.superbwarfare.item_screen_provider": "Press %1$s key to open GUI",
"des.superbwarfare.artillery_indicator_1": "Right-click on artillery or intelligent mortar while sneaking to add to target list",
"des.superbwarfare.artillery_indicator_2": "Right-click again to remove",
"des.superbwarfare.artillery_indicator_1": "Right-click on artillery or intelligent mortar while sneaking to add to the artillery array",
"des.superbwarfare.artillery_indicator_2": "Right-click again to remove from the artillery array",
"des.superbwarfare.artillery_indicator_3": "Right-click to zoom, scroll wheel to adjust zoom ratio, middle mouse button to mark target location",
"des.superbwarfare.artillery_indicator_4": "Hold left mouse button to send fire command",
"des.superbwarfare.artillery_indicator_5": "When in off-hand: use drone to mark locations (same controls as above)",

View file

@ -255,10 +255,10 @@
"item.superbwarfare.heavy_armament_module": "重型武装模块",
"item.superbwarfare.artillery_indicator": "火炮指示器",
"des.superbwarfare.item_screen_provider": "按下 %1$s 以打开GUI",
"des.superbwarfare.artillery_indicator_1": "潜行时右键火炮或者智能化迫击炮将其添加到目录当中",
"des.superbwarfare.artillery_indicator_2": "再次右键移除",
"des.superbwarfare.artillery_indicator_3": "鼠标右键缩放,滚轮调节缩放倍率,鼠标中键标记目标位置",
"des.superbwarfare.artillery_indicator_4": "长按鼠标左键发送射击指令",
"des.superbwarfare.artillery_indicator_1": "潜行时右键火炮或者智能迫击炮将其添加到火炮阵列当中",
"des.superbwarfare.artillery_indicator_2": "再次右键移除",
"des.superbwarfare.artillery_indicator_3": "按住右键缩放,滚轮调节缩放倍率,使用中键标记目标位置",
"des.superbwarfare.artillery_indicator_4": "长按左键发送射击指令",
"des.superbwarfare.artillery_indicator_5": "放置在副手时可使用无人机标记位置,操作方式同上",
"des.superbwarfare.artillery_indicator.add": "已将%1$s添加至火炮阵列",
"des.superbwarfare.artillery_indicator.remove": "已将%1$s从火炮阵列中移除",