-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-introduce custom data in menu screen opening
- Loading branch information
1 parent
0792e87
commit 3a52359
Showing
6 changed files
with
167 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/net/neoforged/neoforge/network/payload/AdvancedOpenScreenPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package net.neoforged.neoforge.network.payload; | ||
|
||
import io.netty.buffer.Unpooled; | ||
import java.util.function.Consumer; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.inventory.MenuType; | ||
import net.neoforged.neoforge.internal.versions.neoforge.NeoForgeVersion; | ||
|
||
public record AdvancedOpenScreenPayload( | ||
int windowId, | ||
MenuType<?> menuType, | ||
Component name, | ||
byte[] additionalData | ||
) implements CustomPacketPayload { | ||
public static final ResourceLocation ID = new ResourceLocation(NeoForgeVersion.MOD_ID, "advanced_open_screen"); | ||
|
||
public AdvancedOpenScreenPayload(int windowId, MenuType<?> menuType, Component name, Consumer<FriendlyByteBuf> dataWriter) { | ||
this(windowId, menuType, name, writeCustomData(dataWriter)); | ||
} | ||
|
||
private static byte[] writeCustomData(Consumer<FriendlyByteBuf> dataWriter) { | ||
final FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); | ||
try { | ||
dataWriter.accept(buf); | ||
return buf.array(); | ||
} finally { | ||
buf.release(); | ||
} | ||
} | ||
|
||
public AdvancedOpenScreenPayload(FriendlyByteBuf buffer) { | ||
this(buffer.readVarInt(), buffer.readById(BuiltInRegistries.MENU), buffer.readComponentTrusted(), buffer.readByteArray()); | ||
} | ||
@Override | ||
public void write(FriendlyByteBuf buffer) { | ||
buffer.writeVarInt(windowId()); | ||
buffer.writeId(BuiltInRegistries.MENU, menuType()); | ||
buffer.writeComponent(name()); | ||
buffer.writeByteArray(additionalData()); | ||
} | ||
|
||
@Override | ||
public ResourceLocation id() { | ||
return ID; | ||
} | ||
} |