From 76f332c03ea0a7ff6c9c6c5e54b1b4d23901dbe8 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 20 Oct 2020 00:52:56 +0200 Subject: [PATCH] added a display that shows items that are currently being crafted --- .../compat/jei/JEIPrettyPipesPlugin.java | 9 ++- .../prettypipes/misc/ItemTerminalWidget.java | 1 - .../prettypipes/packets/PacketButton.java | 4 ++ .../packets/PacketNetworkItems.java | 12 +++- .../terminal/ItemTerminalTileEntity.java | 47 ++++++++++++++- .../terminal/containers/ItemTerminalGui.java | 54 +++++++++++++++++- .../assets/prettypipes/font/unicode.json | 10 ---- .../assets/prettypipes/lang/en_us.json | 5 +- .../textures/gui/item_terminal.png | Bin 1672 -> 1713 bytes 9 files changed, 123 insertions(+), 19 deletions(-) delete mode 100644 src/main/resources/assets/prettypipes/font/unicode.json diff --git a/src/main/java/de/ellpeck/prettypipes/compat/jei/JEIPrettyPipesPlugin.java b/src/main/java/de/ellpeck/prettypipes/compat/jei/JEIPrettyPipesPlugin.java index e2d99e1..9f61265 100644 --- a/src/main/java/de/ellpeck/prettypipes/compat/jei/JEIPrettyPipesPlugin.java +++ b/src/main/java/de/ellpeck/prettypipes/compat/jei/JEIPrettyPipesPlugin.java @@ -30,6 +30,7 @@ import net.minecraftforge.event.TickEvent.ClientTickEvent; import net.minecraftforge.event.world.PistonEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -67,7 +68,13 @@ public class JEIPrettyPipesPlugin implements IModPlugin { registration.addGuiContainerHandler(ItemTerminalGui.class, new IGuiContainerHandler() { @Override public List getGuiExtraAreas(ItemTerminalGui containerScreen) { - return Collections.singletonList(new Rectangle2d(containerScreen.getGuiLeft() - 22, containerScreen.getGuiTop(), 22, 64)); + List ret = new ArrayList<>(); + // sorting buttons + ret.add(new Rectangle2d(containerScreen.getGuiLeft() - 22, containerScreen.getGuiTop(), 22, 64)); + // crafting hud + if (containerScreen.currentlyCrafting != null && !containerScreen.currentlyCrafting.isEmpty()) + ret.add(new Rectangle2d(containerScreen.getGuiLeft() + containerScreen.getXSize(), containerScreen.getGuiTop() + 4, 65, 89)); + return ret; } }); } diff --git a/src/main/java/de/ellpeck/prettypipes/misc/ItemTerminalWidget.java b/src/main/java/de/ellpeck/prettypipes/misc/ItemTerminalWidget.java index 714cac6..f8973da 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/ItemTerminalWidget.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/ItemTerminalWidget.java @@ -22,7 +22,6 @@ import java.util.List; public class ItemTerminalWidget extends Widget { - private static final ResourceLocation FONT = new ResourceLocation(PrettyPipes.ID, "unicode"); private final ItemTerminalGui screen; public final int gridX; public final int gridY; diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java index a35fd6b..a716132 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketButton.java @@ -114,6 +114,10 @@ public class PacketButton { CRAFT_TERMINAL_REQUEST((pos, data, player) -> { CraftingTerminalTileEntity tile = Utility.getTileEntity(CraftingTerminalTileEntity.class, player.world, pos); tile.requestCraftingItems(player, data[0]); + }), + CANCEL_CRAFTING((pos, data, player) -> { + ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, pos); + tile.cancelCrafting(); }); public final TriConsumer action; diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketNetworkItems.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketNetworkItems.java index 944541e..061d15c 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketNetworkItems.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketNetworkItems.java @@ -23,10 +23,12 @@ public class PacketNetworkItems { private List items; private List craftables; + private List currentlyCrafting; - public PacketNetworkItems(List items, List craftables) { + public PacketNetworkItems(List items, List craftables, List currentlyCrafting) { this.items = items; this.craftables = craftables; + this.currentlyCrafting = currentlyCrafting; } private PacketNetworkItems() { @@ -44,6 +46,9 @@ public class PacketNetworkItems { client.craftables = new ArrayList<>(); for (int i = buf.readVarInt(); i > 0; i--) client.craftables.add(buf.readItemStack()); + client.currentlyCrafting = new ArrayList<>(); + for (int i = buf.readVarInt(); i > 0; i--) + client.currentlyCrafting.add(buf.readItemStack()); return client; } @@ -58,6 +63,9 @@ public class PacketNetworkItems { buf.writeVarInt(packet.craftables.size()); for (ItemStack stack : packet.craftables) buf.writeItemStack(stack); + buf.writeVarInt(packet.currentlyCrafting.size()); + for (ItemStack stack : packet.currentlyCrafting) + buf.writeItemStack(stack); } @SuppressWarnings("Convert2Lambda") @@ -67,7 +75,7 @@ public class PacketNetworkItems { public void run() { Minecraft mc = Minecraft.getInstance(); if (mc.currentScreen instanceof ItemTerminalGui) - ((ItemTerminalGui) mc.currentScreen).updateItemList(message.items, message.craftables); + ((ItemTerminalGui) mc.currentScreen).updateItemList(message.items, message.craftables, message.currentlyCrafting); } }); ctx.get().setPacketHandled(true); diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java index ec3930d..5fdad28 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalTileEntity.java @@ -133,15 +133,17 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine return; this.networkItems = this.collectItems(); if (playersToSync.length > 0) { + List> craftables = PipeNetwork.get(this.world).getAllCraftables(pipe.getPos()); List clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList()); - List clientCraftables = PipeNetwork.get(this.world).getAllCraftables(pipe.getPos()).stream().map(Pair::getRight).collect(Collectors.toList()); + List clientCraftables = craftables.stream().map(Pair::getRight).collect(Collectors.toList()); + List currentlyCrafting = this.getCurrentlyCrafting(craftables).stream().sorted(Comparator.comparingInt(ItemStack::getCount).reversed()).collect(Collectors.toList()); for (PlayerEntity player : playersToSync) { if (!(player.openContainer instanceof ItemTerminalContainer)) continue; ItemTerminalTileEntity tile = ((ItemTerminalContainer) player.openContainer).tile; if (tile != this) continue; - PacketHandler.sendTo(player, new PacketNetworkItems(clientItems, clientCraftables)); + PacketHandler.sendTo(player, new PacketNetworkItems(clientItems, clientCraftables, currentlyCrafting)); } } } @@ -190,6 +192,47 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine return items; } + private List getCurrentlyCrafting(List> craftables) { + PipeNetwork network = PipeNetwork.get(this.world); + List> items = new ArrayList<>(); + for (Pair craftable : craftables) { + PipeTileEntity pipe = network.getPipe(craftable.getLeft()); + if (pipe == null) + continue; + for (Pair request : pipe.craftResultRequests) { + BlockPos dest = request.getLeft(); + ItemStack stack = request.getRight(); + // add up all the items that should go to the same location + Optional> existing = items.stream() + .filter(s -> s.getLeft() == dest && ItemEqualityType.compareItems(s.getRight(), stack, ItemEqualityType.NBT)) + .findFirst(); + if (existing.isPresent()) { + existing.get().getRight().grow(stack.getCount()); + } else { + items.add(Pair.of(dest, stack.copy())); + } + } + } + return items.stream().map(Pair::getRight).collect(Collectors.toList()); + } + + public void cancelCrafting() { + PipeNetwork network = PipeNetwork.get(this.world); + PipeTileEntity pipe = this.getConnectedPipe(); + if (pipe == null) + return; + for (Pair craftable : network.getAllCraftables(pipe.getPos())) { + PipeTileEntity otherPipe = network.getPipe(craftable.getLeft()); + if (otherPipe != null) { + otherPipe.craftIngredientRequests.clear(); + otherPipe.craftResultRequests.clear(); + } + } + PlayerEntity[] lookingPlayers = this.getLookingPlayers(); + if (lookingPlayers.length > 0) + this.updateItems(lookingPlayers); + } + @Override public CompoundNBT write(CompoundNBT compound) { compound.put("items", this.items.serializeNBT()); diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java b/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java index 6faa555..2259996 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java @@ -8,6 +8,7 @@ import de.ellpeck.prettypipes.misc.PlayerPrefs; import de.ellpeck.prettypipes.packets.PacketButton; import de.ellpeck.prettypipes.packets.PacketHandler; import de.ellpeck.prettypipes.packets.PacketRequest; +import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui; import joptsimple.internal.Strings; import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.client.gui.widget.TextFieldWidget; @@ -32,6 +33,9 @@ public class ItemTerminalGui extends ContainerScreen { private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/item_terminal.png"); + public List currentlyCrafting; + public TextFieldWidget search; + // craftables have the second parameter set to true private final List> sortedItems = new ArrayList<>(); private List items; @@ -41,10 +45,11 @@ public class ItemTerminalGui extends ContainerScreen { private Button requestButton; private Button orderButton; private Button ascendingButton; + private Button cancelCraftingButton; private String lastSearchText; private int requestAmount = 1; private int scrollOffset; - public TextFieldWidget search; + private ItemStack hoveredCrafting; public ItemTerminalGui(ItemTerminalContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) { super(screenContainer, inv, titleIn); @@ -98,6 +103,12 @@ public class ItemTerminalGui extends ContainerScreen { prefs.save(); this.updateWidgets(); })); + this.cancelCraftingButton = this.addButton(new Button(this.guiLeft + this.xSize + 4, this.guiTop + 4 + 64, 54, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".cancel_all"), button -> { + if (this.currentlyCrafting == null || this.currentlyCrafting.isEmpty()) + return; + PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CANCEL_CRAFTING)); + })); + this.cancelCraftingButton.visible = false; for (int y = 0; y < 4; y++) { for (int x = 0; x < 9; x++) this.addButton(new ItemTerminalWidget(this.guiLeft + this.getXOffset() + 8 + x * 18, this.guiTop + 18 + y * 18, x, y, this)); @@ -141,9 +152,10 @@ public class ItemTerminalGui extends ContainerScreen { return super.keyPressed(x, y, z); } - public void updateItemList(List items, List craftables) { + public void updateItemList(List items, List craftables, List currentlyCrafting) { this.items = items; this.craftables = craftables; + this.currentlyCrafting = currentlyCrafting; this.updateWidgets(); } @@ -151,6 +163,7 @@ public class ItemTerminalGui extends ContainerScreen { PlayerPrefs prefs = PlayerPrefs.get(); this.ascendingButton.setMessage(new StringTextComponent(prefs.terminalAscending ? "^" : "v")); this.orderButton.setMessage(new StringTextComponent(prefs.terminalItemOrder.name().substring(0, 1))); + this.cancelCraftingButton.visible = this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty(); Comparator comparator = prefs.terminalItemOrder.comparator; if (!prefs.terminalAscending) @@ -218,6 +231,12 @@ public class ItemTerminalGui extends ContainerScreen { if (this.ascendingButton.isHovered()) this.renderTooltip(matrix, new TranslationTextComponent("info." + PrettyPipes.ID + "." + (prefs.terminalAscending ? "ascending" : "descending")), mouseX, mouseY); } + if (this.cancelCraftingButton.isHovered()) { + String[] tooltip = I18n.format("info." + PrettyPipes.ID + ".cancel_all.desc").split("\n"); + this.func_243308_b(matrix, Arrays.stream(tooltip).map(StringTextComponent::new).collect(Collectors.toList()), mouseX, mouseY); + } + if (!this.hoveredCrafting.isEmpty()) + this.renderTooltip(matrix, this.hoveredCrafting, mouseX, mouseY); this.func_230459_a_(matrix, mouseX, mouseY); } @@ -228,6 +247,12 @@ public class ItemTerminalGui extends ContainerScreen { String amount = String.valueOf(this.requestAmount); this.font.drawString(matrix, amount, (176 + 15 - this.font.getStringWidth(amount)) / 2F - 7 + this.getXOffset(), 106, 4210752); + + if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) { + this.font.drawString(matrix, I18n.format("info." + PrettyPipes.ID + ".crafting"), this.xSize + 4, 4 + 6, 4210752); + if (this.currentlyCrafting.size() > 6) + this.font.drawString(matrix, ". . .", this.xSize + 24, 4 + 51, 4210752); + } } @Override @@ -241,6 +266,31 @@ public class ItemTerminalGui extends ContainerScreen { } else { this.blit(matrix, this.guiLeft + this.getXOffset() + 172, this.guiTop + 18, 244, 241, 12, 15); } + + // draw the items that are currently crafting + this.hoveredCrafting = ItemStack.EMPTY; + if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) { + this.getMinecraft().getTextureManager().bindTexture(TEXTURE); + this.blit(matrix, this.guiLeft + this.xSize, this.guiTop + 4, 191, 0, 65, 89); + + int x = 0; + int y = 0; + for (ItemStack stack : this.currentlyCrafting) { + int itemX = this.guiLeft + this.xSize + 4 + x * 18; + int itemY = this.guiTop + 4 + 16 + y * 18; + this.itemRenderer.renderItemAndEffectIntoGUI(stack, itemX, itemY); + this.itemRenderer.renderItemOverlayIntoGUI(this.font, stack, itemX, itemY, String.valueOf(stack.getCount())); + if (mouseX >= itemX && mouseY >= itemY && mouseX < itemX + 16 && mouseY < itemY + 18) + this.hoveredCrafting = stack; + x++; + if (x >= 3) { + x = 0; + y++; + if (y >= 2) + break; + } + } + } } protected ResourceLocation getTexture() { diff --git a/src/main/resources/assets/prettypipes/font/unicode.json b/src/main/resources/assets/prettypipes/font/unicode.json deleted file mode 100644 index 3b31a44..0000000 --- a/src/main/resources/assets/prettypipes/font/unicode.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "_comment": "Unicode fonts only", - "providers": [ - { - "type": "legacy_unicode", - "sizes": "minecraft:font/glyph_sizes.bin", - "template": "minecraft:font/unicode_page_%s.png" - } - ] -} \ No newline at end of file diff --git a/src/main/resources/assets/prettypipes/lang/en_us.json b/src/main/resources/assets/prettypipes/lang/en_us.json index 1bbcd4e..49b769f 100644 --- a/src/main/resources/assets/prettypipes/lang/en_us.json +++ b/src/main/resources/assets/prettypipes/lang/en_us.json @@ -74,5 +74,8 @@ "info.prettypipes.descending": "Descending", "info.prettypipes.sync_jei.on": "Sync JEI Search", "info.prettypipes.sync_jei.off": "Don't Sync JEI Search", - "info.prettypipes.energy": "%s / %s FE" + "info.prettypipes.energy": "%s / %s FE", + "info.prettypipes.crafting": "Crafting", + "info.prettypipes.cancel_all": "Cancel", + "info.prettypipes.cancel_all.desc": "Cancels all ongoing crafting operations\nDoesn't remove inputs from blocks" } \ No newline at end of file diff --git a/src/main/resources/assets/prettypipes/textures/gui/item_terminal.png b/src/main/resources/assets/prettypipes/textures/gui/item_terminal.png index 96baf5275531b4c07afa90966684b51fe9ddd00d..7da03d7204ac8297a627cb743fa3655d76c8386f 100644 GIT binary patch delta 1253 zcmZXTc~DbV6vkg32?S&jYG$ZVlj=~4RFf(~GKCOYv;rkMktOUPQbY(_WKke5fhl$z zi`ZwCfuMF=B9S6#YEVP-LYcy_MvE5078IMv5z@1Fx$~X*e&<^k zkxP95bT}eBET){VoyyH0PxP$4uN7vloIbws0`~jtFdzGBLD<$31~oMCD3%p{n>@YT z=F@z6Pc%YE+jI)fYg|EE@}%iAeyH3M8d7Up3*8EX-8+$~m8Z3gpI#`>>-xCbT8 z_ybw7V$@h(U>U@dEe(+C)D3JMf0n45EDpY4sjwVrG_7GjqZpHrMZGel=o8TF=6SP<=EyJgoShVt3jqewmu5!HD{Wae%HTX<3Y zpi|`=CRDE?IgQsCk)magxKyr$D(#c?T`}qU3gATdqp99=kWf{0Q5mmLgaB>D8y9uu zx=O0nY38!S076xWhm00Uf$NFxkwvdEv-L#|>gnBQ>g-e56nUx=nv^B^gY>7bs^+7( zNv&D4QBAh2m@Ds5(UyJ*+Yv4=HdmdA-_mRwE!$cvbfQVBBOVGIG% zLtr|}2Tlj=KVm+S+9ASmiP#*AC=HnQ-v-$c%CzZ6hN4#Ni-SkThhN5<-$k(j$4lMI znowGVs>PGE{agIOkh=3Q3iPod;P`1%%KAfM<)j&7lo4mijhVwk?7MB!3Rft|i_73> zxfRac`+JH4dihNn=Jl^BsUX~i@`CFz9@MdJzrde2*Q;?Rk875^CU62GA*gYr&$gH9cecMhh3q=2{F zFo)lH2W(qFXaH#K$|i0cCQwjI(cA!ac;I!F9~{9+CbYXQQdu1nbC0EVb_>R*#5uERO?;NoZ&*@=n$|#I-%KHS&{8#; zQ?f**_ROT&w)|=`(+#-Zz2?a2dyYoJff>i!AUD0uHiSQbRXYLIcmCf-rJ$JcE?Xs2 k`GP2gS}-p8b#)P%4~>Y_>K(QuBd`5L?52meeV$(ZH-OY<>Hq)$ literal 1672 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6&2?&#~tz_78e=6B#^1_m~J zPZ!6KiaBrZ#^&A15^1}5Ht_h9?kcHy9xCUXyd*h%nnPYKsnLsynzc=!uE)OO`lNHN zSLeuzJXSyEYqt7Vs#Zna>ZS4y-rwSTGH1>CZ?peuR;VhI{oioEx~4sQ_lEAg^*1y0 zJ=2G;udhFq<301{>({NTR+-KAovPjVtKn(vfZY~=X5`RQ$O?hr00(x{y#t8FOHGt zaKTk|iQ^l$-Ck??EXL;f2d$TPD(fU)SeP>^LQTeLC9*_WiTnWr9`ne^)IQ5CnW3SV zO?*SYKEK_3ni1{+S-lR=Oze-l&HuTB9hZ-gjYoJ@ zy75eA9pC4Tf+yxYdwzq%L>?^A*X!`PkRNNnU^fOBVrEP;FaMEwmaII%^6dGIf*E!Y z0qMqPkL57K7pE~mi5wQAAP7My#L+3KiTG# z@SB;k)@9zV2RLi@?%v0;s(m z;~9H*Pp;G)Hv7brC`rzC@r*}Vd`L>?9 zKl$Q(<{!6v9o6fl|CP$ftbe}g$9YB>yGEOt5B7=u_dKAb{!h7Z&AihW8EjtfX10Gl z`NqdbF%#eO{W-J$%au#lZ+^_W|L8kI!&43tLJOpQP1J8I>$tbpzxFYhow1oV@XV0FP zznpD}E8do6_gRXcfBF00E6YE3FEWJG+A~~7