Skip to content

Commit

Permalink
Remove crafting extension registry
Browse files Browse the repository at this point in the history
Temporarily disable FlagIngredient + misc. cleanup
  • Loading branch information
BrokenK3yboard committed Dec 9, 2024
1 parent 92c67f2 commit 5f1da59
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 344 deletions.
7 changes: 2 additions & 5 deletions src/main/java/org/violetmoon/zeta/Zeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public Zeta(String modid, Logger log, ZetaSide side) {
this.registry = createRegistry();
this.renderLayerRegistry = createRenderLayerRegistry();
this.dyeables = createDyeablesRegistry();
this.craftingExtensions = createCraftingExtensionsRegistry();
this.brewingRegistry = createBrewingRegistry();
this.advancementModifierRegistry = createAdvancementModifierRegistry();
this.pottedPlantRegistry = createPottedPlantRegistry();
Expand All @@ -67,8 +66,7 @@ public Zeta(String modid, Logger log, ZetaSide side) {

this.entitySpawn = createEntitySpawnHandler();

loadBus.subscribe(craftingExtensions)
.subscribe(dyeables)
loadBus.subscribe(dyeables)
.subscribe(brewingRegistry)
.subscribe(advancementModifierRegistry)
.subscribe(fuel)
Expand All @@ -92,7 +90,6 @@ public Zeta(String modid, Logger log, ZetaSide side) {
public final RegistryUtil registryUtil = new RegistryUtil(this); //TODO: Delete this, only needed cause there's no way to get early registry names.
public final RenderLayerRegistry renderLayerRegistry;
public final DyeablesRegistry dyeables;
public final CraftingExtensionsRegistry craftingExtensions;
public final BrewingRegistry brewingRegistry;
public final AdvancementModifierRegistry advancementModifierRegistry;
public final PottedPlantRegistry pottedPlantRegistry;
Expand Down Expand Up @@ -159,7 +156,7 @@ public ZetaModuleManager createModuleManager() {
public RenderLayerRegistry createRenderLayerRegistry() {
return new RenderLayerRegistry();
}
public abstract CraftingExtensionsRegistry createCraftingExtensionsRegistry();

public DyeablesRegistry createDyeablesRegistry() {
return new DyeablesRegistry();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public CategoryButton(int x, int y, int w, int h, Component text, ItemStack icon

@Override
public void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
super.render(guiGraphics, mouseX, mouseY, partialTicks);
super.renderWidget(guiGraphics, mouseX, mouseY, partialTicks);

if(!active)
setTooltip(Tooltip.create(Component.translatable("quark.gui.config.missingaddon"))); // todo: QUARK REFERENCE
Expand Down
31 changes: 13 additions & 18 deletions src/main/java/org/violetmoon/zeta/config/ConfigFlagManager.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package org.violetmoon.zeta.config;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
import org.violetmoon.zeta.Zeta;
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.load.ZRegister;
import org.violetmoon.zeta.module.ZetaModule;
import org.violetmoon.zeta.recipe.FlagIngredient;
import org.violetmoon.zeta.registry.CraftingExtensionsRegistry;

import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public final class ConfigFlagManager {

Expand All @@ -24,8 +21,8 @@ public final class ConfigFlagManager {
private final Set<String> allFlags = new HashSet<>();
private final Map<String, Boolean> flags = new HashMap<>();

//TODO augh; needed for BrewingRegistry
public final FlagIngredient.Serializer flagIngredientSerializer = new FlagIngredient.Serializer(this);
// TODO augh; needed for BrewingRegistry
// public final FlagIngredient.Serializer flagIngredientSerializer = new FlagIngredient.Serializer(this);

public static final LootItemConditionType FLAG_CONDITION_TYPE = new LootItemConditionType(FlagLootCondition.CODEC);

Expand All @@ -37,15 +34,15 @@ public ConfigFlagManager(Zeta zeta) {

@LoadEvent
public void onRegister(ZRegister event) {
/*
CraftingExtensionsRegistry ext = event.getCraftingExtensionsRegistry();

//Note: These SHOULD be Quark-independent already, but hell if I know. Todo: Double check it.
ext.registerConditionSerializer(new FlagCondition.Serializer(this, ResourceLocation.fromNamespaceAndPath(zeta.modid, "flag")));
ext.registerConditionSerializer(new FlagCondition.Serializer(this, ResourceLocation.fromNamespaceAndPath(zeta.modid, "advancement_flag"), () -> ZetaGeneralConfig.enableModdedAdvancements));

*/
Registry.register(BuiltInRegistries.LOOT_CONDITION_TYPE, ResourceLocation.fromNamespaceAndPath(zeta.modid, "flag"), FLAG_CONDITION_TYPE);
ext.registerIngredientSerializer(ResourceLocation.fromNamespaceAndPath(zeta.modid, "flag"), flagIngredientSerializer);

// ext.registerIngredientSerializer(ResourceLocation.fromNamespaceAndPath(zeta.modid, "flag"), flagIngredientSerializer);
SyncedFlagHandler.setupFlagManager(this);
}

Expand All @@ -55,9 +52,7 @@ public void clear() {

public void putFlag(ZetaModule module, String flag, boolean value) {
flags.put(flag, value && module.enabled);
if(!allFlags.contains(flag)) {
allFlags.add(flag);
}
allFlags.add(flag);
}

public void putModuleFlag(ZetaModule module) {
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/org/violetmoon/zeta/config/FlagCondition.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package org.violetmoon.zeta.config;

import java.util.function.BooleanSupplier;

import com.mojang.serialization.MapCodec;
import net.minecraft.resources.ResourceLocation;
import org.violetmoon.zeta.recipe.IZetaCondition;
import org.violetmoon.zeta.recipe.IZetaConditionSerializer;
import org.violetmoon.zeta.util.BooleanSuppliers;

import com.google.gson.JsonObject;

import net.minecraft.resources.ResourceLocation;
import java.util.function.BooleanSupplier;

/**
* @author WireSegal
Expand All @@ -17,8 +13,8 @@
public record FlagCondition(ConfigFlagManager cfm, String flag, ResourceLocation loc, BooleanSupplier extraCondition) implements IZetaCondition {

@Override
public ResourceLocation getID() {
return loc;
public MapCodec<? extends IZetaCondition> codec() {
return null;
}

@Override
Expand All @@ -27,11 +23,12 @@ public boolean test(IContext context) {
throw new RuntimeException("Illegal flag: " + flag);

if(!cfm.isValidFlag(flag))
cfm.zeta.log.warn("Non-existent flag " + flag + " being used");
cfm.zeta.log.warn("Non-existent flag {} being used", flag);

return extraCondition.getAsBoolean() && cfm.getFlag(flag);
}

/*
public static class Serializer implements IZetaConditionSerializer<FlagCondition> {
private final ConfigFlagManager cfm;
private final ResourceLocation location;
Expand Down Expand Up @@ -62,4 +59,5 @@ public ResourceLocation getID() {
return location;
}
}
}
*/
}
5 changes: 0 additions & 5 deletions src/main/java/org/violetmoon/zeta/event/load/ZRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.violetmoon.zeta.advancement.AdvancementModifierRegistry;
import org.violetmoon.zeta.event.bus.IZetaLoadEvent;
import org.violetmoon.zeta.registry.BrewingRegistry;
import org.violetmoon.zeta.registry.CraftingExtensionsRegistry;
import org.violetmoon.zeta.registry.RenderLayerRegistry;
import org.violetmoon.zeta.registry.VariantRegistry;
import org.violetmoon.zeta.registry.ZetaRegistry;
Expand All @@ -21,10 +20,6 @@ public ZetaRegistry getRegistry() {
return zeta.registry;
}

public CraftingExtensionsRegistry getCraftingExtensionsRegistry() {
return zeta.craftingExtensions;
}

public BrewingRegistry getBrewingRegistry() {
return zeta.brewingRegistry;
}
Expand Down
78 changes: 44 additions & 34 deletions src/main/java/org/violetmoon/zeta/recipe/FlagIngredient.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,39 @@
package org.violetmoon.zeta.recipe;

import java.util.Arrays;
import java.util.stream.Stream;

import net.neoforged.neoforge.common.crafting.ICustomIngredient;
import org.jetbrains.annotations.NotNull;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.neoforged.neoforge.common.crafting.IngredientType;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.zeta.Zeta;
import org.violetmoon.zeta.config.ConfigFlagManager;

import com.google.gson.JsonObject;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import java.util.Arrays;
import java.util.stream.Stream;

/**
* @author WireSegal
* Created at 3:44 PM on 10/20/19.
*/
public class FlagIngredient implements ICustomIngredient, IZetaIngredient<FlagIngredient> { //AccessWidener? Idk I think this is cooked.
public class FlagIngredient implements IZetaCustomIngredient { // TODO: Abstract later, use NF-provided CustomIngredient for now

private final Ingredient parent;

private final ConfigFlagManager cfm;
private final String flag;
private final IZetaIngredientSerializer<FlagIngredient> serializer;

public FlagIngredient(Ingredient parent, String flag, ConfigFlagManager cfm, IZetaIngredientSerializer<FlagIngredient> serializer) {
public FlagIngredient(Ingredient parent, String flag, ConfigFlagManager cfm) {
this.parent = parent;
this.cfm = cfm;
this.flag = flag;
this.serializer = serializer;
}

@Override
public Stream<ItemStack> getItems() {
if (!cfm.getFlag(flag))
return Stream.empty();
return Arrays.stream(parent.getItems());
return (!cfm.getFlag(flag)) ? Stream.empty() : Arrays.stream(parent.getItems());
}

@Override
public boolean test(@Nullable ItemStack target) {
if (target == null || !cfm.getFlag(flag))
return false;

return parent.test(target);
return cfm.getFlag(flag) && parent.test(target);
}

@Override
Expand All @@ -55,19 +42,47 @@ public boolean isSimple() {
}

@Override
public IZetaIngredientSerializer<FlagIngredient> zetaGetSerializer() {
return serializer;
public IngredientType<?> getType() {
return null;
}

@Override
public Zeta getZeta() {
return cfm.zeta;
}

public record Serializer(ConfigFlagManager cfm) implements IZetaIngredientSerializer<FlagIngredient> {
/*
public record Serializer(ConfigFlagManager cfm) implements IZetaCustomIngredient {
@Override
public boolean test(ItemStack stack) {
return false;
}
@Override
public Stream<ItemStack> getItems() {
return Stream.empty();
}
@Deprecated(forRemoval = true)
public static Serializer INSTANCE;
@Override
public boolean isSimple() {
return false;
}
@Override
public IngredientType<?> getType() {
return null;
}
@Override
public Zeta getZeta() {
return cfm.zeta;
}
@NotNull
@Override
public FlagIngredient parse(@NotNull FriendlyByteBuf buffer) {
return new FlagIngredient(Ingredient.fromNetwork(buffer), buffer.readUtf(), cfm, this);
return new FlagIngredient(Ingredient.CONTENTS_STREAM_CODEC.decode(buffer), buffer.readUtf(), cfm, this);
}
@NotNull
Expand All @@ -83,10 +98,5 @@ public void write(@NotNull FriendlyByteBuf buffer, @NotNull FlagIngredient ingre
ingredient.parent.toNetwork(buffer);
buffer.writeUtf(ingredient.flag);
}

@Override
public Zeta getZeta() {
return cfm.zeta;
}
}
*/
}
15 changes: 8 additions & 7 deletions src/main/java/org/violetmoon/zeta/recipe/IZetaCondition.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package org.violetmoon.zeta.recipe;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import com.mojang.serialization.MapCodec;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

// Copy of Forge ICondition
public interface IZetaCondition {

ResourceLocation getID();
boolean test(IContext context);
MapCodec<? extends IZetaCondition> codec();

//TODO: do we need this
interface IContext {

default <T> Collection<Holder<T>> getTag(TagKey<T> key) {
return getAllTags(key.registry()).getOrDefault(key.location(), Set.of());
return this.getAllTags(key.registry()).getOrDefault(key.location(), Set.of());
}

<T> Map<ResourceLocation, Collection<Holder<T>>> getAllTags(ResourceKey<? extends Registry<T>> registry);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.violetmoon.zeta.recipe;

import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.common.crafting.ICustomIngredient;
import net.neoforged.neoforge.common.crafting.IngredientType;
import org.violetmoon.zeta.Zeta;

import java.util.stream.Stream;

// Copy of Neoforge ICustomIngredient
public interface IZetaCustomIngredient extends ICustomIngredient { // TODO: Abstract later, use NF-provided CustomIngredient for now
boolean test(ItemStack var1);

Stream<ItemStack> getItems();

boolean isSimple();

IngredientType<?> getType();

Zeta getZeta();
}
Loading

0 comments on commit 5f1da59

Please sign in to comment.