mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 03:43:30 +01:00
added the ability to clear modules by putting them in the crafting grid
This commit is contained in:
parent
494ddc5391
commit
90e73a537c
3 changed files with 61 additions and 0 deletions
|
@ -4,6 +4,7 @@ import de.ellpeck.prettypipes.entities.PipeFrameEntity;
|
|||
import de.ellpeck.prettypipes.entities.PipeFrameRenderer;
|
||||
import de.ellpeck.prettypipes.items.*;
|
||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||
import de.ellpeck.prettypipes.misc.ModuleClearingRecipe;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
||||
|
@ -189,6 +190,10 @@ public final class Registry {
|
|||
.forEach(b -> output.accept(b.getValue()))).build()
|
||||
);
|
||||
});
|
||||
|
||||
event.register(ForgeRegistries.Keys.RECIPE_SERIALIZERS, h -> {
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "module_clearing"), ModuleClearingRecipe.SERIALIZER);
|
||||
});
|
||||
}
|
||||
|
||||
private static <T extends AbstractPipeContainer<?>> MenuType<T> registerPipeContainer(RegisterEvent.RegisterHelper<MenuType<?>> helper, String name) {
|
||||
|
@ -229,5 +234,7 @@ public final class Registry {
|
|||
MenuScreens.register(Registry.craftingModuleContainer, CraftingModuleGui::new);
|
||||
MenuScreens.register(Registry.filterModifierModuleContainer, FilterModifierModuleGui::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package de.ellpeck.prettypipes.misc;
|
||||
|
||||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class ModuleClearingRecipe extends CustomRecipe {
|
||||
|
||||
public static final RecipeSerializer<ModuleClearingRecipe> SERIALIZER = new SimpleCraftingRecipeSerializer<>(ModuleClearingRecipe::new);
|
||||
|
||||
public ModuleClearingRecipe(ResourceLocation res, CraftingBookCategory cat) {
|
||||
super(res, cat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(CraftingContainer container, Level level) {
|
||||
var foundModule = false;
|
||||
for (var stack : container.getItems()) {
|
||||
if (!foundModule && stack.getItem() instanceof IModule) {
|
||||
foundModule = true;
|
||||
} else if (!stack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return foundModule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack assemble(CraftingContainer container, RegistryAccess access) {
|
||||
var module = container.getItems().stream().filter(i -> i.getItem() instanceof IModule).findFirst().orElse(ItemStack.EMPTY);
|
||||
if (!module.isEmpty())
|
||||
module = new ItemStack(module.getItem());
|
||||
return module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraftInDimensions(int x, int y) {
|
||||
return x >= 1 && y >= 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return ModuleClearingRecipe.SERIALIZER;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"type": "prettypipes:module_clearing",
|
||||
"category": "misc"
|
||||
}
|
Loading…
Reference in a new issue