Skip to content

Commit

Permalink
fix: Avaritia与jei在服务器中一些合成表不显示
Browse files Browse the repository at this point in the history
Closes #38
  • Loading branch information
cnlimiter committed Jan 9, 2024
1 parent 5677ca2 commit 1408a40
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 142 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ tasks.withType(ProcessResources).configureEach {
}

tasks.named('jar', Jar).configure {

manifest {
attributes([
'Specification-Title' : mod_id,
Expand All @@ -165,7 +166,6 @@ tasks.named('jar', Jar).configure {
finalizedBy 'reobfJar'
}


publishing {
publications {
register('mavenJava', MavenPublication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@
{
"item": "avaritia:record_fragment"
}
],
"result": {
"item": "avaritia:infinity_catalyst"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"avaritia:singularity"
]
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ default boolean matches(Container inv, Level level) {
}

@Override
default NonNullList<ItemStack> getRemainingItems(Container inv) {
default @NotNull NonNullList<ItemStack> getRemainingItems(Container inv) {
return this.getRemainingItems(new InvWrapper(inv));
}


ItemStack assemble(IItemHandler var1);

default boolean matches(IItemHandler inventory) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package committee.nova.mods.avaritia.common.crafting.recipe;

import com.google.gson.JsonObject;
import committee.nova.mods.avaritia.api.common.crafting.ICraftRecipe;
import committee.nova.mods.avaritia.api.common.crafting.ISpecialRecipe;
import committee.nova.mods.avaritia.init.handler.SingularityRegistryHandler;
import committee.nova.mods.avaritia.init.registry.ModItems;
import committee.nova.mods.avaritia.init.registry.ModRecipeSerializers;
import committee.nova.mods.avaritia.init.registry.ModRecipeTypes;
import committee.nova.mods.avaritia.util.SingularityUtil;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.FriendlyByteBuf;
Expand All @@ -16,6 +13,7 @@
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
Expand All @@ -36,15 +34,15 @@
* Description:
*/

public class InfinityCatalystCraftRecipe implements ISpecialRecipe, ICraftRecipe {
private boolean ingredientsLoaded = false;
public class InfinityCatalystCraftRecipe implements ISpecialRecipe{
private final ResourceLocation recipeId;
public final NonNullList<Ingredient> inputs;
public NonNullList<Ingredient> inputs;
private Map<Integer, Function<ItemStack, ItemStack>> transformers;

public InfinityCatalystCraftRecipe(ResourceLocation recipeId, NonNullList<Ingredient> inputs) {
this.recipeId = recipeId;
this.inputs = inputs;

}

@Override
Expand All @@ -59,17 +57,6 @@ public boolean canCraftInDimensions(int width, int height) {

@Override
public @NotNull NonNullList<Ingredient> getIngredients() {
if (!this.ingredientsLoaded) {
SingularityRegistryHandler.getInstance().getSingularities()
.stream()
.filter(singularity -> singularity.getIngredient() != Ingredient.EMPTY)
.limit(74)
.map(SingularityUtil::getItemForSingularity)
.map(Ingredient::of)
.forEach(this.inputs::add);
this.ingredientsLoaded = true;
}

return this.inputs;
}

Expand All @@ -78,6 +65,11 @@ public boolean canCraftInDimensions(int width, int height) {
return this.recipeId;
}

@Override
public @NotNull RecipeSerializer<?> getSerializer() {
return ModRecipeSerializers.INFINITY_SERIALIZER.get();
}

@Override
public @NotNull RecipeType<?> getType() {
return ModRecipeTypes.EXTREME_CRAFT_RECIPE.get();
Expand Down Expand Up @@ -134,17 +126,11 @@ public void setTransformers(Map<Integer, Function<ItemStack, ItemStack>> transfo
this.transformers = transformers;
}

@Override
public @NotNull RecipeSerializer<?> getSerializer() {
return ModRecipeSerializers.INFINITY_SERIALIZER.get();
}

public static class Serializer implements RecipeSerializer<InfinityCatalystCraftRecipe> {
@Override
public @NotNull InfinityCatalystCraftRecipe fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject json) {
NonNullList<Ingredient> inputs = NonNullList.create();
var ingredients = GsonHelper.getAsJsonArray(json, "ingredients");

for (int i = 0; i < ingredients.size(); i++) {
inputs.add(Ingredient.fromJson(ingredients.get(i)));
}
Expand All @@ -165,7 +151,6 @@ public InfinityCatalystCraftRecipe fromNetwork(@NotNull ResourceLocation recipeI
@Override
public void toNetwork(@NotNull FriendlyByteBuf buffer, @NotNull InfinityCatalystCraftRecipe recipe) {
buffer.writeVarInt(recipe.inputs.size());

for (var ingredient : recipe.inputs) {
ingredient.toNetwork(buffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import committee.nova.mods.avaritia.api.common.crafting.ICraftRecipe;
import committee.nova.mods.avaritia.api.common.crafting.ISpecialRecipe;
import committee.nova.mods.avaritia.init.registry.ModRecipeSerializers;
import committee.nova.mods.avaritia.init.registry.ModRecipeTypes;
Expand All @@ -14,10 +13,7 @@
import net.minecraft.util.GsonHelper;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.level.Level;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;
Expand All @@ -32,7 +28,7 @@
* Date: 2022/4/2 9:16
* Version: 1.0
*/
public class ShapedExtremeCraftingRecipe implements ISpecialRecipe, ICraftRecipe {
public class ShapedExtremeCraftingRecipe implements ISpecialRecipe{
private final ResourceLocation recipeId;
private final NonNullList<Ingredient> inputs;
private final ItemStack output;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package committee.nova.mods.avaritia.common.crafting.recipe;

import com.google.gson.JsonObject;
import committee.nova.mods.avaritia.api.common.crafting.ICraftRecipe;
import committee.nova.mods.avaritia.api.common.crafting.ISpecialRecipe;
import committee.nova.mods.avaritia.init.registry.ModRecipeSerializers;
import committee.nova.mods.avaritia.init.registry.ModRecipeTypes;
Expand All @@ -12,10 +11,7 @@
import net.minecraft.util.GsonHelper;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.util.RecipeMatcher;
import net.minecraftforge.items.IItemHandler;
Expand All @@ -33,7 +29,7 @@
* Date: 2022/4/2 9:16
* Version: 1.0
*/
public class ShapelessExtremeCraftingRecipe implements ISpecialRecipe, ICraftRecipe {
public class ShapelessExtremeCraftingRecipe implements ISpecialRecipe{
private final ResourceLocation recipeId;
public final NonNullList<Ingredient> inputs;
private final ItemStack output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import net.minecraftforge.server.ServerLifecycleHooks;
import org.openzen.zencode.java.ZenCodeType;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -205,5 +203,4 @@ private static NonNullList<Ingredient> toIngredientsList(IIngredient... ingredie
.map(IIngredient::asVanillaIngredient)
.collect(Collectors.toCollection(NonNullList::create));
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package committee.nova.mods.avaritia.init.compat.jei.category;

import committee.nova.mods.avaritia.Static;
import committee.nova.mods.avaritia.api.common.crafting.ICraftRecipe;
import committee.nova.mods.avaritia.api.common.crafting.ISpecialRecipe;
import committee.nova.mods.avaritia.common.crafting.recipe.InfinityCatalystCraftRecipe;
import committee.nova.mods.avaritia.common.crafting.recipe.ShapedExtremeCraftingRecipe;
import committee.nova.mods.avaritia.common.crafting.recipe.ShapelessExtremeCraftingRecipe;
import committee.nova.mods.avaritia.init.compat.jei.JeiCompat;
import committee.nova.mods.avaritia.init.registry.ModBlocks;
import committee.nova.mods.avaritia.init.registry.ModItems;
import committee.nova.mods.avaritia.util.lang.Localizable;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
Expand All @@ -18,7 +18,6 @@
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.core.NonNullList;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -35,24 +34,22 @@
* Date: 2022/5/16 23:46
* Version: 1.0
*/
public class ExtremeCraftingTableCategory implements IRecipeCategory<ICraftRecipe> {
public class ExtremeCraftingTableCategory implements IRecipeCategory<ISpecialRecipe> {

public static final RecipeType<ICraftRecipe> RECIPE_TYPE = RecipeType.create(Static.MOD_ID, "extreme_craft", ICraftRecipe.class);
public static final RecipeType<ISpecialRecipe> RECIPE_TYPE = RecipeType.create(Static.MOD_ID, "extreme_craft", ISpecialRecipe.class);
private static final ResourceLocation TEXTURE = new ResourceLocation(Static.MOD_ID, "textures/gui/jei/extreme_jei.png");

private final IDrawable background;
private final IDrawable icon;
private final IDrawable shapeless;

public ExtremeCraftingTableCategory(IGuiHelper helper) {
this.background = helper.createDrawable(TEXTURE, 0, 0, 190, 163);
this.icon = helper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(ModBlocks.extreme_crafting_table.get()));
this.shapeless = helper.createDrawable(JeiCompat.ICONS, 17, 0, 19, 15);
}


@Override
public @NotNull RecipeType<ICraftRecipe> getRecipeType() {
public @NotNull RecipeType<ISpecialRecipe> getRecipeType() {
return RECIPE_TYPE;
}

Expand All @@ -72,7 +69,7 @@ public ExtremeCraftingTableCategory(IGuiHelper helper) {
}

@Override
public void setRecipe(@NotNull IRecipeLayoutBuilder builder, ICraftRecipe recipe, @NotNull IFocusGroup focuses) {
public void setRecipe(@NotNull IRecipeLayoutBuilder builder, ISpecialRecipe recipe, @NotNull IFocusGroup focuses) {
var level = Minecraft.getInstance().level;
assert level != null;
var inputs = recipe.getIngredients();
Expand All @@ -85,17 +82,17 @@ public void setRecipe(@NotNull IRecipeLayoutBuilder builder, ICraftRecipe recipe
for (int i = heightOffset; i < shaped.getHeight() + heightOffset; i++) {
for (int j = widthOffset; j < shaped.getWidth() + widthOffset; j++) {
builder.addSlot(RecipeIngredientRole.INPUT, j * 18 + 1, i * 18 + 1).addIngredients(inputs.get(stackIndex));

stackIndex++;
}
}
builder.addSlot(RecipeIngredientRole.OUTPUT, 167, 73).addItemStack(output);
} else if (recipe instanceof ShapelessExtremeCraftingRecipe) {
shapelessRecipe(builder, inputs);
builder.addSlot(RecipeIngredientRole.OUTPUT, 167, 73).addItemStack(output);
} else if (recipe instanceof InfinityCatalystCraftRecipe) {
shapelessRecipe(builder, inputs);
builder.addSlot(RecipeIngredientRole.OUTPUT, 167, 73).addItemStack(new ItemStack(ModItems.infinity_catalyst.get()));
}

builder.addSlot(RecipeIngredientRole.OUTPUT, 167, 73).addItemStack(output);
builder.moveRecipeTransferButton(170, 100);
}

Expand All @@ -113,7 +110,7 @@ private void shapelessRecipe(@NotNull IRecipeLayoutBuilder builder, NonNullList<
}

@Override
public @NotNull List<Component> getTooltipStrings(ICraftRecipe recipe, IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) {
public @NotNull List<Component> getTooltipStrings(@NotNull ISpecialRecipe recipe, @NotNull IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) {
var shapeless = recipe instanceof ShapelessExtremeCraftingRecipe;
int sX = (shapeless ? 340 : 306) / 2, sY = 200 / 2;

Expand All @@ -124,19 +121,4 @@ private void shapelessRecipe(@NotNull IRecipeLayoutBuilder builder, NonNullList<
return Collections.emptyList();
}

// @Override
// public void draw(ICraftRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics gfx, double mouseX, double mouseY) {
// var matrix = gfx.pose();
// matrix.pushPose();
// matrix.scale(0.5F, 0.5F, 0.5F);
//
// var shapeless = recipe instanceof ShapelessExtremeCraftingRecipe || recipe instanceof InfinityCatalystCraftRecipe;
//
// if (shapeless)
// this.shapeless.draw(gfx, 170, 50);
//
// matrix.popPose();
// }


}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void gatherData(GatherDataEvent event) {
if (event.includeServer()) {
generator.addProvider(true, new ModRecipes(generator));
generator.addProvider(true, new ModLootTables(generator));
generator.addProvider(true, new ModItemTags(generator, future, helper));
generator.addProvider(true, new ModBlockTags(generator, future, helper));
generator.addProvider(true, new ModEntityTags(generator, future, helper));
// generator.addProvider(true, new ModAdvancements(output, future, helper));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package committee.nova.mods.avaritia.init.data.provider;

import committee.nova.mods.avaritia.Static;
import committee.nova.mods.avaritia.init.handler.SingularityRegistryHandler;
import committee.nova.mods.avaritia.init.registry.ModBlocks;
import committee.nova.mods.avaritia.init.registry.ModItems;
import committee.nova.mods.avaritia.init.registry.ModTags;
import committee.nova.mods.avaritia.util.SingularityUtil;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.tags.IntrinsicHolderTagsProvider;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.data.ExistingFileHelper;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import java.util.concurrent.CompletableFuture;

/**
* Author cnlimiter
* CreateTime 2023/6/17 23:35
* Name ModBlockTags
* Description
*/

public class ModItemTags extends IntrinsicHolderTagsProvider<Item> {

public ModItemTags(DataGenerator output, CompletableFuture<HolderLookup.Provider> future, @Nullable ExistingFileHelper existingFileHelper) {
super(output.getPackOutput(), Registries.ITEM, future, block -> block.builtInRegistryHolder().key(), Static.MOD_ID, existingFileHelper);
}

@Override
public @NotNull String getName() {
return "Avaritia Item Tags";
}


@Override
protected void addTags(HolderLookup.@NotNull Provider p_256380_) {
tag(ModTags.SINGULARITY).add(ModItems.singularity.get());
}
}
Loading

0 comments on commit 1408a40

Please sign in to comment.