From a9c1b5328941c9a33e0a65c0bff523a3096cdd51 Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Sat, 29 May 2021 17:33:26 +0200 Subject: [PATCH] Initial 1.17 port --- .github/workflows/build.yml | 6 +- .github/workflows/release.yml | 2 +- build.gradle | 15 +- gradle.properties | 8 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../pb4/polymer/block/VirtualHeadBlock.java | 20 +- .../java/eu/pb4/polymer/item/ItemHelper.java | 210 ++---------------- .../java/eu/pb4/polymer/item/VirtualItem.java | 10 +- .../mixin/block/ChunkDataS2CPacketMixin.java | 12 +- .../mixin/block/ServerChunkManagerMixin.java | 4 +- .../block/ServerPlayNetworkHandlerMixin.java | 2 - .../ServerPlayerInteractionManagerMixin.java | 14 +- .../polymer/mixin/block/WorldChunkMixin.java | 13 +- .../mixin/entity/EntityTrackerEntryMixin.java | 2 +- .../EntityTrackerUpdateS2CPacketMixin.java | 4 +- .../mixin/entity/LivingEntityMixin.java | 4 +- .../mixin/entity/MobSpawnS2CPacketMixin.java | 4 +- .../item/ServerPlayNetworkHandlerMixin.java | 8 +- .../SynchronizeRecipesS2CPacketMixin.java | 4 +- .../java/eu/pb4/polymer/other/FakeWorld.java | 19 +- src/main/resources/fabric.mod.json | 2 +- .../eu/pb4/polymertest/TestPickaxeItem.java | 2 +- src/testmod/resources/fabric.mod.json | 4 +- 23 files changed, 111 insertions(+), 260 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 31c38eec..097404a7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,9 +12,7 @@ jobs: matrix: # Use these Java versions java: [ - 1.8, # Minimum supported by Minecraft - 11, # Current Java LTS - 15 # Latest version + 16 # Latest version ] # and run on both Linux and Windows os: [ubuntu-20.04, windows-latest] @@ -34,7 +32,7 @@ jobs: - name: build run: ./gradlew build - name: capture build artifacts - if: ${{ runner.os == 'Linux' && matrix.java == '11' }} # Only upload artifacts built from LTS java on one OS + if: ${{ runner.os == 'Linux' && matrix.java == '16' }} # Only upload artifacts built from LTS java on one OS uses: actions/upload-artifact@v2 with: name: Artifacts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cbb79ca0..07a7edb0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,7 +24,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 16 - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/build.gradle b/build.gradle index 9d85949c..617cd5ae 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,12 @@ plugins { - id 'fabric-loom' version '0.6-SNAPSHOT' + id 'fabric-loom' version '0.8-SNAPSHOT' id 'maven-publish' } def env = System.getenv() -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 +sourceCompatibility = JavaVersion.VERSION_16 +targetCompatibility = JavaVersion.VERSION_16 archivesBaseName = project.archives_base_name version = project.mod_version @@ -21,7 +21,6 @@ repositories { maven { url "https://jitpack.io" } maven { url = "https://maven.nucleoid.xyz/" } - //maven { url = "https://maven.tomthegeek.ml" } mavenLocal() } @@ -66,7 +65,7 @@ dependencies { exclude module: 'artifice' } - modImplementation include("fr.catcore:server-translations-api:1.4.1") + //modImplementation include("fr.catcore:server-translations-api:1.4.1") // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // You may need to force-disable transitiveness on them. @@ -91,10 +90,8 @@ tasks.withType(JavaCompile).configureEach { // The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too // JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. // We'll use that if it's available, but otherwise we'll use the older option. - def targetVersion = 8 - if (JavaVersion.current().isJava9Compatible()) { - it.options.release = targetVersion - } + + it.options.release = 16 } java { diff --git a/gradle.properties b/gradle.properties index 418d5da1..5c29714d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.16.5 - yarn_mappings=1.16.5+build.6 + minecraft_version=1.17-pre1 + yarn_mappings=1.17-pre1+build.1 loader_version=0.11.3 # Mod Properties - mod_version = 0.0.3 + mod_version = 0.1.0-pre0 maven_group = eu.pb4 archives_base_name = polymer # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.32.5+1.16 + fabric_version=0.34.8+1.17 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 442d9132..0f80bbf5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/eu/pb4/polymer/block/VirtualHeadBlock.java b/src/main/java/eu/pb4/polymer/block/VirtualHeadBlock.java index 0c8251ab..a2a89aba 100644 --- a/src/main/java/eu/pb4/polymer/block/VirtualHeadBlock.java +++ b/src/main/java/eu/pb4/polymer/block/VirtualHeadBlock.java @@ -3,8 +3,8 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtList; import net.minecraft.network.Packet; import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; @@ -28,13 +28,13 @@ default Block getVirtualBlock() { * Creates tag of Skull block entity * * @param state Server-side BlockState - * @return CompoundTag representing client-side + * @return NbtCompound representing client-side */ - default CompoundTag getVirtualHeadSkullOwner(BlockState state) { - CompoundTag skullOwner = new CompoundTag(); - CompoundTag properties = new CompoundTag(); - CompoundTag data = new CompoundTag(); - ListTag textures = new ListTag(); + default NbtCompound getVirtualHeadSkullOwner(BlockState state) { + NbtCompound skullOwner = new NbtCompound(); + NbtCompound properties = new NbtCompound(); + NbtCompound data = new NbtCompound(); + NbtList textures = new NbtList(); textures.add(data); data.putString("Value", ((VirtualHeadBlock) state.getBlock()).getVirtualHeadSkin(state)); @@ -53,8 +53,8 @@ default CompoundTag getVirtualHeadSkullOwner(BlockState state) { * @return A Packet */ default Packet getVirtualHeadPacket(BlockState state, BlockPos pos) { - CompoundTag main = new CompoundTag(); - CompoundTag skullOwner = this.getVirtualHeadSkullOwner(state); + NbtCompound main = new NbtCompound(); + NbtCompound skullOwner = this.getVirtualHeadSkullOwner(state); main.putString("id", "minecraft:skull"); main.put("SkullOwner", skullOwner); main.putInt("x", pos.getX()); diff --git a/src/main/java/eu/pb4/polymer/item/ItemHelper.java b/src/main/java/eu/pb4/polymer/item/ItemHelper.java index aedf4b90..1ea49642 100644 --- a/src/main/java/eu/pb4/polymer/item/ItemHelper.java +++ b/src/main/java/eu/pb4/polymer/item/ItemHelper.java @@ -1,46 +1,30 @@ package eu.pb4.polymer.item; -import com.google.common.collect.Lists; import com.google.common.collect.Multimap; -import com.google.gson.JsonParseException; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import eu.pb4.polymer.interfaces.VirtualObject; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.command.argument.BlockArgumentParser; +import net.minecraft.client.item.TooltipContext; import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; -import net.minecraft.entity.EntityGroup; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.attribute.EntityAttribute; import net.minecraft.entity.attribute.EntityAttributeModifier; -import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtList; +import net.minecraft.nbt.NbtString; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.tag.BlockTags; -import net.minecraft.tag.Tag; import net.minecraft.text.*; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; import org.jetbrains.annotations.Nullable; -import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; public class ItemHelper { - protected static final UUID ATTACK_DAMAGE_MODIFIER_ID = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"); - protected static final UUID ATTACK_SPEED_MODIFIER_ID = UUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3"); - public static final String VIRTUAL_ITEM_ID = "Polymer$itemId"; public static final String REAL_TAG = "Polymer$itemTag"; @@ -52,8 +36,8 @@ public static ItemStack getVirtualItemStack(ItemStack itemStack, ServerPlayerEnt VirtualItem item = (VirtualItem) itemStack.getItem(); return item.getVirtualItemStack(itemStack, player); } else if (itemStack.hasEnchantments()) { - for (net.minecraft.nbt.Tag enchantment : itemStack.getEnchantments()) { - String id = ((CompoundTag) enchantment).getString("id"); + for (NbtElement enchantment : itemStack.getEnchantments()) { + String id = ((NbtCompound) enchantment).getString("id"); Enchantment ench = Registry.ENCHANTMENT.get(Identifier.tryParse(id)); @@ -76,7 +60,7 @@ public static ItemStack getRealItemStack(ItemStack itemStack) { Identifier identifier = Identifier.tryParse(id); Item item = Registry.ITEM.get(identifier); out = new ItemStack(item, itemStack.getCount()); - CompoundTag tag = itemStack.getSubTag(REAL_TAG); + NbtCompound tag = itemStack.getSubTag(REAL_TAG); if (tag != null) { out.setTag(tag); } @@ -117,7 +101,7 @@ public static ItemStack createBasicVirtualItemStack(ItemStack itemStack, @Nullab out.getOrCreateTag().putString(ItemHelper.VIRTUAL_ITEM_ID, Registry.ITEM.getId(itemStack.getItem()).toString()); out.getOrCreateTag().putInt("HideFlags", 127); - ListTag lore = new ListTag(); + NbtList lore = new NbtList(); if (itemStack.getTag() != null) { out.getOrCreateTag().put(ItemHelper.REAL_TAG, itemStack.getTag()); @@ -138,13 +122,13 @@ public static ItemStack createBasicVirtualItemStack(ItemStack itemStack, @Nullab out.addEnchantment(Enchantments.VANISHING_CURSE, 0); } - net.minecraft.nbt.Tag canDestroy = itemStack.getTag().get("CanDestroy"); + NbtElement canDestroy = itemStack.getTag().get("CanDestroy"); if (canDestroy != null) { out.getTag().put("CanDestroy", canDestroy); } - net.minecraft.nbt.Tag canPlaceOn = itemStack.getTag().get("CanPlaceOn"); + NbtElement canPlaceOn = itemStack.getTag().get("CanPlaceOn"); if (canPlaceOn != null) { out.getTag().put("CanPlaceOn", canPlaceOn); @@ -161,14 +145,15 @@ public static ItemStack createBasicVirtualItemStack(ItemStack itemStack, @Nullab } - List tooltip = ItemHelper.buildTooltip(itemStack, player); + List tooltip = itemStack.getTooltip(player, TooltipContext.Default.NORMAL); + tooltip.remove(0); if (itemStack.getItem() instanceof VirtualItem) { - ((VirtualItem) itemStack.getItem()).addTextToTooltip(tooltip, itemStack, player); + ((VirtualItem) itemStack.getItem()).modifyTooltip(tooltip, itemStack, player); } for (Text t : tooltip) { - lore.add(StringTag.of(Text.Serializer.toJson(new LiteralText("").append(t).setStyle(ItemHelper.CLEAN_STYLE)))); + lore.add(NbtString.of(Text.Serializer.toJson(new LiteralText("").append(t).setStyle(ItemHelper.CLEAN_STYLE)))); } if (lore.size() > 0) { @@ -176,169 +161,4 @@ public static ItemStack createBasicVirtualItemStack(ItemStack itemStack, @Nullab } return out; } - - protected static List buildTooltip(ItemStack stack, @Nullable ServerPlayerEntity player) { - List list = Lists.newArrayList(); - int hideFlags = getHideFlags(stack); - - int j; - if (stack.hasTag()) { - if (isSectionHidden(hideFlags, ItemStack.TooltipSection.ENCHANTMENTS)) { - for (int u = 0; u < stack.getEnchantments().size(); ++u) { - CompoundTag compoundTag = stack.getEnchantments().getCompound(hideFlags); - Registry.ENCHANTMENT.getOrEmpty(Identifier.tryParse(compoundTag.getString("id"))).ifPresent((e) -> list.add(e.getName(compoundTag.getInt("lvl")))); - } - } - - if (stack.getTag() != null && stack.getTag().contains("display", 10)) { - CompoundTag compoundTag = stack.getTag().getCompound("display"); - - if (compoundTag.getType("Lore") == 9) { - ListTag listTag = compoundTag.getList("Lore", 8); - - for (j = 0; j < listTag.size(); ++j) { - String string = listTag.getString(j); - - try { - MutableText mutableText2 = Text.Serializer.fromJson(string); - if (mutableText2 != null) { - list.add(Texts.setStyleIfAbsent(mutableText2, Style.EMPTY.withItalic(true).withColor(Formatting.DARK_PURPLE))); - } - } catch (JsonParseException var19) { - compoundTag.remove("Lore"); - } - } - } - } - } - - int l; - if (isSectionHidden(hideFlags, ItemStack.TooltipSection.MODIFIERS)) { - EquipmentSlot[] var20 = EquipmentSlot.values(); - l = var20.length; - - for (j = 0; j < l; ++j) { - EquipmentSlot equipmentSlot = var20[j]; - Multimap multimap = stack.getAttributeModifiers(equipmentSlot); - if (!multimap.isEmpty()) { - list.add(LiteralText.EMPTY); - list.add((new TranslatableText("item.modifiers." + equipmentSlot.getName())).formatted(Formatting.GRAY)); - - for (Map.Entry entry : multimap.entries()) { - EntityAttributeModifier entityAttributeModifier = entry.getValue(); - double value = entityAttributeModifier.getValue(); - boolean bl = false; - - if (player != null) { - if (entityAttributeModifier.getId().equals(ATTACK_DAMAGE_MODIFIER_ID)) { - value += player.getAttributeBaseValue(EntityAttributes.GENERIC_ATTACK_DAMAGE); - value += EnchantmentHelper.getAttackDamage(stack, EntityGroup.DEFAULT); - bl = true; - } else if (entityAttributeModifier.getId().equals(ATTACK_SPEED_MODIFIER_ID)) { - value += player.getAttributeBaseValue(EntityAttributes.GENERIC_ATTACK_SPEED); - bl = true; - } - } else { - if (entityAttributeModifier.getId().equals(ATTACK_DAMAGE_MODIFIER_ID)) { - value += 1; - value += EnchantmentHelper.getAttackDamage(stack, EntityGroup.DEFAULT); - bl = true; - } else if (entityAttributeModifier.getId().equals(ATTACK_SPEED_MODIFIER_ID)) { - value += 4; - bl = true; - } - } - - double g; - if (entityAttributeModifier.getOperation() != EntityAttributeModifier.Operation.MULTIPLY_BASE && entityAttributeModifier.getOperation() != EntityAttributeModifier.Operation.MULTIPLY_TOTAL) { - if ((entry.getKey()).equals(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE)) { - g = value * 10.0D; - } else { - g = value; - } - } else { - g = value * 100.0D; - } - - if (bl) { - list.add((new LiteralText(" ")).append(new TranslatableText("attribute.modifier.equals." + entityAttributeModifier.getOperation().getId(), ItemStack.MODIFIER_FORMAT.format(g), new TranslatableText(entry.getKey().getTranslationKey()))).formatted(Formatting.DARK_GREEN)); - } else if (value > 0.0D) { - list.add((new TranslatableText("attribute.modifier.plus." + entityAttributeModifier.getOperation().getId(), ItemStack.MODIFIER_FORMAT.format(g), new TranslatableText(entry.getKey().getTranslationKey()))).formatted(Formatting.BLUE)); - } else if (value < 0.0D) { - g *= -1.0D; - list.add((new TranslatableText("attribute.modifier.take." + entityAttributeModifier.getOperation().getId(), ItemStack.MODIFIER_FORMAT.format(g), new TranslatableText(entry.getKey().getTranslationKey()))).formatted(Formatting.RED)); - } - } - } - } - } - - if (stack.getTag() != null) { - if (isSectionHidden(hideFlags, ItemStack.TooltipSection.UNBREAKABLE) && stack.getTag().getBoolean("Unbreakable")) { - list.add((new TranslatableText("item.unbreakable")).formatted(Formatting.BLUE)); - } - - ListTag listTag3; - if (isSectionHidden(hideFlags, ItemStack.TooltipSection.CAN_DESTROY) && stack.getTag().contains("CanDestroy", 9)) { - listTag3 = stack.getTag().getList("CanDestroy", 8); - if (!listTag3.isEmpty()) { - list.add(LiteralText.EMPTY); - list.add((new TranslatableText("item.canBreak")).formatted(Formatting.GRAY)); - - for (l = 0; l < listTag3.size(); ++l) { - list.addAll(parseBlockTag(listTag3.getString(l))); - } - } - } - - if (isSectionHidden(hideFlags, ItemStack.TooltipSection.CAN_PLACE) && stack.getTag().contains("CanPlaceOn", 9)) { - listTag3 = stack.getTag().getList("CanPlaceOn", 8); - if (!listTag3.isEmpty()) { - list.add(LiteralText.EMPTY); - list.add((new TranslatableText("item.canPlace")).formatted(Formatting.GRAY)); - - for (l = 0; l < listTag3.size(); ++l) { - list.addAll(parseBlockTag(listTag3.getString(l))); - } - } - } - } - return list; - } - - private static Collection parseBlockTag(String tag) { - try { - BlockArgumentParser blockArgumentParser = (new BlockArgumentParser(new StringReader(tag), true)).parse(true); - BlockState blockState = blockArgumentParser.getBlockState(); - Identifier identifier = blockArgumentParser.getTagId(); - boolean bl = blockState != null; - boolean bl2 = identifier != null; - if (bl || bl2) { - if (bl) { - return Lists.newArrayList(new Text[]{blockState.getBlock().getName().formatted(Formatting.DARK_GRAY)}); - } - - Tag tag2 = BlockTags.getTagGroup().getTag(identifier); - if (tag2 != null) { - Collection collection = tag2.values(); - if (!collection.isEmpty()) { - return collection.stream().map(Block::getName).map((text) -> text.formatted(Formatting.DARK_GRAY)).collect(Collectors.toList()); - } - } - } - } catch (CommandSyntaxException var8) { - return Lists.newArrayList(new Text[]{(new LiteralText("missingno")).formatted(Formatting.DARK_GRAY)}); - } - - return Lists.newArrayList(new Text[]{(new LiteralText("missingno")).formatted(Formatting.DARK_GRAY)}); - } - - - private static boolean isSectionHidden(int flags, ItemStack.TooltipSection tooltipSection) { - return (flags & tooltipSection.getFlag()) == 0; - } - - public static int getHideFlags(ItemStack stack) { - return stack.getTag() != null && stack.getTag().contains("HideFlags", 99) ? stack.getTag().getInt("HideFlags") : 0; - } } diff --git a/src/main/java/eu/pb4/polymer/item/VirtualItem.java b/src/main/java/eu/pb4/polymer/item/VirtualItem.java index 30392306..d75ab633 100644 --- a/src/main/java/eu/pb4/polymer/item/VirtualItem.java +++ b/src/main/java/eu/pb4/polymer/item/VirtualItem.java @@ -36,9 +36,17 @@ default ItemStack getVirtualItemStack(ItemStack itemStack, @Nullable ServerPlaye /** * This method allows to add (or modify) tooltip text * - * @param tooltip Currient tooltip text + * @param tooltip Current tooltip text * @param stack Server-side ItemStack * @param player Target player */ + default void modifyTooltip(List tooltip, ItemStack stack, @Nullable ServerPlayerEntity player) { + this.addTextToTooltip(tooltip, stack, player); + } + + /** + * Use modifyTooltip instead! + */ + @Deprecated(forRemoval = true) default void addTextToTooltip(List tooltip, ItemStack stack, @Nullable ServerPlayerEntity player) {} } \ No newline at end of file diff --git a/src/main/java/eu/pb4/polymer/mixin/block/ChunkDataS2CPacketMixin.java b/src/main/java/eu/pb4/polymer/mixin/block/ChunkDataS2CPacketMixin.java index 4c068b2f..8f6fbdf7 100644 --- a/src/main/java/eu/pb4/polymer/mixin/block/ChunkDataS2CPacketMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/block/ChunkDataS2CPacketMixin.java @@ -2,7 +2,7 @@ import eu.pb4.polymer.PolymerMod; import eu.pb4.polymer.interfaces.ChunkDataS2CPacketInterface; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; import net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket; import net.minecraft.world.chunk.WorldChunk; import org.spongepowered.asm.mixin.Mixin; @@ -19,14 +19,14 @@ public class ChunkDataS2CPacketMixin implements ChunkDataS2CPacketInterface { @Unique private WorldChunk worldChunk; - @Inject(method = "(Lnet/minecraft/world/chunk/WorldChunk;I)V", at = @At("TAIL")) - private void storeWorldChunk(WorldChunk chunk, int includedSectionsMask, CallbackInfo ci) { + @Inject(method = "(Lnet/minecraft/world/chunk/WorldChunk;)V", at = @At("TAIL")) + private void storeWorldChunk(WorldChunk chunk, CallbackInfo ci) { this.worldChunk = chunk; } - @Redirect(method = "(Lnet/minecraft/world/chunk/WorldChunk;I)V", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z")) - private boolean dontAddVirtualBlockEntities(List list, Object e) { - CompoundTag tag = (CompoundTag) e; + @Redirect(method = "(Lnet/minecraft/world/chunk/WorldChunk;)V", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z")) + private boolean dontAddVirtualBlockEntities(List list, Object e) { + NbtCompound tag = (NbtCompound) e; if (!PolymerMod.isVirtualBlockEntity(tag.getString("Id"))) { return list.add(tag); diff --git a/src/main/java/eu/pb4/polymer/mixin/block/ServerChunkManagerMixin.java b/src/main/java/eu/pb4/polymer/mixin/block/ServerChunkManagerMixin.java index 8d380899..560ab8d7 100644 --- a/src/main/java/eu/pb4/polymer/mixin/block/ServerChunkManagerMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/block/ServerChunkManagerMixin.java @@ -86,12 +86,12 @@ private void sendLightUpdates(LightType type, ChunkSectionPos pos, CallbackInfo } if (sendUpdate) { - Packet packet = new LightUpdateS2CPacket(pos.toChunkPos(), this.getLightingProvider(), true); + //Packet packet = new LightUpdateS2CPacket(pos.toChunkPos(), this.getLightingProvider(), true); Set players = this.threadedAnvilChunkStorage.getPlayersWatchingChunk(pos.toChunkPos(), false).collect(Collectors.toSet()); if (players.size() > 0) { this.lastUpdates.put(pos.toChunkPos(), System.currentTimeMillis()); for (ServerPlayerEntity player : players) { - player.networkHandler.sendPacket(packet); + //player.networkHandler.sendPacket(packet); } } } diff --git a/src/main/java/eu/pb4/polymer/mixin/block/ServerPlayNetworkHandlerMixin.java b/src/main/java/eu/pb4/polymer/mixin/block/ServerPlayNetworkHandlerMixin.java index dee928df..17d5d406 100644 --- a/src/main/java/eu/pb4/polymer/mixin/block/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/block/ServerPlayNetworkHandlerMixin.java @@ -36,8 +36,6 @@ public abstract class ServerPlayNetworkHandlerMixin { @Shadow public ServerPlayerEntity player; - @Shadow public abstract void sendPacket(Packet packet); - @Inject(method = "sendPacket(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", at = @At("TAIL")) private void catchBlockUpdates(Packet packet, GenericFutureListener> listener, CallbackInfo cb) { try { diff --git a/src/main/java/eu/pb4/polymer/mixin/block/ServerPlayerInteractionManagerMixin.java b/src/main/java/eu/pb4/polymer/mixin/block/ServerPlayerInteractionManagerMixin.java index 09752098..81f2161f 100644 --- a/src/main/java/eu/pb4/polymer/mixin/block/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/block/ServerPlayerInteractionManagerMixin.java @@ -76,12 +76,12 @@ private void onUpdateBreakStatus(BlockState state, BlockPos pos, int i, Callback private void packetReceivedInject(BlockPos pos, PlayerActionC2SPacket.Action action, Direction direction, int worldHeight, CallbackInfo ci) { if (this.player.getServerWorld().getBlockState(pos).getBlock() instanceof VirtualBlock || this.player.getMainHandStack().getItem() instanceof VirtualItem) { if (action == PlayerActionC2SPacket.Action.START_DESTROY_BLOCK) { - this.player.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(this.player.getEntityId(), new StatusEffectInstance(StatusEffects.MINING_FATIGUE, 20, -1, true, false))); + this.player.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(this.player.getId(), new StatusEffectInstance(StatusEffects.MINING_FATIGUE, 20, -1, true, false))); } else if (action == PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK) { - this.player.networkHandler.sendPacket(new RemoveEntityStatusEffectS2CPacket(this.player.getEntityId(), StatusEffects.MINING_FATIGUE)); + this.player.networkHandler.sendPacket(new RemoveEntityStatusEffectS2CPacket(this.player.getId(), StatusEffects.MINING_FATIGUE)); if (this.player.hasStatusEffect(StatusEffects.MINING_FATIGUE)) { StatusEffectInstance effectInstance = player.getStatusEffect(StatusEffects.MINING_FATIGUE); - this.player.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(this.player.getEntityId(), effectInstance)); + this.player.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(this.player.getId(), effectInstance)); } this.player.networkHandler.sendPacket(new BlockBreakingProgressS2CPacket(-1, pos, -1)); } @@ -100,15 +100,15 @@ private void enforceBlockBreakingCooldown(BlockPos pos, PlayerActionC2SPacket.Ac @Inject(method = "finishMining", at = @At("HEAD")) private void clearEffects(BlockPos pos, PlayerActionC2SPacket.Action action, String reason, CallbackInfo ci) { if (this.player.getServerWorld().getBlockState(pos).getBlock() instanceof VirtualBlock || this.player.getMainHandStack().getItem() instanceof VirtualItem) { - this.player.networkHandler.sendPacket(new RemoveEntityStatusEffectS2CPacket(player.getEntityId(), StatusEffects.MINING_FATIGUE)); + this.player.networkHandler.sendPacket(new RemoveEntityStatusEffectS2CPacket(player.getId(), StatusEffects.MINING_FATIGUE)); if (this.player.hasStatusEffect(StatusEffects.MINING_FATIGUE)) { StatusEffectInstance effectInstance = this.player.getStatusEffect(StatusEffects.MINING_FATIGUE); - this.player.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(this.player.getEntityId(), effectInstance)); + this.player.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(this.player.getId(), effectInstance)); } } } - @Redirect(method = "processBlockBreakingAction", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;warn(Ljava/lang/String;)V")) - private void noOneCaresAboutMismatch(Logger logger, String message) {} + @Redirect(method = "processBlockBreakingAction", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V")) + private void noOneCaresAboutMismatch(Logger logger, String message, Object p0, Object p1) {} } \ No newline at end of file diff --git a/src/main/java/eu/pb4/polymer/mixin/block/WorldChunkMixin.java b/src/main/java/eu/pb4/polymer/mixin/block/WorldChunkMixin.java index a9f7fe33..ac6be7cc 100644 --- a/src/main/java/eu/pb4/polymer/mixin/block/WorldChunkMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/block/WorldChunkMixin.java @@ -6,6 +6,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.fluid.Fluid; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.TickScheduler; @@ -47,10 +48,18 @@ private void virtualHeadBlocksInit1(World world, ChunkPos pos, BiomeArray biomes } @Inject( - method = "(Lnet/minecraft/world/World;Lnet/minecraft/world/chunk/ProtoChunk;)V", + method = "(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/ProtoChunk;Ljava/util/function/Consumer;)V", at = @At("TAIL") ) - private void virtualBlocksInit2(World world, ProtoChunk protoChunk, CallbackInfo info) { + private void virtualBlocksInit2(ServerWorld serverWorld, ProtoChunk protoChunk, Consumer consumer, CallbackInfo ci) { + this.generateVirtualBlockSet(); + } + + @Inject( + method = "(Lnet/minecraft/world/World;Lnet/minecraft/util/math/ChunkPos;Lnet/minecraft/world/biome/source/BiomeArray;)V", + at = @At("TAIL") + ) + private void virtualBlocksInit3(World world, ChunkPos pos, BiomeArray biomes, CallbackInfo ci) { this.generateVirtualBlockSet(); } diff --git a/src/main/java/eu/pb4/polymer/mixin/entity/EntityTrackerEntryMixin.java b/src/main/java/eu/pb4/polymer/mixin/entity/EntityTrackerEntryMixin.java index ff4476b9..535d93b5 100644 --- a/src/main/java/eu/pb4/polymer/mixin/entity/EntityTrackerEntryMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/entity/EntityTrackerEntryMixin.java @@ -43,7 +43,7 @@ private void sendVirtualStuff(Consumer> sender, CallbackInfo ci) { } List> list = ((VirtualEntity) this.entity).getVirtualEntityEquipment(map); - sender.accept(new EntityEquipmentUpdateS2CPacket(this.entity.getEntityId(), list)); + sender.accept(new EntityEquipmentUpdateS2CPacket(this.entity.getId(), list)); ((VirtualEntity) this.entity).sendPacketsAfterCreation(sender); } } catch (Exception e) { diff --git a/src/main/java/eu/pb4/polymer/mixin/entity/EntityTrackerUpdateS2CPacketMixin.java b/src/main/java/eu/pb4/polymer/mixin/entity/EntityTrackerUpdateS2CPacketMixin.java index 14813386..a748ba3c 100644 --- a/src/main/java/eu/pb4/polymer/mixin/entity/EntityTrackerUpdateS2CPacketMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/entity/EntityTrackerUpdateS2CPacketMixin.java @@ -6,6 +6,7 @@ import net.minecraft.entity.data.DataTracker; import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -16,7 +17,8 @@ @Mixin(EntityTrackerUpdateS2CPacket.class) public class EntityTrackerUpdateS2CPacketMixin { - @Shadow private List> trackedValues; + @Shadow @Mutable + private List> trackedValues; @Inject(method = "(ILnet/minecraft/entity/data/DataTracker;Z)V", at = @At("TAIL")) private void removeInvalidEntries(int id, DataTracker tracker, boolean forceUpdateAll, CallbackInfo ci) { diff --git a/src/main/java/eu/pb4/polymer/mixin/entity/LivingEntityMixin.java b/src/main/java/eu/pb4/polymer/mixin/entity/LivingEntityMixin.java index a7c0ab16..477a60e0 100644 --- a/src/main/java/eu/pb4/polymer/mixin/entity/LivingEntityMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/entity/LivingEntityMixin.java @@ -21,11 +21,11 @@ @Mixin(LivingEntity.class) public abstract class LivingEntityMixin extends Entity { - @Inject(method = "method_30123", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getChunkManager()Lnet/minecraft/server/world/ServerChunkManager;"), cancellable = true) + @Inject(method = "setEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;getChunkManager()Lnet/minecraft/server/world/ServerChunkManager;"), cancellable = true) private void sendVirtualInventory(Map map, CallbackInfo ci) { if (this instanceof VirtualEntity) { List> list = ((VirtualEntity) this).getVirtualEntityEquipment(map); - ((ServerWorld)this.world).getChunkManager().sendToOtherNearbyPlayers(this, new EntityEquipmentUpdateS2CPacket(this.getEntityId(), list)); + ((ServerWorld)this.world).getChunkManager().sendToOtherNearbyPlayers(this, new EntityEquipmentUpdateS2CPacket(this.getId(), list)); ci.cancel(); } } diff --git a/src/main/java/eu/pb4/polymer/mixin/entity/MobSpawnS2CPacketMixin.java b/src/main/java/eu/pb4/polymer/mixin/entity/MobSpawnS2CPacketMixin.java index cd5683e3..dc61bc2d 100644 --- a/src/main/java/eu/pb4/polymer/mixin/entity/MobSpawnS2CPacketMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/entity/MobSpawnS2CPacketMixin.java @@ -5,6 +5,7 @@ import net.minecraft.network.packet.s2c.play.MobSpawnS2CPacket; import net.minecraft.util.registry.Registry; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -12,7 +13,8 @@ @Mixin(value = MobSpawnS2CPacket.class, priority = 500) public class MobSpawnS2CPacketMixin { - @Shadow private int entityTypeId; + @Shadow @Mutable + private int entityTypeId; @Inject(method = "(Lnet/minecraft/entity/LivingEntity;)V", at = @At(value = "TAIL")) private void replaceWithVirtual(LivingEntity entity, CallbackInfo ci) { diff --git a/src/main/java/eu/pb4/polymer/mixin/item/ServerPlayNetworkHandlerMixin.java b/src/main/java/eu/pb4/polymer/mixin/item/ServerPlayNetworkHandlerMixin.java index 05c28a54..f3d1a642 100644 --- a/src/main/java/eu/pb4/polymer/mixin/item/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/item/ServerPlayNetworkHandlerMixin.java @@ -39,7 +39,7 @@ private void resendToolIfItsBlockClientSide(PlayerInteractBlockC2SPacket packet, ItemStack itemStack = this.player.getStackInHand(packet.getHand()); if (itemStack.getItem() instanceof VirtualItem && (((VirtualItem) itemStack.getItem()).getVirtualItem() instanceof BlockItem || ((VirtualItem) itemStack.getItem()).getVirtualItem() instanceof BucketItem)) { - this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId, packet.getHand() == Hand.MAIN_HAND ? 36 + this.player.inventory.selectedSlot : 45, itemStack)); + this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId, packet.getHand() == Hand.MAIN_HAND ? 36 + this.player.getInventory().selectedSlot : 45, itemStack)); } } @@ -67,7 +67,7 @@ private void updateMoreBlocks(PlayerInteractBlockC2SPacket packet, CallbackInfo @Inject(method = "onClickSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;updateLastActionTime()V", shift = At.Shift.AFTER)) private void storeSomeData(ClickSlotC2SPacket packet, CallbackInfo ci) { if (this.player.currentScreenHandler == this.player.playerScreenHandler) { - for (ItemStack stack : this.player.inventory.armor) { + for (ItemStack stack : this.player.getInventory().armor) { armorItems.add(stack.copy()); } } @@ -77,7 +77,7 @@ private void storeSomeData(ClickSlotC2SPacket packet, CallbackInfo ci) { private void resendArmorIfNeeded(ClickSlotC2SPacket packet, CallbackInfo ci) { if (this.player.currentScreenHandler == this.player.playerScreenHandler && packet.getSlot() != -999) { int x = 0; - for (ItemStack stack : this.player.inventory.armor) { + for (ItemStack stack : this.player.getInventory().armor) { if (stack.getItem() instanceof VirtualItem && !ItemStack.areEqual(this.armorItems.get(x), stack)) { this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId, 8 - x, @@ -90,7 +90,7 @@ private void resendArmorIfNeeded(ClickSlotC2SPacket packet, CallbackInfo ci) { this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(-1, 0, - this.player.inventory.getCursorStack())); + this.player.currentScreenHandler.getCursorStack())); return; } x++; diff --git a/src/main/java/eu/pb4/polymer/mixin/other/SynchronizeRecipesS2CPacketMixin.java b/src/main/java/eu/pb4/polymer/mixin/other/SynchronizeRecipesS2CPacketMixin.java index cf699b4a..f4f17711 100644 --- a/src/main/java/eu/pb4/polymer/mixin/other/SynchronizeRecipesS2CPacketMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/other/SynchronizeRecipesS2CPacketMixin.java @@ -5,6 +5,7 @@ import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket; import net.minecraft.recipe.Recipe; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -20,7 +21,8 @@ @Mixin(SynchronizeRecipesS2CPacket.class) public class SynchronizeRecipesS2CPacketMixin { - @Shadow private List> recipes; + @Shadow @Mutable + private List> recipes; @Inject(method = "write", at = @At("HEAD")) public void onWrite(PacketByteBuf buf, CallbackInfo callbackInfo) { diff --git a/src/main/java/eu/pb4/polymer/other/FakeWorld.java b/src/main/java/eu/pb4/polymer/other/FakeWorld.java index 0f419764..a47912b3 100644 --- a/src/main/java/eu/pb4/polymer/other/FakeWorld.java +++ b/src/main/java/eu/pb4/polymer/other/FakeWorld.java @@ -21,6 +21,8 @@ import net.minecraft.world.biome.Biome; import net.minecraft.world.chunk.ChunkManager; import net.minecraft.world.dimension.DimensionType; +import net.minecraft.world.entity.EntityLookup; +import net.minecraft.world.event.GameEvent; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -49,6 +51,11 @@ public void playSoundFromEntity(@Nullable PlayerEntity player, Entity entity, So } + @Override + public String asString() { + return "FakeWorld!"; + } + @Nullable @Override public Entity getEntityById(int id) { @@ -62,7 +69,7 @@ public MapState getMapState(String id) { } @Override - public void putMapState(MapState mapState) { + public void putMapState(String id, MapState state) { } @@ -91,6 +98,11 @@ public TagManager getTagManager() { return null; } + @Override + protected EntityLookup getEntityLookup() { + return null; + } + @Override public TickScheduler getBlockTickScheduler() { return null; @@ -111,6 +123,11 @@ public void syncWorldEvent(@Nullable PlayerEntity player, int eventId, BlockPos } + @Override + public void emitGameEvent(@Nullable Entity entity, GameEvent event, BlockPos pos) { + + } + @Override public DynamicRegistryManager getRegistryManager() { return null; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 029730d2..f59a1973 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -28,6 +28,6 @@ "depends": { "fabricloader": ">=0.7.4", "fabric": "*", - "minecraft": "1.16.x" + "minecraft": "1.17.x" } } diff --git a/src/testmod/java/eu/pb4/polymertest/TestPickaxeItem.java b/src/testmod/java/eu/pb4/polymertest/TestPickaxeItem.java index b94484d5..567c62fc 100644 --- a/src/testmod/java/eu/pb4/polymertest/TestPickaxeItem.java +++ b/src/testmod/java/eu/pb4/polymertest/TestPickaxeItem.java @@ -19,7 +19,7 @@ public Item getVirtualItem() { } @Override - public void addTextToTooltip(List tooltip, ItemStack stack, ServerPlayerEntity player) { + public void modifyTooltip(List tooltip, ItemStack stack, ServerPlayerEntity player) { tooltip.add(0, new LiteralText("Hello")); tooltip.add(new LiteralText("World!")); } diff --git a/src/testmod/resources/fabric.mod.json b/src/testmod/resources/fabric.mod.json index 03326ca3..ce8e21af 100644 --- a/src/testmod/resources/fabric.mod.json +++ b/src/testmod/resources/fabric.mod.json @@ -26,9 +26,7 @@ ], "depends": { - "fabricloader": ">=0.7.4", - "fabric": "*", - "minecraft": "1.16.x" + }, "suggests": { "another-mod": "*"