mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-26 05:28:33 +01:00
added the basic crafting module setup
This commit is contained in:
parent
33262328ed
commit
eb8f2695de
8 changed files with 149 additions and 5 deletions
|
@ -8,6 +8,9 @@ import de.ellpeck.prettypipes.pipe.modules.FilterModifierModuleItem;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.LowPriorityModuleItem;
|
import de.ellpeck.prettypipes.pipe.modules.LowPriorityModuleItem;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.RedstoneModuleItem;
|
import de.ellpeck.prettypipes.pipe.modules.RedstoneModuleItem;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.SpeedModuleItem;
|
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.ExtractionModuleContainer;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.extraction.ExtractionModuleGui;
|
import de.ellpeck.prettypipes.pipe.modules.extraction.ExtractionModuleGui;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.extraction.ExtractionModuleItem;
|
import de.ellpeck.prettypipes.pipe.modules.extraction.ExtractionModuleItem;
|
||||||
|
@ -114,6 +117,7 @@ public final class Registry {
|
||||||
public static ContainerType<RetrievalModuleContainer> retrievalModuleContainer;
|
public static ContainerType<RetrievalModuleContainer> retrievalModuleContainer;
|
||||||
public static ContainerType<StackSizeModuleContainer> stackSizeModuleContainer;
|
public static ContainerType<StackSizeModuleContainer> stackSizeModuleContainer;
|
||||||
public static ContainerType<FilterIncreaseModuleContainer> filterIncreaseModuleContainer;
|
public static ContainerType<FilterIncreaseModuleContainer> filterIncreaseModuleContainer;
|
||||||
|
public static ContainerType<CraftingModuleContainer> craftingModuleContainer;
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerBlocks(RegistryEvent.Register<Block> event) {
|
public static void registerBlocks(RegistryEvent.Register<Block> 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.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 RedstoneModuleItem("redstone_module"));
|
||||||
registry.register(new FilterIncreaseModuleItem("filter_increase_modifier"));
|
registry.register(new FilterIncreaseModuleItem("filter_increase_modifier"));
|
||||||
|
registry.registerAll(createTieredModule("crafting_module", CraftingModuleItem::new));
|
||||||
|
|
||||||
ForgeRegistries.BLOCKS.getValues().stream()
|
ForgeRegistries.BLOCKS.getValues().stream()
|
||||||
.filter(b -> b.getRegistryName().getNamespace().equals(PrettyPipes.ID))
|
.filter(b -> b.getRegistryName().getNamespace().equals(PrettyPipes.ID))
|
||||||
|
@ -176,7 +181,8 @@ public final class Registry {
|
||||||
filterModuleContainer = createPipeContainer("filter_module"),
|
filterModuleContainer = createPipeContainer("filter_module"),
|
||||||
retrievalModuleContainer = createPipeContainer("retrieval_module"),
|
retrievalModuleContainer = createPipeContainer("retrieval_module"),
|
||||||
stackSizeModuleContainer = createPipeContainer("stack_size_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(retrievalModuleContainer, RetrievalModuleGui::new);
|
||||||
ScreenManager.registerFactory(stackSizeModuleContainer, StackSizeModuleGui::new);
|
ScreenManager.registerFactory(stackSizeModuleContainer, StackSizeModuleGui::new);
|
||||||
ScreenManager.registerFactory(filterIncreaseModuleContainer, FilterIncreaseModuleGui::new);
|
ScreenManager.registerFactory(filterIncreaseModuleContainer, FilterIncreaseModuleGui::new);
|
||||||
|
ScreenManager.registerFactory(craftingModuleContainer, CraftingModuleGui::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,12 @@ import net.minecraftforge.items.IItemHandler;
|
||||||
import net.minecraftforge.items.SlotItemHandler;
|
import net.minecraftforge.items.SlotItemHandler;
|
||||||
|
|
||||||
public class FilterSlot extends 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);
|
super(itemHandler, index, xPosition, yPosition);
|
||||||
|
this.onlyOneItem = onlyOneItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkFilter(Container container, int slotId, PlayerEntity player) {
|
public static boolean checkFilter(Container container, int slotId, PlayerEntity player) {
|
||||||
|
@ -31,6 +35,7 @@ public class FilterSlot extends SlotItemHandler {
|
||||||
this.putStack(ItemStack.EMPTY);
|
this.putStack(ItemStack.EMPTY);
|
||||||
} else if (!heldStack.isEmpty()) {
|
} else if (!heldStack.isEmpty()) {
|
||||||
ItemStack s = heldStack.copy();
|
ItemStack s = heldStack.copy();
|
||||||
|
if (this.onlyOneItem)
|
||||||
s.setCount(1);
|
s.setCount(1);
|
||||||
this.putStack(s);
|
this.putStack(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
public List<Slot> getSlots(int x, int y) {
|
public List<Slot> getSlots(int x, int y) {
|
||||||
List<Slot> slots = new ArrayList<>();
|
List<Slot> slots = new ArrayList<>();
|
||||||
for (int i = 0; i < this.getSlots(); i++)
|
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;
|
return slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.util.List;
|
||||||
|
|
||||||
public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extends ContainerScreen<T> {
|
public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extends ContainerScreen<T> {
|
||||||
|
|
||||||
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<Tab> tabs = new ArrayList<>();
|
private final List<Tab> tabs = new ArrayList<>();
|
||||||
private final ItemStack[] lastItems = new ItemStack[this.container.tile.modules.getSlots()];
|
private final ItemStack[] lastItems = new ItemStack[this.container.tile.modules.getSlots()];
|
||||||
|
|
||||||
|
|
|
@ -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<CraftingModuleItem> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<CraftingModuleContainer> {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in a new issue