mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-12-23 07:39:22 +01:00
backport 0228932472
This commit is contained in:
parent
e3fad2bd6a
commit
58f665452d
2 changed files with 14 additions and 2 deletions
|
@ -14,11 +14,13 @@ public class PacketRequest {
|
|||
|
||||
private BlockPos pos;
|
||||
private ItemStack stack;
|
||||
private int nbtHash;
|
||||
private int amount;
|
||||
|
||||
public PacketRequest(BlockPos pos, ItemStack stack, int amount) {
|
||||
this.pos = pos;
|
||||
this.stack = stack;
|
||||
this.nbtHash = stack.getTag().hashCode();
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
|
@ -30,6 +32,7 @@ public class PacketRequest {
|
|||
PacketRequest packet = new PacketRequest();
|
||||
packet.pos = buf.readBlockPos();
|
||||
packet.stack = buf.readItemStack();
|
||||
packet.nbtHash = buf.readVarInt();
|
||||
packet.amount = buf.readVarInt();
|
||||
return packet;
|
||||
}
|
||||
|
@ -37,6 +40,7 @@ public class PacketRequest {
|
|||
public static void toBytes(PacketRequest packet, PacketBuffer buf) {
|
||||
buf.writeBlockPos(packet.pos);
|
||||
buf.writeItemStack(packet.stack);
|
||||
buf.writeVarInt(packet.nbtHash);
|
||||
buf.writeVarInt(packet.amount);
|
||||
}
|
||||
|
||||
|
@ -48,7 +52,7 @@ public class PacketRequest {
|
|||
PlayerEntity player = ctx.get().getSender();
|
||||
ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, message.pos);
|
||||
message.stack.setCount(message.amount);
|
||||
tile.requestItem(player, message.stack);
|
||||
tile.requestItem(player, message.stack, message.nbtHash);
|
||||
}
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
|
|
|
@ -154,10 +154,18 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
}
|
||||
}
|
||||
|
||||
public void requestItem(PlayerEntity player, ItemStack stack) {
|
||||
public void requestItem(PlayerEntity player, ItemStack stack, int nbtHash) {
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
network.startProfile("terminal_request_item");
|
||||
this.updateItems();
|
||||
if (nbtHash != 0) {
|
||||
ItemStack filter = stack;
|
||||
stack = this.networkItems.values().stream()
|
||||
.map(NetworkItem::asStack)
|
||||
// don't compare with nbt equality here or the whole hashing thing is pointless
|
||||
.filter(s -> ItemEquality.compareItems(s, filter) && s.getTag().hashCode() == nbtHash)
|
||||
.findFirst().orElse(filter);
|
||||
}
|
||||
int requested = this.requestItemImpl(stack, onItemUnavailable(player));
|
||||
if (requested > 0) {
|
||||
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
|
||||
|
|
Loading…
Reference in a new issue