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 18, 2024
1 parent 667c8ec commit 88d10af
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Move Config Classes to Config Package
- Correct BWG Pitcher Plant Item Models
- Slight Change to FruitBlockProcessor#finalizeProcessing to be more Efficient
- Add Config to Enable/Disable Spawning of Oddion and Man O War

# 2.2.5
- Make Pale Pumpkin Set Compostable
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 @@ -38,6 +38,7 @@ private static <E extends Entity> Supplier<EntityType<E>> createEntity(String id
return PlatformHandler.PLATFORM_HANDLER.register(BuiltInRegistries.ENTITY_TYPE, id, ()-> EntityType.Builder.of(factory, category).sized(width, height).clientTrackingRange(trackingRange).build(id));
}

@SuppressWarnings("unchecked")
public static <T extends Mob> void registerSpawnPlacements(Consumer<SpawnPlacement<T>> consumer) {
consumer.accept((SpawnPlacement<T>) new SpawnPlacement<>(MAN_O_WAR, SpawnPlacementTypes.IN_WATER, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, ManOWar::checkManOWarSpawnRules));
consumer.accept((SpawnPlacement<T>) new SpawnPlacement<>(ODDION, SpawnPlacementTypes.ON_GROUND, Heightmap.Types.WORLD_SURFACE, Oddion::checkOddionSpawnRules));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.pathfinder.PathType;
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 @@ -122,7 +123,7 @@ public boolean canBeLeashed() {
}

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 @@ -121,11 +122,11 @@ 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);
}

@Override
public @Nullable SpawnGroupData finalizeSpawn(ServerLevelAccessor level, @NotNull DifficultyInstance difficulty, @NotNull MobSpawnType spawnType, @Nullable SpawnGroupData spawnGroupData) {
public @Nullable SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor level, @NotNull DifficultyInstance difficulty, @NotNull MobSpawnType spawnType, @Nullable SpawnGroupData spawnGroupData) {
this.setVariant(Variant.getSpawnVariant(level.getRandom()));
return super.finalizeSpawn(level, difficulty, spawnType, spawnGroupData);
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fabric_api_version=0.110.0

forge_version=52.0.28

neoforge_version=21.1.84
neoforge_version=21.1.90

parchment=2024.11.17

Expand Down

0 comments on commit 88d10af

Please sign in to comment.