Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fix): crash when effect gets saved #18

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public static void init() {
MANAGER = Suppliers.memoize(() -> RegistrarManager.get(MOD_ID));
ObjectRegistry.init();
EntityTypeRegistry.init();
MobEffectRegistry.init();
TabRegistry.init();
ScreenhandlerTypeRegistry.init();
RecipeTypeRegistry.init();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.satisfy.farm_and_charm.platform;

import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.core.Holder;
import net.minecraft.world.effect.MobEffect;

import java.util.function.Supplier;

public class EffectRegister {
@ExpectPlatform
public static Holder<MobEffect> registerEffect(String name, Supplier<MobEffect> effect) {throw new AssertionError();}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,39 @@
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.Registrar;
import dev.architectury.registry.registries.RegistrySupplier;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.effect.MobEffect;
import net.satisfy.farm_and_charm.FarmAndCharm;
import net.satisfy.farm_and_charm.effect.*;
import net.satisfy.farm_and_charm.platform.EffectRegister;
import net.satisfy.farm_and_charm.util.FarmAndCharmIdentifier;

import java.util.function.Supplier;

public class MobEffectRegistry {
private static final DeferredRegister<MobEffect> MOB_EFFECTS = DeferredRegister.create(FarmAndCharm.MOD_ID, Registries.MOB_EFFECT);
private static final Registrar<MobEffect> MOB_EFFECTS_REGISTRAR = MOB_EFFECTS.getRegistrar();

public static final RegistrySupplier<MobEffect> SWEETS;
public static final RegistrySupplier<MobEffect> HORSE_FODDER;
public static final RegistrySupplier<MobEffect> DOG_FOOD;
public static final RegistrySupplier<MobEffect> CLUCK;
public static final RegistrySupplier<MobEffect> GRANDMAS_BLESSING;
public static final RegistrySupplier<MobEffect> RESTED;
public static final RegistrySupplier<MobEffect> FARMERS_BLESSING;
public static final RegistrySupplier<MobEffect> SUSTENANCE;
public static final RegistrySupplier<MobEffect> SATIATION;
public static final RegistrySupplier<MobEffect> FEAST;

private static RegistrySupplier<MobEffect> registerEffect(String name, Supplier<MobEffect> effect) {
if (Platform.isNeoForge()) {
return MOB_EFFECTS.register(name, effect);
}
return MOB_EFFECTS_REGISTRAR.register(FarmAndCharmIdentifier.of(name), effect);
}

public static void init() {
FarmAndCharm.LOGGER.debug("Registering MobEffects for " + FarmAndCharm.MOD_ID);
MOB_EFFECTS.register();
}
public static final Holder<MobEffect> SWEETS;
public static final Holder<MobEffect> HORSE_FODDER;
public static final Holder<MobEffect> DOG_FOOD;
public static final Holder<MobEffect> CLUCK;
public static final Holder<MobEffect> GRANDMAS_BLESSING;
public static final Holder<MobEffect> RESTED;
public static final Holder<MobEffect> FARMERS_BLESSING;
public static final Holder<MobEffect> SUSTENANCE;
public static final Holder<MobEffect> SATIATION;
public static final Holder<MobEffect> FEAST;

static {
SWEETS = registerEffect("sweets", SweetsEffect::new);
HORSE_FODDER = registerEffect("horse_fodder", HorseFodderEffect::new);
DOG_FOOD = registerEffect("dog_food", DogFoodEffect::new);
CLUCK = registerEffect("cluck", ChickenEffect::new);
GRANDMAS_BLESSING = registerEffect("grandmas_blessing", GrandmasBlessingEffect::new);
RESTED = registerEffect("rested", RestedEffect::new);
FARMERS_BLESSING = registerEffect("farmers_blessing", FarmersBlessingEffect::new);
SUSTENANCE = registerEffect("sustenance", SustenanceEffect::new);
SATIATION = registerEffect("satiation", SatiationEffect::new);
FEAST = registerEffect("feast", FeastEffect::new);
SWEETS = EffectRegister.registerEffect("sweets", SweetsEffect::new);
HORSE_FODDER = EffectRegister.registerEffect("horse_fodder", HorseFodderEffect::new);
DOG_FOOD = EffectRegister.registerEffect("dog_food", DogFoodEffect::new);
CLUCK = EffectRegister.registerEffect("cluck", ChickenEffect::new);
GRANDMAS_BLESSING = EffectRegister.registerEffect("grandmas_blessing", GrandmasBlessingEffect::new);
RESTED = EffectRegister.registerEffect("rested", RestedEffect::new);
FARMERS_BLESSING = EffectRegister.registerEffect("farmers_blessing", FarmersBlessingEffect::new);
SUSTENANCE = EffectRegister.registerEffect("sustenance", SustenanceEffect::new);
SATIATION = EffectRegister.registerEffect("satiation", SatiationEffect::new);
FEAST = EffectRegister.registerEffect("feast", FeastEffect::new);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.satisfy.farm_and_charm.platform.fabric;

import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.effect.MobEffect;
import net.satisfy.farm_and_charm.util.FarmAndCharmIdentifier;

import java.util.function.Supplier;

public class EffectRegisterImpl {
public static Holder<MobEffect> registerEffect(String name, Supplier<MobEffect> effect) {
return Registry.registerForHolder(BuiltInRegistries.MOB_EFFECT, FarmAndCharmIdentifier.of(name), effect.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.satisfy.farm_and_charm.FarmAndCharm;
import net.satisfy.farm_and_charm.platform.neoforge.EffectRegisterImpl;
import net.satisfy.farm_and_charm.registry.CompostableRegistry;

@Mod(FarmAndCharm.MOD_ID)
public class FarmAndCharmNeoForge {

public FarmAndCharmNeoForge(IEventBus modBus) {
FarmAndCharm.init();
EffectRegisterImpl.MOB_EFFECTS.register(modBus);
modBus.addListener(this::commonSetup);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.satisfy.farm_and_charm.platform.neoforge;

import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.effect.MobEffect;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.satisfy.farm_and_charm.FarmAndCharm;

import java.util.function.Supplier;

public class EffectRegisterImpl {
public static final DeferredRegister<MobEffect> MOB_EFFECTS = DeferredRegister.create(BuiltInRegistries.MOB_EFFECT, FarmAndCharm.MOD_ID);

public static Holder<MobEffect> registerEffect(String name, Supplier<MobEffect> effect) {
return MOB_EFFECTS.register(name, effect);
}
}