diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cfea9c92..68f1fbcd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Correct BWG Pitcher Plant Item Models - Slight Change to FruitBlockProcessor#finalizeProcessing to be more Efficient - Use SpawnPlacementRegisterEvent on Forge to Register Entity Spawn Placements +- Add Config to Enable/Disable Spawning of Oddion and Man O War # 1.4.4 - Add Russian Translations (ru_ru) (Credits: j-tap) diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/config/ConfigLoader.java b/Common/src/main/java/net/potionstudios/biomeswevegone/config/ConfigLoader.java new file mode 100644 index 000000000..1d84f7be4 --- /dev/null +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/config/ConfigLoader.java @@ -0,0 +1,41 @@ +package net.potionstudios.biomeswevegone.config; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import net.potionstudios.biomeswevegone.PlatformHandler; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * Makes or loads a config file + * @see Gson + * @author Joseph T. McQuigg + */ +public class ConfigLoader { + /** The Gson instance for the Config Loader. */ + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + + /** + * Loads or Creates a config file + * + * @param clazz The class of the config file. + * @return The config file. + */ + public static T loadConfig(@NotNull Class clazz, String name) { + try { + Path configPath = PlatformHandler.PLATFORM_HANDLER.configPath().resolve(name + ".json"); + T value = clazz.getConstructor().newInstance(); + + if (Files.notExists(configPath)) Files.createDirectories(configPath.getParent()); + else if (Files.exists(configPath)) value = GSON.fromJson(Files.newBufferedReader(configPath), clazz); + + Files.writeString(configPath, GSON.toJson(value)); + return value; + } catch (Exception e) { + throw new RuntimeException("Failed to load config.", e); + } + } +} diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/config/configs/BWGMobSpawnConfig.java b/Common/src/main/java/net/potionstudios/biomeswevegone/config/configs/BWGMobSpawnConfig.java new file mode 100644 index 000000000..566a2cf83 --- /dev/null +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/config/configs/BWGMobSpawnConfig.java @@ -0,0 +1,15 @@ +package net.potionstudios.biomeswevegone.config.configs; + +import net.potionstudios.biomeswevegone.config.ConfigLoader; + +public class BWGMobSpawnConfig { + + public static final BWGSpawnConfig INSTANCE = ConfigLoader.loadConfig(BWGMobSpawnConfig.class, "mob_spawn").spawn; + + public BWGSpawnConfig spawn = new BWGSpawnConfig(); + + public static class BWGSpawnConfig { + public boolean man_o_war = true; + public boolean oddion = true; + } +} diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/manowar/ManOWar.java b/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/manowar/ManOWar.java index dc0c3adac..f28202fca 100644 --- a/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/manowar/ManOWar.java +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/manowar/ManOWar.java @@ -32,6 +32,7 @@ import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.pathfinder.BlockPathTypes; import net.minecraft.world.phys.Vec3; +import net.potionstudios.biomeswevegone.config.configs.BWGMobSpawnConfig; import net.potionstudios.biomeswevegone.world.entity.BWGEntities; import net.potionstudios.biomeswevegone.world.item.BWGItems; import org.jetbrains.annotations.NotNull; @@ -131,7 +132,7 @@ public boolean canBeLeashed(@NotNull Player player) { } public static boolean checkManOWarSpawnRules(EntityType entity, LevelAccessor world, MobSpawnType spawnType, BlockPos pos, RandomSource rand) { - return pos.getY() <= (world.getSeaLevel() - 2) && world.getFluidState(pos.below()).is(FluidTags.WATER); + return BWGMobSpawnConfig.INSTANCE.man_o_war && pos.getY() <= (world.getSeaLevel() - 2) && world.getFluidState(pos.below()).is(FluidTags.WATER); } @Override diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/oddion/Oddion.java b/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/oddion/Oddion.java index c3f9e39f1..d5bbb6eab 100644 --- a/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/oddion/Oddion.java +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/oddion/Oddion.java @@ -32,6 +32,7 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.AABB; +import net.potionstudios.biomeswevegone.config.configs.BWGMobSpawnConfig; import net.potionstudios.biomeswevegone.sounds.BWGSounds; import net.potionstudios.biomeswevegone.world.item.BWGItems; import org.jetbrains.annotations.NotNull; @@ -105,7 +106,6 @@ protected void registerGoals() { this.goalSelector.addGoal(2, new LookAtPlayerGoal(this, Player.class, 2.0F)); this.goalSelector.addGoal(3, new RandomLookAroundGoal(this)); this.goalSelector.addGoal(4, new TemptGoal(this, 1.2D, Ingredient.of(Items.BONE_MEAL), false)); - super.registerGoals(); } @Override @@ -121,7 +121,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) { } public static boolean checkOddionSpawnRules(EntityType entity, LevelAccessor world, MobSpawnType spawnType, BlockPos pos, RandomSource rand) { - return world.getBlockState(pos.below()).is(BlockTags.DIRT); + return BWGMobSpawnConfig.INSTANCE.oddion && world.getBlockState(pos.below()).is(BlockTags.DIRT); } @Nullable