Skip to content

Commit

Permalink
Add Config to Enable/Disable Spawning of Oddion and Man O War. Closes #…
Browse files Browse the repository at this point in the history
…182

Signed-off-by: Joseph T. McQuigg <[email protected]>
  • Loading branch information
JT122406 committed Dec 20, 2024
1 parent 4ff8137 commit d5d61f5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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> T loadConfig(@NotNull Class<T> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -131,7 +132,7 @@ public boolean canBeLeashed(@NotNull Player player) {
}

public static boolean checkManOWarSpawnRules(EntityType<? extends ManOWar> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -121,7 +121,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) {
}

public static boolean checkOddionSpawnRules(EntityType<? extends Oddion> 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
Expand Down

0 comments on commit d5d61f5

Please sign in to comment.