From 426380d58880ca8d6c61001781f6d0485c550695 Mon Sep 17 00:00:00 2001 From: imreallybadatnames Date: Thu, 9 May 2024 14:54:33 +1100 Subject: [PATCH 1/6] something --- .../revelationary/RevelationRegistry.java | 155 +++++++++--------- 1 file changed, 78 insertions(+), 77 deletions(-) diff --git a/src/main/java/de/dafuqs/revelationary/RevelationRegistry.java b/src/main/java/de/dafuqs/revelationary/RevelationRegistry.java index 3492281..c6d9c6b 100644 --- a/src/main/java/de/dafuqs/revelationary/RevelationRegistry.java +++ b/src/main/java/de/dafuqs/revelationary/RevelationRegistry.java @@ -6,6 +6,7 @@ import de.dafuqs.revelationary.api.advancements.AdvancementHelper; import de.dafuqs.revelationary.api.revelations.RevelationAware; import de.dafuqs.revelationary.config.RevelationaryConfig; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.block.*; import net.minecraft.command.argument.BlockArgumentParser; import net.minecraft.entity.player.PlayerEntity; @@ -26,21 +27,21 @@ public class RevelationRegistry { - private static final Map> ADVANCEMENT_BLOCK_REGISTRY = new HashMap<>(); - private static final Map BLOCK_ADVANCEMENT_REGISTRY = new HashMap<>(); - private static final Map BLOCK_STATE_REGISTRY = new HashMap<>(); - private static final Map BLOCK_REGISTRY = new HashMap<>(); + private static final Object2ObjectOpenHashMap> advToBlockStates = new Object2ObjectOpenHashMap<>(); + private static final Object2ObjectOpenHashMap blockStateToAdv = new Object2ObjectOpenHashMap<>(); + private static final Object2ObjectOpenHashMap blockStateCloaks = new Object2ObjectOpenHashMap<>(); + private static final Object2ObjectOpenHashMap blockCloaks = new Object2ObjectOpenHashMap<>(); - private static final Map> ADVANCEMENT_ITEM_REGISTRY = new HashMap<>(); - private static final Map ITEM_ADVANCEMENT_REGISTRY = new HashMap<>(); - private static final Map ITEM_REGISTRY = new HashMap<>(); + private static final Object2ObjectOpenHashMap> advToItems = new Object2ObjectOpenHashMap<>(); + private static final Object2ObjectOpenHashMap itemToAdv = new Object2ObjectOpenHashMap<>(); + private static final Object2ObjectOpenHashMap itemCloaks = new Object2ObjectOpenHashMap<>(); - private static final Map ALTERNATE_BLOCK_TRANSLATION_STRING_REGISTRY = new HashMap<>(); - private static final Map ALTERNATE_ITEM_TRANSLATION_STRING_REGISTRY = new HashMap<>(); + private static final Object2ObjectOpenHashMap cloakedBlockNameTranslations = new Object2ObjectOpenHashMap<>(); + private static final Object2ObjectOpenHashMap cloakedItemNameTranslations = new Object2ObjectOpenHashMap<>(); public static MutableText getTranslationString(Item item) { - if (ALTERNATE_ITEM_TRANSLATION_STRING_REGISTRY.containsKey(item)) { - return ALTERNATE_ITEM_TRANSLATION_STRING_REGISTRY.get(item); + if (cloakedItemNameTranslations.containsKey(item)) { + return cloakedItemNameTranslations.get(item); } boolean isBlockItem = item instanceof BlockItem; if(isBlockItem && !RevelationaryConfig.get().NameForUnrevealedBlocks.isEmpty()) { @@ -50,33 +51,33 @@ public static MutableText getTranslationString(Item item) { return Text.translatable(RevelationaryConfig.get().NameForUnrevealedItems); } if(RevelationaryConfig.get().UseTargetBlockOrItemNameInsteadOfScatter) { - return Text.translatable(ITEM_REGISTRY.get(item).getTranslationKey()); + return Text.translatable(itemCloaks.get(item).getTranslationKey()); } // Get the localized name of the item and scatter it using §k to make it unreadable return Text.literal("§k" + Language.getInstance().get(item.getTranslationKey())); } public static MutableText getTranslationString(Block block) { - if (ALTERNATE_BLOCK_TRANSLATION_STRING_REGISTRY.containsKey(block)) { - return ALTERNATE_BLOCK_TRANSLATION_STRING_REGISTRY.get(block); + if (cloakedBlockNameTranslations.containsKey(block)) { + return cloakedBlockNameTranslations.get(block); } if(!RevelationaryConfig.get().NameForUnrevealedBlocks.isEmpty()) { return Text.translatable(RevelationaryConfig.get().NameForUnrevealedBlocks); } if(RevelationaryConfig.get().UseTargetBlockOrItemNameInsteadOfScatter) { - return BLOCK_REGISTRY.get(block).getName(); + return blockCloaks.get(block).getName(); } // Get the localized name of the block and scatter it using §k to make it unreadable return Text.literal("§k" + Language.getInstance().get(block.getTranslationKey())); } public static void clear() { - ADVANCEMENT_BLOCK_REGISTRY.clear(); - ADVANCEMENT_ITEM_REGISTRY.clear(); - BLOCK_STATE_REGISTRY.clear(); - ITEM_REGISTRY.clear(); - ALTERNATE_BLOCK_TRANSLATION_STRING_REGISTRY.clear(); - ALTERNATE_ITEM_TRANSLATION_STRING_REGISTRY.clear(); + advToBlockStates.clear(); + advToItems.clear(); + blockStateCloaks.clear(); + itemCloaks.clear(); + cloakedBlockNameTranslations.clear(); + cloakedItemNameTranslations.clear(); } private static final Set revelationAwares = new HashSet<>(); @@ -139,11 +140,11 @@ public static void registerFromJson(JsonObject jsonObject) { MutableText targetText = Text.translatable(blockNameEntry.getValue().getAsString()); Block sourceBlock = Registries.BLOCK.get(sourceId); - ALTERNATE_BLOCK_TRANSLATION_STRING_REGISTRY.put(sourceBlock, targetText); + cloakedBlockNameTranslations.put(sourceBlock, targetText); Item blockItem = sourceBlock.asItem(); if (blockItem != null && blockItem != Items.AIR) { - ALTERNATE_ITEM_TRANSLATION_STRING_REGISTRY.put(blockItem, targetText); + cloakedItemNameTranslations.put(blockItem, targetText); } } } @@ -153,7 +154,7 @@ public static void registerFromJson(JsonObject jsonObject) { MutableText targetText = Text.translatable(itemNameEntry.getValue().getAsString()); Item sourceItem = Registries.ITEM.get(sourceId); - ALTERNATE_ITEM_TRANSLATION_STRING_REGISTRY.put(sourceItem, targetText); + cloakedItemNameTranslations.put(sourceItem, targetText); } } } @@ -168,13 +169,13 @@ private static void registerBlockState(Identifier advancementIdentifier, BlockSt } List list; - if (ADVANCEMENT_BLOCK_REGISTRY.containsKey(advancementIdentifier)) { - list = ADVANCEMENT_BLOCK_REGISTRY.get(advancementIdentifier); + if (advToBlockStates.containsKey(advancementIdentifier)) { + list = advToBlockStates.get(advancementIdentifier); list.add(sourceBlockState); } else { list = new ArrayList<>(); list.add(sourceBlockState); - ADVANCEMENT_BLOCK_REGISTRY.put(advancementIdentifier, list); + advToBlockStates.put(advancementIdentifier, list); } Item sourceBlockItem = sourceBlockState.getBlock().asItem(); @@ -185,27 +186,27 @@ private static void registerBlockState(Identifier advancementIdentifier, BlockSt } } - BLOCK_STATE_REGISTRY.put(sourceBlockState, targetBlockState); - BLOCK_REGISTRY.putIfAbsent(sourceBlockState.getBlock(), targetBlockState.getBlock()); - BLOCK_ADVANCEMENT_REGISTRY.put(sourceBlockState, advancementIdentifier); + blockStateCloaks.put(sourceBlockState, targetBlockState); + blockCloaks.putIfAbsent(sourceBlockState.getBlock(), targetBlockState.getBlock()); + blockStateToAdv.put(sourceBlockState, advancementIdentifier); } private static void registerBlockTranslation(Block sourceBlock, MutableText targetTranslation) { - ALTERNATE_BLOCK_TRANSLATION_STRING_REGISTRY.put(sourceBlock, targetTranslation); + cloakedBlockNameTranslations.put(sourceBlock, targetTranslation); } public static boolean hasCloak(BlockState blockState) { - return BLOCK_STATE_REGISTRY.containsKey(blockState); + return blockStateCloaks.containsKey(blockState); } public static boolean isVisibleTo(BlockState state, PlayerEntity player) { - return AdvancementHelper.hasAdvancement(player, BLOCK_ADVANCEMENT_REGISTRY.getOrDefault(state, null)); + return AdvancementHelper.hasAdvancement(player, blockStateToAdv.getOrDefault(state, null)); } public static @NotNull Collection getRevealedBlockStates(Identifier advancement) { List blockStates = new ArrayList<>(); - if (ADVANCEMENT_BLOCK_REGISTRY.containsKey(advancement)) { - for (Object entry : ADVANCEMENT_BLOCK_REGISTRY.get(advancement)) { + if (advToBlockStates.containsKey(advancement)) { + for (Object entry : advToBlockStates.get(advancement)) { if (entry instanceof BlockState blockState) { blockStates.add(blockState); } @@ -215,16 +216,16 @@ public static boolean isVisibleTo(BlockState state, PlayerEntity player) { } public static Map> getBlockStateEntries() { - return ADVANCEMENT_BLOCK_REGISTRY; + return advToBlockStates; } public static List getBlockStateEntries(Identifier advancement) { - return ADVANCEMENT_BLOCK_REGISTRY.getOrDefault(advancement, Collections.EMPTY_LIST); + return advToBlockStates.getOrDefault(advancement, Collections.EMPTY_LIST); } public static List getBlockEntries() { List blocks = new ArrayList<>(); - for (List states : ADVANCEMENT_BLOCK_REGISTRY.values()) { + for (List states : advToBlockStates.values()) { for (BlockState state : states) { Block block = state.getBlock(); if (!blocks.contains(block)) { @@ -236,8 +237,8 @@ public static List getBlockEntries() { } public static List getBlockEntries(Identifier advancement) { - if (ADVANCEMENT_BLOCK_REGISTRY.containsKey(advancement)) { - List states = ADVANCEMENT_BLOCK_REGISTRY.get(advancement); + if (advToBlockStates.containsKey(advancement)) { + List states = advToBlockStates.get(advancement); List blocks = new ArrayList<>(); for (BlockState state : states) { Block block = state.getBlock(); @@ -260,8 +261,8 @@ private static void registerItem(Identifier advancementIdentifier, Item sourceIt return; } - if (ADVANCEMENT_ITEM_REGISTRY.containsKey(advancementIdentifier)) { - List list = ADVANCEMENT_ITEM_REGISTRY.get(advancementIdentifier); + if (advToItems.containsKey(advancementIdentifier)) { + List list = advToItems.get(advancementIdentifier); if (list.contains(sourceItem)) { return; } @@ -269,38 +270,38 @@ private static void registerItem(Identifier advancementIdentifier, Item sourceIt } else { List list = new ArrayList<>(); list.add(sourceItem); - ADVANCEMENT_ITEM_REGISTRY.put(advancementIdentifier, list); + advToItems.put(advancementIdentifier, list); } - ITEM_REGISTRY.put(sourceItem, targetItem); - ITEM_ADVANCEMENT_REGISTRY.put(sourceItem, advancementIdentifier); + itemCloaks.put(sourceItem, targetItem); + itemToAdv.put(sourceItem, advancementIdentifier); } private static void registerItemTranslation(Item sourceItem, MutableText targetTranslation) { - ALTERNATE_ITEM_TRANSLATION_STRING_REGISTRY.put(sourceItem, targetTranslation); + cloakedItemNameTranslations.put(sourceItem, targetTranslation); } public static boolean hasCloak(Item item) { - return ITEM_REGISTRY.containsKey(item); + return itemCloaks.containsKey(item); } @Nullable public static Item getCloak(Item item) { - return ITEM_REGISTRY.getOrDefault(item, null); + return itemCloaks.getOrDefault(item, null); } public static boolean isVisibleTo(Item item, PlayerEntity player) { - return AdvancementHelper.hasAdvancement(player, ITEM_ADVANCEMENT_REGISTRY.getOrDefault(item, null)); + return AdvancementHelper.hasAdvancement(player, itemToAdv.getOrDefault(item, null)); } @Nullable public static BlockState getCloak(BlockState blockState) { - return BLOCK_STATE_REGISTRY.getOrDefault(blockState, null); + return blockStateCloaks.getOrDefault(blockState, null); } public static @NotNull Collection getRevealedItems(Identifier advancement) { List items = new ArrayList<>(); - if (ADVANCEMENT_ITEM_REGISTRY.containsKey(advancement)) { - for (Object entry : ADVANCEMENT_ITEM_REGISTRY.get(advancement)) { + if (advToItems.containsKey(advancement)) { + for (Object entry : advToItems.get(advancement)) { if (entry instanceof Item item) { items.add(item); } @@ -310,11 +311,11 @@ public static BlockState getCloak(BlockState blockState) { } public static Map> getItemEntries() { - return ADVANCEMENT_ITEM_REGISTRY; + return advToItems; } public static List getItemEntries(Identifier advancement) { - return ADVANCEMENT_ITEM_REGISTRY.getOrDefault(advancement, Collections.EMPTY_LIST); + return advToItems.getOrDefault(advancement, Collections.EMPTY_LIST); } private static void writeText(PacketByteBuf buf, Text text) { @@ -327,37 +328,37 @@ private static Text readText(PacketByteBuf buf) { public static void write(PacketByteBuf buf) { // Block States - buf.writeInt(ADVANCEMENT_BLOCK_REGISTRY.size()); - for (Map.Entry> advancementBlocks : ADVANCEMENT_BLOCK_REGISTRY.entrySet()) { + buf.writeInt(advToBlockStates.size()); + for (Map.Entry> advancementBlocks : advToBlockStates.entrySet()) { buf.writeIdentifier(advancementBlocks.getKey()); buf.writeInt(advancementBlocks.getValue().size()); for (BlockState blockState : advancementBlocks.getValue()) { buf.writeString(BlockArgumentParser.stringifyBlockState(blockState)); - buf.writeString(BlockArgumentParser.stringifyBlockState(BLOCK_STATE_REGISTRY.get(blockState))); + buf.writeString(BlockArgumentParser.stringifyBlockState(blockStateCloaks.get(blockState))); } } // Items - buf.writeInt(ADVANCEMENT_ITEM_REGISTRY.size()); - for (Map.Entry> advancementItems : ADVANCEMENT_ITEM_REGISTRY.entrySet()) { + buf.writeInt(advToItems.size()); + for (Map.Entry> advancementItems : advToItems.entrySet()) { buf.writeIdentifier(advancementItems.getKey()); buf.writeInt(advancementItems.getValue().size()); for (Item item : advancementItems.getValue()) { buf.writeString(Registries.ITEM.getId(item).toString()); - buf.writeString(Registries.ITEM.getId(ITEM_REGISTRY.get(item)).toString()); + buf.writeString(Registries.ITEM.getId(itemCloaks.get(item)).toString()); } } // Block Translations - buf.writeInt(ALTERNATE_BLOCK_TRANSLATION_STRING_REGISTRY.size()); - for (Map.Entry blockTranslation : ALTERNATE_BLOCK_TRANSLATION_STRING_REGISTRY.entrySet()) { + buf.writeInt(cloakedBlockNameTranslations.size()); + for (Map.Entry blockTranslation : cloakedBlockNameTranslations.entrySet()) { buf.writeIdentifier(Registries.BLOCK.getId(blockTranslation.getKey())); writeText(buf, blockTranslation.getValue()); } // Item Translations - buf.writeInt(ALTERNATE_ITEM_TRANSLATION_STRING_REGISTRY.size()); - for (Map.Entry itemTranslation : ALTERNATE_ITEM_TRANSLATION_STRING_REGISTRY.entrySet()) { + buf.writeInt(cloakedItemNameTranslations.size()); + for (Map.Entry itemTranslation : cloakedItemNameTranslations.entrySet()) { buf.writeIdentifier(Registries.ITEM.getId(itemTranslation.getKey())); writeText(buf, itemTranslation.getValue()); } @@ -377,17 +378,17 @@ public static void fromPacket(PacketByteBuf buf) throws CommandSyntaxException { BlockState sourceState = BlockArgumentParser.block(Registries.BLOCK.getReadOnlyWrapper(), buf.readString(), true).blockState(); BlockState targetState = BlockArgumentParser.block(Registries.BLOCK.getReadOnlyWrapper(), buf.readString(), true).blockState(); - if (ADVANCEMENT_BLOCK_REGISTRY.containsKey(advancementIdentifier)) { - List advancementStates = ADVANCEMENT_BLOCK_REGISTRY.get(advancementIdentifier); + if (advToBlockStates.containsKey(advancementIdentifier)) { + List advancementStates = advToBlockStates.get(advancementIdentifier); advancementStates.add(sourceState); } else { List advancementStates = new ArrayList<>(); advancementStates.add(sourceState); - ADVANCEMENT_BLOCK_REGISTRY.put(advancementIdentifier, advancementStates); + advToBlockStates.put(advancementIdentifier, advancementStates); } - BLOCK_ADVANCEMENT_REGISTRY.put(sourceState, advancementIdentifier); - BLOCK_STATE_REGISTRY.put(sourceState, targetState); - BLOCK_REGISTRY.putIfAbsent(sourceState.getBlock(), targetState.getBlock()); + blockStateToAdv.put(sourceState, advancementIdentifier); + blockStateCloaks.put(sourceState, targetState); + blockCloaks.putIfAbsent(sourceState.getBlock(), targetState.getBlock()); } } @@ -402,16 +403,16 @@ public static void fromPacket(PacketByteBuf buf) throws CommandSyntaxException { Item sourceItem = Registries.ITEM.get(sourceId); Item targetItem = Registries.ITEM.get(targetId); - if (ADVANCEMENT_ITEM_REGISTRY.containsKey(advancementIdentifier)) { - List advancementItems = ADVANCEMENT_ITEM_REGISTRY.get(advancementIdentifier); + if (advToItems.containsKey(advancementIdentifier)) { + List advancementItems = advToItems.get(advancementIdentifier); advancementItems.add(sourceItem); } else { List advancementItems = new ArrayList<>(); advancementItems.add(sourceItem); - ADVANCEMENT_ITEM_REGISTRY.put(advancementIdentifier, advancementItems); + advToItems.put(advancementIdentifier, advancementItems); } - ITEM_ADVANCEMENT_REGISTRY.put(sourceItem, advancementIdentifier); - ITEM_REGISTRY.put(sourceItem, targetItem); + itemToAdv.put(sourceItem, advancementIdentifier); + itemCloaks.put(sourceItem, targetItem); } } @@ -420,7 +421,7 @@ public static void fromPacket(PacketByteBuf buf) throws CommandSyntaxException { for (int i = 0; i < blockTranslations; i++) { Block block = Registries.BLOCK.get(buf.readIdentifier()); MutableText text = (MutableText) readText(buf); - ALTERNATE_BLOCK_TRANSLATION_STRING_REGISTRY.put(block, text); + cloakedBlockNameTranslations.put(block, text); } // Item Translations @@ -428,7 +429,7 @@ public static void fromPacket(PacketByteBuf buf) throws CommandSyntaxException { for (int i = 0; i < itemTranslations; i++) { Item item = Registries.ITEM.get(buf.readIdentifier()); MutableText text = (MutableText) readText(buf); - ALTERNATE_ITEM_TRANSLATION_STRING_REGISTRY.put(item, text); + cloakedItemNameTranslations.put(item, text); } } From d6dc5da7a5df91ee7e395bab498e6c119e32e54d Mon Sep 17 00:00:00 2001 From: imreallybadatnames Date: Thu, 9 May 2024 18:46:06 +1100 Subject: [PATCH 2/6] gaming --- .../revelationary/RevelationDataLoader.java | 1 + .../revelationary/RevelationRegistry.java | 299 +++++++++--------- .../dafuqs/revelationary/Revelationary.java | 6 +- .../mixin/client/WorldRendererMixin.java | 2 + .../networking/RevelationaryPackets.java | 158 ++++++++- .../RevelationaryS2CPacketReceivers.java | 2 +- .../RevelationaryS2CPacketSenders.java | 8 +- 7 files changed, 311 insertions(+), 165 deletions(-) diff --git a/src/main/java/de/dafuqs/revelationary/RevelationDataLoader.java b/src/main/java/de/dafuqs/revelationary/RevelationDataLoader.java index b11b9f4..1d43366 100644 --- a/src/main/java/de/dafuqs/revelationary/RevelationDataLoader.java +++ b/src/main/java/de/dafuqs/revelationary/RevelationDataLoader.java @@ -21,6 +21,7 @@ private RevelationDataLoader() { @Override protected void apply(Map prepared, ResourceManager manager, Profiler profiler) { prepared.forEach((identifier, jsonElement) -> RevelationRegistry.registerFromJson(jsonElement.getAsJsonObject())); + RevelationRegistry.deepTrim(); } @Override diff --git a/src/main/java/de/dafuqs/revelationary/RevelationRegistry.java b/src/main/java/de/dafuqs/revelationary/RevelationRegistry.java index c6d9c6b..f33fe0d 100644 --- a/src/main/java/de/dafuqs/revelationary/RevelationRegistry.java +++ b/src/main/java/de/dafuqs/revelationary/RevelationRegistry.java @@ -2,20 +2,19 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import de.dafuqs.revelationary.api.advancements.AdvancementHelper; import de.dafuqs.revelationary.api.revelations.RevelationAware; import de.dafuqs.revelationary.config.RevelationaryConfig; +import de.dafuqs.revelationary.networking.RevelationaryPackets; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.block.*; import net.minecraft.command.argument.BlockArgumentParser; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.*; -import net.minecraft.network.PacketByteBuf; import net.minecraft.registry.*; import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import net.minecraft.text.TextCodecs; import net.minecraft.util.Identifier; import net.minecraft.util.JsonHelper; import net.minecraft.util.Language; @@ -27,17 +26,17 @@ public class RevelationRegistry { - private static final Object2ObjectOpenHashMap> advToBlockStates = new Object2ObjectOpenHashMap<>(); - private static final Object2ObjectOpenHashMap blockStateToAdv = new Object2ObjectOpenHashMap<>(); - private static final Object2ObjectOpenHashMap blockStateCloaks = new Object2ObjectOpenHashMap<>(); - private static final Object2ObjectOpenHashMap blockCloaks = new Object2ObjectOpenHashMap<>(); + private static Object2ObjectOpenHashMap> advToBlockStates = new Object2ObjectOpenHashMap<>(); + private static Object2ObjectOpenHashMap blockStateToAdv = new Object2ObjectOpenHashMap<>(); + private static Object2ObjectOpenHashMap blockStateCloaks = new Object2ObjectOpenHashMap<>(); + private static Object2ObjectOpenHashMap blockCloaks = new Object2ObjectOpenHashMap<>(); - private static final Object2ObjectOpenHashMap> advToItems = new Object2ObjectOpenHashMap<>(); - private static final Object2ObjectOpenHashMap itemToAdv = new Object2ObjectOpenHashMap<>(); - private static final Object2ObjectOpenHashMap itemCloaks = new Object2ObjectOpenHashMap<>(); + private static Object2ObjectOpenHashMap> advToItems = new Object2ObjectOpenHashMap<>(); + private static Object2ObjectOpenHashMap itemToAdv = new Object2ObjectOpenHashMap<>(); + private static Object2ObjectOpenHashMap itemCloaks = new Object2ObjectOpenHashMap<>(); - private static final Object2ObjectOpenHashMap cloakedBlockNameTranslations = new Object2ObjectOpenHashMap<>(); - private static final Object2ObjectOpenHashMap cloakedItemNameTranslations = new Object2ObjectOpenHashMap<>(); + private static Object2ObjectOpenHashMap cloakedBlockNameTranslations = new Object2ObjectOpenHashMap<>(); + private static Object2ObjectOpenHashMap cloakedItemNameTranslations = new Object2ObjectOpenHashMap<>(); public static MutableText getTranslationString(Item item) { if (cloakedItemNameTranslations.containsKey(item)) { @@ -79,19 +78,59 @@ public static void clear() { cloakedBlockNameTranslations.clear(); cloakedItemNameTranslations.clear(); } + + public static void trim() { + advToBlockStates.trim(); + advToItems.trim(); + blockStateCloaks.trim(); + itemCloaks.trim(); + cloakedBlockNameTranslations.trim(); + cloakedItemNameTranslations.trim(); + } + + public static void deepTrim() { + trim(); + for (ObjectArrayList blockList : advToBlockStates.values()) blockList.trim(); + for (ObjectArrayList itemList : advToItems.values()) itemList.trim(); + } private static final Set revelationAwares = new HashSet<>(); public static void registerRevelationAware(RevelationAware revelationAware) { revelationAwares.add(revelationAware); } - + + private static void prepareForRevelationAwaresRegistration(int amount) { + // Items + advToItems.ensureCapacity(advToItems.size() + amount); + itemToAdv.ensureCapacity(itemToAdv.size() + amount); + itemCloaks.ensureCapacity(itemCloaks.size() + amount); + // Translations + cloakedBlockNameTranslations.ensureCapacity(cloakedBlockNameTranslations.size() + amount); + cloakedItemNameTranslations.ensureCapacity(cloakedItemNameTranslations.size() + amount); + } + public static void addRevelationAwares() { + prepareForRevelationAwaresRegistration(revelationAwares.size()); for (RevelationAware revelationAware : revelationAwares) { Identifier advancementIdentifier = revelationAware.getCloakAdvancementIdentifier(); - for (Map.Entry states : revelationAware.getBlockStateCloaks().entrySet()) { - registerBlockState(advancementIdentifier, states.getKey(), states.getValue()); + + Map blockStateCloaks = revelationAware.getBlockStateCloaks(); + ObjectArrayList sourceBlockStates = new ObjectArrayList<>(blockStateCloaks.size()); + ObjectArrayList targetBlockStates = new ObjectArrayList<>(blockStateCloaks.size()); + for (Map.Entry states : blockStateCloaks.entrySet()) { + BlockState sourceBlockState = states.getKey(); + if (!sourceBlockState.isAir()) { + sourceBlockStates.add(sourceBlockState); + targetBlockStates.add(states.getValue()); + } else { + Revelationary.logError("Trying to register invalid block cloak. Advancement: " + advancementIdentifier + + " Source Block: " + Registries.BLOCK.getId(sourceBlockState.getBlock()) + + " Target Block: " + Registries.BLOCK.getId(states.getValue().getBlock())); + } } + registerBlockStatesForIdentifier(advancementIdentifier, sourceBlockStates, targetBlockStates); + Pair item = revelationAware.getItemCloak(); if (item != null) { registerItem(advancementIdentifier, item.getLeft(), item.getRight()); @@ -112,16 +151,26 @@ public static void registerFromJson(JsonObject jsonObject) { Identifier advancementIdentifier = Identifier.tryParse(JsonHelper.getString(jsonObject, "advancement")); if (jsonObject.has("block_states")) { + JsonObject blockStates = jsonObject.get("block_states").getAsJsonObject(); + ObjectArrayList sourceBlockStates = new ObjectArrayList<>(blockStates.size()); + ObjectArrayList targetBlockStates = new ObjectArrayList<>(blockStates.size()); for (Map.Entry stateEntry : jsonObject.get("block_states").getAsJsonObject().entrySet()) { try { BlockState sourceBlockState = BlockArgumentParser.block(Registries.BLOCK.getReadOnlyWrapper(), stateEntry.getKey(), true).blockState(); BlockState targetBlockState = BlockArgumentParser.block(Registries.BLOCK.getReadOnlyWrapper(), stateEntry.getValue().getAsString(), true).blockState(); - - registerBlockState(advancementIdentifier, sourceBlockState, targetBlockState); + if (!sourceBlockState.isAir()) { + sourceBlockStates.add(sourceBlockState); + targetBlockStates.add(targetBlockState); + } else { + Revelationary.logError("Trying to register invalid block cloak. Advancement: " + advancementIdentifier + + " Source Block: " + Registries.BLOCK.getId(sourceBlockState.getBlock()) + + " Target Block: " + Registries.BLOCK.getId(targetBlockState.getBlock())); + } } catch (Exception e) { Revelationary.logError("Error parsing block state: " + e); } } + registerBlockStatesForIdentifier(advancementIdentifier, sourceBlockStates, targetBlockStates); } if (jsonObject.has("items")) { for (Map.Entry itemEntry : jsonObject.get("items").getAsJsonObject().entrySet()) { @@ -168,12 +217,12 @@ private static void registerBlockState(Identifier advancementIdentifier, BlockSt return; } - List list; + ObjectArrayList list; if (advToBlockStates.containsKey(advancementIdentifier)) { list = advToBlockStates.get(advancementIdentifier); list.add(sourceBlockState); } else { - list = new ArrayList<>(); + list = new ObjectArrayList<>(); list.add(sourceBlockState); advToBlockStates.put(advancementIdentifier, list); } @@ -190,6 +239,38 @@ private static void registerBlockState(Identifier advancementIdentifier, BlockSt blockCloaks.putIfAbsent(sourceBlockState.getBlock(), targetBlockState.getBlock()); blockStateToAdv.put(sourceBlockState, advancementIdentifier); } + + private static void registerBlockStatesForIdentifier(Identifier advancementIdentifier, ObjectArrayList sourceBlockStates, ObjectArrayList targetBlockStates) { + if (sourceBlockStates.size() != targetBlockStates.size()) throw new IllegalArgumentException("Unequal sizes of sourceBlockStates and targetBlockStates arrays"); + int sz = sourceBlockStates.size(); + if(advToBlockStates.containsKey(advancementIdentifier)) { + ObjectArrayList blockStates = advToBlockStates.get(advancementIdentifier); + blockStates.ensureCapacity(blockStates.size() + sz); // preallocate + blockStates.addAll(sourceBlockStates); + } else advToBlockStates.put(advancementIdentifier, sourceBlockStates); + + blockStateCloaks.ensureCapacity(blockStateCloaks.size() + sz); + blockStateToAdv.ensureCapacity(blockStateToAdv.size() + sz); + // assume amount of blocks is roughly equal to amount of blockstates (in real case scenario) + blockCloaks.ensureCapacity(blockCloaks.size() + sz); + // assume amount of items is roughly equal to amount of blockstates (in real case scenario) + ObjectArrayList sourceItems = new ObjectArrayList<>(sz); + ObjectArrayList targetItems = new ObjectArrayList<>(sz); + for (int i = 0; i < sz; i++) { + BlockState sourceBlockState = sourceBlockStates.get(i); + BlockState targetBlockState = targetBlockStates.get(i); + blockStateCloaks.put(sourceBlockState, targetBlockState); + blockStateToAdv.put(sourceBlockState, advancementIdentifier); + blockCloaks.put(sourceBlockState.getBlock(), targetBlockState.getBlock()); + Item sourceBlockItem = sourceBlockState.getBlock().asItem(); + Item targetBlockItem = targetBlockState.getBlock().asItem(); + if (sourceBlockItem != Items.AIR && targetBlockItem != Items.AIR) { + sourceItems.add(sourceBlockItem); + targetItems.add(targetBlockItem); + } + } + registerItemsForIdentifier(advancementIdentifier, sourceItems, targetItems); + } private static void registerBlockTranslation(Block sourceBlock, MutableText targetTranslation) { cloakedBlockNameTranslations.put(sourceBlock, targetTranslation); @@ -216,11 +297,13 @@ public static boolean isVisibleTo(BlockState state, PlayerEntity player) { } public static Map> getBlockStateEntries() { - return advToBlockStates; + // fighting invariance of java generic types + //noinspection unchecked + return (Map>) (Map) advToBlockStates; } public static List getBlockStateEntries(Identifier advancement) { - return advToBlockStates.getOrDefault(advancement, Collections.EMPTY_LIST); + return advToBlockStates.getOrDefault(advancement, ObjectArrayList.of()); } public static List getBlockEntries() { @@ -262,19 +345,37 @@ private static void registerItem(Identifier advancementIdentifier, Item sourceIt } if (advToItems.containsKey(advancementIdentifier)) { - List list = advToItems.get(advancementIdentifier); + ObjectArrayList list = advToItems.get(advancementIdentifier); if (list.contains(sourceItem)) { return; } list.add(sourceItem); } else { - List list = new ArrayList<>(); + ObjectArrayList list = new ObjectArrayList<>(); list.add(sourceItem); advToItems.put(advancementIdentifier, list); } itemCloaks.put(sourceItem, targetItem); itemToAdv.put(sourceItem, advancementIdentifier); } + + private static void registerItemsForIdentifier(Identifier advancementIdentifier, ObjectArrayList sourceItems, ObjectArrayList targetItems) { + if (sourceItems.size() != targetItems.size()) throw new IllegalArgumentException("Unequal sizes of sourceItems and targetItems arrays"); + int sz = sourceItems.size(); + if (advToItems.containsKey(advancementIdentifier)) { + ObjectArrayList items = advToItems.get(advancementIdentifier); + items.ensureCapacity(items.size() + sz); + items.addAll(sourceItems); + } else advToItems.put(advancementIdentifier, sourceItems); + + itemCloaks.ensureCapacity(itemCloaks.size() + sz); + itemToAdv.ensureCapacity(itemToAdv.size() + sz); + for (int i = 0; i < sz; i++) { + Item sourceItem = sourceItems.get(i); + itemCloaks.put(sourceItem, targetItems.get(i)); + itemToAdv.put(sourceItem, advancementIdentifier); + } + } private static void registerItemTranslation(Item sourceItem, MutableText targetTranslation) { cloakedItemNameTranslations.put(sourceItem, targetTranslation); @@ -299,138 +400,44 @@ public static BlockState getCloak(BlockState blockState) { } public static @NotNull Collection getRevealedItems(Identifier advancement) { - List items = new ArrayList<>(); - if (advToItems.containsKey(advancement)) { - for (Object entry : advToItems.get(advancement)) { - if (entry instanceof Item item) { - items.add(item); - } - } - } - return items; + if (advToItems.containsKey(advancement)) return advToItems.get(advancement).clone(); + return ObjectArrayList.of(); } public static Map> getItemEntries() { - return advToItems; + // fighting invariance of java generic types + //noinspection unchecked + return (Map>) (Map) advToItems; } public static List getItemEntries(Identifier advancement) { - return advToItems.getOrDefault(advancement, Collections.EMPTY_LIST); + return advToItems.getOrDefault(advancement, ObjectArrayList.of()); } - private static void writeText(PacketByteBuf buf, Text text) { - TextCodecs.PACKET_CODEC.encode(buf, text); - } + public static void fromPacket(RevelationaryPackets.RevelationSync syncPacket) { + advToBlockStates = syncPacket.advToBlockStates(); + blockStateToAdv = syncPacket.blockStateToAdv(); + blockStateCloaks = syncPacket.blockStateCloaks(); + blockCloaks = syncPacket.blockCloaks(); + advToItems = syncPacket.advToItems(); + itemToAdv = syncPacket.itemToAdv(); + itemCloaks = syncPacket.itemCloaks(); + cloakedBlockNameTranslations = syncPacket.cloakedBlockNameTranslations(); + cloakedItemNameTranslations = syncPacket.cloakedItemNameTranslations(); - private static Text readText(PacketByteBuf buf) { - return TextCodecs.PACKET_CODEC.decode(buf); - } - - public static void write(PacketByteBuf buf) { - // Block States - buf.writeInt(advToBlockStates.size()); - for (Map.Entry> advancementBlocks : advToBlockStates.entrySet()) { - buf.writeIdentifier(advancementBlocks.getKey()); - buf.writeInt(advancementBlocks.getValue().size()); - for (BlockState blockState : advancementBlocks.getValue()) { - buf.writeString(BlockArgumentParser.stringifyBlockState(blockState)); - buf.writeString(BlockArgumentParser.stringifyBlockState(blockStateCloaks.get(blockState))); - } - } - - // Items - buf.writeInt(advToItems.size()); - for (Map.Entry> advancementItems : advToItems.entrySet()) { - buf.writeIdentifier(advancementItems.getKey()); - buf.writeInt(advancementItems.getValue().size()); - for (Item item : advancementItems.getValue()) { - buf.writeString(Registries.ITEM.getId(item).toString()); - buf.writeString(Registries.ITEM.getId(itemCloaks.get(item)).toString()); - } - } - - // Block Translations - buf.writeInt(cloakedBlockNameTranslations.size()); - for (Map.Entry blockTranslation : cloakedBlockNameTranslations.entrySet()) { - buf.writeIdentifier(Registries.BLOCK.getId(blockTranslation.getKey())); - writeText(buf, blockTranslation.getValue()); - } - - // Item Translations - buf.writeInt(cloakedItemNameTranslations.size()); - for (Map.Entry itemTranslation : cloakedItemNameTranslations.entrySet()) { - buf.writeIdentifier(Registries.ITEM.getId(itemTranslation.getKey())); - writeText(buf, itemTranslation.getValue()); - } - - } - - public static void fromPacket(PacketByteBuf buf) throws CommandSyntaxException { - RevelationRegistry.clear(); RevelationRegistry.addRevelationAwares(); - - // Block States - int blockEntries = buf.readInt(); - for (int i = 0; i < blockEntries; i++) { - Identifier advancementIdentifier = buf.readIdentifier(); - int blockStateCount = buf.readInt(); - for (int j = 0; j < blockStateCount; j++) { - BlockState sourceState = BlockArgumentParser.block(Registries.BLOCK.getReadOnlyWrapper(), buf.readString(), true).blockState(); - BlockState targetState = BlockArgumentParser.block(Registries.BLOCK.getReadOnlyWrapper(), buf.readString(), true).blockState(); - - if (advToBlockStates.containsKey(advancementIdentifier)) { - List advancementStates = advToBlockStates.get(advancementIdentifier); - advancementStates.add(sourceState); - } else { - List advancementStates = new ArrayList<>(); - advancementStates.add(sourceState); - advToBlockStates.put(advancementIdentifier, advancementStates); - } - blockStateToAdv.put(sourceState, advancementIdentifier); - blockStateCloaks.put(sourceState, targetState); - blockCloaks.putIfAbsent(sourceState.getBlock(), targetState.getBlock()); - } - } - - // Items - int itemEntries = buf.readInt(); - for (int i = 0; i < itemEntries; i++) { - Identifier advancementIdentifier = buf.readIdentifier(); - int itemCount = buf.readInt(); - for (int j = 0; j < itemCount; j++) { - Identifier sourceId = Identifier.tryParse(buf.readString()); - Identifier targetId = Identifier.tryParse(buf.readString()); - Item sourceItem = Registries.ITEM.get(sourceId); - Item targetItem = Registries.ITEM.get(targetId); - - if (advToItems.containsKey(advancementIdentifier)) { - List advancementItems = advToItems.get(advancementIdentifier); - advancementItems.add(sourceItem); - } else { - List advancementItems = new ArrayList<>(); - advancementItems.add(sourceItem); - advToItems.put(advancementIdentifier, advancementItems); - } - itemToAdv.put(sourceItem, advancementIdentifier); - itemCloaks.put(sourceItem, targetItem); - } - } - - // Block Translations - int blockTranslations = buf.readInt(); - for (int i = 0; i < blockTranslations; i++) { - Block block = Registries.BLOCK.get(buf.readIdentifier()); - MutableText text = (MutableText) readText(buf); - cloakedBlockNameTranslations.put(block, text); - } - - // Item Translations - int itemTranslations = buf.readInt(); - for (int i = 0; i < itemTranslations; i++) { - Item item = Registries.ITEM.get(buf.readIdentifier()); - MutableText text = (MutableText) readText(buf); - cloakedItemNameTranslations.put(item, text); - } + RevelationRegistry.deepTrim(); + } + + public static RevelationaryPackets.RevelationSync intoPacket() { + return new RevelationaryPackets.RevelationSync(advToBlockStates, + blockStateToAdv, + blockStateCloaks, + blockCloaks, + advToItems, + itemToAdv, + itemCloaks, + cloakedBlockNameTranslations, + cloakedItemNameTranslations); } - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/Revelationary.java b/src/main/java/de/dafuqs/revelationary/Revelationary.java index b0edace..b9ac620 100644 --- a/src/main/java/de/dafuqs/revelationary/Revelationary.java +++ b/src/main/java/de/dafuqs/revelationary/Revelationary.java @@ -38,8 +38,10 @@ public void onInitialize() { CommandRegistrationCallback.EVENT.register(Commands::register); ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(RevelationDataLoader.INSTANCE); - ServerLifecycleEvents.SERVER_STARTED.register(server -> RevelationRegistry.addRevelationAwares()); - + ServerLifecycleEvents.SERVER_STARTED.register(server -> { + RevelationRegistry.addRevelationAwares(); + RevelationRegistry.deepTrim(); + }); if (FabricLoader.getInstance().isModLoaded("sodium")) { logWarning("Sodium detected. Chunk rebuilding will be done in cursed mode."); } diff --git a/src/main/java/de/dafuqs/revelationary/mixin/client/WorldRendererMixin.java b/src/main/java/de/dafuqs/revelationary/mixin/client/WorldRendererMixin.java index 242f2bf..fcaf045 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/client/WorldRendererMixin.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/client/WorldRendererMixin.java @@ -14,6 +14,7 @@ import net.minecraft.world.chunk.WorldChunk; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; @Environment(EnvType.CLIENT) @Mixin(value = WorldRenderer.class, priority = 900) @@ -45,6 +46,7 @@ public void rebuildAllChunks() { } } + @Unique private static void rebuildAllChunksSodium() { World world = MinecraftClient.getInstance().world; if (world == null) { diff --git a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryPackets.java b/src/main/java/de/dafuqs/revelationary/networking/RevelationaryPackets.java index 8bc0362..b8d49f4 100644 --- a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryPackets.java +++ b/src/main/java/de/dafuqs/revelationary/networking/RevelationaryPackets.java @@ -1,32 +1,170 @@ package de.dafuqs.revelationary.networking; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import de.dafuqs.revelationary.Revelationary; -import net.minecraft.network.PacketByteBuf; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.command.argument.BlockArgumentParser; +import net.minecraft.item.Item; import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.packet.CustomPayload; +import net.minecraft.registry.Registries; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.text.TextCodecs; import net.minecraft.util.Identifier; +import java.util.Map; + public class RevelationaryPackets { public static final Identifier REVELATION_SYNC = new Identifier(Revelationary.MOD_ID, "revelation_sync"); // 1.20.5 port note: this whole buf-juggling thing is an obvious workaround for the fact that RevelationRegistry // relies heavily on reading the buffer straight up - public record RevelationSync(PacketByteBuf bufCopy) implements CustomPayload { + public record RevelationSync(Object2ObjectOpenHashMap> advToBlockStates, + Object2ObjectOpenHashMap blockStateToAdv, + Object2ObjectOpenHashMap blockStateCloaks, + Object2ObjectOpenHashMap blockCloaks, + Object2ObjectOpenHashMap> advToItems, + Object2ObjectOpenHashMap itemToAdv, + Object2ObjectOpenHashMap itemCloaks, + Object2ObjectOpenHashMap cloakedBlockNameTranslations, + Object2ObjectOpenHashMap cloakedItemNameTranslations) implements CustomPayload { public static final PacketCodec CODEC = CustomPayload.codecOf(RevelationSync::write, RevelationSync::read); public static final CustomPayload.Id ID = new Id<>(REVELATION_SYNC); - private static RevelationSync read(RegistryByteBuf buf) { - // copy buffer to retain it for RevelationRegistry reading - PacketByteBuf copy = new PacketByteBuf(buf.copy()); - // skip all the readable bytes in the original buffer to prevent decoder exception - buf.skipBytes(buf.readableBytes()); - return new RevelationSync(copy); + private static void writeText(RegistryByteBuf buf, Text text) { + TextCodecs.REGISTRY_PACKET_CODEC.encode(buf, text); + } + + private static Text readText(RegistryByteBuf buf) { + return TextCodecs.REGISTRY_PACKET_CODEC.decode(buf); } - private void write(RegistryByteBuf buf) { - buf.writeBytes(bufCopy); + public static RevelationSync read(RegistryByteBuf buf) { + /* Block States */ + + final Object2ObjectOpenHashMap blockCloaks = new Object2ObjectOpenHashMap<>(buf.readInt()); + final Object2ObjectOpenHashMap blockStateToAdv = new Object2ObjectOpenHashMap<>(buf.readInt()); + final Object2ObjectOpenHashMap blockStateCloaks = new Object2ObjectOpenHashMap<>(buf.readInt()); + int blockEntries = buf.readInt(); + final Object2ObjectOpenHashMap> advToBlockStates = new Object2ObjectOpenHashMap<>(blockEntries); + for (int i = 0; i < blockEntries; i++) { + Identifier advancementIdentifier = buf.readIdentifier(); + int blockStateCount = buf.readInt(); + ObjectArrayList advancementStates = new ObjectArrayList<>(blockStateCount); + for (int j = 0; j < blockStateCount; j++) { + try { + BlockState sourceState = BlockArgumentParser.block(Registries.BLOCK.getReadOnlyWrapper(), buf.readString(), true).blockState(); + BlockState targetState = BlockArgumentParser.block(Registries.BLOCK.getReadOnlyWrapper(), buf.readString(), true).blockState(); + + advancementStates.add(sourceState); + blockStateToAdv.put(sourceState, advancementIdentifier); + blockStateCloaks.put(sourceState, targetState); + blockCloaks.putIfAbsent(sourceState.getBlock(), targetState.getBlock()); + } catch (CommandSyntaxException e) { + Revelationary.logError(e.getMessage()); + }; + } + advToBlockStates.put(advancementIdentifier, advancementStates); + } + + /* Items */ + + final Object2ObjectOpenHashMap itemToAdv = new Object2ObjectOpenHashMap<>(buf.readInt()); + Object2ObjectOpenHashMap itemCloaks = new Object2ObjectOpenHashMap<>(buf.readInt()); + int itemEntries = buf.readInt(); + final Object2ObjectOpenHashMap> advToItems = new Object2ObjectOpenHashMap<>(itemEntries); // preallocate this map too + for (int i = 0; i < itemEntries; i++) { + Identifier advancementIdentifier = buf.readIdentifier(); + int itemCount = buf.readInt(); + ObjectArrayList advancementItems = new ObjectArrayList<>(itemCount); + for (int j = 0; j < itemCount; j++) { + Identifier sourceId = Identifier.tryParse(buf.readString()); + Identifier targetId = Identifier.tryParse(buf.readString()); + Item sourceItem = Registries.ITEM.get(sourceId); + Item targetItem = Registries.ITEM.get(targetId); + + advancementItems.add(sourceItem); + itemToAdv.put(sourceItem, advancementIdentifier); + itemCloaks.put(sourceItem, targetItem); + } + advToItems.put(advancementIdentifier, advancementItems); + } + + /* Block Translations */ + int blockTranslations = buf.readInt(); + final Object2ObjectOpenHashMap cloakedBlockNameTranslations = new Object2ObjectOpenHashMap<>(blockTranslations); // preallocate translations + for (int i = 0; i < blockTranslations; i++) { + Block block = Registries.BLOCK.get(buf.readIdentifier()); + MutableText text = (MutableText) readText(buf); + cloakedBlockNameTranslations.put(block, text); + } + + /* Item Translations */ + int itemTranslations = buf.readInt(); + final Object2ObjectOpenHashMap cloakedItemNameTranslations = new Object2ObjectOpenHashMap<>(itemTranslations); // preallocate translations + for (int i = 0; i < itemTranslations; i++) { + Item item = Registries.ITEM.get(buf.readIdentifier()); + MutableText text = (MutableText) readText(buf); + cloakedItemNameTranslations.put(item, text); + } + return new RevelationSync(advToBlockStates, + blockStateToAdv, + blockStateCloaks, + blockCloaks, + advToItems, + itemToAdv, + itemCloaks, + cloakedBlockNameTranslations, + cloakedItemNameTranslations); + } + + public void write(RegistryByteBuf buf) { + // Block States + buf.writeInt(blockCloaks.size()); // for preallocation on packet read + buf.writeInt(blockStateToAdv.size()); // for preallocation on packet read + buf.writeInt(blockStateCloaks.size()); // for preallocation on packet read + buf.writeInt(advToBlockStates.size()); + for (Map.Entry> advancementBlocks : advToBlockStates.entrySet()) { + buf.writeIdentifier(advancementBlocks.getKey()); + buf.writeInt(advancementBlocks.getValue().size()); + for (BlockState blockState : advancementBlocks.getValue()) { + buf.writeString(BlockArgumentParser.stringifyBlockState(blockState)); + buf.writeString(BlockArgumentParser.stringifyBlockState(blockStateCloaks.get(blockState))); + } + } + + // Items + buf.writeInt(itemToAdv.size()); // for preallocation on packet read + buf.writeInt(itemCloaks.size()); // for preallocation on packet read + buf.writeInt(advToItems.size()); + for (Map.Entry> advancementItems : advToItems.entrySet()) { + buf.writeIdentifier(advancementItems.getKey()); + buf.writeInt(advancementItems.getValue().size()); + for (Item item : advancementItems.getValue()) { + buf.writeString(Registries.ITEM.getId(item).toString()); + buf.writeString(Registries.ITEM.getId(itemCloaks.get(item)).toString()); + } + } + + // Block Translations + buf.writeInt(cloakedBlockNameTranslations.size()); + for (Map.Entry blockTranslation : cloakedBlockNameTranslations.entrySet()) { + buf.writeIdentifier(Registries.BLOCK.getId(blockTranslation.getKey())); + writeText(buf, blockTranslation.getValue()); + } + + // Item Translations + buf.writeInt(cloakedItemNameTranslations.size()); + for (Map.Entry itemTranslation : cloakedItemNameTranslations.entrySet()) { + buf.writeIdentifier(Registries.ITEM.getId(itemTranslation.getKey())); + writeText(buf, itemTranslation.getValue()); + } } @Override diff --git a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketReceivers.java b/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketReceivers.java index abbb059..f704d79 100644 --- a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketReceivers.java +++ b/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketReceivers.java @@ -9,7 +9,7 @@ public class RevelationaryS2CPacketReceivers { public static void register() { ClientPlayNetworking.registerGlobalReceiver(RevelationaryPackets.RevelationSync.ID, (payload, context) -> { try { - RevelationRegistry.fromPacket(payload.bufCopy()); + RevelationRegistry.fromPacket(payload); } catch (Exception e) { Revelationary.logError("Error fetching results from sync packet"); e.printStackTrace(); diff --git a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketSenders.java b/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketSenders.java index 8ccf5a9..213522b 100644 --- a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketSenders.java +++ b/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketSenders.java @@ -1,17 +1,13 @@ package de.dafuqs.revelationary.networking; import de.dafuqs.revelationary.RevelationRegistry; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.network.PacketByteBuf; import net.minecraft.server.network.ServerPlayerEntity; public class RevelationaryS2CPacketSenders { public static void sendRevelations(ServerPlayerEntity player) { - PacketByteBuf packetByteBuf = PacketByteBufs.create(); - RevelationRegistry.write(packetByteBuf); - ServerPlayNetworking.send(player, new RevelationaryPackets.RevelationSync(packetByteBuf)); + ServerPlayNetworking.send(player, RevelationRegistry.intoPacket()); } - + } From abfafd3616c2b19c5ccfc020f1921f5ab250e1b3 Mon Sep 17 00:00:00 2001 From: imreallybadatnames Date: Thu, 9 May 2024 18:48:07 +1100 Subject: [PATCH 3/6] remove outdated comment --- .../dafuqs/revelationary/networking/RevelationaryPackets.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryPackets.java b/src/main/java/de/dafuqs/revelationary/networking/RevelationaryPackets.java index b8d49f4..25663cb 100644 --- a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryPackets.java +++ b/src/main/java/de/dafuqs/revelationary/networking/RevelationaryPackets.java @@ -23,8 +23,6 @@ public class RevelationaryPackets { public static final Identifier REVELATION_SYNC = new Identifier(Revelationary.MOD_ID, "revelation_sync"); - // 1.20.5 port note: this whole buf-juggling thing is an obvious workaround for the fact that RevelationRegistry - // relies heavily on reading the buffer straight up public record RevelationSync(Object2ObjectOpenHashMap> advToBlockStates, Object2ObjectOpenHashMap blockStateToAdv, Object2ObjectOpenHashMap blockStateCloaks, From c978e43d8d46385c60fee49332b627ef053432b3 Mon Sep 17 00:00:00 2001 From: imreallybadatnames Date: Thu, 9 May 2024 19:13:30 +1100 Subject: [PATCH 4/6] ci fix --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5f6112b..aa5300a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,9 +10,9 @@ jobs: strategy: matrix: # Use these Java versions - java: [17] # Current Java LTS & minimum supported by Minecraft + java: [21] # Current Java LTS & minimum supported by Minecraft # Test on both Linux and Windows - os: [ubuntu-20.04, windows-latest] + os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} @@ -38,7 +38,7 @@ jobs: - name: capture build artifacts # Only capture artifacts from one OS (Linux) - if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS + if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS uses: actions/upload-artifact@v2 with: name: Artifacts From d15297ef82462f643bc1202b85f5ea04b853c602 Mon Sep 17 00:00:00 2001 From: imreallybadatnames Date: Fri, 10 May 2024 17:47:58 +1100 Subject: [PATCH 5/6] suggested changes + evil style changes absolutely diabolical --- .../revelationary/ClientAdvancements.java | 2 - .../revelationary/ClientRevelationHolder.java | 2 +- .../revelationary/RevelationDataLoader.java | 2 - .../revelationary/RevelationRegistry.java | 48 ++----------------- .../dafuqs/revelationary/Revelationary.java | 9 ++-- .../revelationary/RevelationaryClient.java | 2 - ...kets.java => RevelationaryNetworking.java} | 40 +++++++++++++--- .../AdvancementCountCriterion.java | 2 - .../AdvancementGottenCriterion.java | 2 - .../HadRevelationCriterion.java | 2 - .../api/advancements/AdvancementCriteria.java | 2 - .../api/advancements/AdvancementHelper.java | 2 - .../ClientAdvancementPacketCallback.java | 2 - .../api/revelations/CloakedBlock.java | 2 - .../api/revelations/CloakedBlockItem.java | 2 - .../api/revelations/CloakedItem.java | 2 - .../api/revelations/RevealingCallback.java | 2 - .../api/revelations/RevelationAware.java | 2 - .../revelations/WorldRendererAccessor.java | 4 +- .../config/RevelationaryConfig.java | 2 - .../mixin/AbstractBlockMixin.java | 4 +- .../mixin/BlockUnbreakingMixin.java | 4 +- .../mixin/MixinPlayerManager.java | 8 ++-- .../mixin/PlayerAdvancementTrackerMixin.java | 4 +- .../AccessorClientAdvancementManager.java | 2 - .../mixin/client/BlockClientMixin.java | 4 +- .../mixin/client/BlockModelsMixin.java | 4 +- .../client/ClientAdvancementManagerMixin.java | 4 +- .../revelationary/mixin/client/ItemMixin.java | 4 +- .../mixin/client/ItemModelsMixin.java | 2 - .../mixin/client/MinecraftClientMixin.java | 2 - .../mixin/client/WorldRendererMixin.java | 4 +- .../client/WorldRendererMixinAccessor.java | 2 - .../RevelationaryS2CPacketReceivers.java | 20 -------- .../RevelationaryS2CPacketSenders.java | 13 ----- 35 files changed, 53 insertions(+), 161 deletions(-) rename src/main/java/de/dafuqs/revelationary/{networking/RevelationaryPackets.java => RevelationaryNetworking.java} (85%) delete mode 100644 src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketReceivers.java delete mode 100644 src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketSenders.java diff --git a/src/main/java/de/dafuqs/revelationary/ClientAdvancements.java b/src/main/java/de/dafuqs/revelationary/ClientAdvancements.java index b411c19..af2bb94 100644 --- a/src/main/java/de/dafuqs/revelationary/ClientAdvancements.java +++ b/src/main/java/de/dafuqs/revelationary/ClientAdvancements.java @@ -17,7 +17,6 @@ @Environment(EnvType.CLIENT) public class ClientAdvancements { - protected static boolean receivedFirstAdvancementPacket = false; public static List callbacks = new ArrayList<>(); @@ -77,5 +76,4 @@ public static boolean hasDone(Identifier identifier) { public static void playerLogout() { receivedFirstAdvancementPacket = false; } - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/ClientRevelationHolder.java b/src/main/java/de/dafuqs/revelationary/ClientRevelationHolder.java index 660b919..cae7aeb 100644 --- a/src/main/java/de/dafuqs/revelationary/ClientRevelationHolder.java +++ b/src/main/java/de/dafuqs/revelationary/ClientRevelationHolder.java @@ -116,7 +116,7 @@ public static void processRemovedAdvancements(@NotNull Set removedAd // rerender chunks to show newly swapped blocks static void rebuildAllChunks() { WorldRenderer renderer = MinecraftClient.getInstance().worldRenderer; - ((WorldRendererAccessor) renderer).rebuildAllChunks(); + ((WorldRendererAccessor) renderer).revelationary$rebuildAllChunks(); } // BLOCKS diff --git a/src/main/java/de/dafuqs/revelationary/RevelationDataLoader.java b/src/main/java/de/dafuqs/revelationary/RevelationDataLoader.java index 1d43366..cfbd985 100644 --- a/src/main/java/de/dafuqs/revelationary/RevelationDataLoader.java +++ b/src/main/java/de/dafuqs/revelationary/RevelationDataLoader.java @@ -11,7 +11,6 @@ import java.util.Map; public class RevelationDataLoader extends JsonDataLoader implements IdentifiableResourceReloadListener { - public static final RevelationDataLoader INSTANCE = new RevelationDataLoader(); private RevelationDataLoader() { @@ -28,5 +27,4 @@ protected void apply(Map prepared, ResourceManager mana public Identifier getFabricId() { return new Identifier(Revelationary.MOD_ID, "revelations"); } - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/RevelationRegistry.java b/src/main/java/de/dafuqs/revelationary/RevelationRegistry.java index f33fe0d..5724ab9 100644 --- a/src/main/java/de/dafuqs/revelationary/RevelationRegistry.java +++ b/src/main/java/de/dafuqs/revelationary/RevelationRegistry.java @@ -5,7 +5,6 @@ import de.dafuqs.revelationary.api.advancements.AdvancementHelper; import de.dafuqs.revelationary.api.revelations.RevelationAware; import de.dafuqs.revelationary.config.RevelationaryConfig; -import de.dafuqs.revelationary.networking.RevelationaryPackets; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.block.*; @@ -25,7 +24,6 @@ import java.util.*; public class RevelationRegistry { - private static Object2ObjectOpenHashMap> advToBlockStates = new Object2ObjectOpenHashMap<>(); private static Object2ObjectOpenHashMap blockStateToAdv = new Object2ObjectOpenHashMap<>(); private static Object2ObjectOpenHashMap blockStateCloaks = new Object2ObjectOpenHashMap<>(); @@ -69,15 +67,6 @@ public static MutableText getTranslationString(Block block) { // Get the localized name of the block and scatter it using §k to make it unreadable return Text.literal("§k" + Language.getInstance().get(block.getTranslationKey())); } - - public static void clear() { - advToBlockStates.clear(); - advToItems.clear(); - blockStateCloaks.clear(); - itemCloaks.clear(); - cloakedBlockNameTranslations.clear(); - cloakedItemNameTranslations.clear(); - } public static void trim() { advToBlockStates.trim(); @@ -209,37 +198,6 @@ public static void registerFromJson(JsonObject jsonObject) { } // BLOCKS - private static void registerBlockState(Identifier advancementIdentifier, BlockState sourceBlockState, BlockState targetBlockState) { - if(sourceBlockState.isAir()) { - Revelationary.logError("Trying to register invalid block cloak. Advancement: " + advancementIdentifier - + " Source Block: " + Registries.BLOCK.getId(sourceBlockState.getBlock()) - + " Target Block: " + Registries.BLOCK.getId(targetBlockState.getBlock())); - return; - } - - ObjectArrayList list; - if (advToBlockStates.containsKey(advancementIdentifier)) { - list = advToBlockStates.get(advancementIdentifier); - list.add(sourceBlockState); - } else { - list = new ObjectArrayList<>(); - list.add(sourceBlockState); - advToBlockStates.put(advancementIdentifier, list); - } - - Item sourceBlockItem = sourceBlockState.getBlock().asItem(); - if (sourceBlockItem != Items.AIR) { - Item targetBlockItem = targetBlockState.getBlock().asItem(); - if (targetBlockItem != Items.AIR) { - registerItem(advancementIdentifier, sourceBlockItem, targetBlockItem); - } - } - - blockStateCloaks.put(sourceBlockState, targetBlockState); - blockCloaks.putIfAbsent(sourceBlockState.getBlock(), targetBlockState.getBlock()); - blockStateToAdv.put(sourceBlockState, advancementIdentifier); - } - private static void registerBlockStatesForIdentifier(Identifier advancementIdentifier, ObjectArrayList sourceBlockStates, ObjectArrayList targetBlockStates) { if (sourceBlockStates.size() != targetBlockStates.size()) throw new IllegalArgumentException("Unequal sizes of sourceBlockStates and targetBlockStates arrays"); int sz = sourceBlockStates.size(); @@ -414,7 +372,7 @@ public static List getItemEntries(Identifier advancement) { return advToItems.getOrDefault(advancement, ObjectArrayList.of()); } - public static void fromPacket(RevelationaryPackets.RevelationSync syncPacket) { + public static void fromPacket(RevelationaryNetworking.RevelationSync syncPacket) { advToBlockStates = syncPacket.advToBlockStates(); blockStateToAdv = syncPacket.blockStateToAdv(); blockStateCloaks = syncPacket.blockStateCloaks(); @@ -429,8 +387,8 @@ public static void fromPacket(RevelationaryPackets.RevelationSync syncPacket) { RevelationRegistry.deepTrim(); } - public static RevelationaryPackets.RevelationSync intoPacket() { - return new RevelationaryPackets.RevelationSync(advToBlockStates, + public static RevelationaryNetworking.RevelationSync intoPacket() { + return new RevelationaryNetworking.RevelationSync(advToBlockStates, blockStateToAdv, blockStateCloaks, blockCloaks, diff --git a/src/main/java/de/dafuqs/revelationary/Revelationary.java b/src/main/java/de/dafuqs/revelationary/Revelationary.java index b9ac620..c010003 100644 --- a/src/main/java/de/dafuqs/revelationary/Revelationary.java +++ b/src/main/java/de/dafuqs/revelationary/Revelationary.java @@ -1,18 +1,15 @@ package de.dafuqs.revelationary; import de.dafuqs.revelationary.api.advancements.*; -import de.dafuqs.revelationary.networking.RevelationaryPackets; import net.fabricmc.api.*; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.*; -import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.resource.*; import net.fabricmc.loader.api.*; import net.minecraft.resource.*; import org.slf4j.*; public class Revelationary implements ModInitializer { - public static final String MOD_ID = "revelationary"; private static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); @@ -27,12 +24,15 @@ public static void logWarning(String message) { public static void logError(String message) { LOGGER.error("[Revelationary] {}", message); } + public static void logException(Throwable t) { + LOGGER.error("[Revelationary] ", t); + } @Override public void onInitialize() { logInfo("Starting Common Startup"); - PayloadTypeRegistry.playS2C().register(RevelationaryPackets.RevelationSync.ID, RevelationaryPackets.RevelationSync.CODEC); + RevelationaryNetworking.register(); AdvancementCriteria.register(); CommandRegistrationCallback.EVENT.register(Commands::register); @@ -48,5 +48,4 @@ public void onInitialize() { logInfo("Common startup completed!"); } - } diff --git a/src/main/java/de/dafuqs/revelationary/RevelationaryClient.java b/src/main/java/de/dafuqs/revelationary/RevelationaryClient.java index 73a4dfd..368dc2e 100644 --- a/src/main/java/de/dafuqs/revelationary/RevelationaryClient.java +++ b/src/main/java/de/dafuqs/revelationary/RevelationaryClient.java @@ -1,13 +1,11 @@ package de.dafuqs.revelationary; -import de.dafuqs.revelationary.networking.RevelationaryS2CPacketReceivers; import net.fabricmc.api.ClientModInitializer; public class RevelationaryClient implements ClientModInitializer { @Override public void onInitializeClient() { - RevelationaryS2CPacketReceivers.register(); } } diff --git a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryPackets.java b/src/main/java/de/dafuqs/revelationary/RevelationaryNetworking.java similarity index 85% rename from src/main/java/de/dafuqs/revelationary/networking/RevelationaryPackets.java rename to src/main/java/de/dafuqs/revelationary/RevelationaryNetworking.java index 25663cb..d289999 100644 --- a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryPackets.java +++ b/src/main/java/de/dafuqs/revelationary/RevelationaryNetworking.java @@ -1,9 +1,14 @@ -package de.dafuqs.revelationary.networking; +package de.dafuqs.revelationary; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import de.dafuqs.revelationary.Revelationary; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.command.argument.BlockArgumentParser; @@ -12,6 +17,7 @@ import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.packet.CustomPayload; import net.minecraft.registry.Registries; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.text.TextCodecs; @@ -19,9 +25,29 @@ import java.util.Map; -public class RevelationaryPackets { - - public static final Identifier REVELATION_SYNC = new Identifier(Revelationary.MOD_ID, "revelation_sync"); +public class RevelationaryNetworking { + public static void register() { + PayloadTypeRegistry.playS2C().register(RevelationSync.ID, RevelationSync.CODEC); + if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) registerPacketReceivers(); + } + + @Environment(EnvType.CLIENT) + public static void registerPacketReceivers() { + ClientPlayNetworking.registerGlobalReceiver(RevelationaryNetworking.RevelationSync.ID, (payload, context) -> { + try { + RevelationRegistry.fromPacket(payload); + } catch (Exception e) { + Revelationary.logError("Error fetching results from sync packet"); + Revelationary.logException(e); + } + ClientRevelationHolder.cloakAll(); + }); + } + + @Environment(EnvType.SERVER) + public static void sendRevelations(ServerPlayerEntity player) { + ServerPlayNetworking.send(player, RevelationRegistry.intoPacket()); + } public record RevelationSync(Object2ObjectOpenHashMap> advToBlockStates, Object2ObjectOpenHashMap blockStateToAdv, @@ -33,7 +59,7 @@ public record RevelationSync(Object2ObjectOpenHashMap cloakedBlockNameTranslations, Object2ObjectOpenHashMap cloakedItemNameTranslations) implements CustomPayload { public static final PacketCodec CODEC = CustomPayload.codecOf(RevelationSync::write, RevelationSync::read); - public static final CustomPayload.Id ID = new Id<>(REVELATION_SYNC); + public static final CustomPayload.Id ID = new Id<>(new Identifier(Revelationary.MOD_ID, "revelation_sync")); private static void writeText(RegistryByteBuf buf, Text text) { TextCodecs.REGISTRY_PACKET_CODEC.encode(buf, text); @@ -66,7 +92,7 @@ public static RevelationSync read(RegistryByteBuf buf) { blockCloaks.putIfAbsent(sourceState.getBlock(), targetState.getBlock()); } catch (CommandSyntaxException e) { Revelationary.logError(e.getMessage()); - }; + } } advToBlockStates.put(advancementIdentifier, advancementStates); } diff --git a/src/main/java/de/dafuqs/revelationary/advancement_criteria/AdvancementCountCriterion.java b/src/main/java/de/dafuqs/revelationary/advancement_criteria/AdvancementCountCriterion.java index f0a8653..367da49 100644 --- a/src/main/java/de/dafuqs/revelationary/advancement_criteria/AdvancementCountCriterion.java +++ b/src/main/java/de/dafuqs/revelationary/advancement_criteria/AdvancementCountCriterion.java @@ -13,7 +13,6 @@ import java.util.*; public class AdvancementCountCriterion extends AbstractCriterion { - public void trigger(ServerPlayerEntity player) { this.trigger(player, (conditions) -> conditions.matches(player)); } @@ -55,5 +54,4 @@ public boolean matches(ServerPlayerEntity serverPlayerEntity) { return this.range == null ? allMatched : this.range.test(matchingAdvancements); } } - } diff --git a/src/main/java/de/dafuqs/revelationary/advancement_criteria/AdvancementGottenCriterion.java b/src/main/java/de/dafuqs/revelationary/advancement_criteria/AdvancementGottenCriterion.java index 183daa0..22c9b4c 100644 --- a/src/main/java/de/dafuqs/revelationary/advancement_criteria/AdvancementGottenCriterion.java +++ b/src/main/java/de/dafuqs/revelationary/advancement_criteria/AdvancementGottenCriterion.java @@ -11,7 +11,6 @@ import java.util.Optional; public class AdvancementGottenCriterion extends AbstractCriterion { - public void trigger(ServerPlayerEntity player, AdvancementEntry advancement) { this.trigger(player, (conditions) -> conditions.matches(advancement)); } @@ -35,5 +34,4 @@ public Identifier getAdvancementIdentifier() { return advancementIdentifier; } } - } diff --git a/src/main/java/de/dafuqs/revelationary/advancement_criteria/HadRevelationCriterion.java b/src/main/java/de/dafuqs/revelationary/advancement_criteria/HadRevelationCriterion.java index 7027804..443da94 100644 --- a/src/main/java/de/dafuqs/revelationary/advancement_criteria/HadRevelationCriterion.java +++ b/src/main/java/de/dafuqs/revelationary/advancement_criteria/HadRevelationCriterion.java @@ -13,7 +13,6 @@ import java.util.Optional; public class HadRevelationCriterion extends AbstractCriterion { - public void trigger(ServerPlayerEntity player, Block block) { this.trigger(player, (conditions) -> conditions.matches(block)); } @@ -42,5 +41,4 @@ public boolean matches(Object object) { } } } - } diff --git a/src/main/java/de/dafuqs/revelationary/api/advancements/AdvancementCriteria.java b/src/main/java/de/dafuqs/revelationary/api/advancements/AdvancementCriteria.java index e80b5f1..7cfaeaf 100644 --- a/src/main/java/de/dafuqs/revelationary/api/advancements/AdvancementCriteria.java +++ b/src/main/java/de/dafuqs/revelationary/api/advancements/AdvancementCriteria.java @@ -4,7 +4,6 @@ import net.minecraft.advancement.criterion.Criteria; public class AdvancementCriteria { - /** * Triggered every time a player gets a new advancement */ @@ -24,5 +23,4 @@ public static void register() { HAD_REVELATION = Criteria.register("revelationary:had_revelation", new HadRevelationCriterion()); ADVANCEMENT_GOTTEN = Criteria.register("revelationary:advancement_gotten", new AdvancementGottenCriterion()); } - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/api/advancements/AdvancementHelper.java b/src/main/java/de/dafuqs/revelationary/api/advancements/AdvancementHelper.java index f294bab..2a89ddd 100644 --- a/src/main/java/de/dafuqs/revelationary/api/advancements/AdvancementHelper.java +++ b/src/main/java/de/dafuqs/revelationary/api/advancements/AdvancementHelper.java @@ -10,7 +10,6 @@ import net.minecraft.util.Identifier; public class AdvancementHelper { - /** * Checks if any player has the advancement. Can be used both server- and clientside * Special cases: @@ -57,5 +56,4 @@ public static boolean hasAdvancement(PlayerEntity playerEntity, Identifier advan public static boolean hasAdvancementClient(Identifier advancementIdentifier) { return ClientAdvancements.hasDone(advancementIdentifier); } - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/api/advancements/ClientAdvancementPacketCallback.java b/src/main/java/de/dafuqs/revelationary/api/advancements/ClientAdvancementPacketCallback.java index 34ec13b..503c489 100644 --- a/src/main/java/de/dafuqs/revelationary/api/advancements/ClientAdvancementPacketCallback.java +++ b/src/main/java/de/dafuqs/revelationary/api/advancements/ClientAdvancementPacketCallback.java @@ -15,7 +15,6 @@ @Environment(EnvType.CLIENT) public interface ClientAdvancementPacketCallback { - /** * Gets called every time advancements get synched from server- to client side * @@ -32,5 +31,4 @@ public interface ClientAdvancementPacketCallback { static void registerCallback(ClientAdvancementPacketCallback callback) { ClientAdvancements.callbacks.add(callback); } - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/api/revelations/CloakedBlock.java b/src/main/java/de/dafuqs/revelationary/api/revelations/CloakedBlock.java index 9bd380a..acf5ed8 100644 --- a/src/main/java/de/dafuqs/revelationary/api/revelations/CloakedBlock.java +++ b/src/main/java/de/dafuqs/revelationary/api/revelations/CloakedBlock.java @@ -9,7 +9,6 @@ import java.util.Map; public abstract class CloakedBlock extends Block implements RevelationAware { - final Block cloakedBlock; public CloakedBlock(Settings settings, Block cloakedBlock) { @@ -29,5 +28,4 @@ public Map getBlockStateCloaks() { public Pair getItemCloak() { return null; } - } diff --git a/src/main/java/de/dafuqs/revelationary/api/revelations/CloakedBlockItem.java b/src/main/java/de/dafuqs/revelationary/api/revelations/CloakedBlockItem.java index b84a57d..b922568 100644 --- a/src/main/java/de/dafuqs/revelationary/api/revelations/CloakedBlockItem.java +++ b/src/main/java/de/dafuqs/revelationary/api/revelations/CloakedBlockItem.java @@ -10,7 +10,6 @@ import java.util.Map; public class CloakedBlockItem extends BlockItem implements RevelationAware { - Identifier cloakAdvancementIdentifier; BlockItem cloakItem; @@ -36,5 +35,4 @@ public Map getBlockStateCloaks() { public Pair getItemCloak() { return new Pair<>(this, cloakItem); } - } diff --git a/src/main/java/de/dafuqs/revelationary/api/revelations/CloakedItem.java b/src/main/java/de/dafuqs/revelationary/api/revelations/CloakedItem.java index f0696b6..6e8f675 100644 --- a/src/main/java/de/dafuqs/revelationary/api/revelations/CloakedItem.java +++ b/src/main/java/de/dafuqs/revelationary/api/revelations/CloakedItem.java @@ -9,7 +9,6 @@ import java.util.Map; public class CloakedItem extends Item implements RevelationAware { - Identifier cloakAdvancementIdentifier; Item cloakItem; @@ -35,5 +34,4 @@ public Map getBlockStateCloaks() { public Pair getItemCloak() { return new Pair<>(this, cloakItem); } - } diff --git a/src/main/java/de/dafuqs/revelationary/api/revelations/RevealingCallback.java b/src/main/java/de/dafuqs/revelationary/api/revelations/RevealingCallback.java index b70d744..d89db7c 100644 --- a/src/main/java/de/dafuqs/revelationary/api/revelations/RevealingCallback.java +++ b/src/main/java/de/dafuqs/revelationary/api/revelations/RevealingCallback.java @@ -11,7 +11,6 @@ * Interface to react to the event of blocks/items getting revealed after getting advancements */ public interface RevealingCallback { - /** * Gets called every time blocks or items get revealed. * The block and item lists are complete and do contain all entries from all mods @@ -45,5 +44,4 @@ static void register(RevealingCallback callback) { static void unregister(RevealingCallback callback) { ClientRevelationHolder.callbacks.remove(callback); } - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/api/revelations/RevelationAware.java b/src/main/java/de/dafuqs/revelationary/api/revelations/RevelationAware.java index 7195ee9..4aa605e 100644 --- a/src/main/java/de/dafuqs/revelationary/api/revelations/RevelationAware.java +++ b/src/main/java/de/dafuqs/revelationary/api/revelations/RevelationAware.java @@ -27,7 +27,6 @@ * Disguised blocks will drop item stacks as if they were the block they are disguised as */ public interface RevelationAware { - /** * The advancement identifier that the player must have to see this block/item */ @@ -127,5 +126,4 @@ static PlayerEntity getLootPlayerEntity(LootContextParameterSet.Builder lootCont } return null; } - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/api/revelations/WorldRendererAccessor.java b/src/main/java/de/dafuqs/revelationary/api/revelations/WorldRendererAccessor.java index e57a70c..225a1e8 100644 --- a/src/main/java/de/dafuqs/revelationary/api/revelations/WorldRendererAccessor.java +++ b/src/main/java/de/dafuqs/revelationary/api/revelations/WorldRendererAccessor.java @@ -6,7 +6,5 @@ * to apply your changes to all visible chunks */ public interface WorldRendererAccessor { - - void rebuildAllChunks(); - + void revelationary$rebuildAllChunks(); } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/config/RevelationaryConfig.java b/src/main/java/de/dafuqs/revelationary/config/RevelationaryConfig.java index 54a780a..a37c2df 100644 --- a/src/main/java/de/dafuqs/revelationary/config/RevelationaryConfig.java +++ b/src/main/java/de/dafuqs/revelationary/config/RevelationaryConfig.java @@ -7,7 +7,6 @@ import java.io.*; public class RevelationaryConfig { - private static final File CONFIG_FILE_PATH = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Revelationary.json"); private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); private static Config CONFIG = null; @@ -59,5 +58,4 @@ private void save() { } } - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/mixin/AbstractBlockMixin.java b/src/main/java/de/dafuqs/revelationary/mixin/AbstractBlockMixin.java index b6f40fe..20627e7 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/AbstractBlockMixin.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/AbstractBlockMixin.java @@ -13,14 +13,13 @@ @Mixin(AbstractBlock.class) public abstract class AbstractBlockMixin { - @Shadow public abstract RegistryKey getLootTableKey(); @Redirect( method = "getDroppedStacks(Lnet/minecraft/block/BlockState;Lnet/minecraft/loot/context/LootContextParameterSet$Builder;)Ljava/util/List;", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/AbstractBlock;getLootTableKey()Lnet/minecraft/registry/RegistryKey;") ) - private RegistryKey spectrum$switchLootTableForCloakedBlock(AbstractBlock instance, BlockState state, LootContextParameterSet.Builder builder) { + private RegistryKey revelationary$switchLootTableForCloakedBlock(AbstractBlock instance, BlockState state, LootContextParameterSet.Builder builder) { BlockState cloakState = RevelationRegistry.getCloak(state); if (cloakState != null) { PlayerEntity lootPlayerEntity = RevelationAware.getLootPlayerEntity(builder); @@ -30,5 +29,4 @@ public abstract class AbstractBlockMixin { } return getLootTableKey(); } - } diff --git a/src/main/java/de/dafuqs/revelationary/mixin/BlockUnbreakingMixin.java b/src/main/java/de/dafuqs/revelationary/mixin/BlockUnbreakingMixin.java index ccf957f..65e8549 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/BlockUnbreakingMixin.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/BlockUnbreakingMixin.java @@ -11,16 +11,14 @@ @Mixin(AbstractBlock.class) public abstract class BlockUnbreakingMixin { - /** * Prevent players from accidentally mining unrevealed blocks. In no way exhaustive. * Cloaked plants will still drop themselves when the block below them is broken, for example */ @Inject(method = "calcBlockBreakingDelta(Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)F", at = @At("HEAD"), cancellable = true) - public void calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos, CallbackInfoReturnable cir) { + public void revelationary$calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos, CallbackInfoReturnable cir) { if(!RevelationRegistry.isVisibleTo(state, player)) { cir.setReturnValue(0F); } } - } diff --git a/src/main/java/de/dafuqs/revelationary/mixin/MixinPlayerManager.java b/src/main/java/de/dafuqs/revelationary/mixin/MixinPlayerManager.java index 71b8373..f9f1fa9 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/MixinPlayerManager.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/MixinPlayerManager.java @@ -1,6 +1,6 @@ package de.dafuqs.revelationary.mixin; -import de.dafuqs.revelationary.networking.RevelationaryS2CPacketSenders; +import de.dafuqs.revelationary.RevelationaryNetworking; import net.minecraft.network.ClientConnection; import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ConnectedClientData; @@ -12,10 +12,8 @@ @Mixin(PlayerManager.class) public class MixinPlayerManager { - @Inject(method = "onPlayerConnect", at = @At(value = "RETURN")) - private void onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) { - RevelationaryS2CPacketSenders.sendRevelations(player); + private void revelationary$onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) { + RevelationaryNetworking.sendRevelations(player); } - } diff --git a/src/main/java/de/dafuqs/revelationary/mixin/PlayerAdvancementTrackerMixin.java b/src/main/java/de/dafuqs/revelationary/mixin/PlayerAdvancementTrackerMixin.java index 454353f..e65b0cc 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/PlayerAdvancementTrackerMixin.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/PlayerAdvancementTrackerMixin.java @@ -17,12 +17,11 @@ @Mixin(PlayerAdvancementTracker.class) public abstract class PlayerAdvancementTrackerMixin { - @Shadow private ServerPlayerEntity owner; @Inject(at = @At("RETURN"), method = "grantCriterion(Lnet/minecraft/advancement/AdvancementEntry;Ljava/lang/String;)Z") - public void triggerAdvancementCriteria(AdvancementEntry advancement, String criterionName, CallbackInfoReturnable cir) { + public void revelationary$triggerAdvancementCriteria(AdvancementEntry advancement, String criterionName, CallbackInfoReturnable cir) { AdvancementProgress advancementProgress = ((PlayerAdvancementTracker) (Object) this).getProgress(advancement); if (advancementProgress.isDone()) { AdvancementCriteria.ADVANCEMENT_GOTTEN.trigger(owner, advancement); @@ -34,5 +33,4 @@ public void triggerAdvancementCriteria(AdvancementEntry advancement, String crit } } } - } diff --git a/src/main/java/de/dafuqs/revelationary/mixin/client/AccessorClientAdvancementManager.java b/src/main/java/de/dafuqs/revelationary/mixin/client/AccessorClientAdvancementManager.java index 6c051f5..4f7e277 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/client/AccessorClientAdvancementManager.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/client/AccessorClientAdvancementManager.java @@ -10,8 +10,6 @@ @Mixin(ClientAdvancementManager.class) public interface AccessorClientAdvancementManager { - @Accessor Map getAdvancementProgresses(); - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/mixin/client/BlockClientMixin.java b/src/main/java/de/dafuqs/revelationary/mixin/client/BlockClientMixin.java index 934e6ed..d3a63f5 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/client/BlockClientMixin.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/client/BlockClientMixin.java @@ -11,13 +11,11 @@ @Mixin(Block.class) public class BlockClientMixin { - @Inject(method = "getName()Lnet/minecraft/text/MutableText;", at = @At("RETURN"), cancellable = true) - private void getCloakedName(CallbackInfoReturnable callbackInfoReturnable) { + private void revelationary$getCloakedName(CallbackInfoReturnable callbackInfoReturnable) { Block thisBlock = (Block) (Object) this; if (ClientRevelationHolder.isCloaked(thisBlock)) { callbackInfoReturnable.setReturnValue(RevelationRegistry.getTranslationString(thisBlock)); } } - } diff --git a/src/main/java/de/dafuqs/revelationary/mixin/client/BlockModelsMixin.java b/src/main/java/de/dafuqs/revelationary/mixin/client/BlockModelsMixin.java index d86dc23..e5b99f8 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/client/BlockModelsMixin.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/client/BlockModelsMixin.java @@ -16,7 +16,6 @@ @Mixin(BlockModels.class) public class BlockModelsMixin { - @Shadow private Map models; @@ -25,12 +24,11 @@ public class BlockModelsMixin { private BakedModelManager modelManager; @Inject(at = @At("HEAD"), method = "getModel", cancellable = true) - private void getModel(BlockState blockState, CallbackInfoReturnable callbackInfoReturnable) { + private void revelationary$getModel(BlockState blockState, CallbackInfoReturnable callbackInfoReturnable) { if (ClientRevelationHolder.isCloaked(blockState)) { BlockState destinationBlockState = ClientRevelationHolder.getCloakTarget(blockState); BakedModel overriddenModel = this.models.getOrDefault(destinationBlockState, modelManager.getMissingModel()); callbackInfoReturnable.setReturnValue(overriddenModel); } } - } diff --git a/src/main/java/de/dafuqs/revelationary/mixin/client/ClientAdvancementManagerMixin.java b/src/main/java/de/dafuqs/revelationary/mixin/client/ClientAdvancementManagerMixin.java index f2f316b..85b4058 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/client/ClientAdvancementManagerMixin.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/client/ClientAdvancementManagerMixin.java @@ -10,7 +10,6 @@ @Mixin(ClientAdvancementManager.class) public abstract class ClientAdvancementManagerMixin { - /** * Intercepts advancement packets sent from server to client * When new advancements are added ClientAdvancements is triggered @@ -20,8 +19,7 @@ public abstract class ClientAdvancementManagerMixin { * @param info Mixin callback info */ @Inject(at = @At("RETURN"), method = "onAdvancements") - public void onAdvancementSync(AdvancementUpdateS2CPacket packet, CallbackInfo info) { + public void revelationary$onAdvancementSync(AdvancementUpdateS2CPacket packet, CallbackInfo info) { ClientAdvancements.onClientPacket(packet); } - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/mixin/client/ItemMixin.java b/src/main/java/de/dafuqs/revelationary/mixin/client/ItemMixin.java index 62a42a6..e2daee2 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/client/ItemMixin.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/client/ItemMixin.java @@ -15,13 +15,11 @@ @Environment(EnvType.CLIENT) @Mixin(Item.class) public abstract class ItemMixin { - @Inject(at = @At("HEAD"), method = "getName(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/text/Text;", cancellable = true) - public void getCloakedName(ItemStack stack, CallbackInfoReturnable callbackInfoReturnable) { + public void revelationary$getCloakedName(ItemStack stack, CallbackInfoReturnable callbackInfoReturnable) { Item thisItem = (Item) (Object) this; if (ClientRevelationHolder.isCloaked(thisItem)) { callbackInfoReturnable.setReturnValue(RevelationRegistry.getTranslationString(thisItem)); } } - } diff --git a/src/main/java/de/dafuqs/revelationary/mixin/client/ItemModelsMixin.java b/src/main/java/de/dafuqs/revelationary/mixin/client/ItemModelsMixin.java index 8699c0d..58aaf59 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/client/ItemModelsMixin.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/client/ItemModelsMixin.java @@ -13,7 +13,6 @@ @Mixin(ItemModels.class) public abstract class ItemModelsMixin { - @Shadow public abstract BakedModel getModel(ItemStack stack); @@ -25,5 +24,4 @@ public abstract class ItemModelsMixin { callbackInfoReturnable.setReturnValue(overriddenModel); } } - } diff --git a/src/main/java/de/dafuqs/revelationary/mixin/client/MinecraftClientMixin.java b/src/main/java/de/dafuqs/revelationary/mixin/client/MinecraftClientMixin.java index afd4068..0c21f32 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/client/MinecraftClientMixin.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/client/MinecraftClientMixin.java @@ -10,10 +10,8 @@ @Mixin(MinecraftClient.class) public abstract class MinecraftClientMixin { - @Inject(at = @At("HEAD"), method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;)V") public void revelationary$onLogout(Screen screen, CallbackInfo info) { ClientAdvancements.playerLogout(); } - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/mixin/client/WorldRendererMixin.java b/src/main/java/de/dafuqs/revelationary/mixin/client/WorldRendererMixin.java index fcaf045..3574d4a 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/client/WorldRendererMixin.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/client/WorldRendererMixin.java @@ -19,7 +19,6 @@ @Environment(EnvType.CLIENT) @Mixin(value = WorldRenderer.class, priority = 900) public abstract class WorldRendererMixin implements WorldRendererAccessor { - @Shadow private BuiltChunkStorage chunks; @@ -30,7 +29,7 @@ public abstract class WorldRendererMixin implements WorldRendererAccessor { * When triggered on client side lets the client redraw ALL chunks * Warning: Costly + LagSpike! */ - public void rebuildAllChunks() { + public void revelationary$rebuildAllChunks() { if (FabricLoader.getInstance().isModLoaded("sodium")) { rebuildAllChunksSodium(); return; @@ -77,5 +76,4 @@ private static void rebuildAllChunksSodium() { } } } - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/mixin/client/WorldRendererMixinAccessor.java b/src/main/java/de/dafuqs/revelationary/mixin/client/WorldRendererMixinAccessor.java index 7dcb7f9..d2f6b0d 100644 --- a/src/main/java/de/dafuqs/revelationary/mixin/client/WorldRendererMixinAccessor.java +++ b/src/main/java/de/dafuqs/revelationary/mixin/client/WorldRendererMixinAccessor.java @@ -6,8 +6,6 @@ @Mixin(WorldRenderer.class) public interface WorldRendererMixinAccessor { - @Invoker("scheduleChunkRender") void invokeScheduleChunkRender(int x, int y, int z, boolean important); - } \ No newline at end of file diff --git a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketReceivers.java b/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketReceivers.java deleted file mode 100644 index f704d79..0000000 --- a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketReceivers.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.dafuqs.revelationary.networking; - -import de.dafuqs.revelationary.ClientRevelationHolder; -import de.dafuqs.revelationary.RevelationRegistry; -import de.dafuqs.revelationary.Revelationary; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; - -public class RevelationaryS2CPacketReceivers { - public static void register() { - ClientPlayNetworking.registerGlobalReceiver(RevelationaryPackets.RevelationSync.ID, (payload, context) -> { - try { - RevelationRegistry.fromPacket(payload); - } catch (Exception e) { - Revelationary.logError("Error fetching results from sync packet"); - e.printStackTrace(); - } - ClientRevelationHolder.cloakAll(); - }); - } -} diff --git a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketSenders.java b/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketSenders.java deleted file mode 100644 index 213522b..0000000 --- a/src/main/java/de/dafuqs/revelationary/networking/RevelationaryS2CPacketSenders.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.dafuqs.revelationary.networking; - -import de.dafuqs.revelationary.RevelationRegistry; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.server.network.ServerPlayerEntity; - -public class RevelationaryS2CPacketSenders { - - public static void sendRevelations(ServerPlayerEntity player) { - ServerPlayNetworking.send(player, RevelationRegistry.intoPacket()); - } - -} From 091d5d8542ac105690adeec18e84d022562417a9 Mon Sep 17 00:00:00 2001 From: Isegrim Date: Sun, 12 May 2024 12:02:09 +0200 Subject: [PATCH 6/6] fix crash in singleplayer --- src/main/java/de/dafuqs/revelationary/RevelationaryClient.java | 1 + .../java/de/dafuqs/revelationary/RevelationaryNetworking.java | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/de/dafuqs/revelationary/RevelationaryClient.java b/src/main/java/de/dafuqs/revelationary/RevelationaryClient.java index 368dc2e..f72ea7c 100644 --- a/src/main/java/de/dafuqs/revelationary/RevelationaryClient.java +++ b/src/main/java/de/dafuqs/revelationary/RevelationaryClient.java @@ -6,6 +6,7 @@ public class RevelationaryClient implements ClientModInitializer { @Override public void onInitializeClient() { + RevelationaryNetworking.registerPacketReceivers(); } } diff --git a/src/main/java/de/dafuqs/revelationary/RevelationaryNetworking.java b/src/main/java/de/dafuqs/revelationary/RevelationaryNetworking.java index d289999..dc0da86 100644 --- a/src/main/java/de/dafuqs/revelationary/RevelationaryNetworking.java +++ b/src/main/java/de/dafuqs/revelationary/RevelationaryNetworking.java @@ -28,7 +28,6 @@ public class RevelationaryNetworking { public static void register() { PayloadTypeRegistry.playS2C().register(RevelationSync.ID, RevelationSync.CODEC); - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) registerPacketReceivers(); } @Environment(EnvType.CLIENT) @@ -44,7 +43,6 @@ public static void registerPacketReceivers() { }); } - @Environment(EnvType.SERVER) public static void sendRevelations(ServerPlayerEntity player) { ServerPlayNetworking.send(player, RevelationRegistry.intoPacket()); }