Skip to content

Commit

Permalink
Code style improvements and review findings
Browse files Browse the repository at this point in the history
- var -> explicit type, unless it's obvious from a constructor call
- extracted API interface for ConfigDataManager
- replace "drop nothing" flag in LooniumComponent with "override drop"; mobs will drop whatever is defined as "to drop" when that flag is set
- don't bother creating specialized map types for detected structures
- adjust variable names in renderHUD code
- replaced some manually validated attribute CODECs with corresponding predefined ExtraCodecs variants
- allow configured mana cost for a structure to be zero
- add default translation for botania:loonium_offhand_equipment tag
  • Loading branch information
TheRealWormbo committed Aug 18, 2024
1 parent 1c516fd commit 39cc716
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
import vazkii.botania.common.brew.BotaniaBrews;
import vazkii.botania.common.brew.BotaniaMobEffects;
import vazkii.botania.common.command.SkyblockCommand;
import vazkii.botania.common.config.ConfigDataManager;
import vazkii.botania.common.config.ConfigDataManagerImpl;
import vazkii.botania.common.crafting.BotaniaRecipeTypes;
import vazkii.botania.common.entity.BotaniaEntities;
import vazkii.botania.common.entity.GaiaGuardianEntity;
Expand Down Expand Up @@ -139,7 +139,7 @@ public void onInitialize() {
PatchouliAPI.get().registerMultiblock(prefix("gaia_ritual"), GaiaGuardianEntity.ARENA_MULTIBLOCK.get());

OrechidManager.registerListener();
ConfigDataManager.registerListener();
ConfigDataManagerImpl.registerListener();
CraftyCrateBlockEntity.registerListener();
CorporeaNodeDetectors.register(new FabricTransferCorporeaNodeDetector());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
import vazkii.botania.common.brew.BotaniaMobEffects;
import vazkii.botania.common.brew.effect.SoulCrossMobEffect;
import vazkii.botania.common.command.SkyblockCommand;
import vazkii.botania.common.config.ConfigDataManager;
import vazkii.botania.common.config.ConfigDataManagerImpl;
import vazkii.botania.common.crafting.BotaniaRecipeTypes;
import vazkii.botania.common.entity.BotaniaEntities;
import vazkii.botania.common.entity.GaiaGuardianEntity;
Expand Down Expand Up @@ -167,7 +167,7 @@ public void commonSetup(FMLCommonSetupEvent evt) {
PatchouliAPI.get().registerMultiblock(prefix("gaia_ritual"), GaiaGuardianEntity.ARENA_MULTIBLOCK.get());

OrechidManager.registerListener();
ConfigDataManager.registerListener();
ConfigDataManagerImpl.registerListener();
CraftyCrateBlockEntity.registerListener();
CorporeaNodeDetectors.register(new ForgeCapCorporeaNodeDetector());
if (ModList.get().isLoaded("inventorysorter")) {
Expand Down
2 changes: 1 addition & 1 deletion Xplat/src/main/java/vazkii/botania/api/BotaniaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
import org.slf4j.LoggerFactory;

import vazkii.botania.api.brew.Brew;
import vazkii.botania.api.configdata.ConfigDataManager;
import vazkii.botania.api.corporea.CorporeaNodeDetector;
import vazkii.botania.api.internal.DummyManaNetwork;
import vazkii.botania.api.internal.ManaNetwork;
import vazkii.botania.common.config.ConfigDataManager;

import java.util.Collections;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package vazkii.botania.api.configdata;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.PreparableReloadListener;

import org.jetbrains.annotations.Nullable;

public interface ConfigDataManager extends PreparableReloadListener {
@Nullable
LooniumStructureConfiguration getEffectiveLooniumStructureConfiguration(ResourceLocation id);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package vazkii.botania.api.configdata;

import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.codecs.RecordCodecBuilder;

import net.minecraft.core.registries.BuiltInRegistries;
Expand All @@ -17,11 +16,7 @@ public class LooniumMobEffectToApply {
public static final Codec<LooniumMobEffectToApply> CODEC = RecordCodecBuilder.create(
instance -> instance.group(
BuiltInRegistries.MOB_EFFECT.byNameCodec().fieldOf("effect").forGetter(me -> me.effect),
ExtraCodecs.validate(Codec.INT,
duration -> duration > 0
? DataResult.success(duration)
: DataResult.error(() -> "Invalid effect duration"))
.optionalFieldOf("duration", MobEffectInstance.INFINITE_DURATION)
ExtraCodecs.POSITIVE_INT.optionalFieldOf("duration", MobEffectInstance.INFINITE_DURATION)
.forGetter(me -> me.duration),
Codec.intRange(0, 255).optionalFieldOf("amplifier", 0)
.forGetter(me -> me.amplifier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
import net.minecraft.world.level.levelgen.structure.StructureSpawnOverride;

import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.common.block.flower.functional.LooniumBlockEntity;

import java.util.List;
import java.util.Optional;
import java.util.function.Function;

public class LooniumStructureConfiguration {
public static final int DEFAULT_COST = 35000;
public static final int DEFAULT_MAX_NEARBY_MOBS = 10;
public static final Codec<LooniumStructureConfiguration> CODEC = ExtraCodecs.validate(
RecordCodecBuilder.create(
instance -> instance.group(
ResourceLocation.CODEC.optionalFieldOf("parent")
.forGetter(lsc -> Optional.ofNullable(lsc.parent)),
ExtraCodecs.POSITIVE_INT.optionalFieldOf("manaCost")
ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("manaCost")
.forGetter(lsc -> Optional.ofNullable(lsc.manaCost)),
ExtraCodecs.POSITIVE_INT.optionalFieldOf("maxNearbyMobs")
.forGetter(lsc -> Optional.ofNullable(lsc.maxNearbyMobs)),
Expand All @@ -47,9 +48,9 @@ public class LooniumStructureConfiguration {
if (lsc.spawnedMobs != null && lsc.spawnedMobs.isEmpty()) {
return DataResult.error(() -> "Spawned mobs cannot be empty");
}
if (lsc.manaCost != null && lsc.manaCost > LooniumBlockEntity.DEFAULT_COST) {
if (lsc.manaCost != null && lsc.manaCost > DEFAULT_COST) {
return DataResult.error(() -> "Mana costs above %d are currently not supported"
.formatted(LooniumBlockEntity.DEFAULT_COST));
.formatted(DEFAULT_COST));
}
return DataResult.success(lsc);
});
Expand Down
Loading

0 comments on commit 39cc716

Please sign in to comment.