添加新接口

This commit is contained in:
17146 2025-07-12 19:46:32 +08:00 committed by Light_Quanta
parent 7add137f27
commit c1794973c0
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
10 changed files with 61 additions and 112 deletions

View file

@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.component.ModDataComponents;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.LockTargetEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
@ -60,7 +61,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import static com.atsuishio.superbwarfare.tools.RangeTool.calculateLaunchVector;
public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity, Container {
public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity, Container, LockTargetEntity {
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -220,6 +221,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
return super.interact(player, hand);
}
@Override
public boolean setTarget(ItemStack stack) {
var parameters = stack.get(ModDataComponents.FIRING_PARAMETERS);
if (parameters == null) return false;
@ -258,6 +260,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
return true;
}
@Override
public void resetTarget() {
Vec3 randomPos = VectorTool.randomPos(new Vec3(entityData.get(TARGET_POS)), entityData.get(RADIUS));
Vec3 launchVector = calculateLaunchVector(getEyePosition(), randomPos, 15, -shellGravity, entityData.get(DEPRESSED));
@ -272,7 +275,8 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
}
}
private void look(Vec3 pTarget) {
@Override
public void look(Vec3 pTarget) {
Matrix4f transform = getVehicleFlatTransform(1);
Vector4f worldPosition = transformPosition(transform, 0f, 2.16f, 0.5175f);
Vec3 shootPos = new Vec3(worldPosition.x, worldPosition.y, worldPosition.z);
@ -445,7 +449,6 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
}
}
@Override
public void travel() {
Entity passenger = this.getFirstPassenger();

View file

@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.component.ModDataComponents;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.LockTargetEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
@ -61,7 +62,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import static com.atsuishio.superbwarfare.tools.RangeTool.calculateLaunchVector;
public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEntity, Container {
public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEntity, Container, LockTargetEntity {
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> TYPE = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT);
@ -228,6 +229,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
}
//这个炮仰角太低只能用低伸弹道
@Override
public boolean setTarget(ItemStack stack) {
var parameters = stack.get(ModDataComponents.FIRING_PARAMETERS);
if (parameters == null) return false;
@ -266,6 +268,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
return true;
}
@Override
public void resetTarget() {
Vec3 randomPos = VectorTool.randomPos(new Vec3(entityData.get(TARGET_POS)), entityData.get(RADIUS));
Vec3 launchVector = calculateLaunchVector(getEyePosition(), randomPos, 15, -shellGravity, entityData.get(DEPRESSED));
@ -280,7 +283,8 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
}
}
private void look(Vec3 pTarget) {
@Override
public void look(Vec3 pTarget) {
Matrix4f transform = getVehicleFlatTransform(1);
Vector4f worldPosition = transformPosition(transform, 0, 1.4992625f, 1.52065f);
Vec3 shootPos = new Vec3(worldPosition.x, worldPosition.y, worldPosition.z);
@ -291,10 +295,6 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
}
@Override
public double getEyeY() {
return 2.16F;
}
public void positionRider(@NotNull Entity passenger, @NotNull MoveFunction callback) {
if (!this.hasPassenger(passenger)) {
return;
@ -354,7 +354,6 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
setYRot(getYRot() + (float) interpolatedYaw / (float) interpolationSteps);
setXRot(getXRot() + (float) (serverXRot - (double) getXRot()) / (float) interpolationSteps);
setRot(getYRot(), getXRot());
}
@Override
@ -449,7 +448,6 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
Mth.clamp(count--, 1, 5), 0.15, 0.15, 0.15, 0.0025);
}
// 右炮管
if (salvoShoot) {
var entityToSpawnRight = ((CannonShellWeapon) getWeapon(0)).create(player);

View file

@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.entity.vehicle;
import com.atsuishio.superbwarfare.component.ModDataComponents;
import com.atsuishio.superbwarfare.entity.projectile.MortarShellEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.LockTargetEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
@ -47,7 +48,8 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import static com.atsuishio.superbwarfare.tools.RangeTool.calculateLaunchVector;
public class MortarEntity extends VehicleEntity implements GeoEntity, Container {
public class MortarEntity extends VehicleEntity implements GeoEntity, Container, LockTargetEntity {
public static final EntityDataAccessor<Integer> FIRE_TIME = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> PITCH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> YAW = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT);
@ -230,6 +232,7 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container
return InteractionResult.FAIL;
}
@Override
public boolean setTarget(ItemStack stack) {
var parameters = stack.get(ModDataComponents.FIRING_PARAMETERS);
if (parameters == null) return false;
@ -263,6 +266,7 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container
return true;
}
@Override
public void resetTarget() {
Vec3 randomPos = VectorTool.randomPos(new Vec3(entityData.get(TARGET_POS)), entityData.get(RADIUS));
Vec3 launchVector = calculateLaunchVector(getEyePosition(), randomPos, 13, -0.11, entityData.get(DEPRESSED));
@ -277,8 +281,8 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container
}
}
private void look(Vec3 pTarget) {
@Override
public void look(Vec3 pTarget) {
Vec3 vec3 = EntityAnchorArgument.Anchor.EYES.apply(this);
double d0 = (pTarget.x - vec3.x) * 0.2;
double d2 = (pTarget.z - vec3.z) * 0.2;

View file

@ -0,0 +1,13 @@
package com.atsuishio.superbwarfare.entity.vehicle.base;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
public interface LockTargetEntity {
boolean setTarget(ItemStack stack);
void resetTarget();
void look(Vec3 pTarget);
}

View file

@ -2,6 +2,8 @@ package com.atsuishio.superbwarfare.item;
import com.atsuishio.superbwarfare.client.TooltipTool;
import com.atsuishio.superbwarfare.client.screens.ArtilleryIndicatorScreen;
import com.atsuishio.superbwarfare.entity.vehicle.base.LockTargetEntity;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.screens.Screen;
@ -12,6 +14,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
@ -132,4 +135,18 @@ public class ArtilleryIndicator extends Item implements ItemScreenProvider {
public @Nullable Screen getItemScreen(ItemStack stack, Player player, InteractionHand hand) {
return new ArtilleryIndicatorScreen(stack, hand);
}
public void setTarget(ItemStack stack, Player player) {
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 LockTargetEntity lockTargetEntity) {
if (!lockTargetEntity.setTarget(stack)) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.warn", entity.getDisplayName())
.withStyle(ChatFormatting.RED), true);
}
}
}
}
}

View file

@ -3,11 +3,9 @@ package com.atsuishio.superbwarfare.network.message.send;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.component.ModDataComponents;
import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity;
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.init.ModSounds;
import com.atsuishio.superbwarfare.item.ArtilleryIndicator;
import com.atsuishio.superbwarfare.item.FiringParameters;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.NBTTool;
@ -15,21 +13,16 @@ import com.atsuishio.superbwarfare.tools.SoundTool;
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.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.network.handling.IPayloadContext;
import org.jetbrains.annotations.NotNull;
import org.joml.Vector3f;
import static com.atsuishio.superbwarfare.item.ArtilleryIndicator.TAG_CANNON;
public record DroneFireMessage(Vector3f pos) implements CustomPacketPayload {
public static final Type<DroneFireMessage> TYPE = new Type<>(Mod.loc("drone_fire"));
@ -66,28 +59,8 @@ public record DroneFireMessage(Vector3f pos) implements CustomPacketPayload {
SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1);
if (offStack.is(ModItems.ARTILLERY_INDICATOR.get())) {
ListTag tags = NBTTool.getTag(offStack).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(offStack)) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.warn").withStyle(ChatFormatting.RED), true);
}
}
if (entity instanceof Mk42Entity mk42Entity) {
if (!mk42Entity.setTarget(offStack)) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.mk_42.warn").withStyle(ChatFormatting.RED), true);
}
}
if (entity instanceof Mle1934Entity mle1934Entity) {
if (!mle1934Entity.setTarget(offStack)) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.mle_1934.warn").withStyle(ChatFormatting.RED), true);
}
}
}
if (offStack.getItem() instanceof ArtilleryIndicator indicator) {
indicator.setTarget(offStack, player);
}
} else {
drone.fire = true;

View file

@ -2,29 +2,18 @@ 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.ArtilleryIndicator;
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
@ -50,25 +39,8 @@ 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);
}
}
if (stack.getItem() instanceof ArtilleryIndicator indicator) {
indicator.setTarget(stack, player);
}
}

View file

@ -2,21 +2,15 @@ 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.init.ModSounds;
import com.atsuishio.superbwarfare.item.ArtilleryIndicator;
import com.atsuishio.superbwarfare.item.FiringParameters;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.NBTTool;
import com.atsuishio.superbwarfare.tools.SoundTool;
import com.atsuishio.superbwarfare.tools.TraceTool;
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.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
@ -31,8 +25,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.Objects;
import static com.atsuishio.superbwarfare.item.ArtilleryIndicator.TAG_CANNON;
public enum SetFiringParametersMessage implements CustomPacketPayload {
INSTANCE;
public static final Type<SetFiringParametersMessage> TYPE = new Type<>(Mod.loc("set_firing_parameters"));
@ -74,7 +66,7 @@ public enum SetFiringParametersMessage implements CustomPacketPayload {
+ "]")), true);
}
if (mainStack.is(ModItems.ARTILLERY_INDICATOR.get())) {
if (mainStack.getItem() instanceof ArtilleryIndicator indicator) {
BlockPos pos;
if (lookAtEntity) {
pos = lookingEntity.blockPosition();
@ -91,26 +83,7 @@ public enum SetFiringParametersMessage implements CustomPacketPayload {
+ "]")), true);
SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1);
ListTag tags = NBTTool.getTag(mainStack).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(mainStack)) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.mortar.warn").withStyle(ChatFormatting.RED), true);
}
}
if (entity instanceof Mk42Entity mk42Entity) {
if (!mk42Entity.setTarget(mainStack)) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.mk_42.warn").withStyle(ChatFormatting.RED), true);
}
}
if (entity instanceof Mle1934Entity mle1934Entity) {
if (!mle1934Entity.setTarget(mainStack)) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.mle_1934.warn").withStyle(ChatFormatting.RED), true);
}
}
}
indicator.setTarget(mainStack, player);
}
}

View file

@ -584,9 +584,7 @@
"tips.superbwarfare.mortar.target_pos.radius": "Hit Radius: %1$s",
"tips.superbwarfare.mortar.target_pos.depressed_trajectory": "Depressed Trajectory",
"tips.superbwarfare.mortar.target_pos.lofted_trajectory": "Lofted Trajectory",
"tips.superbwarfare.mortar.warn": "This mortar cannot aim at this position",
"tips.superbwarfare.mk_42.warn": "MK_42 cannot aim at this position",
"tips.superbwarfare.mle_1934.warn": "Mle_1934 cannot aim at this position",
"tips.superbwarfare.mortar.warn": "%1$s cannot aim at this position",
"container.superbwarfare.reforging_table": "Gun Reforge Table",
"container.superbwarfare.charging_station": "Charging Station",

View file

@ -311,6 +311,7 @@
"des.superbwarfare.vehicle_deployer.fail": "请使用集装箱点击!",
"block.superbwarfare.aircraft_catapult": "飞行器弹射装置",
"block.superbwarfare.superb_item_interface": "卓越物品接口",
"des.superbwarfare.superb_item_interface": "可快速给指向实体传输物品的全方向漏斗",
"item.superbwarfare.high_energy_explosives": "高能炸药",
"item.superbwarfare.grain": "推进药柱",
@ -583,16 +584,13 @@
"tips.superbwarfare.mortar.target_pos.radius": "打击半径:%1$s",
"tips.superbwarfare.mortar.target_pos.depressed_trajectory": "低伸弹道",
"tips.superbwarfare.mortar.target_pos.lofted_trajectory": "传统弹道",
"tips.superbwarfare.mortar.warn": "迫击炮无法瞄准该位置",
"tips.superbwarfare.mk_42.warn": "MK-42无法瞄准该位置",
"tips.superbwarfare.mle_1934.warn": "MLE-1934无法瞄准该位置",
"tips.superbwarfare.mortar.warn": "%1$s无法瞄准该位置",
"container.superbwarfare.reforging_table": "枪械重铸台",
"container.superbwarfare.charging_station": "充电站",
"container.superbwarfare.charging_station.show_range": "显示范围",
"container.superbwarfare.charging_station.hide_range": "隐藏范围",
"container.superbwarfare.superb_item_interface": "卓越物品接口",
"des.superbwarfare.superb_item_interface": "可快速给指向实体传输物品的全方向漏斗",
"config.superbwarfare.title": "卓越前线",
"config.superbwarfare.client.reload": "换弹配置",