mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 19:58:35 +01:00
parent
0228932472
commit
1c5a3a118d
5 changed files with 21 additions and 9 deletions
|
@ -112,7 +112,7 @@ public class PacketButton {
|
||||||
}),
|
}),
|
||||||
CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
|
CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
|
||||||
var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, player.level, pos);
|
var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, player.level, pos);
|
||||||
tile.requestCraftingItems(player, data[0]);
|
tile.requestCraftingItems(player, data[0], data[1] > 0);
|
||||||
}),
|
}),
|
||||||
CANCEL_CRAFTING((pos, data, player) -> {
|
CANCEL_CRAFTING((pos, data, player) -> {
|
||||||
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, pos);
|
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, pos);
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestCraftingItems(Player player, int maxAmount) {
|
public void requestCraftingItems(Player player, int maxAmount, boolean force) {
|
||||||
var pipe = this.getConnectedPipe();
|
var pipe = this.getConnectedPipe();
|
||||||
if (pipe == null)
|
if (pipe == null)
|
||||||
return;
|
return;
|
||||||
|
@ -116,7 +116,10 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
||||||
var lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> {
|
var lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> {
|
||||||
var item = this.networkItems.get(s);
|
var 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)
|
||||||
|
@ -127,10 +130,13 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
||||||
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 TranslatableComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID());
|
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID());
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".hold_alt"), UUID.randomUUID());
|
||||||
|
}
|
||||||
network.endProfile();
|
network.endProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,11 +163,11 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
||||||
.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);
|
||||||
}
|
}
|
||||||
var requested = this.requestItemImpl(stack, onItemUnavailable(player));
|
var requested = this.requestItemImpl(stack, onItemUnavailable(player, false));
|
||||||
if (requested > 0) {
|
if (requested > 0) {
|
||||||
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID());
|
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID());
|
||||||
} else {
|
} else {
|
||||||
onItemUnavailable(player).accept(stack);
|
onItemUnavailable(player, false).accept(stack);
|
||||||
}
|
}
|
||||||
network.endProfile();
|
network.endProfile();
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,11 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
||||||
return Pair.of(requests, remain);
|
return Pair.of(requests, remain);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Consumer<ItemStack> onItemUnavailable(Player player) {
|
public static Consumer<ItemStack> onItemUnavailable(Player player, boolean ignore) {
|
||||||
return s -> player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".not_found", s.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.RED)), UUID.randomUUID());
|
return s -> {
|
||||||
|
if (ignore)
|
||||||
|
return;
|
||||||
|
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".not_found", s.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.RED)), UUID.randomUUID());
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,8 @@ public class CraftingTerminalGui extends ItemTerminalGui {
|
||||||
super.init();
|
super.init();
|
||||||
this.requestButton = this.addRenderableWidget(new Button(this.leftPos + 8, this.topPos + 100, 50, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".request"), button -> {
|
this.requestButton = this.addRenderableWidget(new Button(this.leftPos + 8, this.topPos + 100, 50, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".request"), button -> {
|
||||||
var amount = requestModifier();
|
var amount = requestModifier();
|
||||||
PacketHandler.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount));
|
var force = hasAltDown() ? 1 : 0;
|
||||||
|
PacketHandler.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), 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