mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 11:53:29 +01:00
added filter modules
This commit is contained in:
parent
23462bbe00
commit
592e524153
12 changed files with 135 additions and 5 deletions
|
@ -10,6 +10,9 @@ import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||||
import de.ellpeck.prettypipes.pipe.*;
|
import de.ellpeck.prettypipes.pipe.*;
|
||||||
import de.ellpeck.prettypipes.pipe.containers.*;
|
import de.ellpeck.prettypipes.pipe.containers.*;
|
||||||
|
import de.ellpeck.prettypipes.pipe.insertion.FilterModuleContainer;
|
||||||
|
import de.ellpeck.prettypipes.pipe.insertion.FilterModuleGui;
|
||||||
|
import de.ellpeck.prettypipes.pipe.insertion.FilterModuleItem;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.gui.ScreenManager;
|
import net.minecraft.client.gui.ScreenManager;
|
||||||
import net.minecraft.client.renderer.RenderType;
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
@ -63,6 +66,7 @@ public final class Registry {
|
||||||
|
|
||||||
public static ContainerType<MainPipeContainer> pipeContainer;
|
public static ContainerType<MainPipeContainer> pipeContainer;
|
||||||
public static ContainerType<ExtractionModuleContainer> extractionModuleContainer;
|
public static ContainerType<ExtractionModuleContainer> extractionModuleContainer;
|
||||||
|
public static ContainerType<FilterModuleContainer> filterModuleContainer;
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerBlocks(RegistryEvent.Register<Block> event) {
|
public static void registerBlocks(RegistryEvent.Register<Block> event) {
|
||||||
|
@ -78,6 +82,7 @@ public final class Registry {
|
||||||
wrenchItem = new WrenchItem().setRegistryName("wrench")
|
wrenchItem = new WrenchItem().setRegistryName("wrench")
|
||||||
);
|
);
|
||||||
registry.registerAll(createTieredModule("extraction_module", ExtractionModuleItem::new));
|
registry.registerAll(createTieredModule("extraction_module", ExtractionModuleItem::new));
|
||||||
|
registry.registerAll(createTieredModule("filter_module", FilterModuleItem::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))
|
||||||
|
@ -95,7 +100,9 @@ public final class Registry {
|
||||||
public static void registerContainer(RegistryEvent.Register<ContainerType<?>> event) {
|
public static void registerContainer(RegistryEvent.Register<ContainerType<?>> event) {
|
||||||
event.getRegistry().registerAll(
|
event.getRegistry().registerAll(
|
||||||
pipeContainer = (ContainerType<MainPipeContainer>) IForgeContainerType.create((windowId, inv, data) -> new MainPipeContainer(pipeContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pipe"),
|
pipeContainer = (ContainerType<MainPipeContainer>) IForgeContainerType.create((windowId, inv, data) -> new MainPipeContainer(pipeContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pipe"),
|
||||||
extractionModuleContainer = (ContainerType<ExtractionModuleContainer>) IForgeContainerType.create((windowId, inv, data) -> new ExtractionModuleContainer(extractionModuleContainer, windowId, inv.player, data.readBlockPos(), data.readInt())).setRegistryName("extraction_module"));
|
extractionModuleContainer = (ContainerType<ExtractionModuleContainer>) IForgeContainerType.create((windowId, inv, data) -> new ExtractionModuleContainer(extractionModuleContainer, windowId, inv.player, data.readBlockPos(), data.readInt())).setRegistryName("extraction_module"),
|
||||||
|
filterModuleContainer = (ContainerType<FilterModuleContainer>) IForgeContainerType.create((windowId, inv, data) -> new FilterModuleContainer(filterModuleContainer, windowId, inv.player, data.readBlockPos(), data.readInt())).setRegistryName("filter_module")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setup(FMLCommonSetupEvent event) {
|
public static void setup(FMLCommonSetupEvent event) {
|
||||||
|
@ -128,6 +135,7 @@ public final class Registry {
|
||||||
|
|
||||||
ScreenManager.registerFactory(pipeContainer, MainPipeGui::new);
|
ScreenManager.registerFactory(pipeContainer, MainPipeGui::new);
|
||||||
ScreenManager.registerFactory(extractionModuleContainer, ExtractionModuleGui::new);
|
ScreenManager.registerFactory(extractionModuleContainer, ExtractionModuleGui::new);
|
||||||
|
ScreenManager.registerFactory(filterModuleContainer, FilterModuleGui::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,10 +44,8 @@ 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 SlotFilter(this, i, x, y));
|
slots.add(new SlotFilter(this, i, x + i % 9 * 18, y + i / 9 * 18));
|
||||||
x += 18;
|
|
||||||
}
|
|
||||||
return slots;
|
return slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package de.ellpeck.prettypipes.pipe.insertion;
|
||||||
|
|
||||||
|
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||||
|
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
||||||
|
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.inventory.container.ContainerType;
|
||||||
|
import net.minecraft.inventory.container.Slot;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleItem> implements IFilteredContainer {
|
||||||
|
|
||||||
|
public ItemFilter filter;
|
||||||
|
|
||||||
|
public FilterModuleContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||||
|
super(type, id, player, pos, moduleIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addSlots() {
|
||||||
|
this.filter = new ItemFilter(this.module.filterSlots, this.moduleStack);
|
||||||
|
for (Slot slot : this.filter.getSlots((176 - Math.min(this.module.filterSlots, 9) * 18) / 2 + 1, 17 + 32))
|
||||||
|
this.addSlot(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onContainerClosed(PlayerEntity playerIn) {
|
||||||
|
super.onContainerClosed(playerIn);
|
||||||
|
this.filter.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemFilter getFilter() {
|
||||||
|
return this.filter;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package de.ellpeck.prettypipes.pipe.insertion;
|
||||||
|
|
||||||
|
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||||
|
import net.minecraft.client.gui.widget.Widget;
|
||||||
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
|
||||||
|
public class FilterModuleGui extends AbstractPipeGui<FilterModuleContainer> {
|
||||||
|
public FilterModuleGui(FilterModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||||
|
super(screenContainer, inv, titleIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
super.init();
|
||||||
|
for (Widget widget : this.container.filter.getButtons(this.guiLeft + 7, this.guiTop + 17 + 32 + 18 * MathHelper.ceil(this.container.filter.getSlots() / 9F) + 2))
|
||||||
|
this.addButton(widget);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package de.ellpeck.prettypipes.pipe.insertion;
|
||||||
|
|
||||||
|
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.misc.ItemFilter;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class FilterModuleItem extends ModuleItem {
|
||||||
|
|
||||||
|
public final int filterSlots;
|
||||||
|
|
||||||
|
public FilterModuleItem(String name, ModuleTier tier) {
|
||||||
|
super(name);
|
||||||
|
this.filterSlots = tier.forTier(5, 9, 18);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack) {
|
||||||
|
ItemFilter filter = new ItemFilter(this.filterSlots, module);
|
||||||
|
return filter.isAllowed(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||||
|
return !(other instanceof FilterModuleItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 FilterModuleContainer(Registry.filterModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,11 @@
|
||||||
"item.prettypipes.low_extraction_module": "Low Extraction Module",
|
"item.prettypipes.low_extraction_module": "Low Extraction Module",
|
||||||
"item.prettypipes.medium_extraction_module": "Medium Extraction Module",
|
"item.prettypipes.medium_extraction_module": "Medium Extraction Module",
|
||||||
"item.prettypipes.high_extraction_module": "High Extraction Module",
|
"item.prettypipes.high_extraction_module": "High Extraction Module",
|
||||||
|
"item.prettypipes.low_filter_module": "Low Filter Module",
|
||||||
|
"item.prettypipes.medium_filter_module": "Medium Filter Module",
|
||||||
|
"item.prettypipes.high_filter_module": "High Filter Module",
|
||||||
"info.prettypipes.extraction_module": "Pulls items from adjacent inventories\nFilters and pull rates vary by tier",
|
"info.prettypipes.extraction_module": "Pulls items from adjacent inventories\nFilters and pull rates vary by tier",
|
||||||
|
"info.prettypipes.filter_module": "Restricts flow from pipes into adjacent inventories\nFilter amount varies by tier",
|
||||||
"block.prettypipes.pipe": "Pipe",
|
"block.prettypipes.pipe": "Pipe",
|
||||||
"itemGroup.prettypipes": "Pretty Pipes",
|
"itemGroup.prettypipes": "Pretty Pipes",
|
||||||
"container.prettypipes.pipe": "Pipe",
|
"container.prettypipes.pipe": "Pipe",
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "prettypipes:item/high_filter_module"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "prettypipes:item/low_filter_module"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "prettypipes:item/medium_filter_module"
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 339 B |
Binary file not shown.
After Width: | Height: | Size: 327 B |
Binary file not shown.
After Width: | Height: | Size: 353 B |
Loading…
Reference in a new issue