Skip to content

Commit

Permalink
refactor: more documentation + tweaks + shuffle classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed Dec 31, 2024
1 parent 5da94ac commit 1e9e31c
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 31 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.gradle.debug=false


# Version
mod_version=1.2.01
mod_version=1.2.02

# Mod
mod_id=zenith
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.ItemLike;
import net.zepalesque.zenith.api.function.type.RecipeTypePredicate;
import net.zepalesque.zenith.api.recipe.recipes.StackingRecipe;
import net.zepalesque.zenith.core.recipe.recipes.StackingRecipe;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.zepalesque.zenith.api.blockset.BlockSet;
import net.zepalesque.zenith.api.entity.misc.ZenithBoat;
import net.zepalesque.zenith.api.entity.misc.ZenithChestBoat;
import net.zepalesque.zenith.api.tile.ZenithHangingSignBlockEntity;
import net.zepalesque.zenith.api.tile.ZenithSignBlockEntity;
import net.zepalesque.zenith.core.entity.misc.ZenithBoat;
import net.zepalesque.zenith.core.entity.misc.ZenithChestBoat;
import net.zepalesque.zenith.core.tile.ZenithHangingSignBlockEntity;
import net.zepalesque.zenith.core.tile.ZenithSignBlockEntity;

import java.util.Map;
import java.util.function.Supplier;

/**
* Should implement methods by having the first of each (with the parameters) used as a construction method and the second (without parameters) as a getter function
*/
public abstract class AbstractWoodSet implements BlockSet {
public abstract class AbstractWoodSet implements BlockSet {

// Blocks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeType;
import net.zepalesque.zenith.api.recipe.recipes.AbstractStackingRecipe;
import net.zepalesque.zenith.core.recipe.recipes.StackingRecipe;

import javax.annotation.Nullable;
import java.util.Optional;

// Will be used for Veridium tools in redux in order to change their infusion value
/**
* An interface that allows items to utilize custom {@link StackingRecipe StackingRecipe} mechanics.
*/
public interface CustomStackingBehavior {

/**
* Performs additional modifications to an {@link ItemStack} result of a stacking recipe
* @param ingredient The ingredient of the recipe.
* @param result The initial result {@link ItemStack}.
* @param type The relevant {@link RecipeType}.
* @param additionalData Additional data stored in the recipe JSON.
* @return The modified {@code original} {@link ItemStack}, if (and only if) any changes have been made.
*/
@Nullable
ItemStack transformStack(Ingredient ingredient, ItemStack original, RecipeType<?> type, Optional<CompoundTag> additionalData);
ItemStack transformStack(Ingredient ingredient, ItemStack result, RecipeType<? extends AbstractStackingRecipe> type, @Nullable CompoundTag additionalData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,43 @@
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.event.ItemStackedOnOtherEvent;
import net.zepalesque.zenith.core.recipe.recipes.StackingRecipe;
import net.zepalesque.zenith.core.registry.ZenithAdvancementTriggers;
import net.zepalesque.zenith.api.recipe.recipes.AbstractStackingRecipe;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;

/**
* Helps with implementing {@link StackingRecipe StackingRecipe} mechanics.
*
* <p>Example implementation from <a href="https://github.com/Zepalesque/The-Aether-Redux">The Aether: Redux</a>:</p>
*
* <pre><code>
* <literal>@SubscribeEvent</literal>
* public static void onStackItem(ItemStackedOnOtherEvent event) {
* if (event.getClickAction() == ClickAction.SECONDARY &&
* StackingRecipeHelper.stack(event, stack -> stack.is(AetherItems.AMBROSIUM_SHARD), ReduxRecipes.INFUSION.get())) {
* event.setCanceled(true);
* }
* }
* </code></pre>
* NOTE: Future versions of Zenith may automate this process for you.
*/
public class StackingRecipeHelper {

private static final Map<RecipeType<?>, Holder<RecipeType<?>>> DIRECT_HOLDERS = new HashMap<>();

// Additional behavior such as ClickAction types should be done in the event listener/hook
// The return value of this should be used to cancel the event. False means do not cancel, true means DO cancel
/**
* <p>Replaces an item via a stacking recipe, if applicable.</p>
* <p>Additional behavior such as ClickAction types should be done in the event listener/hook</p>
*
* @param event The relevant {@link ItemStackedOnOtherEvent}
* @param carriedPredicate A predicate determining whether the held item is valid for this recipe type.
* @param type The relevant {@link RecipeType}.
* @return Whether the associated {@link ItemStackedOnOtherEvent} should be canceled.
* <p>Do NOT use {@link net.neoforged.bus.api.ICancellableEvent#setCanceled(boolean) ICancellableEvent#setCanceled(boolean)}. Use an {@code if} check, and cancel the event if it passes.</p>
*/
public static <R extends AbstractStackingRecipe> boolean stack(ItemStackedOnOtherEvent event, Predicate<ItemStack> carriedPredicate, RecipeType<R> type) {
// These seem to be inverted for whatever reason?
ItemStack carried = event.getStackedOnItem();
Expand Down Expand Up @@ -70,6 +94,4 @@ public static <R extends AbstractStackingRecipe> boolean stack(ItemStackedOnOthe
}
return false;
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@
import net.minecraft.world.level.Level;
import net.zepalesque.zenith.api.itemstack.ItemStackConstructor;
import net.zepalesque.zenith.api.item.CustomStackingBehavior;
import net.zepalesque.zenith.core.recipe.recipes.StackingRecipe;

import javax.annotation.Nullable;
import java.util.Optional;

public abstract class AbstractStackingRecipe implements StackingRecipe {

protected final RecipeType<?> type;
protected final RecipeType<? extends AbstractStackingRecipe> type;
protected final Ingredient ingredient;
protected final ItemStackConstructor result;
protected final Optional<CompoundTag> additional;
protected final Optional<Holder<SoundEvent>> sound;

public AbstractStackingRecipe(RecipeType<?> type, Ingredient ingredient, ItemStackConstructor result, Optional<CompoundTag> additional, Optional<Holder<SoundEvent>> sound) {
public AbstractStackingRecipe(RecipeType<? extends AbstractStackingRecipe> type, Ingredient ingredient, ItemStackConstructor result, Optional<CompoundTag> additional, Optional<Holder<SoundEvent>> sound) {
this.type = type;
this.ingredient = ingredient;
this.result = result;
Expand All @@ -49,13 +50,13 @@ public ItemStack getResultStack(ItemStack originalStack) {

resultStack.setCount(originalStack.getCount());
if (resultStack.getItem() instanceof CustomStackingBehavior custom) {
resultStack = custom.transformStack(this.ingredient, resultStack, this.type, this.additional);
resultStack = custom.transformStack(this.ingredient, resultStack, this.type, this.additional.orElse(null));
}
return resultStack;
}

@Override
public RecipeType<?> getType() {
public RecipeType<? extends AbstractStackingRecipe> getType() {
return this.type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

import java.util.Map;

/**
* Additional {@link Codec} types that may be of use.
*/
public class MoreCodecs {
public static final Codec<Map<Holder<Biome>, Integer>> BIOME_COLOR_MAP = ExtraCodecs.strictUnboundedMap(Biome.CODEC, Codec.INT);
public static final Codec<HolderSet<SoundEvent>> SOUND_EVENT_SET = RegistryCodecs.homogeneousList(Registries.SOUND_EVENT, SoundEvent.DIRECT_CODEC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
import net.neoforged.neoforge.common.ModConfigSpec;
import net.zepalesque.zenith.api.condition.type.ConfigCondition;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

public class DataSerializableConfig {
/**
* A class for config files that can be used with {@link ConfigCondition ConfigConditions}
*/
public abstract class DataSerializableConfig {

protected final Supplier<ModConfigSpec> spec;
protected final String id;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/zepalesque/zenith/core/Zenith.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import net.zepalesque.zenith.core.data.generator.ZenithRegistrySets;
import net.zepalesque.zenith.core.registry.ZenithLootConditions;
import net.zepalesque.zenith.core.network.packet.BiomeTintSyncPacket;
import net.zepalesque.zenith.api.recipe.condition.ZenithRecipeConditions;
import net.zepalesque.zenith.core.registry.ZenithRecipeConditions;
import net.zepalesque.zenith.core.registry.ZenithBiomeModifiers;
import net.zepalesque.zenith.core.registry.ZenithDensityFunctions;
import net.zepalesque.zenith.core.registry.ZenithFeatures;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zepalesque.zenith.api.entity.misc;
package net.zepalesque.zenith.core.entity.misc;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.EntityType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zepalesque.zenith.api.entity.misc;
package net.zepalesque.zenith.core.entity.misc;

import net.minecraft.tags.FluidTags;
import net.minecraft.world.entity.vehicle.Boat;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zepalesque.zenith.api.entity.misc;
package net.zepalesque.zenith.core.entity.misc;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.EntityType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zepalesque.zenith.api.recipe.input;
package net.zepalesque.zenith.core.recipe.input;

import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeInput;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zepalesque.zenith.api.recipe.recipes;
package net.zepalesque.zenith.core.recipe.recipes;

import net.minecraft.core.HolderLookup;
import net.minecraft.core.NonNullList;
Expand All @@ -7,7 +7,7 @@
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.level.Level;
import net.zepalesque.zenith.api.itemstack.ItemStackConstructor;
import net.zepalesque.zenith.api.recipe.input.EmptyRecipeInput;
import net.zepalesque.zenith.core.recipe.input.EmptyRecipeInput;

/**
* Overrides anything container-related or item-related because these in-world recipes have no container. Instead, custom behavior is implemented by recipes that extend this.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package net.zepalesque.zenith.api.recipe.condition;
package net.zepalesque.zenith.core.registry;

import com.mojang.serialization.MapCodec;
import net.neoforged.neoforge.common.conditions.ICondition;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
import net.zepalesque.zenith.api.recipe.condition.ConditionRecipeModule;
import net.zepalesque.zenith.core.Zenith;

public class ZenithRecipeConditions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zepalesque.zenith.api.tile;
package net.zepalesque.zenith.core.tile;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zepalesque.zenith.api.tile;
package net.zepalesque.zenith.core.tile;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand Down

0 comments on commit 1e9e31c

Please sign in to comment.