|
2 | 2 |
|
3 | 3 | import com.google.common.collect.ForwardingMultimap; |
4 | 4 | import com.google.common.collect.Maps; |
| 5 | +import com.hamusuke.packetcap.event.RegisterHighlightInstructionEvent; |
5 | 6 | import com.hamusuke.packetcap.highlight.DataHighlightInstruction.PacketDataHighlighterBuilder; |
6 | 7 | import com.hamusuke.packetcap.invoker.LoginHelloS2CPacketAccessor; |
7 | 8 | import com.hamusuke.packetcap.invoker.LoginKeyC2SPacketAccessor; |
8 | 9 | import com.mojang.authlib.GameProfile; |
9 | 10 | import com.mojang.authlib.properties.Property; |
10 | 11 | import com.mojang.authlib.properties.PropertyMap; |
11 | 12 | import io.netty.buffer.ByteBuf; |
12 | | -import it.unimi.dsi.fastutil.ints.IntList; |
13 | 13 | import net.minecraft.component.ComponentChanges; |
14 | 14 | import net.minecraft.component.MergedComponentMap; |
15 | 15 | import net.minecraft.item.ItemStack; |
|
41 | 41 | import java.util.List; |
42 | 42 | import java.util.Map; |
43 | 43 | import java.util.Objects; |
44 | | -import java.util.Set; |
45 | 44 | import java.util.function.Consumer; |
46 | 45 | import java.util.function.Function; |
47 | 46 |
|
|
50 | 49 | public class DataHighlightInstructions { |
51 | 50 | private static final Map<Class<?>, DataHighlightInstruction<? extends ByteBuf, ?>> HIGHLIGHTERS = Maps.newHashMap(); |
52 | 51 |
|
53 | | - private static final DataHighlightInstruction<ByteBuf, Property> PROPERTY = register(Property.class, builder -> builder |
| 52 | + public static final DataHighlightInstruction<ByteBuf, Property> PROPERTY = register(Property.class, builder -> builder |
54 | 53 | .field(STRING.withDescription(s -> "Property Name: " + s), Property::name) |
55 | 54 | .field(STRING.withDescription(s -> "Property Value: " + s), Property::value) |
56 | 55 | .sub(bufNullable(String.class, s -> "Signature", (buf, value) -> StringEncoding.encode(buf, value, 1024)), Property::signature)); |
57 | 56 |
|
58 | | - private static final DataHighlightInstruction<ByteBuf, PropertyMap> PROPERTY_MAP = register(PropertyMap.class, builder -> builder |
| 57 | + public static final DataHighlightInstruction<ByteBuf, PropertyMap> PROPERTY_MAP = register(PropertyMap.class, builder -> builder |
59 | 58 | .list(PROPERTY, ForwardingMultimap::values)); |
60 | 59 |
|
61 | | - private static final DataHighlightInstruction<ByteBuf, GameProfile> GAME_PROFILE = register(GameProfile.class, builder -> builder |
| 60 | + public static final DataHighlightInstruction<ByteBuf, GameProfile> GAME_PROFILE = register(GameProfile.class, builder -> builder |
62 | 61 | .field(UUID.withDescription(uuid -> "UUID: " + uuid), GameProfile::getId) |
63 | 62 | .field(STRING.withDescription(s -> "Name: " + s), GameProfile::getName) |
64 | 63 | .sub(PROPERTY_MAP, GameProfile::getProperties)); |
65 | 64 |
|
66 | | - private static final DataHighlightInstruction<RegistryByteBuf, RegistryKey> REGISTRY_KEY = registry(RegistryKey.class, builder -> builder |
| 65 | + public static final DataHighlightInstruction<RegistryByteBuf, RegistryKey> REGISTRY_KEY = registry(RegistryKey.class, builder -> builder |
67 | 66 | .packetEncoder(PacketByteBuf::writeRegistryKey, RegistryKey::toString, Function.identity())); |
68 | 67 |
|
69 | | - private static final DataHighlightInstruction<PacketByteBuf, byte[]> BYTE_ARRAY_WITH_LEN = packet(byte[].class, builder -> builder |
| 68 | + public static final DataHighlightInstruction<PacketByteBuf, byte[]> BYTE_ARRAY_WITH_LEN = packet(byte[].class, builder -> builder |
70 | 69 | .field(VAR_INT.withDescription(length -> "Byte Array Length: " + length), bytes -> bytes.length) |
71 | 70 | .field(BYTE_ARRAY.withDescription(bytes -> "Data"), Function.identity())); |
72 | | - private static final DataHighlightInstruction<RegistryByteBuf, ItemStack> ITEM_STACK = registry(ItemStack.class, builder -> builder |
| 71 | + |
| 72 | + public static final DataHighlightInstruction<RegistryByteBuf, ItemStack> ITEM_STACK = registry(ItemStack.class, builder -> builder |
73 | 73 | .field(VAR_INT.withDescription(count -> count <= 0 ? "Empty" : "Count: " + count), ItemStack::getCount, count -> count > 0) |
74 | 74 | .packetCodec(PacketCodecs.registryEntry(RegistryKeys.ITEM), e -> "ID: " + e.getIdAsString(), ItemStack::getRegistryEntry) |
75 | 75 | .packetCodec(ComponentChanges.PACKET_CODEC, componentChanges -> "ComponentChanges", stack -> stack.getComponents() instanceof MergedComponentMap m ? m.getChanges() : ComponentChanges.EMPTY)); |
@@ -157,37 +157,40 @@ public class DataHighlightInstructions { |
157 | 157 | .field(VAR_INT, ScreenHandlerSlotUpdateS2CPacket::getRevision) |
158 | 158 | .field(SHORT, p -> (short) p.getSlot()) |
159 | 159 | .sub(ITEM_STACK, ScreenHandlerSlotUpdateS2CPacket::getStack)); |
| 160 | + |
| 161 | + // Fire event |
| 162 | + RegisterHighlightInstructionEvent.EVENT.invoker().onRegister(); |
160 | 163 | } |
161 | 164 |
|
162 | | - private static <T> DataHighlightInstruction<PacketByteBuf, T> nullable(Class<T> clazz, PacketEncoder<PacketByteBuf, T> encoder) { |
| 165 | + public static <T> DataHighlightInstruction<PacketByteBuf, T> nullable(Class<T> clazz, PacketEncoder<PacketByteBuf, T> encoder) { |
163 | 166 | return nullable(clazz, t -> "", encoder); |
164 | 167 | } |
165 | 168 |
|
166 | | - private static <T> DataHighlightInstruction<PacketByteBuf, T> nullable(Class<T> clazz, Function<T, String> descriptor, PacketEncoder<PacketByteBuf, T> encoder) { |
| 169 | + public static <T> DataHighlightInstruction<PacketByteBuf, T> nullable(Class<T> clazz, Function<T, String> descriptor, PacketEncoder<PacketByteBuf, T> encoder) { |
167 | 170 | return packet(clazz, b -> b |
168 | 171 | .field(BOOL.withDescription(bool -> bool ? "Not Null" : "Null"), Objects::nonNull, Boolean::booleanValue) |
169 | 172 | .packetEncoder(encoder, descriptor, Function.identity())); |
170 | 173 | } |
171 | 174 |
|
172 | | - private static <T> DataHighlightInstruction<ByteBuf, T> bufNullable(Class<T> clazz, PacketEncoder<ByteBuf, T> encoder) { |
| 175 | + public static <T> DataHighlightInstruction<ByteBuf, T> bufNullable(Class<T> clazz, PacketEncoder<ByteBuf, T> encoder) { |
173 | 176 | return bufNullable(clazz, t -> "", encoder); |
174 | 177 | } |
175 | 178 |
|
176 | | - private static <T> DataHighlightInstruction<ByteBuf, T> bufNullable(Class<T> clazz, Function<T, String> descriptor, PacketEncoder<ByteBuf, T> encoder) { |
| 179 | + public static <T> DataHighlightInstruction<ByteBuf, T> bufNullable(Class<T> clazz, Function<T, String> descriptor, PacketEncoder<ByteBuf, T> encoder) { |
177 | 180 | return register(clazz, b -> b |
178 | 181 | .field(BOOL.withDescription(bool -> bool ? "Not Null" : "Null"), Objects::nonNull, Boolean::booleanValue) |
179 | 182 | .packetEncoder(encoder, descriptor, Function.identity())); |
180 | 183 | } |
181 | 184 |
|
182 | | - private static <T> DataHighlightInstruction<PacketByteBuf, T> packet(Class<T> clazz, Consumer<PacketDataHighlighterBuilder<PacketByteBuf, T>> consumer) { |
| 185 | + public static <T> DataHighlightInstruction<PacketByteBuf, T> packet(Class<T> clazz, Consumer<PacketDataHighlighterBuilder<PacketByteBuf, T>> consumer) { |
183 | 186 | return register(clazz, consumer); |
184 | 187 | } |
185 | 188 |
|
186 | | - private static <T> DataHighlightInstruction<RegistryByteBuf, T> registry(Class<T> clazz, Consumer<PacketDataHighlighterBuilder<RegistryByteBuf, T>> consumer) { |
| 189 | + public static <T> DataHighlightInstruction<RegistryByteBuf, T> registry(Class<T> clazz, Consumer<PacketDataHighlighterBuilder<RegistryByteBuf, T>> consumer) { |
187 | 190 | return register(clazz, consumer); |
188 | 191 | } |
189 | 192 |
|
190 | | - private static <B extends ByteBuf, T> DataHighlightInstruction<B, T> register(Class<T> clazz, Consumer<PacketDataHighlighterBuilder<B, T>> consumer) { |
| 193 | + public static <B extends ByteBuf, T> DataHighlightInstruction<B, T> register(Class<T> clazz, Consumer<PacketDataHighlighterBuilder<B, T>> consumer) { |
191 | 194 | var builder = PacketDataHighlighterBuilder.<B, T>builder(); |
192 | 195 | consumer.accept(builder); |
193 | 196 | var built = builder.build(); |
|
0 commit comments