重置碰撞配置

This commit is contained in:
17146 2025-03-18 01:15:58 +08:00
parent ed023bebea
commit 490e340ea9
3 changed files with 16 additions and 23 deletions

View file

@ -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<List<? extends String>> COLLISION_ENTITY_BLACKLIST;
public static ForgeConfigSpec.ConfigValue<List<? extends String>> COLLISION_ENTITY_WHITELIST;
@SuppressWarnings("SpellCheckingInspection")
public static final List<? extends String> DEFAULT_COLLISION_ENTITY_BLACKLIST =
List.of("create:super_glue", "zombieawareness:scent", "mts:builder_rendering");
public static final List<? extends String> 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");

View file

@ -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
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())))
) {
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());
|| VehicleConfig.COLLISION_ENTITY_WHITELIST.get().contains(type.toString());
}
return false;
}

View file

@ -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());
}
}