mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-17 01:43:12 +01:00
backport 1c5a3a118d
This commit is contained in:
parent
58f665452d
commit
43bf12924f
5 changed files with 21 additions and 14 deletions
|
@ -112,7 +112,7 @@ public class PacketButton {
|
||||||
}),
|
}),
|
||||||
CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
|
CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
|
||||||
CraftingTerminalTileEntity tile = Utility.getTileEntity(CraftingTerminalTileEntity.class, player.world, pos);
|
CraftingTerminalTileEntity tile = Utility.getTileEntity(CraftingTerminalTileEntity.class, player.world, pos);
|
||||||
tile.requestCraftingItems(player, data[0]);
|
tile.requestCraftingItems(player, data[0], data[1] > 0);
|
||||||
}),
|
}),
|
||||||
CANCEL_CRAFTING((pos, data, player) -> {
|
CANCEL_CRAFTING((pos, data, player) -> {
|
||||||
ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, pos);
|
ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, pos);
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestCraftingItems(PlayerEntity player, int maxAmount) {
|
public void requestCraftingItems(PlayerEntity player, int maxAmount, boolean force) {
|
||||||
PipeTileEntity pipe = this.getConnectedPipe();
|
PipeTileEntity pipe = this.getConnectedPipe();
|
||||||
if (pipe == null)
|
if (pipe == null)
|
||||||
return;
|
return;
|
||||||
|
@ -117,7 +117,10 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
||||||
int lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> {
|
int lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> {
|
||||||
NetworkItem item = this.networkItems.get(s);
|
NetworkItem item = this.networkItems.get(s);
|
||||||
return item != null ? item.getLocations() : Collections.emptyList();
|
return item != null ? item.getLocations() : Collections.emptyList();
|
||||||
}, onItemUnavailable(player), new Stack<>(), ItemEquality.NBT);
|
}, onItemUnavailable(player, force), new Stack<>(), ItemEquality.NBT);
|
||||||
|
// if we're forcing, just pretend we have one available
|
||||||
|
if (lowestAvailable <= 0 && force)
|
||||||
|
lowestAvailable = maxAmount;
|
||||||
if (lowestAvailable > 0) {
|
if (lowestAvailable > 0) {
|
||||||
// if we're limiting the amount, pretend we only have that amount available
|
// if we're limiting the amount, pretend we only have that amount available
|
||||||
if (maxAmount < lowestAvailable)
|
if (maxAmount < lowestAvailable)
|
||||||
|
@ -128,9 +131,11 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
||||||
continue;
|
continue;
|
||||||
requested = requested.copy();
|
requested = requested.copy();
|
||||||
requested.setCount(lowestAvailable);
|
requested.setCount(lowestAvailable);
|
||||||
this.requestItemImpl(requested, onItemUnavailable(player));
|
this.requestItemImpl(requested, onItemUnavailable(player, force));
|
||||||
}
|
}
|
||||||
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
|
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
|
||||||
|
} else {
|
||||||
|
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".hold_alt"), UUID.randomUUID());
|
||||||
}
|
}
|
||||||
network.endProfile();
|
network.endProfile();
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,11 +166,11 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
||||||
.filter(s -> ItemEquality.compareItems(s, filter) && s.getTag().hashCode() == nbtHash)
|
.filter(s -> ItemEquality.compareItems(s, filter) && s.getTag().hashCode() == nbtHash)
|
||||||
.findFirst().orElse(filter);
|
.findFirst().orElse(filter);
|
||||||
}
|
}
|
||||||
int requested = this.requestItemImpl(stack, onItemUnavailable(player));
|
int requested = this.requestItemImpl(stack, onItemUnavailable(player, false));
|
||||||
if (requested > 0) {
|
if (requested > 0) {
|
||||||
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
|
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
|
||||||
} else {
|
} else {
|
||||||
onItemUnavailable(player).accept(stack);
|
onItemUnavailable(player, false).accept(stack);
|
||||||
}
|
}
|
||||||
network.endProfile();
|
network.endProfile();
|
||||||
}
|
}
|
||||||
|
@ -321,7 +321,11 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
||||||
return Pair.of(requests, remain);
|
return Pair.of(requests, remain);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Consumer<ItemStack> onItemUnavailable(PlayerEntity player) {
|
public static Consumer<ItemStack> onItemUnavailable(PlayerEntity player, boolean ignore) {
|
||||||
return s -> player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".not_found", s.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.RED)), UUID.randomUUID());
|
return s -> {
|
||||||
|
if (ignore)
|
||||||
|
return;
|
||||||
|
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".not_found", s.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.RED)), UUID.randomUUID());
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
package de.ellpeck.prettypipes.terminal.containers;
|
package de.ellpeck.prettypipes.terminal.containers;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import de.ellpeck.prettypipes.PrettyPipes;
|
import de.ellpeck.prettypipes.PrettyPipes;
|
||||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||||
import de.ellpeck.prettypipes.packets.PacketRequest;
|
|
||||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
|
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
|
||||||
import net.minecraft.client.gui.widget.Widget;
|
|
||||||
import net.minecraft.client.gui.widget.button.Button;
|
import net.minecraft.client.gui.widget.button.Button;
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.inventory.container.Slot;
|
import net.minecraft.inventory.container.Slot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -19,6 +14,7 @@ import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TranslationTextComponent;
|
import net.minecraft.util.text.TranslationTextComponent;
|
||||||
|
|
||||||
public class CraftingTerminalGui extends ItemTerminalGui {
|
public class CraftingTerminalGui extends ItemTerminalGui {
|
||||||
|
|
||||||
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/crafting_terminal.png");
|
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/crafting_terminal.png");
|
||||||
private Button requestButton;
|
private Button requestButton;
|
||||||
|
|
||||||
|
@ -32,7 +28,8 @@ public class CraftingTerminalGui extends ItemTerminalGui {
|
||||||
super.init();
|
super.init();
|
||||||
this.requestButton = this.addButton(new Button(this.guiLeft + 8, this.guiTop + 100, 50, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".request"), button -> {
|
this.requestButton = this.addButton(new Button(this.guiLeft + 8, this.guiTop + 100, 50, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".request"), button -> {
|
||||||
int amount = requestModifier();
|
int amount = requestModifier();
|
||||||
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount));
|
int force = hasAltDown() ? 1 : 0;
|
||||||
|
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount, force));
|
||||||
}));
|
}));
|
||||||
this.tick();
|
this.tick();
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@
|
||||||
"info.prettypipes.limit_to_max_off": "Don't limit to one stack",
|
"info.prettypipes.limit_to_max_off": "Don't limit to one stack",
|
||||||
"info.prettypipes.request": "Request",
|
"info.prettypipes.request": "Request",
|
||||||
"info.prettypipes.not_found": "%s not found",
|
"info.prettypipes.not_found": "%s not found",
|
||||||
|
"info.prettypipes.hold_alt": "Hold Alt to request anyway",
|
||||||
"info.prettypipes.sending": "Sending %s %s",
|
"info.prettypipes.sending": "Sending %s %s",
|
||||||
"info.prettypipes.sending_ingredients": "Sending %s sets of ingredients",
|
"info.prettypipes.sending_ingredients": "Sending %s sets of ingredients",
|
||||||
"info.prettypipes.order": "Order by %s",
|
"info.prettypipes.order": "Order by %s",
|
||||||
|
|
Loading…
Reference in a new issue