mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 19:58:35 +01:00
added the filter increase modifier
This commit is contained in:
parent
e3cbbae905
commit
6fbedff388
10 changed files with 162 additions and 20 deletions
|
@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.entities.PipeFrameEntity;
|
||||||
import de.ellpeck.prettypipes.entities.PipeFrameRenderer;
|
import de.ellpeck.prettypipes.entities.PipeFrameRenderer;
|
||||||
import de.ellpeck.prettypipes.items.*;
|
import de.ellpeck.prettypipes.items.*;
|
||||||
import de.ellpeck.prettypipes.misc.ItemEqualityType;
|
import de.ellpeck.prettypipes.misc.ItemEqualityType;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.FilterModifierModule;
|
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;
|
||||||
|
@ -15,6 +15,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.modules.filter.FilterIncreaseModuleContainer;
|
||||||
|
import de.ellpeck.prettypipes.pipe.modules.filter.FilterIncreaseModuleGui;
|
||||||
|
import de.ellpeck.prettypipes.pipe.modules.filter.FilterIncreaseModuleItem;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.insertion.FilterModuleContainer;
|
import de.ellpeck.prettypipes.pipe.modules.insertion.FilterModuleContainer;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.insertion.FilterModuleGui;
|
import de.ellpeck.prettypipes.pipe.modules.insertion.FilterModuleGui;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.insertion.FilterModuleItem;
|
import de.ellpeck.prettypipes.pipe.modules.insertion.FilterModuleItem;
|
||||||
|
@ -110,6 +113,7 @@ public final class Registry {
|
||||||
public static ContainerType<FilterModuleContainer> filterModuleContainer;
|
public static ContainerType<FilterModuleContainer> filterModuleContainer;
|
||||||
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;
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerBlocks(RegistryEvent.Register<Block> event) {
|
public static void registerBlocks(RegistryEvent.Register<Block> event) {
|
||||||
|
@ -135,8 +139,9 @@ public final class Registry {
|
||||||
registry.registerAll(createTieredModule("low_priority_module", LowPriorityModuleItem::new));
|
registry.registerAll(createTieredModule("low_priority_module", LowPriorityModuleItem::new));
|
||||||
registry.registerAll(createTieredModule("retrieval_module", RetrievalModuleItem::new));
|
registry.registerAll(createTieredModule("retrieval_module", RetrievalModuleItem::new));
|
||||||
registry.register(new StackSizeModuleItem("stack_size_module"));
|
registry.register(new StackSizeModuleItem("stack_size_module"));
|
||||||
registry.registerAll(Arrays.stream(ItemEqualityType.values()).map(t -> new FilterModifierModule(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"));
|
||||||
|
|
||||||
ForgeRegistries.BLOCKS.getValues().stream()
|
ForgeRegistries.BLOCKS.getValues().stream()
|
||||||
.filter(b -> b.getRegistryName().getNamespace().equals(PrettyPipes.ID))
|
.filter(b -> b.getRegistryName().getNamespace().equals(PrettyPipes.ID))
|
||||||
|
@ -170,7 +175,8 @@ public final class Registry {
|
||||||
extractionModuleContainer = createPipeContainer("extraction_module"),
|
extractionModuleContainer = createPipeContainer("extraction_module"),
|
||||||
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")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,6 +226,7 @@ public final class Registry {
|
||||||
ScreenManager.registerFactory(filterModuleContainer, FilterModuleGui::new);
|
ScreenManager.registerFactory(filterModuleContainer, FilterModuleGui::new);
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import de.ellpeck.prettypipes.PrettyPipes;
|
import de.ellpeck.prettypipes.PrettyPipes;
|
||||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||||
import de.ellpeck.prettypipes.pipe.modules.FilterModifierModule;
|
import de.ellpeck.prettypipes.pipe.modules.FilterModifierModuleItem;
|
||||||
|
import de.ellpeck.prettypipes.pipe.modules.filter.FilterIncreaseModuleItem;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.widget.Widget;
|
import net.minecraft.client.gui.widget.Widget;
|
||||||
import net.minecraft.client.gui.widget.button.Button;
|
import net.minecraft.client.gui.widget.button.Button;
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.inventory.container.Slot;
|
import net.minecraft.inventory.container.Slot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
@ -77,8 +77,10 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
if (id == 0 && this.canModifyWhitelist) {
|
if (id == 0 && this.canModifyWhitelist) {
|
||||||
this.isWhitelist = !this.isWhitelist;
|
this.isWhitelist = !this.isWhitelist;
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
|
this.save();
|
||||||
} else if (id == 1 && this.canPopulateFromInventories) {
|
} else if (id == 1 && this.canPopulateFromInventories) {
|
||||||
// populate filter from inventories
|
// populate filter from inventories
|
||||||
|
List<ItemFilter> filters = this.getAllFilters();
|
||||||
for (Direction direction : Direction.values()) {
|
for (Direction direction : Direction.values()) {
|
||||||
IItemHandler handler = this.pipe.getItemHandler(direction, null);
|
IItemHandler handler = this.pipe.getItemHandler(direction, null);
|
||||||
if (handler == null)
|
if (handler == null)
|
||||||
|
@ -89,12 +91,16 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
continue;
|
continue;
|
||||||
ItemStack copy = stack.copy();
|
ItemStack copy = stack.copy();
|
||||||
copy.setCount(1);
|
copy.setCount(1);
|
||||||
ItemHandlerHelper.insertItem(this, copy, false);
|
// try inserting into ourselves and any filter increase modifiers
|
||||||
|
for (ItemStackHandler filter : filters) {
|
||||||
|
if (ItemHandlerHelper.insertItem(filter, copy, false).isEmpty())
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.modified = true;
|
|
||||||
}
|
}
|
||||||
this.save();
|
for (ItemFilter filter : filters)
|
||||||
|
filter.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowed(ItemStack stack) {
|
public boolean isAllowed(ItemStack stack) {
|
||||||
|
@ -103,21 +109,34 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
|
|
||||||
private boolean isFiltered(ItemStack stack) {
|
private boolean isFiltered(ItemStack stack) {
|
||||||
ItemEqualityType[] types = this.getEqualityTypes();
|
ItemEqualityType[] types = this.getEqualityTypes();
|
||||||
for (int i = 0; i < this.getSlots(); i++) {
|
// also check if any filter increase modules have the item we need
|
||||||
ItemStack filter = this.getStackInSlot(i);
|
for (ItemStackHandler handler : this.getAllFilters()) {
|
||||||
|
for (int i = 0; i < handler.getSlots(); i++) {
|
||||||
|
ItemStack filter = handler.getStackInSlot(i);
|
||||||
if (filter.isEmpty())
|
if (filter.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
if (ItemEqualityType.compareItems(stack, filter, types))
|
if (ItemEqualityType.compareItems(stack, filter, types))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<ItemFilter> getAllFilters() {
|
||||||
|
List<ItemFilter> filters = this.pipe.streamModules()
|
||||||
|
.filter(p -> p.getRight() instanceof FilterIncreaseModuleItem)
|
||||||
|
.map(p -> new ItemFilter(18, p.getLeft(), this.pipe))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
// add ourselves to the front
|
||||||
|
filters.add(0, this);
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
|
||||||
public ItemEqualityType[] getEqualityTypes() {
|
public ItemEqualityType[] getEqualityTypes() {
|
||||||
return this.pipe.streamModules()
|
return this.pipe.streamModules()
|
||||||
.map(Pair::getRight)
|
.map(Pair::getRight)
|
||||||
.filter(m -> m instanceof FilterModifierModule)
|
.filter(m -> m instanceof FilterModifierModuleItem)
|
||||||
.map(m -> ((FilterModifierModule) m).type)
|
.map(m -> ((FilterModifierModuleItem) m).type)
|
||||||
.toArray(ItemEqualityType[]::new);
|
.toArray(ItemEqualityType[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +150,7 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
@Override
|
@Override
|
||||||
public CompoundNBT serializeNBT() {
|
public CompoundNBT serializeNBT() {
|
||||||
CompoundNBT nbt = super.serializeNBT();
|
CompoundNBT nbt = super.serializeNBT();
|
||||||
|
if (this.canModifyWhitelist)
|
||||||
nbt.putBoolean("whitelist", this.isWhitelist);
|
nbt.putBoolean("whitelist", this.isWhitelist);
|
||||||
return nbt;
|
return nbt;
|
||||||
}
|
}
|
||||||
|
@ -138,6 +158,7 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
@Override
|
@Override
|
||||||
public void deserializeNBT(CompoundNBT nbt) {
|
public void deserializeNBT(CompoundNBT nbt) {
|
||||||
super.deserializeNBT(nbt);
|
super.deserializeNBT(nbt);
|
||||||
|
if (this.canModifyWhitelist)
|
||||||
this.isWhitelist = nbt.getBoolean("whitelist");
|
this.isWhitelist = nbt.getBoolean("whitelist");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,11 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class FilterModifierModule extends ModuleItem {
|
public class FilterModifierModuleItem extends ModuleItem {
|
||||||
|
|
||||||
public final ItemEqualityType type;
|
public final ItemEqualityType type;
|
||||||
|
|
||||||
public FilterModifierModule(String name, ItemEqualityType type) {
|
public FilterModifierModuleItem(String name, ItemEqualityType type) {
|
||||||
super(name);
|
super(name);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.setRegistryName(name);
|
this.setRegistryName(name);
|
|
@ -0,0 +1,38 @@
|
||||||
|
package de.ellpeck.prettypipes.pipe.modules.filter;
|
||||||
|
|
||||||
|
import de.ellpeck.prettypipes.misc.FilterSlot;
|
||||||
|
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||||
|
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.minecraftforge.items.ItemStackHandler;
|
||||||
|
|
||||||
|
public class FilterIncreaseModuleContainer extends AbstractPipeContainer<FilterIncreaseModuleItem> implements ItemFilter.IFilteredContainer {
|
||||||
|
|
||||||
|
public ItemFilter filter;
|
||||||
|
|
||||||
|
public FilterIncreaseModuleContainer(ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||||
|
super(type, id, player, pos, moduleIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addSlots() {
|
||||||
|
this.filter = new ItemFilter(18, this.moduleStack, this.tile);
|
||||||
|
this.filter.canModifyWhitelist = false;
|
||||||
|
for (Slot slot : this.filter.getSlots(8, 49))
|
||||||
|
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,11 @@
|
||||||
|
package de.ellpeck.prettypipes.pipe.modules.filter;
|
||||||
|
|
||||||
|
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||||
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
|
||||||
|
public class FilterIncreaseModuleGui extends AbstractPipeGui<FilterIncreaseModuleContainer> {
|
||||||
|
public FilterIncreaseModuleGui(FilterIncreaseModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||||
|
super(screenContainer, inv, titleIn);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package de.ellpeck.prettypipes.pipe.modules.filter;
|
||||||
|
|
||||||
|
import de.ellpeck.prettypipes.Registry;
|
||||||
|
import de.ellpeck.prettypipes.items.IModule;
|
||||||
|
import de.ellpeck.prettypipes.items.ModuleItem;
|
||||||
|
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;
|
||||||
|
import net.minecraftforge.items.ItemStackHandler;
|
||||||
|
|
||||||
|
public class FilterIncreaseModuleItem extends ModuleItem {
|
||||||
|
|
||||||
|
public FilterIncreaseModuleItem(String name) {
|
||||||
|
super(name);
|
||||||
|
this.setRegistryName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 FilterIncreaseModuleContainer(Registry.filterIncreaseModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,7 @@
|
||||||
"item.prettypipes.nbt_filter_modifier": "Data Filter Modifier",
|
"item.prettypipes.nbt_filter_modifier": "Data Filter Modifier",
|
||||||
"item.prettypipes.tag_filter_modifier": "Tag Filter Modifier",
|
"item.prettypipes.tag_filter_modifier": "Tag Filter Modifier",
|
||||||
"item.prettypipes.redstone_module": "Redstone Module",
|
"item.prettypipes.redstone_module": "Redstone Module",
|
||||||
|
"item.prettypipes.filter_increase_modifier": "Filter Increase Modifier",
|
||||||
"info.prettypipes.extraction_module": "Pulls items from adjacent inventories\nFilters and pull rates vary by tier\nHigh tiers prevent over-sending",
|
"info.prettypipes.extraction_module": "Pulls items from adjacent inventories\nFilters and pull rates vary by tier\nHigh tiers prevent over-sending",
|
||||||
"info.prettypipes.filter_module": "Restricts flow from pipes into adjacent inventories\nFilter amount varies by tier",
|
"info.prettypipes.filter_module": "Restricts flow from pipes into adjacent inventories\nFilter amount varies by tier",
|
||||||
"info.prettypipes.speed_module": "Increases speed of items exiting adjacent inventories\nSpeed varies by tier",
|
"info.prettypipes.speed_module": "Increases speed of items exiting adjacent inventories\nSpeed varies by tier",
|
||||||
|
@ -36,6 +37,7 @@
|
||||||
"info.prettypipes.item_terminal": "Allows viewing and requesting all items in a pipe network\nAlso has slots for putting items into the network",
|
"info.prettypipes.item_terminal": "Allows viewing and requesting all items in a pipe network\nAlso has slots for putting items into the network",
|
||||||
"info.prettypipes.crafting_terminal": "Allows requesting ingredients for crafting recipes\nSupports auto-filling from JEI if installed",
|
"info.prettypipes.crafting_terminal": "Allows requesting ingredients for crafting recipes\nSupports auto-filling from JEI if installed",
|
||||||
"info.prettypipes.pressurizer": "Drastically increases item speed in the entire pipe network\nRequires FE (or RF) for each item transferred",
|
"info.prettypipes.pressurizer": "Drastically increases item speed in the entire pipe network\nRequires FE (or RF) for each item transferred",
|
||||||
|
"info.prettypipes.filter_increase_modifier": "Adds additional filter slots to the pipe\nSlots will be used by any module that filters items",
|
||||||
"block.prettypipes.pipe": "Pipe",
|
"block.prettypipes.pipe": "Pipe",
|
||||||
"block.prettypipes.item_terminal": "Item Terminal",
|
"block.prettypipes.item_terminal": "Item Terminal",
|
||||||
"block.prettypipes.crafting_terminal": "Crafting Terminal",
|
"block.prettypipes.crafting_terminal": "Crafting Terminal",
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "prettypipes:item/filter_increase_modifier"
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 410 B |
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"type": "minecraft:crafting_shaped",
|
||||||
|
"pattern": [
|
||||||
|
" B ",
|
||||||
|
"RMR",
|
||||||
|
" R "
|
||||||
|
],
|
||||||
|
"key": {
|
||||||
|
"R": {
|
||||||
|
"item": "minecraft:redstone"
|
||||||
|
},
|
||||||
|
"B": {
|
||||||
|
"item": "minecraft:iron_bars"
|
||||||
|
},
|
||||||
|
"M": {
|
||||||
|
"item": "prettypipes:blank_module"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"result": {
|
||||||
|
"item": "prettypipes:filter_increase_modifier"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue