Skip to content

Commit

Permalink
try to fix Singularity rendering error
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlimiter committed Jun 15, 2022
1 parent 08ae35f commit 4856263
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static ExtremeCraftingMenu create(int windowId, Inventory playerInventory

@Override
public void slotsChanged(@NotNull Container matrix) {
var recipe = this.world.getRecipeManager().getRecipeFor(ModRecipeTypes.RecipeTypes.CRAFTING, matrix, this.world);
var recipe = this.world.getRecipeManager().getRecipeFor(ModRecipeTypes.RecipeTypes.EXTREME_CRAFTING, matrix, this.world);

if (recipe.isPresent()) {
var result = recipe.get().assemble(matrix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ public void write(SyncSingularitiesPacket msg, FriendlyByteBuf buf) {

@Override
public void run(SyncSingularitiesPacket msg, Supplier<NetworkEvent.Context> ctx) {
if(ctx.get().getDirection().getReceptionSide().isServer())
return;

ctx.get().enqueueWork(() -> {
SingularityRegistryHandler.getInstance().loadSingularities(msg);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public RecipeSerializer<?> getSerializer() {

@Override
public RecipeType<?> getType() {
return ModRecipeTypes.RecipeTypes.CRAFTING;
return ModRecipeTypes.RecipeTypes.EXTREME_CRAFTING;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public RecipeSerializer<?> getSerializer() {

@Override
public RecipeType<?> getType() {
return ModRecipeTypes.RecipeTypes.CRAFTING;
return ModRecipeTypes.RecipeTypes.EXTREME_CRAFTING;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void onTake(Player player, ItemStack stack) {

NonNullList<ItemStack> remaining;

remaining = player.level.getRecipeManager().getRemainingItemsFor(ModRecipeTypes.RecipeTypes.CRAFTING, this.matrix, player.level);
remaining = player.level.getRecipeManager().getRemainingItemsFor(ModRecipeTypes.RecipeTypes.EXTREME_CRAFTING, this.matrix, player.level);

for (int i = 0; i < remaining.size(); i++) {
var slotStack = this.matrix.getItem(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ public static void remove(IItemStack stack) {
@Override
public void apply() {
var recipes = RecipeUtil.getRecipes()
.getOrDefault(ModRecipeTypes.RecipeTypes.CRAFTING, new HashMap<>())
.getOrDefault(ModRecipeTypes.RecipeTypes.EXTREME_CRAFTING, new HashMap<>())
.values().stream()
.filter(r -> r.getResultItem().sameItem(stack.getInternal()))
.map(Recipe::getId)
.toList();

recipes.forEach(r -> {
RecipeUtil.getRecipes().get(ModRecipeTypes.RecipeTypes.CRAFTING).remove(r);
RecipeUtil.getRecipes().get(ModRecipeTypes.RecipeTypes.EXTREME_CRAFTING).remove(r);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void registerRecipes(@NotNull IRecipeRegistration registration) {
registration.addRecipes(manager.byType(ModRecipeTypes.RecipeTypes.COMPRESSOR).values(), CompressorCategory.UID);

var recipes = Stream.of(1).collect(Collectors.toMap(tier -> tier, tier ->
manager.byType(ModRecipeTypes.RecipeTypes.CRAFTING).values()
manager.byType(ModRecipeTypes.RecipeTypes.EXTREME_CRAFTING).values()
.stream()
.map(recipe -> (ICraftRecipe) recipe)
.collect(Collectors.toList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class NetworkHandler {

@SubscribeEvent
public static void init(FMLCommonSetupEvent event) {
INSTANCE.register(SyncSingularitiesPacket.class, new SyncSingularitiesPacket());
event.enqueueWork(() -> {
INSTANCE.register(SyncSingularitiesPacket.class, new SyncSingularitiesPacket());
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void onRecipesUpdated(RecipesUpdatedEvent event) {
private record SingularityResourceReload(ICondition.IContext context) implements ResourceManagerReloadListener {
@Override
public void onResourceManagerReload(@NotNull ResourceManager manager) {
SingularityRegistryHandler.getInstance().onResourceManagerReload(manager, context);
SingularityRegistryHandler.getInstance().onResourceManagerReload(context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.google.gson.JsonParser;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraftforge.common.crafting.conditions.ICondition;
import net.minecraftforge.event.OnDatapackSyncEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand Down Expand Up @@ -61,7 +60,7 @@ public void onDatapackSync(OnDatapackSyncEvent event) {
}
}

public void onResourceManagerReload(ResourceManager manager, ICondition.IContext context) {
public void onResourceManagerReload(ICondition.IContext context) {
this.loadSingularities(context);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nova.committee.avaritia.init.registry;

import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.item.crafting.Recipe;
Expand All @@ -9,7 +10,6 @@
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.IForgeRegistry;
import nova.committee.avaritia.Static;
import nova.committee.avaritia.common.recipe.*;

Expand All @@ -31,18 +31,20 @@ public class ModRecipeTypes {

@SubscribeEvent
public static void registerRecipes(RegistryEvent.Register<RecipeSerializer<?>> event) {
final IForgeRegistry<RecipeSerializer<?>> registry = event.getRegistry();
var registry = event.getRegistry();

registry.registerAll(
SHAPED_EXTREME_CRAFT_RECIPE.setRegistryName(new ResourceLocation(Static.MOD_ID, "shaped_extreme_craft")),
SHAPELESS_EXTREME_CRAFT_RECIPE.setRegistryName(new ResourceLocation(Static.MOD_ID, "shapeless_extreme_craft")),
COMPRESSOR_RECIPE.setRegistryName(new ResourceLocation(Static.MOD_ID, "compressor"))
);
Registry.register(Registry.RECIPE_TYPE, new ResourceLocation(Static.MOD_ID, "compressor"), RecipeTypes.COMPRESSOR);
Registry.register(Registry.RECIPE_TYPE, new ResourceLocation(Static.MOD_ID, "extreme_craft"), RecipeTypes.EXTREME_CRAFTING);

}

public static class RecipeTypes {
public static final RecipeType<ICraftRecipe> CRAFTING = new RecipeType<>() {
public static final RecipeType<ICraftRecipe> EXTREME_CRAFTING = new RecipeType<>() {
@Override
public <C extends Container> Optional<ICraftRecipe> tryMatch(Recipe<C> recipe, Level world, C inv) {
return recipe.matches(inv, world) ? Optional.of((ICraftRecipe) recipe) : Optional.empty();
Expand Down

0 comments on commit 4856263

Please sign in to comment.