From 490e340ea9e2632c8ad5d678808fe30e2c8fc4a5 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Tue, 18 Mar 2025 01:15:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E7=BD=AE=E7=A2=B0=E6=92=9E=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/server/VehicleConfig.java | 13 ++++++------ .../vehicle/base/MobileVehicleEntity.java | 20 +++++++------------ .../superbwarfare/tools/SeekTool.java | 6 +++--- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/config/server/VehicleConfig.java b/src/main/java/com/atsuishio/superbwarfare/config/server/VehicleConfig.java index 323c67e35..47d9fb043 100644 --- a/src/main/java/com/atsuishio/superbwarfare/config/server/VehicleConfig.java +++ b/src/main/java/com/atsuishio/superbwarfare/config/server/VehicleConfig.java @@ -10,11 +10,10 @@ public class VehicleConfig { public static ForgeConfigSpec.BooleanValue COLLISION_DESTROY_HARD_BLOCKS; public static ForgeConfigSpec.BooleanValue VEHICLE_ITEM_PICKUP; - public static ForgeConfigSpec.ConfigValue> COLLISION_ENTITY_BLACKLIST; + public static ForgeConfigSpec.ConfigValue> COLLISION_ENTITY_WHITELIST; - @SuppressWarnings("SpellCheckingInspection") - public static final List DEFAULT_COLLISION_ENTITY_BLACKLIST = - List.of("create:super_glue", "zombieawareness:scent", "mts:builder_rendering"); + public static final List DEFAULT_COLLISION_ENTITY_WHITELIST = + List.of(); public static ForgeConfigSpec.IntValue REPAIR_COOLDOWN; public static ForgeConfigSpec.DoubleValue REPAIR_AMOUNT; @@ -101,9 +100,9 @@ public class VehicleConfig { builder.comment("Allow vehicles to pick up items"); VEHICLE_ITEM_PICKUP = builder.define("vehicle_item_pickup", true); - builder.comment("List of entities that cannot be damaged by collision"); - COLLISION_ENTITY_BLACKLIST = builder.defineList("collision_entity_blacklist", - DEFAULT_COLLISION_ENTITY_BLACKLIST, + builder.comment("List of entities that can be damaged by collision"); + COLLISION_ENTITY_WHITELIST = builder.defineList("collision_entity_whitelist", + DEFAULT_COLLISION_ENTITY_WHITELIST, e -> e instanceof String); builder.push("repair"); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/MobileVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/MobileVehicleEntity.java index aacb32a4e..054aa4028 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/MobileVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/MobileVehicleEntity.java @@ -31,6 +31,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.entity.EntityTypeTest; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.registries.ForgeRegistries; import org.jetbrains.annotations.NotNull; import org.joml.Math; import org.joml.Vector3f; @@ -316,19 +317,12 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity { var entities = level().getEntities(EntityTypeTest.forClass(Entity.class), frontBox, entity -> entity != this && entity != getFirstPassenger() && entity.getVehicle() == null) .stream().filter(entity -> { - if (entity.isAlive() - && (entity instanceof VehicleEntity - || entity instanceof Boat - || entity instanceof Minecart - || (entity instanceof LivingEntity living && !(living instanceof Player player && player.isSpectator()))) - ) { - return true; - - // todo 添加碰撞白名单 - -// var type = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()); -// if (type == null) return false; -// return !VehicleConfig.COLLISION_ENTITY_BLACKLIST.get().contains(type.toString()); + if (entity.isAlive()) { + var type = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()); + if (type == null) return false; + return (entity instanceof VehicleEntity || entity instanceof Boat || entity instanceof Minecart + || (entity instanceof LivingEntity living && !(living instanceof Player player && player.isSpectator()))) + || VehicleConfig.COLLISION_ENTITY_WHITELIST.get().contains(type.toString()); } return false; } diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java index 2e6448094..e3a65efa8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java @@ -103,12 +103,12 @@ public class SeekTool { return entity.isAlive() && !(entity instanceof ItemEntity || entity instanceof ExperienceOrb || entity instanceof HangingEntity || entity instanceof Projectile || entity instanceof ArmorStand || entity instanceof ClaymoreEntity || entity instanceof C4Entity || entity instanceof AreaEffectCloud) && !(entity instanceof Player player && player.isSpectator()) - && excludedByConfig(entity); + || includedByConfig(entity); } - public static boolean excludedByConfig(Entity entity) { + public static boolean includedByConfig(Entity entity) { var type = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()); if (type == null) return false; - return !VehicleConfig.COLLISION_ENTITY_BLACKLIST.get().contains(type.toString()); + return VehicleConfig.COLLISION_ENTITY_WHITELIST.get().contains(type.toString()); } }