Compare commits

..

No commits in common. "2597923ec8db735ddd53de99bafedab7fa793d20" and "a8d1a99e286bc7fae355d6b44c4fd64b07afb7a1" have entirely different histories.

56 changed files with 132 additions and 168 deletions

View file

@ -34,7 +34,7 @@ mod_name=PrettyPipes
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT
# The mod version. See https://semver.org/
mod_version=1.17.0
mod_version=1.16.3
# 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.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View file

@ -42,7 +42,7 @@ public final class Utility {
public static final Codec<ItemStackHandler> ITEM_STACK_HANDLER_CODEC = RecordCodecBuilder.create(builder -> builder.group(
Codec.INT.fieldOf("size").forGetter(h -> h.getSlots()),
Codec.list(ItemStack.OPTIONAL_CODEC).fieldOf("items").forGetter(h -> IntStream.range(0, h.getSlots()).mapToObj(h::getStackInSlot).toList())
Codec.list(ItemStack.CODEC).fieldOf("items").forGetter(h -> IntStream.range(0, h.getSlots()).mapToObj(h::getStackInSlot).toList())
).apply(builder, (size, items) -> {
var ret = new ItemStackHandler(size);
for (var i = 0; i < items.size(); i++)

View file

@ -103,7 +103,7 @@ public class JEIPrettyPipesPlugin implements IModPlugin {
}
@SubscribeEvent
public void onClientTick(ClientTickEvent.Pre event) {
public void onClientTick(ClientTickEvent event) {
if (!PlayerPrefs.get().syncJei)
return;

View file

@ -5,7 +5,6 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import de.ellpeck.prettypipes.PrettyPipes;
import de.ellpeck.prettypipes.packets.PacketButton;
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
import joptsimple.internal.Strings;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.core.Direction;
import net.minecraft.core.component.DataComponentType;
@ -69,13 +68,13 @@ public class DirectionSelector {
if (!this.modified)
return;
this.modified = false;
this.stack.set(Data.TYPE, new Data(this.direction != null ? this.direction.getName() : ""));
this.stack.set(Data.TYPE, new Data(this.direction.getName()));
}
public void load() {
var data = this.stack.get(Data.TYPE);
if (data != null)
this.direction = !Strings.isNullOrEmpty(data.direction) ? Direction.byName(data.direction) : null;
this.direction = Direction.byName(data.direction);
}
public Direction[] directions() {

View file

@ -45,7 +45,8 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable
@Override
public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) {
this.pipes.clear();
for (var tag : nbt.getList("pipes", Tag.TAG_INT_ARRAY))
var list = nbt.getList("pipes", Tag.TAG_COMPOUND);
for (var tag : list)
this.pipes.add(Utility.readBlockPos(tag));
}

View file

@ -274,7 +274,8 @@ public class PipeItem implements IPipeItem {
this.y = nbt.getFloat("y");
this.z = nbt.getFloat("z");
this.path.clear();
for (var tag : nbt.getList("path", Tag.TAG_INT_ARRAY))
var list = nbt.getList("path", Tag.TAG_COMPOUND);
for (var tag : list)
this.path.add(Utility.readBlockPos(tag));
}

View file

@ -64,7 +64,8 @@ public class PipeNetwork extends SavedData implements GraphListener<BlockPos, Ne
public PipeNetwork(CompoundTag nbt, HolderLookup.Provider provider) {
this();
for (var node : nbt.getList("nodes", Tag.TAG_INT_ARRAY))
var nodes = nbt.getList("nodes", Tag.TAG_COMPOUND);
for (var node : nodes)
this.graph.addVertex(Utility.readBlockPos(node));
var edges = nbt.getList("edges", Tag.TAG_COMPOUND);
for (var i = 0; i < edges.size(); i++)

View file

@ -19,8 +19,8 @@ public record PacketCraftingModuleTransfer(List<ItemStack> inputs, List<ItemStac
public static final Type<PacketCraftingModuleTransfer> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "crafting_module_transfer"));
public static final StreamCodec<RegistryFriendlyByteBuf, PacketCraftingModuleTransfer> CODEC = StreamCodec.composite(
ItemStack.LIST_STREAM_CODEC, PacketCraftingModuleTransfer::inputs,
ItemStack.LIST_STREAM_CODEC, PacketCraftingModuleTransfer::outputs,
ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), PacketCraftingModuleTransfer::inputs,
ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), PacketCraftingModuleTransfer::outputs,
PacketCraftingModuleTransfer::new);
@Override

View file

@ -21,7 +21,6 @@ import net.neoforged.neoforge.network.handling.IPayloadContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public record PacketGhostSlot(BlockPos pos, List<Entry> stacks) implements CustomPacketPayload {
@ -44,27 +43,28 @@ public record PacketGhostSlot(BlockPos pos, List<Entry> stacks) implements Custo
tile.setGhostItems(message.stacks);
}
public record Entry(Optional<List<ItemStack>> stacks, Optional<TagKey<Item>> tag) {
public record Entry(List<ItemStack> stacks, TagKey<Item> tag) {
public static final StreamCodec<RegistryFriendlyByteBuf, Entry> CODEC = StreamCodec.composite(
ByteBufCodecs.optional(ItemStack.OPTIONAL_LIST_STREAM_CODEC), Entry::stacks,
ByteBufCodecs.optional(ByteBufCodecs.fromCodec(TagKey.codec(Registries.ITEM))), Entry::tag,
ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), Entry::stacks,
ByteBufCodecs.fromCodec(TagKey.codec(Registries.ITEM)), Entry::tag,
Entry::new);
public static Entry fromStacks(Level level, List<ItemStack> stacks) {
var tag = Entry.getTagForStacks(level, stacks);
if (tag != null) {
return new Entry(Optional.empty(), Optional.of(tag));
return new Entry(null, tag);
} else {
return new Entry(Optional.of(stacks), Optional.empty());
return new Entry(stacks, null);
}
}
public List<ItemStack> getStacks(Level level) {
return this.stacks.orElseGet(() ->
Streams.stream(level.registryAccess().registry(Registries.ITEM).orElseThrow().getTagOrEmpty(this.tag.orElseThrow()).iterator())
.filter(h -> h.value() != null & h.value() != Items.AIR)
.map(h -> new ItemStack(h.value())).collect(Collectors.toList()));
if (this.stacks != null)
return this.stacks;
return Streams.stream(level.registryAccess().registry(Registries.ITEM).orElseThrow().getTagOrEmpty(this.tag).iterator())
.filter(h -> h.value() != null & h.value() != Items.AIR)
.map(h -> new ItemStack(h.value())).collect(Collectors.toList());
}
private static TagKey<Item> getTagForStacks(Level level, List<ItemStack> stacks) {

View file

@ -18,9 +18,9 @@ public record PacketNetworkItems(List<ItemStack> items, List<ItemStack> craftabl
public static final Type<PacketNetworkItems> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "network_items"));
public static final StreamCodec<RegistryFriendlyByteBuf, PacketNetworkItems> CODEC = StreamCodec.composite(
ItemStack.LIST_STREAM_CODEC, PacketNetworkItems::items,
ItemStack.LIST_STREAM_CODEC, PacketNetworkItems::craftables,
ItemStack.LIST_STREAM_CODEC, PacketNetworkItems::currentlyCrafting,
ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), PacketNetworkItems::items,
ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), PacketNetworkItems::craftables,
ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), PacketNetworkItems::currentlyCrafting,
PacketNetworkItems::new);
@Override

View file

@ -9,10 +9,7 @@ import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.*;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable;
@ -31,7 +28,7 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
@Override
protected void addOwnSlots(Player player) {
this.craftInventory = new WrappedCraftingInventory(this.getTile().craftItems, this);
this.craftInventory = new WrappedCraftingInventory(this.getTile().craftItems, this, 3, 3);
this.craftResult = new ResultContainer() {
@Override
public void setChanged() {
@ -49,7 +46,14 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
@Override
public void slotsChanged(Container inventoryIn) {
super.slotsChanged(inventoryIn);
CraftingTerminalContainer.slotChangedCraftingGrid(this, this.player.level(), this.player, this.craftInventory, this.craftResult, null);
if (!this.player.level().isClientSide) {
var ret = ItemStack.EMPTY;
var optional = this.player.level().getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, this.craftInventory.asCraftInput(), this.player.level());
if (optional.isPresent())
ret = optional.get().value().assemble(this.craftInventory.asCraftInput(), this.player.level().registryAccess());
this.craftResult.setItem(0, ret);
((ServerPlayer) this.player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, 0, 0, ret));
}
}
@Override
@ -76,28 +80,4 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
return (CraftingTerminalBlockEntity) this.tile;
}
// copied from CraftingMenu
protected static void slotChangedCraftingGrid(AbstractContainerMenu menu, Level level, Player player, CraftingContainer craftSlots, ResultContainer resultSlots, @Nullable RecipeHolder<CraftingRecipe> recipe) {
if (!level.isClientSide) {
var craftinginput = craftSlots.asCraftInput();
var serverplayer = (ServerPlayer) player;
var itemstack = ItemStack.EMPTY;
var optional = level.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftinginput, level, recipe);
if (optional.isPresent()) {
var recipeholder = optional.get();
var craftingrecipe = recipeholder.value();
if (resultSlots.setRecipeUsed(level, serverplayer, recipeholder)) {
var itemstack1 = craftingrecipe.assemble(craftinginput, level.registryAccess());
if (itemstack1.isItemEnabled(level.enabledFeatures())) {
itemstack = itemstack1;
}
}
}
resultSlots.setItem(0, itemstack);
menu.setRemoteSlot(0, itemstack);
serverplayer.connection.send(new ClientboundContainerSetSlotPacket(menu.containerId, menu.incrementStateId(), 0, itemstack));
}
}
}

View file

@ -1,20 +1,17 @@
package de.ellpeck.prettypipes.terminal.containers;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.StackedContents;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.TransientCraftingContainer;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.ItemStackHandler;
import java.util.List;
import java.util.stream.IntStream;
public class WrappedCraftingInventory implements CraftingContainer {
public class WrappedCraftingInventory extends TransientCraftingContainer {
private final ItemStackHandler items;
private final CraftingTerminalContainer eventHandler;
public WrappedCraftingInventory(ItemStackHandler items, CraftingTerminalContainer eventHandlerIn) {
public WrappedCraftingInventory(ItemStackHandler items, CraftingTerminalContainer eventHandlerIn, int width, int height) {
super(eventHandlerIn, width, height);
this.eventHandler = eventHandlerIn;
this.items = items;
}
@ -50,7 +47,8 @@ public class WrappedCraftingInventory implements CraftingContainer {
var slotStack = this.items.getStackInSlot(index);
var ret = !slotStack.isEmpty() && count > 0 ? slotStack.split(count) : ItemStack.EMPTY;
if (!ret.isEmpty()) {
this.eventHandler.slotsChanged(this);
for (var player : this.eventHandler.getTile().getLookingPlayers())
player.containerMenu.slotsChanged(this);
}
return ret;
}
@ -58,17 +56,8 @@ public class WrappedCraftingInventory implements CraftingContainer {
@Override
public void setItem(int index, ItemStack stack) {
this.items.setStackInSlot(index, stack);
this.eventHandler.slotsChanged(this);
}
@Override
public void setChanged() {
this.eventHandler.slotsChanged(this);
}
@Override
public boolean stillValid(Player player) {
return true;
for (var player : this.eventHandler.getTile().getLookingPlayers())
player.containerMenu.slotsChanged(this);
}
@Override
@ -82,20 +71,4 @@ public class WrappedCraftingInventory implements CraftingContainer {
for (var i = 0; i < this.items.getSlots(); i++)
helper.accountStack(this.items.getStackInSlot(i));
}
@Override
public int getWidth() {
return 3;
}
@Override
public int getHeight() {
return 3;
}
@Override
public List<ItemStack> getItems() {
return IntStream.range(0, this.getContainerSize()).mapToObj(this::getItem).toList();
}
}

View file

@ -20,6 +20,6 @@
}
},
"result": {
"id": "prettypipes:blank_module"
"item": "prettypipes:blank_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:crafting_terminal"
"item": "prettypipes:crafting_terminal"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:damage_filter_modifier"
"item": "prettypipes:damage_filter_modifier"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:filter_increase_modifier"
"item": "prettypipes:filter_increase_modifier"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:high_crafting_module"
"item": "prettypipes:high_crafting_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:high_extraction_module"
"item": "prettypipes:high_extraction_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:high_filter_module"
"item": "prettypipes:high_filter_module"
}
}

View file

@ -14,6 +14,6 @@
}
},
"result": {
"id": "prettypipes:high_high_priority_module"
"item": "prettypipes:high_high_priority_module"
}
}

View file

@ -7,13 +7,13 @@
],
"key": {
"C": {
"tag": "c:cobblestones"
"tag": "forge:cobblestone"
},
"M": {
"item": "prettypipes:medium_low_priority_module"
}
},
"result": {
"id": "prettypipes:high_low_priority_module"
"item": "prettypipes:high_low_priority_module"
}
}

View file

@ -20,6 +20,6 @@
}
},
"result": {
"id": "prettypipes:high_retrieval_module"
"item": "prettypipes:high_retrieval_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:high_speed_module"
"item": "prettypipes:high_speed_module"
}
}

View file

@ -19,13 +19,13 @@
"item": "minecraft:iron_block"
},
"C": {
"tag": "c:chests"
"tag": "forge:chests"
},
"D": {
"item": "minecraft:diamond"
}
},
"result": {
"id": "prettypipes:item_terminal"
"item": "prettypipes:item_terminal"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:low_crafting_module"
"item": "prettypipes:low_crafting_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:low_extraction_module"
"item": "prettypipes:low_extraction_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:low_filter_module"
"item": "prettypipes:low_filter_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:low_high_priority_module"
"item": "prettypipes:low_high_priority_module"
}
}

View file

@ -10,13 +10,13 @@
"item": "minecraft:redstone"
},
"C": {
"tag": "c:cobblestones"
"tag": "forge:cobblestone"
},
"M": {
"item": "prettypipes:blank_module"
}
},
"result": {
"id": "prettypipes:low_low_priority_module"
"item": "prettypipes:low_low_priority_module"
}
}

View file

@ -20,6 +20,6 @@
}
},
"result": {
"id": "prettypipes:low_retrieval_module"
"item": "prettypipes:low_retrieval_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:low_speed_module"
"item": "prettypipes:low_speed_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:medium_crafting_module"
"item": "prettypipes:medium_crafting_module"
}
}

View file

@ -14,6 +14,6 @@
}
},
"result": {
"id": "prettypipes:medium_extraction_module"
"item": "prettypipes:medium_extraction_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:medium_filter_module"
"item": "prettypipes:medium_filter_module"
}
}

View file

@ -14,6 +14,6 @@
}
},
"result": {
"id": "prettypipes:medium_high_priority_module"
"item": "prettypipes:medium_high_priority_module"
}
}

View file

@ -7,13 +7,13 @@
],
"key": {
"C": {
"tag": "c:cobblestones"
"tag": "forge:cobblestone"
},
"M": {
"item": "prettypipes:low_low_priority_module"
}
},
"result": {
"id": "prettypipes:medium_low_priority_module"
"item": "prettypipes:medium_low_priority_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:medium_retrieval_module"
"item": "prettypipes:medium_retrieval_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:medium_speed_module"
"item": "prettypipes:medium_speed_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:mod_filter_modifier"
"item": "prettypipes:mod_filter_modifier"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:nbt_filter_modifier"
"item": "prettypipes:nbt_filter_modifier"
}
}

View file

@ -13,14 +13,14 @@
"item": "minecraft:iron_bars"
},
"G": {
"tag": "c:glass_blocks"
"tag": "forge:glass"
},
"C": {
"item": "minecraft:copper_ingot"
}
},
"result": {
"id": "prettypipes:pipe",
"item": "prettypipes:pipe",
"count": 4
}
}

View file

@ -12,6 +12,6 @@
}
],
"result": {
"id": "prettypipes:pipe_frame"
"item": "prettypipes:pipe_frame"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:pressurizer"
"item": "prettypipes:pressurizer"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:random_sorting_modifier"
"item": "prettypipes:random_sorting_modifier"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:redstone_module"
"item": "prettypipes:redstone_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:round_robin_sorting_modifier"
"item": "prettypipes:round_robin_sorting_modifier"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:stack_size_module"
"item": "prettypipes:stack_size_module"
}
}

View file

@ -17,6 +17,6 @@
}
},
"result": {
"id": "prettypipes:tag_filter_modifier"
"item": "prettypipes:tag_filter_modifier"
}
}

View file

@ -13,10 +13,10 @@
"item": "minecraft:iron_ingot"
},
"R": {
"tag": "c:dyes/red"
"tag": "forge:dyes/red"
}
},
"result": {
"id": "prettypipes:wrench"
"item": "prettypipes:wrench"
}
}

View file

@ -0,0 +1,9 @@
{
"schemaVersion": 1,
"id": "prettypipes",
"version": "0.0.0",
"contributors": ["SoniEx2"],
"depends": {
"forge": "*"
}
}