Skip to content

Commit d347107

Browse files
committed
wip
1 parent 3d442fd commit d347107

File tree

4 files changed

+45
-34
lines changed

4 files changed

+45
-34
lines changed

src/main/java/com/mrh0/createaddition/compat/jei/CreateAdditionJEI.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import net.minecraft.resources.ResourceLocation;
3535
import net.minecraft.world.item.ItemStack;
3636
import net.minecraft.world.item.crafting.Recipe;
37+
import net.minecraft.world.item.crafting.RecipeHolder;
3738
import net.minecraft.world.item.crafting.RecipeType;
3839
import net.minecraft.world.level.ItemLike;
3940

@@ -49,7 +50,7 @@ public ResourceLocation getPluginUid() {
4950
}
5051

5152
public IIngredientManager ingredientManager;
52-
final List<CreateRecipeCategory<?>> ALL = new ArrayList<>();
53+
static final List<CreateRecipeCategory<?>> ALL = new ArrayList<>();
5354

5455
@Override
5556
public void registerCategories(IRecipeCategoryRegistration registration) {
@@ -89,7 +90,7 @@ public void registerRecipes(IRecipeRegistration registration) {
8990
public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
9091
ALL.forEach(c -> c.registerCatalysts(registration));
9192

92-
registration.getJeiHelpers().getRecipeType(ResourceLocation.fromNamespaceAndPath("create", "sandpaper_polishing"), SandPaperPolishingRecipe.class).ifPresent(type -> {
93+
registration.getJeiHelpers().getRecipeType(ResourceLocation.fromNamespaceAndPath("create", "sandpaper_polishing")).ifPresent(type -> {
9394
registration.addRecipeCatalyst(new ItemStack(CAItems.DIAMOND_GRIT_SANDPAPER.get()), type);
9495
});
9596
//registration.addRecipeCatalyst(new ItemStack(CAItems.DIAMOND_GRIT_SANDPAPER.get()), new ResourceLocation(Create.ID, "deploying"));
@@ -99,27 +100,27 @@ private <T extends Recipe<?>> CategoryBuilder<T> builder(Class<? extends T> reci
99100
return new CategoryBuilder<>(recipeClass);
100101
}
101102

102-
private class CategoryBuilder<T extends Recipe<?>> {
103+
private static class CategoryBuilder<T extends Recipe<?>> {
103104
private final Class<? extends T> recipeClass;
104105
private Predicate<CRecipes> predicate = cRecipes -> true;
105106

106107
private IDrawable background;
107108
private IDrawable icon;
108109

109-
private final List<Consumer<List<T>>> recipeListConsumers = new ArrayList<>();
110+
private final List<Consumer<List<RecipeHolder<T>>>> recipeListConsumers = new ArrayList<>();
110111
private final List<Supplier<? extends ItemStack>> catalysts = new ArrayList<>();
111112

112113
public CategoryBuilder(Class<? extends T> recipeClass) {
113114
this.recipeClass = recipeClass;
114115
}
115116

116-
public CategoryBuilder<T> addRecipeListConsumer(Consumer<List<T>> consumer) {
117+
public CategoryBuilder<T> addRecipeListConsumer(Consumer<List<RecipeHolder<T>>> consumer) {
117118
recipeListConsumers.add(consumer);
118119
return this;
119120
}
120121

121122
public CategoryBuilder<T> addTypedRecipes(Supplier<RecipeType<? extends T>> recipeType) {
122-
return addRecipeListConsumer(recipes -> CreateJEI.<T>consumeTypedRecipes(recipes::add, recipeType.get()));
123+
return addRecipeListConsumer(recipes -> CreateJEI.<T>consumeTypedRecipes((holder) -> recipes.add((RecipeHolder<T>) holder), recipeType.get()));
123124
}
124125

125126
public CategoryBuilder<T> catalystStack(Supplier<ItemStack> supplier) {
@@ -152,6 +153,7 @@ public CategoryBuilder<T> emptyBackground(int width, int height) {
152153
return this;
153154
}
154155

156+
/*
155157
public CreateRecipeCategory<T> build(String name, CreateRecipeCategory.Factory<T> factory) {
156158
Supplier<List<T>> recipesSupplier;
157159
if (predicate.test(AllConfigs.server().recipes)) {
@@ -162,13 +164,33 @@ public CreateRecipeCategory<T> build(String name, CreateRecipeCategory.Factory<T
162164
return recipes;
163165
};
164166
} else {
165-
recipesSupplier = () -> Collections.emptyList();
167+
recipesSupplier = Collections::emptyList;
168+
}
169+
170+
CreateRecipeCategory.Info<T> info = new CreateRecipeCategory.Info<>(
171+
new mezz.jei.api.recipe.RecipeType<>(CreateAddition.asResource(name), recipeClass),
172+
Component.translatable(CreateAddition.MODID + ".recipe." + name), background, icon, recipesSupplier, catalysts);
173+
return factory.create(info);
174+
}*/
175+
176+
public CreateRecipeCategory<T> build(String name, CreateRecipeCategory.Factory<T> factory) {
177+
Supplier<List<RecipeHolder<T>>> recipesSupplier;
178+
if (predicate.test(AllConfigs.server().recipes)) {
179+
recipesSupplier = () -> {
180+
List<RecipeHolder<T>> recipes = new ArrayList<>();
181+
for (Consumer<List<RecipeHolder<T>>> consumer : recipeListConsumers)
182+
consumer.accept(recipes);
183+
return recipes;
184+
};
185+
} else {
186+
recipesSupplier = Collections::emptyList;
166187
}
167188

168189
CreateRecipeCategory.Info<T> info = new CreateRecipeCategory.Info<>(
169190
new mezz.jei.api.recipe.RecipeType<>(CreateAddition.asResource(name), recipeClass),
170191
Component.translatable(CreateAddition.MODID + ".recipe." + name), background, icon, recipesSupplier, catalysts);
171192
CreateRecipeCategory<T> category = factory.create(info);
193+
ALL.add(category);
172194
return category;
173195
}
174196
}

src/main/java/com/mrh0/createaddition/index/CARecipes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ private static <T extends Recipe<?>> Supplier<RecipeType<T>> registerRecipeType(
3737
new SequencedAssemblyRollingRecipeSerializer(new RollingRecipeProcessingFactory()));
3838

3939
public static final Supplier<RecipeType<ChargingRecipe>> CHARGING_TYPE = registerRecipeType("charging");
40-
public static final DeferredHolder<RecipeSerializer<?>, RecipeSerializer<ChargingRecipe>> CHARGING = SERIALIZERS.register("charging", ChargingRecipeSerializer::new);
40+
public static final DeferredHolder<RecipeSerializer<?>, RecipeSerializer<ChargingRecipe>> CHARGING = SERIALIZERS.register("charging", ChargingRecipe.Serializer::new);
4141

4242
public static final Supplier<RecipeType<LiquidBurningRecipe>> LIQUID_BURNING_TYPE = registerRecipeType("liquid_burning");
43-
public static final DeferredHolder<RecipeSerializer<?>, RecipeSerializer<LiquidBurningRecipe>> LIQUID_BURNING = SERIALIZERS.register("liquid_burning", LiquidBurningRecipeSerializer::new);
43+
public static final DeferredHolder<RecipeSerializer<?>, RecipeSerializer<LiquidBurningRecipe>> LIQUID_BURNING = SERIALIZERS.register("liquid_burning", LiquidBurningRecipe.Serializer::new);
4444

4545
public static final Supplier<MapCodec<HasFluidTagCondition>> HAS_FLUID_TAG_CONDITION =
4646
CONDITION_CODECS.register("has_fluid_tag", () -> HasFluidTagCondition.CODEC);

src/main/java/com/mrh0/createaddition/item/WireSpool.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,12 @@ public WireSpool(Properties props) {
3333
@Override
3434
public InteractionResult useOn(UseOnContext c) {
3535
CompoundTag nbt = c.getItemInHand().getTag();
36-
if(nbt == null)
37-
nbt = new CompoundTag();
36+
if(nbt == null) nbt = new CompoundTag();
3837

3938
var clickedPos = c.getClickedPos();
4039
BlockEntity te = c.getLevel().getBlockEntity(clickedPos);
41-
if(te == null)
42-
return InteractionResult.PASS;
43-
if(!(te instanceof IWireNode))
44-
return InteractionResult.PASS;
40+
if(te == null) return InteractionResult.PASS;
41+
if(!(te instanceof IWireNode)) return InteractionResult.PASS;
4542
IWireNode node = (IWireNode) te;
4643
var heldItem = c.getItemInHand().getItem();
4744

@@ -101,8 +98,7 @@ else if(result.isLinked()) {
10198
}
10299
}
103100
int index = node.getAvailableNode(c.getClickLocation());
104-
if(index < 0)
105-
return InteractionResult.PASS;
101+
if(index < 0) return InteractionResult.PASS;
106102
if(!isRemover(heldItem))
107103
c.getPlayer().displayClientMessage(WireConnectResult.getConnect(node.isNodeInput(index), node.isNodeOutput(index)).getMessage(), true);
108104
c.getItemInHand().setTag(null);
@@ -112,26 +108,19 @@ else if(result.isLinked()) {
112108
}
113109

114110
public static boolean hasPos(CompoundTag nbt) {
115-
if(nbt == null)
116-
return false;
117-
return nbt.contains("x") && nbt.contains("y") && nbt.contains("z") && nbt.contains("node");
111+
return nbt.contains("x") && nbt.contains("y") && nbt.contains("z") && nbt.contains("node");
118112
}
119113

120114
public static BlockPos getPos(CompoundTag nbt){
121-
if(nbt == null)
122-
return null;
123-
return new BlockPos(nbt.getInt("x"), nbt.getInt("y"), nbt.getInt("z"));
115+
return new BlockPos(nbt.getInt("x"), nbt.getInt("y"), nbt.getInt("z"));
124116
}
125117

126118
public static int getNode(CompoundTag nbt){
127-
if(nbt == null)
128-
return -1;
129-
return nbt.getInt("node");
119+
return nbt.getInt("node");
130120
}
131121

132122
public static CompoundTag setContent(CompoundTag nbt, BlockPos pos, int node){
133-
if(nbt == null)
134-
return new CompoundTag();
123+
if(nbt == null) return new CompoundTag();
135124
nbt.putInt("x", pos.getX());
136125
nbt.putInt("y", pos.getY());
137126
nbt.putInt("z", pos.getZ());
@@ -140,12 +129,11 @@ public static CompoundTag setContent(CompoundTag nbt, BlockPos pos, int node){
140129
}
141130

142131
@Override
143-
public void appendHoverText(ItemStack stack, Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
132+
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
144133
CompoundTag nbt = stack.getTag();
145-
super.appendHoverText(stack, worldIn, tooltip, flagIn);
146-
if(hasPos(nbt))
147-
tooltip.add(Component.translatable("item."+CreateAddition.MODID+".spool.nbt"));
148-
}
134+
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
135+
if(hasPos(nbt)) tooltipComponents.add(Component.translatable("item."+CreateAddition.MODID+".spool.nbt"));
136+
}
149137

150138
public static boolean isRemover(Item item) {
151139
return item == CAItems.SPOOL.get();

src/main/java/com/mrh0/createaddition/recipe/rolling/SequencedAssemblyRollingRecipeSerializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.mrh0.createaddition.recipe.rolling;
2-
2+
/*
33
import com.google.gson.JsonObject;
44
import com.google.gson.JsonPrimitive;
55
import com.simibubi.create.content.processing.recipe.ProcessingRecipeBuilder;
@@ -79,3 +79,4 @@ protected RollingRecipe readFromBuffer(ResourceLocation recipeId, FriendlyByteBu
7979
return new RollingRecipe(recipeId, input, output);
8080
}
8181
}
82+
*/

0 commit comments

Comments
 (0)