From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sun, 3 Jan 2021 22:27:43 -0800 Subject: [PATCH] Configurable door breaking difficulty diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java index db9d8d1f30c671207617fc75c24b771cd7a23391..75b4da3d38912e52e7ca4d99d51bd97e06808303 100644 --- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java @@ -2,7 +2,10 @@ package com.destroystokyo.paper; import java.util.Arrays; import java.util.List; - +import java.util.stream.Collectors; +import net.minecraft.world.Difficulty; +import net.minecraft.world.entity.monster.Vindicator; +import net.minecraft.world.entity.monster.Zombie; import com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray.EngineMode; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; @@ -89,6 +92,25 @@ public class PaperWorldConfig { disableMobSpawnerSpawnEggTransformation = getBoolean("game-mechanics.disable-mob-spawner-spawn-egg-transformation", disableMobSpawnerSpawnEggTransformation); } + public List zombieBreakDoors; + public List vindicatorBreakDoors; + private void setupEntityBreakingDoors() { + zombieBreakDoors = getEnumList( + "door-breaking-difficulty.zombie", + java.util.Arrays.stream(Difficulty.values()) + .filter(Zombie.DOOR_BREAKING_PREDICATE) + .collect(Collectors.toList()), + Difficulty.class + ); + vindicatorBreakDoors = getEnumList( + "door-breaking-difficulty.vindicator", + java.util.Arrays.stream(Difficulty.values()) + .filter(Vindicator.DOOR_BREAKING_PREDICATE) + .collect(Collectors.toList()), + Difficulty.class + ); + } + public short keepLoadedRange; private void keepLoadedRange() { keepLoadedRange = (short) (getInt("keep-spawn-loaded-range", Math.min(spigotConfig.viewDistance, 10)) * 16); @@ -140,6 +162,11 @@ public class PaperWorldConfig { return config.getString("world-settings." + worldName + "." + path, config.getString("world-settings.default." + path)); } + private > List getEnumList(String path, List def, Class type) { + config.addDefault("world-settings.default." + path, def.stream().map(Enum::name).collect(Collectors.toList())); + return ((List) (config.getList("world-settings." + worldName + "." + path, config.getList("world-settings.default." + path)))).stream().map(s -> Enum.valueOf(type, s)).collect(Collectors.toList()); + } + public int cactusMaxHeight; public int reedMaxHeight; public int bambooMaxHeight; diff --git a/src/main/java/net/minecraft/world/entity/monster/Vindicator.java b/src/main/java/net/minecraft/world/entity/monster/Vindicator.java index e3f900153c10a01fd8b1ba346fe87880c958b76a..beb6943bcab48d914c32c5de07851eb1731005e2 100644 --- a/src/main/java/net/minecraft/world/entity/monster/Vindicator.java +++ b/src/main/java/net/minecraft/world/entity/monster/Vindicator.java @@ -195,7 +195,7 @@ public class Vindicator extends AbstractIllager { static class VindicatorBreakDoorGoal extends BreakDoorGoal { public VindicatorBreakDoorGoal(Mob mob) { - super(mob, 6, Vindicator.DOOR_BREAKING_PREDICATE); + super(mob, 6, com.google.common.base.Predicates.in(mob.level.paperConfig.vindicatorBreakDoors)); // Paper this.setFlags(EnumSet.of(Goal.Flag.MOVE)); } diff --git a/src/main/java/net/minecraft/world/entity/monster/Zombie.java b/src/main/java/net/minecraft/world/entity/monster/Zombie.java index 6c4c5756def8eb368cbc6e9319ae6f7ddccf0499..bb3b932c57fd1e5b1517940c7602c7f4aeeaf17e 100644 --- a/src/main/java/net/minecraft/world/entity/monster/Zombie.java +++ b/src/main/java/net/minecraft/world/entity/monster/Zombie.java @@ -100,7 +100,7 @@ public class Zombie extends Monster { public Zombie(EntityType type, Level world) { super(type, world); - this.breakDoorGoal = new BreakDoorGoal(this, Zombie.DOOR_BREAKING_PREDICATE); + this.breakDoorGoal = new BreakDoorGoal(this, com.google.common.base.Predicates.in(world.paperConfig.zombieBreakDoors)); // Paper } public Zombie(Level world) {