mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-27 05:38:33 +01:00
Compare commits
6 commits
f61178a098
...
21c0483a43
Author | SHA1 | Date | |
---|---|---|---|
21c0483a43 | |||
90e73a537c | |||
494ddc5391 | |||
2ab1b907de | |||
7d54b5d936 | |||
f34c89f914 |
12 changed files with 99 additions and 20 deletions
|
@ -52,7 +52,7 @@ mod_name=PrettyPipes
|
||||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=MIT
|
mod_license=MIT
|
||||||
# The mod version. See https://semver.org/
|
# The mod version. See https://semver.org/
|
||||||
mod_version=1.14.0
|
mod_version=1.15.0
|
||||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
# This should match the base package used for the mod sources.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
|
|
@ -4,6 +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.ItemEquality;
|
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||||
|
import de.ellpeck.prettypipes.misc.ModuleClearingRecipe;
|
||||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||||
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
||||||
|
@ -189,6 +190,10 @@ public final class Registry {
|
||||||
.forEach(b -> output.accept(b.getValue()))).build()
|
.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) {
|
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.craftingModuleContainer, CraftingModuleGui::new);
|
||||||
MenuScreens.register(Registry.filterModifierModuleContainer, FilterModifierModuleGui::new);
|
MenuScreens.register(Registry.filterModifierModuleContainer, FilterModifierModuleGui::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,14 +71,14 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
} else if (id == 1 && this.canPopulateFromInventories) {
|
} else if (id == 1 && this.canPopulateFromInventories) {
|
||||||
var changed = false;
|
var changed = false;
|
||||||
// populate filter from inventories
|
// populate filter from inventories
|
||||||
var filters = this.pipe.getFilters();
|
var filters = this.pipe.getFilters(null);
|
||||||
for (var direction : Direction.values()) {
|
for (var direction : Direction.values()) {
|
||||||
var handler = this.pipe.getItemHandler(direction);
|
var handler = this.pipe.getItemHandler(direction);
|
||||||
if (handler == null)
|
if (handler == null)
|
||||||
continue;
|
continue;
|
||||||
for (var i = 0; i < handler.getSlots(); i++) {
|
for (var i = 0; i < handler.getSlots(); i++) {
|
||||||
var stack = handler.getStackInSlot(i);
|
var stack = handler.getStackInSlot(i);
|
||||||
if (stack.isEmpty() || this.isFiltered(stack))
|
if (stack.isEmpty() || this.isFiltered(stack, null))
|
||||||
continue;
|
continue;
|
||||||
var copy = stack.copy();
|
var copy = stack.copy();
|
||||||
copy.setCount(1);
|
copy.setCount(1);
|
||||||
|
@ -97,14 +97,14 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowed(ItemStack stack) {
|
public boolean isAllowed(ItemStack stack, Direction direction) {
|
||||||
return this.isFiltered(stack) == this.isWhitelist;
|
return this.isFiltered(stack, direction) == this.isWhitelist;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFiltered(ItemStack stack) {
|
private boolean isFiltered(ItemStack stack, Direction direction) {
|
||||||
var types = ItemFilter.getEqualityTypes(this.pipe);
|
var types = ItemFilter.getEqualityTypes(this.pipe);
|
||||||
// also check if any filter increase modules have the item we need
|
// also check if any filter increase modules have the item we need
|
||||||
for (ItemStackHandler handler : this.pipe.getFilters()) {
|
for (ItemStackHandler handler : this.pipe.getFilters(direction)) {
|
||||||
for (var i = 0; i < handler.getSlots(); i++) {
|
for (var i = 0; i < handler.getSlots(); i++) {
|
||||||
var filter = handler.getStackInSlot(i);
|
var filter = handler.getStackInSlot(i);
|
||||||
if (filter.isEmpty())
|
if (filter.isEmpty())
|
||||||
|
@ -162,5 +162,7 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
|
|
||||||
default void onFilterPopulated() {
|
default void onFilterPopulated() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -379,13 +379,18 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
||||||
public int getNextNode(List<BlockPos> nodes, int index) {
|
public int getNextNode(List<BlockPos> nodes, int index) {
|
||||||
return this.streamModules()
|
return this.streamModules()
|
||||||
.map(m -> m.getRight().getCustomNextNode(m.getLeft(), this, nodes, index))
|
.map(m -> m.getRight().getCustomNextNode(m.getLeft(), this, nodes, index))
|
||||||
.filter(Objects::nonNull).findFirst().orElse(index);
|
.filter(m -> m != null && m >= 0).findFirst().orElse(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ItemFilter> getFilters() {
|
public List<ItemFilter> getFilters(Direction direction) {
|
||||||
return this.streamModules()
|
return this.streamModules().map(p -> {
|
||||||
.map(p -> p.getRight().getItemFilter(p.getLeft(), this))
|
if (direction != null) {
|
||||||
.filter(Objects::nonNull).collect(Collectors.toList());
|
var dir = p.getRight().getDirectionSelector(p.getLeft(), this);
|
||||||
|
if (dir != null && !dir.has(direction))
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return p.getRight().getItemFilter(p.getLeft(), this);
|
||||||
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class ExtractionModuleItem extends ModuleItem {
|
||||||
var stack = handler.extractItem(j, this.maxExtraction, true);
|
var stack = handler.extractItem(j, this.maxExtraction, true);
|
||||||
if (stack.isEmpty())
|
if (stack.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
if (!filter.isAllowed(stack))
|
if (!filter.isAllowed(stack, dir))
|
||||||
continue;
|
continue;
|
||||||
var remain = network.routeItem(tile.getBlockPos(), tile.getBlockPos().relative(dir), stack, this.preventOversending);
|
var remain = network.routeItem(tile.getBlockPos(), tile.getBlockPos().relative(dir), stack, this.preventOversending);
|
||||||
if (remain.getCount() != stack.getCount()) {
|
if (remain.getCount() != stack.getCount()) {
|
||||||
|
@ -90,4 +90,5 @@ public class ExtractionModuleItem extends ModuleItem {
|
||||||
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
||||||
return new DirectionSelector(module, tile);
|
return new DirectionSelector(module, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class FilterModuleItem extends ModuleItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
|
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack, Direction direction, IItemHandler destination) {
|
||||||
return !this.getDirectionSelector(module, tile).has(direction) || this.getItemFilter(module, tile).isAllowed(stack);
|
return !this.getDirectionSelector(module, tile).has(direction) || this.getItemFilter(module, tile).isAllowed(stack, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,4 +56,5 @@ public class FilterModuleItem extends ModuleItem {
|
||||||
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
||||||
return new DirectionSelector(module, tile);
|
return new DirectionSelector(module, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class FilterModifierModuleContainer extends AbstractPipeContainer<FilterM
|
||||||
|
|
||||||
public List<ResourceLocation> getTags() {
|
public List<ResourceLocation> getTags() {
|
||||||
Set<ResourceLocation> unsortedTags = new HashSet<>();
|
Set<ResourceLocation> unsortedTags = new HashSet<>();
|
||||||
for (var filter : this.tile.getFilters()) {
|
for (var filter : this.tile.getFilters(null)) {
|
||||||
for (var i = 0; i < filter.getSlots(); i++) {
|
for (var i = 0; i < filter.getSlots(); i++) {
|
||||||
var stack = filter.getStackInSlot(i);
|
var stack = filter.getStackInSlot(i);
|
||||||
stack.getTags().forEach(t -> unsortedTags.add(t.location()));
|
stack.getTags().forEach(t -> unsortedTags.add(t.location()));
|
||||||
|
@ -33,4 +33,5 @@ public class FilterModifierModuleContainer extends AbstractPipeContainer<FilterM
|
||||||
protected void addSlots() {
|
protected void addSlots() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class RetrievalModuleItem extends ModuleItem {
|
public class RetrievalModuleItem extends ModuleItem {
|
||||||
|
|
||||||
private final int maxExtraction;
|
private final int maxExtraction;
|
||||||
|
@ -38,9 +40,9 @@ public class RetrievalModuleItem extends ModuleItem {
|
||||||
var network = PipeNetwork.get(tile.getLevel());
|
var network = PipeNetwork.get(tile.getLevel());
|
||||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||||
// loop through filters to see which items to pull
|
// loop through filters to see which items to pull
|
||||||
for (var subFilter : tile.getFilters()) {
|
Arrays.stream(directions).flatMap(d -> tile.getFilters(d).stream()).distinct().forEach(f -> {
|
||||||
for (var f = 0; f < subFilter.getSlots(); f++) {
|
for (var i = 0; i < f.getSlots(); i++) {
|
||||||
var filtered = subFilter.getStackInSlot(f);
|
var filtered = f.getStackInSlot(i);
|
||||||
if (filtered.isEmpty())
|
if (filtered.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
var copy = filtered.copy();
|
var copy = filtered.copy();
|
||||||
|
@ -54,7 +56,7 @@ public class RetrievalModuleItem extends ModuleItem {
|
||||||
if (network.requestItem(tile.getBlockPos(), dest.getLeft(), remain, equalityTypes).isEmpty())
|
if (network.requestItem(tile.getBlockPos(), dest.getLeft(), remain, equalityTypes).isEmpty())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -94,4 +96,5 @@ public class RetrievalModuleItem extends ModuleItem {
|
||||||
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
|
||||||
return new DirectionSelector(module, tile);
|
return new DirectionSelector(module, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import de.ellpeck.prettypipes.Registry;
|
||||||
import de.ellpeck.prettypipes.items.IModule;
|
import de.ellpeck.prettypipes.items.IModule;
|
||||||
import de.ellpeck.prettypipes.items.ModuleItem;
|
import de.ellpeck.prettypipes.items.ModuleItem;
|
||||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||||
|
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
@ -42,6 +43,7 @@ public class StackSizeModuleItem extends ModuleItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination) {
|
public int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination) {
|
||||||
|
var types = ItemFilter.getEqualityTypes(tile);
|
||||||
var max = StackSizeModuleItem.getMaxStackSizeForModule(module);
|
var max = StackSizeModuleItem.getMaxStackSizeForModule(module);
|
||||||
if (StackSizeModuleItem.getLimitToMaxStackSize(module))
|
if (StackSizeModuleItem.getLimitToMaxStackSize(module))
|
||||||
max = Math.min(max, stack.getMaxStackSize());
|
max = Math.min(max, stack.getMaxStackSize());
|
||||||
|
@ -50,7 +52,7 @@ public class StackSizeModuleItem extends ModuleItem {
|
||||||
var stored = destination.getStackInSlot(i);
|
var stored = destination.getStackInSlot(i);
|
||||||
if (stored.isEmpty())
|
if (stored.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
if (!ItemEquality.compareItems(stored, stack))
|
if (!ItemEquality.compareItems(stored, stack, types))
|
||||||
continue;
|
continue;
|
||||||
amount += stored.getCount();
|
amount += stored.getCount();
|
||||||
if (amount >= max)
|
if (amount >= max)
|
||||||
|
@ -73,4 +75,5 @@ public class StackSizeModuleItem extends ModuleItem {
|
||||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||||
return new StackSizeModuleContainer(Registry.stackSizeModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
return new StackSizeModuleContainer(Registry.stackSizeModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,6 +161,7 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
||||||
// don't compare with nbt equality here or the whole hashing thing is pointless
|
// don't compare with nbt equality here or the whole hashing thing is pointless
|
||||||
.filter(s -> ItemEquality.compareItems(s, filter) && s.hasTag() && s.getTag().hashCode() == nbtHash)
|
.filter(s -> ItemEquality.compareItems(s, filter) && s.hasTag() && s.getTag().hashCode() == nbtHash)
|
||||||
.findFirst().orElse(filter);
|
.findFirst().orElse(filter);
|
||||||
|
stack.setCount(filter.getCount());
|
||||||
}
|
}
|
||||||
var requested = this.requestItemImpl(stack, ItemTerminalBlockEntity.onItemUnavailable(player, false));
|
var requested = this.requestItemImpl(stack, ItemTerminalBlockEntity.onItemUnavailable(player, false));
|
||||||
if (requested > 0) {
|
if (requested > 0) {
|
||||||
|
@ -321,4 +322,5 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
||||||
player.sendSystemMessage(Component.translatable("info." + PrettyPipes.ID + ".not_found", s.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.RED)));
|
player.sendSystemMessage(Component.translatable("info." + PrettyPipes.ID + ".not_found", s.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.RED)));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"type": "prettypipes:module_clearing",
|
||||||
|
"category": "misc"
|
||||||
|
}
|
Loading…
Reference in a new issue