diff --git a/src/main/java/de/ellpeck/prettypipes/Registry.java b/src/main/java/de/ellpeck/prettypipes/Registry.java index a73d6be..de2c7f4 100644 --- a/src/main/java/de/ellpeck/prettypipes/Registry.java +++ b/src/main/java/de/ellpeck/prettypipes/Registry.java @@ -8,6 +8,9 @@ import de.ellpeck.prettypipes.pipe.modules.FilterModifierModuleItem; import de.ellpeck.prettypipes.pipe.modules.LowPriorityModuleItem; import de.ellpeck.prettypipes.pipe.modules.RedstoneModuleItem; import de.ellpeck.prettypipes.pipe.modules.SpeedModuleItem; +import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer; +import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleGui; +import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleItem; import de.ellpeck.prettypipes.pipe.modules.extraction.ExtractionModuleContainer; import de.ellpeck.prettypipes.pipe.modules.extraction.ExtractionModuleGui; import de.ellpeck.prettypipes.pipe.modules.extraction.ExtractionModuleItem; @@ -114,6 +117,7 @@ public final class Registry { public static ContainerType retrievalModuleContainer; public static ContainerType stackSizeModuleContainer; public static ContainerType filterIncreaseModuleContainer; + public static ContainerType craftingModuleContainer; @SubscribeEvent public static void registerBlocks(RegistryEvent.Register event) { @@ -142,6 +146,7 @@ public final class Registry { registry.registerAll(Arrays.stream(ItemEqualityType.values()).map(t -> new FilterModifierModuleItem(t.name().toLowerCase(Locale.ROOT) + "_filter_modifier", t)).toArray(Item[]::new)); registry.register(new RedstoneModuleItem("redstone_module")); registry.register(new FilterIncreaseModuleItem("filter_increase_modifier")); + registry.registerAll(createTieredModule("crafting_module", CraftingModuleItem::new)); ForgeRegistries.BLOCKS.getValues().stream() .filter(b -> b.getRegistryName().getNamespace().equals(PrettyPipes.ID)) @@ -176,7 +181,8 @@ public final class Registry { filterModuleContainer = createPipeContainer("filter_module"), retrievalModuleContainer = createPipeContainer("retrieval_module"), stackSizeModuleContainer = createPipeContainer("stack_size_module"), - filterIncreaseModuleContainer = createPipeContainer("filter_increase_module") + filterIncreaseModuleContainer = createPipeContainer("filter_increase_module"), + craftingModuleContainer = createPipeContainer("crafting_module") ); } @@ -227,6 +233,7 @@ public final class Registry { ScreenManager.registerFactory(retrievalModuleContainer, RetrievalModuleGui::new); ScreenManager.registerFactory(stackSizeModuleContainer, StackSizeModuleGui::new); ScreenManager.registerFactory(filterIncreaseModuleContainer, FilterIncreaseModuleGui::new); + ScreenManager.registerFactory(craftingModuleContainer, CraftingModuleGui::new); } } } diff --git a/src/main/java/de/ellpeck/prettypipes/misc/FilterSlot.java b/src/main/java/de/ellpeck/prettypipes/misc/FilterSlot.java index 64389ee..afc51d3 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/FilterSlot.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/FilterSlot.java @@ -8,8 +8,12 @@ import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.SlotItemHandler; public class FilterSlot extends SlotItemHandler { - public FilterSlot(IItemHandler itemHandler, int index, int xPosition, int yPosition) { + + private final boolean onlyOneItem; + + public FilterSlot(IItemHandler itemHandler, int index, int xPosition, int yPosition, boolean onlyOneItem) { super(itemHandler, index, xPosition, yPosition); + this.onlyOneItem = onlyOneItem; } public static boolean checkFilter(Container container, int slotId, PlayerEntity player) { @@ -31,7 +35,8 @@ public class FilterSlot extends SlotItemHandler { this.putStack(ItemStack.EMPTY); } else if (!heldStack.isEmpty()) { ItemStack s = heldStack.copy(); - s.setCount(1); + if (this.onlyOneItem) + s.setCount(1); this.putStack(s); } } diff --git a/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java b/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java index 37501c0..948cf40 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java @@ -48,7 +48,7 @@ public class ItemFilter extends ItemStackHandler { public List getSlots(int x, int y) { List slots = new ArrayList<>(); for (int i = 0; i < this.getSlots(); i++) - slots.add(new FilterSlot(this, i, x + i % 9 * 18, y + i / 9 * 18)); + slots.add(new FilterSlot(this, i, x + i % 9 * 18, y + i / 9 * 18, true)); return slots; } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeGui.java b/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeGui.java index 0a9ed68..2b0b0ee 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeGui.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeGui.java @@ -21,7 +21,7 @@ import java.util.List; public abstract class AbstractPipeGui> extends ContainerScreen { - private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/pipe.png"); + protected static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/pipe.png"); private final List tabs = new ArrayList<>(); private final ItemStack[] lastItems = new ItemStack[this.container.tile.modules.getSlots()]; diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleContainer.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleContainer.java new file mode 100644 index 0000000..6db6f50 --- /dev/null +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleContainer.java @@ -0,0 +1,51 @@ +package de.ellpeck.prettypipes.pipe.modules.craft; + +import de.ellpeck.prettypipes.misc.FilterSlot; +import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.ContainerType; +import net.minecraft.util.math.BlockPos; +import net.minecraftforge.items.ItemStackHandler; + +public class CraftingModuleContainer extends AbstractPipeContainer { + + public ItemStackHandler input; + public ItemStackHandler output; + private boolean modified; + + public CraftingModuleContainer(ContainerType type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) { + super(type, id, player, pos, moduleIndex); + } + + @Override + protected void addSlots() { + this.input = this.module.getInput(this.moduleStack); + for (int i = 0; i < this.input.getSlots(); i++) { + this.addSlot(new FilterSlot(this.input, i, (176 - this.module.inputSlots * 18) / 2 + 1 + i % 9 * 18, 17 + 32 + i / 9 * 18, false) { + @Override + public void onSlotChanged() { + super.onSlotChanged(); + CraftingModuleContainer.this.modified = true; + } + }); + } + + this.output = this.module.getOutput(this.moduleStack); + for (int i = 0; i < this.output.getSlots(); i++) { + this.addSlot(new FilterSlot(this.output, i, (176 - this.module.outputSlots * 18) / 2 + 1 + i % 9 * 18, 85 + i / 9 * 18, false) { + @Override + public void onSlotChanged() { + super.onSlotChanged(); + CraftingModuleContainer.this.modified = true; + } + }); + } + } + + @Override + public void onContainerClosed(PlayerEntity playerIn) { + super.onContainerClosed(playerIn); + if (this.modified) + this.module.save(this.input, this.output, this.moduleStack); + } +} diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleGui.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleGui.java new file mode 100644 index 0000000..744afcb --- /dev/null +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleGui.java @@ -0,0 +1,19 @@ +package de.ellpeck.prettypipes.pipe.modules.craft; + +import com.mojang.blaze3d.matrix.MatrixStack; +import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; + +public class CraftingModuleGui extends AbstractPipeGui { + public CraftingModuleGui(CraftingModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) { + super(screenContainer, inv, titleIn); + } + + @Override + protected void drawGuiContainerBackgroundLayer(MatrixStack matrix, float partialTicks, int mouseX, int mouseY) { + super.drawGuiContainerBackgroundLayer(matrix, partialTicks, mouseX, mouseY); + this.getMinecraft().getTextureManager().bindTexture(TEXTURE); + this.blit(matrix, this.guiLeft + 176 / 2 - 16 / 2, this.guiTop + 32 + 18 * 2, 176, 80, 16, 16); + } +} diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java new file mode 100644 index 0000000..aa79f34 --- /dev/null +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/craft/CraftingModuleItem.java @@ -0,0 +1,62 @@ +package de.ellpeck.prettypipes.pipe.modules.craft; + +import de.ellpeck.prettypipes.Registry; +import de.ellpeck.prettypipes.items.IModule; +import de.ellpeck.prettypipes.items.ModuleItem; +import de.ellpeck.prettypipes.items.ModuleTier; +import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraftforge.items.ItemStackHandler; + +public class CraftingModuleItem extends ModuleItem { + + public final int inputSlots; + public final int outputSlots; + + public CraftingModuleItem(String name, ModuleTier tier) { + super(name); + this.inputSlots = tier.forTier(1, 4, 9); + this.outputSlots = tier.forTier(1, 2, 4); + } + + @Override + public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + return true; + } + + @Override + public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + return true; + } + + @Override + public AbstractPipeContainer getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) { + return new CraftingModuleContainer(Registry.craftingModuleContainer, windowId, player, tile.getPos(), moduleIndex); + } + + public ItemStackHandler getInput(ItemStack module) { + ItemStackHandler handler = new ItemStackHandler(this.inputSlots); + if (module.hasTag()) + handler.deserializeNBT(module.getTag().getCompound("input")); + return handler; + } + + public ItemStackHandler getOutput(ItemStack module) { + ItemStackHandler handler = new ItemStackHandler(this.outputSlots); + if (module.hasTag()) + handler.deserializeNBT(module.getTag().getCompound("output")); + return handler; + } + + public void save(ItemStackHandler input, ItemStackHandler output, ItemStack module) { + CompoundNBT tag = module.getOrCreateTag(); + if (input != null) + tag.put("input", input.serializeNBT()); + if (output != null) + tag.put("output", output.serializeNBT()); + } +} diff --git a/src/main/resources/assets/prettypipes/textures/gui/pipe.png b/src/main/resources/assets/prettypipes/textures/gui/pipe.png index df326e1..5d2260f 100644 Binary files a/src/main/resources/assets/prettypipes/textures/gui/pipe.png and b/src/main/resources/assets/prettypipes/textures/gui/pipe.png differ