From 61ba12084cfd806256bb397809cfa7230c0b8373 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Thu, 22 May 2025 22:58:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=81=E8=AE=B8=E5=8F=91=E5=B0=84=E5=99=A8?= =?UTF-8?q?=E5=8F=91=E5=B0=84=E8=9C=82=E7=BE=A4=E6=97=A0=E4=BA=BA=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/projectile/SwarmDroneEntity.java | 10 +- .../entity/vehicle/Yx100Entity.java | 2 - .../superbwarfare/init/ModItems.java | 2 +- .../superbwarfare/item/SwarmDrone.java | 125 ++++++++++++++++++ .../assets/superbwarfare/lang/en_us.json | 1 + .../assets/superbwarfare/lang/zh_cn.json | 1 + 6 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/atsuishio/superbwarfare/item/SwarmDrone.java diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java index 8b45d90c8..cb92fccd5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java @@ -59,13 +59,17 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti private float explosionRadius = 5f; private float randomFloat; - private int guide_type = 0; + private int guideType = 0; public SwarmDroneEntity(EntityType type, Level level) { super(type, level); this.noCulling = true; } + public SwarmDroneEntity(double x, double y, double z, Level level) { + super(ModEntities.SWARM_DRONE.get(), x, y, z, level); + } + public SwarmDroneEntity(LivingEntity entity, Level level, float explosionDamage, float explosionRadius) { super(ModEntities.SWARM_DRONE.get(), entity, level); this.explosionDamage = explosionDamage; @@ -87,7 +91,7 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti } public void setGuideType(int guideType) { - this.guide_type = guideType; + this.guideType = guideType; } public void setTargetVec(Vec3 targetPos) { @@ -223,7 +227,7 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti Entity shooter = this.getOwner(); Vec3 targetPos; - if (guide_type == 0 && entity != null) { + if (guideType == 0 && entity != null) { targetPos = entity.getEyePosition(); this.entityData.set(TARGET_X, (float) targetPos.x); this.entityData.set(TARGET_Y, (float) targetPos.y); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java index fee262c86..3951409b0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -648,12 +648,10 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti var swarmDroneEntity = ((SwarmDroneWeapon) getWeapon(2)).create(player); - Vector4f shootPosition1 = transformPosition(transformT, 0, 0, 0); Vector4f shootPosition2 = transformPosition(transformT, 0, 1, 0); Vec3 direct = new Vec3(shootPosition1.x, shootPosition1.y, shootPosition1.z).vectorTo(new Vec3(shootPosition2.x, shootPosition2.y, shootPosition2.z)); - swarmDroneEntity.setPos(worldPosition.x, worldPosition.y, worldPosition.z); swarmDroneEntity.shoot(direct.x, direct.y, direct.z, 1.2f, 10); diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModItems.java b/src/main/java/com/atsuishio/superbwarfare/init/ModItems.java index f5d077b60..030cc4d68 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModItems.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModItems.java @@ -118,7 +118,7 @@ public class ModItems { public static final DeferredHolder ROCKET_70 = AMMO.register("rocket_70", Rocket70::new); public static final DeferredHolder WIRE_GUIDE_MISSILE = AMMO.register("wire_guide_missile", WireGuideMissile::new); public static final DeferredHolder AGM = AMMO.register("agm", Agm::new); - public static final DeferredHolder SWARM_DRONE = AMMO.register("swarm_drone", () -> new Item(new Item.Properties())); + public static final DeferredHolder SWARM_DRONE = AMMO.register("swarm_drone", SwarmDrone::new); public static final DeferredHolder MEDIUM_AERIAL_BOMB = AMMO.register("medium_aerial_bomb", MediumAerialBomb::new); public static final DeferredHolder BEAM_TEST = AMMO.register("beam_test", BeamTest::new); diff --git a/src/main/java/com/atsuishio/superbwarfare/item/SwarmDrone.java b/src/main/java/com/atsuishio/superbwarfare/item/SwarmDrone.java new file mode 100644 index 000000000..facad266a --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/item/SwarmDrone.java @@ -0,0 +1,125 @@ +package com.atsuishio.superbwarfare.item; + +import com.atsuishio.superbwarfare.entity.projectile.SwarmDroneEntity; +import net.minecraft.ChatFormatting; +import net.minecraft.core.Direction; +import net.minecraft.core.Position; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ProjectileItem; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.List; + +public class SwarmDrone extends Item implements ProjectileItem { + + public SwarmDrone() { + super(new Properties()); + } + +// @Override +// public AbstractProjectileDispenseBehavior getLaunchBehavior() { +// return new AbstractProjectileDispenseBehavior() { +// +// @Override +// public ItemStack execute(BlockSource blockSource, ItemStack pStack) { +// Level level = blockSource.getLevel(); +// Position position = DispenserBlock.getDispensePosition(blockSource); +// Direction direction = blockSource.getBlockState().getValue(DispenserBlock.FACING); +// Projectile projectile = this.getProjectile(level, position, pStack); +// +// float yVec = direction.getStepY(); +// if (direction != Direction.DOWN) { +// yVec += 1F; +// } +// +// projectile.shoot(direction.getStepX(), yVec, direction.getStepZ(), this.getPower(), this.getUncertainty()); +// +// BlockHitResult result = level.clip(new ClipContext(new Vec3(position.x(), position.y(), position.z()), +// new Vec3(position.x(), position.y(), position.z()).add(new Vec3(direction.step().mul(128))), +// ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, projectile)); +// Vec3 hitPos = result.getLocation(); +// ((SwarmDroneEntity) projectile).setGuideType(1); +// ((SwarmDroneEntity) projectile).setTargetVec(hitPos); +// +// level.addFreshEntity(projectile); +// pStack.shrink(1); +// return pStack; +// } +// +// @Override +// @ParametersAreNonnullByDefault +// protected @NotNull Projectile getProjectile(Level pLevel, Position pos, ItemStack pStack) { +// return new SwarmDroneEntity(pos.x(), pos.y(), pos.z(), pLevel); +// } +// +// @Override +// protected void playSound(BlockSource blockSource) { +// blockSource.getLevel().playSound(null, blockSource.getPos(), ModSounds.DECOY_FIRE.get(), SoundSource.BLOCKS, 2.0F, 1.0F); +// } +// }; +// } + +// public class SwarmDroneDispenseBehavior extends ProjectileDispenseBehavior { +// +// public SwarmDroneDispenseBehavior(Item projectile) { +// super(projectile); +// } +// +// @Override +// @ParametersAreNonnullByDefault +// public @NotNull ItemStack execute(BlockSource blockSource, ItemStack stack) { +// Level level = blockSource.level(); +// Position position = DispenserBlock.getDispensePosition(blockSource); +// Direction direction = blockSource.state().getValue(DispenserBlock.FACING); +// Projectile projectile = this.getProjectile(level, position, stack); +// +// float yVec = direction.getStepY(); +// if (direction != Direction.DOWN) { +// yVec += 1F; +// } +// +// projectile.shoot(direction.getStepX(), yVec, direction.getStepZ(), this.getPower(), this.getUncertainty()); +// +// BlockHitResult result = level.clip(new ClipContext(new Vec3(position.x(), position.y(), position.z()), +// new Vec3(position.x(), position.y(), position.z()).add(new Vec3(direction.step().mul(128))), +// ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, projectile)); +// Vec3 hitPos = result.getLocation(); +// ((SwarmDroneEntity) projectile).setGuideType(1); +// ((SwarmDroneEntity) projectile).setTargetVec(hitPos); +// +// level.addFreshEntity(projectile); +// pStack.shrink(1); +// return pStack; +// return super.execute(blockSource, stack); +// } +// } + + // TODO 怎么发射? + + @Override + @ParametersAreNonnullByDefault + public void appendHoverText(ItemStack stack, TooltipContext context, List tooltipComponents, TooltipFlag tooltipFlag) { + tooltipComponents.add(Component.translatable("des.superbwarfare.swarm_drone").withStyle(ChatFormatting.GRAY)); + } + + @Override + public @NotNull DispenseConfig createDispenseConfig() { + return ProjectileItem.DispenseConfig.builder() + .uncertainty(1) + .power(0.5f) + .build(); + } + + + @Override + @ParametersAreNonnullByDefault + public @NotNull Projectile asProjectile(Level level, Position pos, ItemStack stack, Direction direction) { + return new SwarmDroneEntity(pos.x(), pos.y(), pos.z(), level); + } +} \ No newline at end of file diff --git a/src/main/resources/assets/superbwarfare/lang/en_us.json b/src/main/resources/assets/superbwarfare/lang/en_us.json index 83f67cacc..11318e3fc 100644 --- a/src/main/resources/assets/superbwarfare/lang/en_us.json +++ b/src/main/resources/assets/superbwarfare/lang/en_us.json @@ -169,6 +169,7 @@ "item.superbwarfare.wire_guide_missile": "Wire Guide Missile", "des.superbwarfare.wire_guide_missile": "Suitable for BMP-2", "item.superbwarfare.swarm_drone": "Swarm Drone", + "des.superbwarfare.swarm_drone": "Suitable for YX-100 MBT", "item.superbwarfare.medium_aerial_bomb": "Medium Aerial Bomb", "des.superbwarfare.medium_aerial_bomb": "Suitable for A-10 Thunderbolt II", "item.superbwarfare.agm": "Air-to-ground Missile", diff --git a/src/main/resources/assets/superbwarfare/lang/zh_cn.json b/src/main/resources/assets/superbwarfare/lang/zh_cn.json index 9333493ac..ef523e85d 100644 --- a/src/main/resources/assets/superbwarfare/lang/zh_cn.json +++ b/src/main/resources/assets/superbwarfare/lang/zh_cn.json @@ -169,6 +169,7 @@ "item.superbwarfare.wire_guide_missile": "线控导弹", "des.superbwarfare.wire_guide_missile": "适配BMP-2步兵战车", "item.superbwarfare.swarm_drone": "蜂群无人机", + "des.superbwarfare.swarm_drone": "适配YX-100主战坦克", "item.superbwarfare.medium_aerial_bomb": "中型航空炸弹", "des.superbwarfare.medium_aerial_bomb": "适配A-10攻击机", "item.superbwarfare.agm": "空对地导弹",