Compare commits

..

No commits in common. "21c0483a43867ebc77a90217ce032bab3c085eb1" and "f61178a098cd1f9f294a443ee6d3853d067f3129" have entirely different histories.

12 changed files with 20 additions and 99 deletions

View file

@ -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.15.0 mod_version=1.14.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

View file

@ -4,7 +4,6 @@ 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;
@ -190,10 +189,6 @@ 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) {
@ -234,7 +229,5 @@ 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);
} }
} }
} }

View file

@ -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(null); var filters = this.pipe.getFilters();
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, null)) if (stack.isEmpty() || this.isFiltered(stack))
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, Direction direction) { public boolean isAllowed(ItemStack stack) {
return this.isFiltered(stack, direction) == this.isWhitelist; return this.isFiltered(stack) == this.isWhitelist;
} }
private boolean isFiltered(ItemStack stack, Direction direction) { private boolean isFiltered(ItemStack stack) {
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(direction)) { for (ItemStackHandler handler : this.pipe.getFilters()) {
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,7 +162,5 @@ public class ItemFilter extends ItemStackHandler {
default void onFilterPopulated() { default void onFilterPopulated() {
} }
} }
} }

View file

@ -1,50 +0,0 @@
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;
}
}

View file

@ -379,18 +379,13 @@ 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(m -> m != null && m >= 0).findFirst().orElse(index); .filter(Objects::nonNull).findFirst().orElse(index);
} }
public List<ItemFilter> getFilters(Direction direction) { public List<ItemFilter> getFilters() {
return this.streamModules().map(p -> { return this.streamModules()
if (direction != null) { .map(p -> p.getRight().getItemFilter(p.getLeft(), this))
var dir = p.getRight().getDirectionSelector(p.getLeft(), this); .filter(Objects::nonNull).collect(Collectors.toList());
if (dir != null && !dir.has(direction))
return null;
}
return p.getRight().getItemFilter(p.getLeft(), this);
}).filter(Objects::nonNull).collect(Collectors.toList());
} }
@Override @Override

View file

@ -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, dir)) if (!filter.isAllowed(stack))
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,5 +90,4 @@ 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);
} }
} }

View file

@ -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, direction); return !this.getDirectionSelector(module, tile).has(direction) || this.getItemFilter(module, tile).isAllowed(stack);
} }
@Override @Override
@ -56,5 +56,4 @@ 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);
} }
} }

View file

@ -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(null)) { for (var filter : this.tile.getFilters()) {
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,5 +33,4 @@ public class FilterModifierModuleContainer extends AbstractPipeContainer<FilterM
protected void addSlots() { protected void addSlots() {
} }
} }

View file

@ -15,8 +15,6 @@ 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;
@ -40,9 +38,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
Arrays.stream(directions).flatMap(d -> tile.getFilters(d).stream()).distinct().forEach(f -> { for (var subFilter : tile.getFilters()) {
for (var i = 0; i < f.getSlots(); i++) { for (var f = 0; f < subFilter.getSlots(); f++) {
var filtered = f.getStackInSlot(i); var filtered = subFilter.getStackInSlot(f);
if (filtered.isEmpty()) if (filtered.isEmpty())
continue; continue;
var copy = filtered.copy(); var copy = filtered.copy();
@ -56,7 +54,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
@ -96,5 +94,4 @@ 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);
} }
} }

View file

@ -4,7 +4,6 @@ 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;
@ -43,7 +42,6 @@ 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());
@ -52,7 +50,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, types)) if (!ItemEquality.compareItems(stored, stack))
continue; continue;
amount += stored.getCount(); amount += stored.getCount();
if (amount >= max) if (amount >= max)
@ -75,5 +73,4 @@ 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);
} }
} }

View file

@ -161,7 +161,6 @@ 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) {
@ -322,5 +321,4 @@ 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)));
}; };
} }
} }

View file

@ -1,4 +0,0 @@
{
"type": "prettypipes:module_clearing",
"category": "misc"
}