Skip to content

Commit

Permalink
Fixed noMirror() for shaped recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Jun 25, 2024
1 parent 8387f54 commit 13e2f24
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.latvian.mods.kubejs.neoforge;

import dev.latvian.mods.rhino.type.TypeInfo;
import net.neoforged.bus.api.Event;
import net.neoforged.bus.api.EventPriority;

Expand All @@ -9,8 +8,6 @@
import java.util.function.Consumer;

public class NativeEventListeners implements Consumer<Event> {
public static final TypeInfo EVENT_CONSUMER_TYPE = TypeInfo.RAW_CONSUMER.withParams(TypeInfo.of(Event.class));

public record Key(Class<?> eventClass, EventPriority priority) {
@Override
public boolean equals(Object o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ static void onEvent(Context cx, EventPriority priority, Class<?> eventClass, Con
bus.addListener(priority, false, (Class) eventClass, listeners);
}

listeners.listeners.add((Consumer<Event>) cx.jsToJava(consumer, NativeEventListeners.EVENT_CONSUMER_TYPE));
listeners.listeners.add(consumer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.item.crafting.ShapedRecipePattern;
import net.minecraft.world.level.Level;

import java.util.List;

Expand All @@ -31,6 +30,10 @@ public ShapedKubeJSRecipe(String group, CraftingBookCategory category, ShapedRec
this.ingredientActions = ingredientActions;
this.modifyResult = modifyResult;
this.stage = stage;

if (!mirror) {
this.pattern.symmetrical = true;
}
}

@Override
Expand Down Expand Up @@ -67,15 +70,8 @@ public ItemStack assemble(CraftingInput input, HolderLookup.Provider registryAcc
return kjs$assemble(input, registryAccess);
}

@Override
public boolean matches(CraftingInput input, Level level) {
// FIXME: mirror
return pattern.matches(input);
}

public static class SerializerKJS implements RecipeSerializer<ShapedKubeJSRecipe> {

// TODO: this is still a bit of a mess
public static final MapCodec<ShapedKubeJSRecipe> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
// manually copied from the shaped recipe codec
// (would be nice if we could just swap out specifically the pattern codec from the underlying codec)
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/kubejs.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ accessible field net/minecraft/tags/TagEntry tag Z

accessible field net/minecraft/world/item/crafting/ShapelessRecipe$Serializer CODEC Lcom/mojang/serialization/MapCodec;
# accessible field net/minecraft/world/item/crafting/ShapedRecipe$Serializer CODEC Lcom/mojang/serialization/MapCodec;
accessible field net/minecraft/world/item/crafting/ShapedRecipePattern symmetrical Z
mutable field net/minecraft/world/item/crafting/ShapedRecipePattern symmetrical Z

# attributes
accessible class net/minecraft/world/effect/MobEffect$AttributeTemplate
Expand Down

0 comments on commit 13e2f24

Please sign in to comment.