From 232c051526fb77d6b07557e383511f4096248ba1 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Thu, 4 May 2023 18:47:22 +0100 Subject: [PATCH] Update to latest Fabric - Use Fabric FakePlayer class - Remove redundant explosion accessor --- gradle/libs.versions.toml | 4 +- .../mixin/ExplosionAccessor.java | 19 -- .../shared/turtle/blocks/TurtleBlock.java | 3 +- .../main/resources/computercraft.mixins.json | 3 +- .../shared/platform/FakeNetHandler.java | 245 ------------------ .../shared/platform/FakePlayer.java | 49 +--- 6 files changed, 7 insertions(+), 316 deletions(-) delete mode 100644 projects/common/src/main/java/dan200/computercraft/mixin/ExplosionAccessor.java delete mode 100644 projects/fabric/src/main/java/dan200/computercraft/shared/platform/FakeNetHandler.java diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9e8596c70..6b9ff91ed 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,8 +7,8 @@ # Minecraft # MC version is specified in gradle.properties, as we need that in settings.gradle. # Remember to update corresponding versions in fabric.mod.json/mods.toml -fabric-api = "0.78.0+1.19.4" -fabric-loader = "0.14.17" +fabric-api = "0.80.0+1.19.4" +fabric-loader = "0.14.19" forge = "45.0.42" forgeSpi = "6.0.0" mixin = "0.8.5" diff --git a/projects/common/src/main/java/dan200/computercraft/mixin/ExplosionAccessor.java b/projects/common/src/main/java/dan200/computercraft/mixin/ExplosionAccessor.java deleted file mode 100644 index 12f742a96..000000000 --- a/projects/common/src/main/java/dan200/computercraft/mixin/ExplosionAccessor.java +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-FileCopyrightText: 2022 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.mixin; - -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.Explosion; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import javax.annotation.Nullable; - -@Mixin(Explosion.class) -public interface ExplosionAccessor { - @Nullable - @Accessor("source") - Entity computercraft$getExploder(); -} diff --git a/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlock.java b/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlock.java index 7c7f6774a..59c3f0c99 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlock.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlock.java @@ -6,7 +6,6 @@ package dan200.computercraft.shared.turtle.blocks; import dan200.computercraft.annotations.ForgeOverride; import dan200.computercraft.api.turtle.TurtleSide; -import dan200.computercraft.mixin.ExplosionAccessor; import dan200.computercraft.shared.computer.blocks.AbstractComputerBlock; import dan200.computercraft.shared.computer.blocks.AbstractComputerBlockEntity; import dan200.computercraft.shared.computer.core.ComputerFamily; @@ -148,7 +147,7 @@ public class TurtleBlock extends AbstractComputerBlock implem @ForgeOverride public float getExplosionResistance(BlockState state, BlockGetter world, BlockPos pos, Explosion explosion) { - var exploder = ((ExplosionAccessor) explosion).computercraft$getExploder(); + var exploder = explosion.getDirectSourceEntity(); if (getFamily() == ComputerFamily.ADVANCED || exploder instanceof LivingEntity || exploder instanceof AbstractHurtingProjectile) { return 2000; } diff --git a/projects/common/src/main/resources/computercraft.mixins.json b/projects/common/src/main/resources/computercraft.mixins.json index 04205823f..6b3dd4a61 100644 --- a/projects/common/src/main/resources/computercraft.mixins.json +++ b/projects/common/src/main/resources/computercraft.mixins.json @@ -7,8 +7,7 @@ "defaultRequire": 1 }, "mixins": [ - "CacheUpdaterMixin", - "ExplosionAccessor" + "CacheUpdaterMixin" ], "refmap": "computercraft.refmap.json" } diff --git a/projects/fabric/src/main/java/dan200/computercraft/shared/platform/FakeNetHandler.java b/projects/fabric/src/main/java/dan200/computercraft/shared/platform/FakeNetHandler.java deleted file mode 100644 index ddbe5f737..000000000 --- a/projects/fabric/src/main/java/dan200/computercraft/shared/platform/FakeNetHandler.java +++ /dev/null @@ -1,245 +0,0 @@ -// SPDX-FileCopyrightText: 2022 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.shared.platform; - -import net.minecraft.network.Connection; -import net.minecraft.network.PacketSendListener; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.PlayerChatMessage; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.PacketFlow; -import net.minecraft.network.protocol.game.*; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; - -import javax.annotation.Nullable; - -class FakeNetHandler extends ServerGamePacketListenerImpl { - protected static final Connection CONNECTION = new Connection(PacketFlow.CLIENTBOUND); - - FakeNetHandler(ServerPlayer player) { - super(player.getLevel().getServer(), CONNECTION, player); - } - - @Override - public void tick() { - } - - @Override - public void resetPosition() { - } - - @Override - public void disconnect(Component textComponent) { - } - - @Override - public void handlePlayerInput(ServerboundPlayerInputPacket packet) { - } - - @Override - public void handleMoveVehicle(ServerboundMoveVehiclePacket packet) { - } - - @Override - public void handleAcceptTeleportPacket(ServerboundAcceptTeleportationPacket packet) { - } - - @Override - public void handleRecipeBookSeenRecipePacket(ServerboundRecipeBookSeenRecipePacket packet) { - } - - @Override - public void handleRecipeBookChangeSettingsPacket(ServerboundRecipeBookChangeSettingsPacket packet) { - } - - @Override - public void handleSeenAdvancements(ServerboundSeenAdvancementsPacket packet) { - } - - @Override - public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket packet) { - } - - @Override - public void handleSetCommandBlock(ServerboundSetCommandBlockPacket packet) { - } - - @Override - public void handleSetCommandMinecart(ServerboundSetCommandMinecartPacket packet) { - } - - @Override - public void handlePickItem(ServerboundPickItemPacket packet) { - } - - @Override - public void handleRenameItem(ServerboundRenameItemPacket packet) { - } - - @Override - public void handleSetBeaconPacket(ServerboundSetBeaconPacket packet) { - } - - @Override - public void handleSetStructureBlock(ServerboundSetStructureBlockPacket packet) { - } - - @Override - public void handleSetJigsawBlock(ServerboundSetJigsawBlockPacket packet) { - } - - @Override - public void handleJigsawGenerate(ServerboundJigsawGeneratePacket packet) { - } - - @Override - public void handleSelectTrade(ServerboundSelectTradePacket packet) { - } - - @Override - public void handleEditBook(ServerboundEditBookPacket packet) { - } - - @Override - public void handleEntityTagQuery(ServerboundEntityTagQuery packet) { - } - - @Override - public void handleBlockEntityTagQuery(ServerboundBlockEntityTagQuery packet) { - } - - @Override - public void handleMovePlayer(ServerboundMovePlayerPacket packet) { - } - - @Override - public void handlePlayerAction(ServerboundPlayerActionPacket packet) { - } - - @Override - public void handleUseItemOn(ServerboundUseItemOnPacket packet) { - } - - @Override - public void handleUseItem(ServerboundUseItemPacket packet) { - } - - @Override - public void handleTeleportToEntityPacket(ServerboundTeleportToEntityPacket packet) { - } - - @Override - public void handleResourcePackResponse(ServerboundResourcePackPacket packet) { - } - - @Override - public void handlePaddleBoat(ServerboundPaddleBoatPacket packet) { - } - - @Override - public void handlePong(ServerboundPongPacket packet) { - } - - @Override - public void onDisconnect(Component reason) { - } - - @Override - public void ackBlockChangesUpTo(int i) { - } - - @Override - public void send(Packet packet, @Nullable PacketSendListener packetSendListener) { - } - - @Override - public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) { - } - - @Override - public void handleChat(ServerboundChatPacket packet) { - } - - @Override - public void handleChatCommand(ServerboundChatCommandPacket serverboundChatCommandPacket) { - } - - @Override - public void handleChatSessionUpdate(ServerboundChatSessionUpdatePacket serverboundChatSessionUpdatePacket) { - } - - @Override - public void handleChatAck(ServerboundChatAckPacket serverboundChatAckPacket) { - } - - @Override - public void handleAnimate(ServerboundSwingPacket packet) { - } - - @Override - public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) { - } - - @Override - public void addPendingMessage(PlayerChatMessage playerChatMessage) { - } - - @Override - public void handleInteract(ServerboundInteractPacket packet) { - } - - @Override - public void handleClientCommand(ServerboundClientCommandPacket packet) { - } - - @Override - public void handleContainerClose(ServerboundContainerClosePacket packet) { - } - - @Override - public void handleContainerClick(ServerboundContainerClickPacket packet) { - } - - @Override - public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) { - } - - @Override - public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) { - } - - @Override - public void handleSetCreativeModeSlot(ServerboundSetCreativeModeSlotPacket packet) { - } - - @Override - public void handleSignUpdate(ServerboundSignUpdatePacket packet) { - } - - @Override - public void handleKeepAlive(ServerboundKeepAlivePacket packet) { - } - - @Override - public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) { - } - - @Override - public void handleClientInformation(ServerboundClientInformationPacket packet) { - } - - @Override - public void handleCustomPayload(ServerboundCustomPayloadPacket packet) { - } - - @Override - public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) { - } - - @Override - public void handleLockDifficulty(ServerboundLockDifficultyPacket packet) { - } -} diff --git a/projects/fabric/src/main/java/dan200/computercraft/shared/platform/FakePlayer.java b/projects/fabric/src/main/java/dan200/computercraft/shared/platform/FakePlayer.java index 14ca95715..5f2b0c412 100644 --- a/projects/fabric/src/main/java/dan200/computercraft/shared/platform/FakePlayer.java +++ b/projects/fabric/src/main/java/dan200/computercraft/shared/platform/FakePlayer.java @@ -6,51 +6,18 @@ package dan200.computercraft.shared.platform; import com.mojang.authlib.GameProfile; import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.stats.Stat; -import net.minecraft.world.MenuProvider; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityDimensions; import net.minecraft.world.entity.Pose; import net.minecraft.world.entity.player.Player; -import javax.annotation.Nullable; -import java.util.OptionalInt; - -final class FakePlayer extends ServerPlayer { +final class FakePlayer extends net.fabricmc.fabric.api.entity.FakePlayer { private FakePlayer(ServerLevel serverLevel, GameProfile gameProfile) { - super(serverLevel.getServer(), serverLevel, gameProfile); - connection = new FakeNetHandler(this); + super(serverLevel, gameProfile); } static FakePlayer create(ServerLevel serverLevel, GameProfile profile) { - // Restore the previous player's advancements. See #564. - var playerList = serverLevel.getServer().getPlayerList(); - var currentPlayer = playerList.getPlayer(profile.getId()); - - var fakePlayer = new FakePlayer(serverLevel, profile); - if (currentPlayer != null) fakePlayer.getAdvancements().setPlayer(currentPlayer); - - return fakePlayer; - } - - @Override - public void tick() { - } - - @Override - public void doTick() { - super.doTick(); - } - - @Override - public void awardStat(Stat stat, int increment) { - } - - @Override - public boolean isInvulnerableTo(DamageSource source) { - return true; + return new FakePlayer(serverLevel, profile); } @Override @@ -62,16 +29,6 @@ final class FakePlayer extends ServerPlayer { public void die(DamageSource damageSource) { } - @Override - public OptionalInt openMenu(@Nullable MenuProvider menu) { - return OptionalInt.empty(); - } - - @Override - public boolean startRiding(Entity vehicle, boolean force) { - return false; - } - @Override public float getStandingEyeHeight(Pose pose, EntityDimensions dimensions) { return 0;