mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-10-30 02:40:51 +01:00
fixes
This commit is contained in:
parent
9f55e87972
commit
4a43c32342
46 changed files with 154 additions and 107 deletions
|
@ -21,6 +21,7 @@ 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 {
|
||||
|
@ -43,28 +44,27 @@ public record PacketGhostSlot(BlockPos pos, List<Entry> stacks) implements Custo
|
|||
tile.setGhostItems(message.stacks);
|
||||
}
|
||||
|
||||
public record Entry(List<ItemStack> stacks, TagKey<Item> tag) {
|
||||
public record Entry(Optional<List<ItemStack>> stacks, Optional<TagKey<Item>> tag) {
|
||||
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, Entry> CODEC = StreamCodec.composite(
|
||||
ItemStack.OPTIONAL_LIST_STREAM_CODEC, Entry::stacks,
|
||||
ByteBufCodecs.fromCodec(TagKey.codec(Registries.ITEM)), Entry::tag,
|
||||
ByteBufCodecs.optional(ItemStack.OPTIONAL_LIST_STREAM_CODEC), Entry::stacks,
|
||||
ByteBufCodecs.optional(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(null, tag);
|
||||
return new Entry(Optional.empty(), Optional.of(tag));
|
||||
} else {
|
||||
return new Entry(stacks, null);
|
||||
return new Entry(Optional.of(stacks), Optional.empty());
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemStack> getStacks(Level level) {
|
||||
if (this.stacks != null)
|
||||
return this.stacks;
|
||||
return Streams.stream(level.registryAccess().registry(Registries.ITEM).orElseThrow().getTagOrEmpty(this.tag).iterator())
|
||||
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());
|
||||
.map(h -> new ItemStack(h.value())).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
private static TagKey<Item> getTagForStacks(Level level, List<ItemStack> stacks) {
|
||||
|
|
|
@ -9,7 +9,10 @@ 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;
|
||||
|
@ -28,7 +31,7 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
|
|||
|
||||
@Override
|
||||
protected void addOwnSlots(Player player) {
|
||||
this.craftInventory = new WrappedCraftingInventory(this.getTile().craftItems, this, 3, 3);
|
||||
this.craftInventory = new WrappedCraftingInventory(this.getTile().craftItems, this);
|
||||
this.craftResult = new ResultContainer() {
|
||||
@Override
|
||||
public void setChanged() {
|
||||
|
@ -46,14 +49,7 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
|
|||
@Override
|
||||
public void slotsChanged(Container inventoryIn) {
|
||||
super.slotsChanged(inventoryIn);
|
||||
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));
|
||||
}
|
||||
CraftingTerminalContainer.slotChangedCraftingGrid(this, this.player.level(), this.player, this.craftInventory, this.craftResult, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,4 +76,28 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
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.TransientCraftingContainer;
|
||||
import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
|
||||
public class WrappedCraftingInventory extends TransientCraftingContainer {
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class WrappedCraftingInventory implements CraftingContainer {
|
||||
|
||||
private final ItemStackHandler items;
|
||||
private final CraftingTerminalContainer eventHandler;
|
||||
|
||||
public WrappedCraftingInventory(ItemStackHandler items, CraftingTerminalContainer eventHandlerIn, int width, int height) {
|
||||
super(eventHandlerIn, width, height);
|
||||
public WrappedCraftingInventory(ItemStackHandler items, CraftingTerminalContainer eventHandlerIn) {
|
||||
this.eventHandler = eventHandlerIn;
|
||||
this.items = items;
|
||||
}
|
||||
|
@ -47,8 +50,7 @@ public class WrappedCraftingInventory extends TransientCraftingContainer {
|
|||
var slotStack = this.items.getStackInSlot(index);
|
||||
var ret = !slotStack.isEmpty() && count > 0 ? slotStack.split(count) : ItemStack.EMPTY;
|
||||
if (!ret.isEmpty()) {
|
||||
for (var player : this.eventHandler.getTile().getLookingPlayers())
|
||||
player.containerMenu.slotsChanged(this);
|
||||
this.eventHandler.slotsChanged(this);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -56,8 +58,17 @@ public class WrappedCraftingInventory extends TransientCraftingContainer {
|
|||
@Override
|
||||
public void setItem(int index, ItemStack stack) {
|
||||
this.items.setStackInSlot(index, stack);
|
||||
for (var player : this.eventHandler.getTile().getLookingPlayers())
|
||||
player.containerMenu.slotsChanged(this);
|
||||
this.eventHandler.slotsChanged(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChanged() {
|
||||
this.eventHandler.slotsChanged(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,4 +82,20 @@ public class WrappedCraftingInventory extends TransientCraftingContainer {
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:blank_module"
|
||||
"id": "prettypipes:blank_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:crafting_terminal"
|
||||
"id": "prettypipes:crafting_terminal"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:damage_filter_modifier"
|
||||
"id": "prettypipes:damage_filter_modifier"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:filter_increase_modifier"
|
||||
"id": "prettypipes:filter_increase_modifier"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:high_crafting_module"
|
||||
"id": "prettypipes:high_crafting_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:high_extraction_module"
|
||||
"id": "prettypipes:high_extraction_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:high_filter_module"
|
||||
"id": "prettypipes:high_filter_module"
|
||||
}
|
||||
}
|
|
@ -14,6 +14,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:high_high_priority_module"
|
||||
"id": "prettypipes:high_high_priority_module"
|
||||
}
|
||||
}
|
|
@ -7,13 +7,13 @@
|
|||
],
|
||||
"key": {
|
||||
"C": {
|
||||
"tag": "forge:cobblestone"
|
||||
"tag": "c:cobblestones"
|
||||
},
|
||||
"M": {
|
||||
"item": "prettypipes:medium_low_priority_module"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:high_low_priority_module"
|
||||
"id": "prettypipes:high_low_priority_module"
|
||||
}
|
||||
}
|
|
@ -20,6 +20,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:high_retrieval_module"
|
||||
"id": "prettypipes:high_retrieval_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:high_speed_module"
|
||||
"id": "prettypipes:high_speed_module"
|
||||
}
|
||||
}
|
|
@ -19,13 +19,13 @@
|
|||
"item": "minecraft:iron_block"
|
||||
},
|
||||
"C": {
|
||||
"tag": "forge:chests"
|
||||
"tag": "c:chests"
|
||||
},
|
||||
"D": {
|
||||
"item": "minecraft:diamond"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:item_terminal"
|
||||
"id": "prettypipes:item_terminal"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:low_crafting_module"
|
||||
"id": "prettypipes:low_crafting_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:low_extraction_module"
|
||||
"id": "prettypipes:low_extraction_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:low_filter_module"
|
||||
"id": "prettypipes:low_filter_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:low_high_priority_module"
|
||||
"id": "prettypipes:low_high_priority_module"
|
||||
}
|
||||
}
|
|
@ -10,13 +10,13 @@
|
|||
"item": "minecraft:redstone"
|
||||
},
|
||||
"C": {
|
||||
"tag": "forge:cobblestone"
|
||||
"tag": "c:cobblestones"
|
||||
},
|
||||
"M": {
|
||||
"item": "prettypipes:blank_module"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:low_low_priority_module"
|
||||
"id": "prettypipes:low_low_priority_module"
|
||||
}
|
||||
}
|
|
@ -20,6 +20,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:low_retrieval_module"
|
||||
"id": "prettypipes:low_retrieval_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:low_speed_module"
|
||||
"id": "prettypipes:low_speed_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:medium_crafting_module"
|
||||
"id": "prettypipes:medium_crafting_module"
|
||||
}
|
||||
}
|
|
@ -14,6 +14,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:medium_extraction_module"
|
||||
"id": "prettypipes:medium_extraction_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:medium_filter_module"
|
||||
"id": "prettypipes:medium_filter_module"
|
||||
}
|
||||
}
|
|
@ -14,6 +14,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:medium_high_priority_module"
|
||||
"id": "prettypipes:medium_high_priority_module"
|
||||
}
|
||||
}
|
|
@ -7,13 +7,13 @@
|
|||
],
|
||||
"key": {
|
||||
"C": {
|
||||
"tag": "forge:cobblestone"
|
||||
"tag": "c:cobblestones"
|
||||
},
|
||||
"M": {
|
||||
"item": "prettypipes:low_low_priority_module"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:medium_low_priority_module"
|
||||
"id": "prettypipes:medium_low_priority_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:medium_retrieval_module"
|
||||
"id": "prettypipes:medium_retrieval_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:medium_speed_module"
|
||||
"id": "prettypipes:medium_speed_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:mod_filter_modifier"
|
||||
"id": "prettypipes:mod_filter_modifier"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:nbt_filter_modifier"
|
||||
"id": "prettypipes:nbt_filter_modifier"
|
||||
}
|
||||
}
|
|
@ -13,14 +13,14 @@
|
|||
"item": "minecraft:iron_bars"
|
||||
},
|
||||
"G": {
|
||||
"tag": "forge:glass"
|
||||
"tag": "c:glass_blocks"
|
||||
},
|
||||
"C": {
|
||||
"item": "minecraft:copper_ingot"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:pipe",
|
||||
"id": "prettypipes:pipe",
|
||||
"count": 4
|
||||
}
|
||||
}
|
|
@ -12,6 +12,6 @@
|
|||
}
|
||||
],
|
||||
"result": {
|
||||
"item": "prettypipes:pipe_frame"
|
||||
"id": "prettypipes:pipe_frame"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:pressurizer"
|
||||
"id": "prettypipes:pressurizer"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:random_sorting_modifier"
|
||||
"id": "prettypipes:random_sorting_modifier"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:redstone_module"
|
||||
"id": "prettypipes:redstone_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:round_robin_sorting_modifier"
|
||||
"id": "prettypipes:round_robin_sorting_modifier"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:stack_size_module"
|
||||
"id": "prettypipes:stack_size_module"
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@
|
|||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:tag_filter_modifier"
|
||||
"id": "prettypipes:tag_filter_modifier"
|
||||
}
|
||||
}
|
|
@ -13,10 +13,10 @@
|
|||
"item": "minecraft:iron_ingot"
|
||||
},
|
||||
"R": {
|
||||
"tag": "forge:dyes/red"
|
||||
"tag": "c:dyes/red"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "prettypipes:wrench"
|
||||
"id": "prettypipes:wrench"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue