From 5ed76d0e9d2f21c08b2d010937666f1b5c52c3da Mon Sep 17 00:00:00 2001 From: Patbox Date: Sun, 2 Jun 2024 10:36:10 +0200 Subject: [PATCH] Update CC and fix some bugs --- build.gradle | 14 ++++---- gradle.properties | 2 +- .../cctpatch/impl/poly/model/TurtleModel.java | 20 ++--------- .../cctpatch/mixin/TurtleToolAccessor.java | 12 ------- .../mod/item/AbstractComputerItemMixin.java | 34 ++++++++++++++++++ .../poly/ServerPlayNetworkHandlerMixin.java | 35 +++++++++++++++++-- .../cc-tweaked-polymer-patch.mixins.json | 2 +- 7 files changed, 78 insertions(+), 41 deletions(-) delete mode 100644 src/main/java/eu/pb4/cctpatch/mixin/TurtleToolAccessor.java create mode 100644 src/main/java/eu/pb4/cctpatch/mixin/mod/item/AbstractComputerItemMixin.java diff --git a/build.gradle b/build.gradle index 200b5d1..556c19e 100644 --- a/build.gradle +++ b/build.gradle @@ -45,17 +45,17 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" // 1.109.6 - modImplementation "maven.modrinth:cc-tweaked:7U8gSlIr" - modImplementation "cc.tweaked:cc-tweaked-1.20.5-fabric:1.110.3" + //modImplementation "maven.modrinth:cc-tweaked:7U8gSlIr" + modImplementation "cc.tweaked:cc-tweaked-1.20.6-fabric:1.111.0" modImplementation include('eu.pb4:sgui:1.5.1+1.20.5') modImplementation include('eu.pb4:player-data-api:0.5.0+1.20.5') modImplementation include('eu.pb4:map-canvas-api:0.3.0+1.20.6') - modImplementation include('eu.pb4:factorytools:0.2.0+1.20.6') - modImplementation 'eu.pb4:polymer-core:0.8.0-pre.1+1.20.6' - modImplementation 'eu.pb4:polymer-resource-pack:0.8.0-pre.1+1.20.6' - modImplementation 'eu.pb4:polymer-autohost:0.8.0-pre.1+1.20.6' - modImplementation 'eu.pb4:polymer-virtual-entity:0.8.0-pre.1+1.20.6' + modImplementation include('eu.pb4:factorytools:0.2.2+1.20.6') + modImplementation 'eu.pb4:polymer-core:0.8.2+1.20.6' + modImplementation 'eu.pb4:polymer-resource-pack:0.8.2+1.20.6' + modImplementation 'eu.pb4:polymer-autohost:0.8.2+1.20.6' + modImplementation 'eu.pb4:polymer-virtual-entity:0.8.2+1.20.6' modCompileOnly ("nl.theepicblock:PolyMc:5.6.1+1.20.4") { diff --git a/gradle.properties b/gradle.properties index 367137d..b5dfc1e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.20.6+build.1 loader_version=0.15.10 # Mod Properties -mod_version=1.110.3.0+1.20.6 +mod_version=1.111.0.0+1.20.6 maven_group=eu.pb4.cctpatch archives_base_name=cc-tweaked-polymer-patch diff --git a/src/main/java/eu/pb4/cctpatch/impl/poly/model/TurtleModel.java b/src/main/java/eu/pb4/cctpatch/impl/poly/model/TurtleModel.java index a8231c1..753d74d 100644 --- a/src/main/java/eu/pb4/cctpatch/impl/poly/model/TurtleModel.java +++ b/src/main/java/eu/pb4/cctpatch/impl/poly/model/TurtleModel.java @@ -1,29 +1,21 @@ package eu.pb4.cctpatch.impl.poly.model; import dan200.computercraft.api.ComputerCraftAPI; +import dan200.computercraft.api.turtle.AbstractTurtleUpgrade; import dan200.computercraft.api.turtle.ITurtleUpgrade; -import dan200.computercraft.api.turtle.TurtleAnimation; import dan200.computercraft.api.turtle.TurtleSide; -import dan200.computercraft.shared.ComputerCraft; import dan200.computercraft.shared.ModRegistry; import dan200.computercraft.shared.turtle.blocks.TurtleBlock; -import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity; import dan200.computercraft.shared.turtle.core.TurtleBrain; import dan200.computercraft.shared.turtle.upgrades.TurtleCraftingTable; -import dan200.computercraft.shared.turtle.upgrades.TurtleModem; import dan200.computercraft.shared.turtle.upgrades.TurtleSpeaker; import dan200.computercraft.shared.turtle.upgrades.TurtleTool; import dan200.computercraft.shared.util.Holiday; -import eu.pb4.cctpatch.impl.poly.model.generic.BlockStateModelManager; import eu.pb4.cctpatch.mixin.TurtleModemAccessor; -import eu.pb4.cctpatch.mixin.TurtleToolAccessor; import eu.pb4.factorytools.api.resourcepack.BaseItemProvider; import eu.pb4.factorytools.api.virtualentity.BlockModel; import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil; -import eu.pb4.polymer.virtualentity.api.ElementHolder; import eu.pb4.polymer.virtualentity.api.VirtualEntityUtils; -import eu.pb4.polymer.virtualentity.api.attachment.BlockBoundAttachment; -import eu.pb4.polymer.virtualentity.api.attachment.ChunkAttachment; import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement; import it.unimi.dsi.fastutil.ints.IntList; import net.minecraft.block.BlockState; @@ -32,20 +24,14 @@ import net.minecraft.component.type.FireworkExplosionComponent; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtIntArray; import net.minecraft.network.listener.ClientPlayPacketListener; import net.minecraft.network.packet.Packet; -import net.minecraft.registry.tag.ItemTags; import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.server.world.ServerWorld; import net.minecraft.util.Identifier; -import net.minecraft.util.Pair; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RotationAxis; import net.minecraft.util.math.Vec3d; -import org.joml.Vector3f; import java.util.HashMap; import java.util.Map; @@ -148,11 +134,9 @@ private ItemStack getUpgradeModel(ITurtleUpgrade upgrade, TurtleBrain brain, Tur return SPEAKER_MODEL.get(turtleSide); } else if (upgrade instanceof TurtleCraftingTable) { return CRAFTING_MODEL.get(turtleSide); - } else if (upgrade instanceof TurtleToolAccessor tool) { - return tool.getItem(); } - return ItemStack.EMPTY; + return upgrade.getCraftingItem(); } public void update(TurtleBrain turtleBrain) { diff --git a/src/main/java/eu/pb4/cctpatch/mixin/TurtleToolAccessor.java b/src/main/java/eu/pb4/cctpatch/mixin/TurtleToolAccessor.java deleted file mode 100644 index 951323f..0000000 --- a/src/main/java/eu/pb4/cctpatch/mixin/TurtleToolAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package eu.pb4.cctpatch.mixin; - -import dan200.computercraft.shared.turtle.upgrades.TurtleTool; -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(TurtleTool.class) -public interface TurtleToolAccessor { - @Accessor - ItemStack getItem(); -} diff --git a/src/main/java/eu/pb4/cctpatch/mixin/mod/item/AbstractComputerItemMixin.java b/src/main/java/eu/pb4/cctpatch/mixin/mod/item/AbstractComputerItemMixin.java new file mode 100644 index 0000000..10b44f8 --- /dev/null +++ b/src/main/java/eu/pb4/cctpatch/mixin/mod/item/AbstractComputerItemMixin.java @@ -0,0 +1,34 @@ +package eu.pb4.cctpatch.mixin.mod.item; + +import dan200.computercraft.shared.computer.items.AbstractComputerItem; +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; +import net.minecraft.registry.Registries; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.sound.SoundCategory; +import net.minecraft.util.ActionResult; +import net.minecraft.util.math.Vec3d; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(AbstractComputerItem.class) +public abstract class AbstractComputerItemMixin extends BlockItem { + public AbstractComputerItemMixin(Block block, Settings settings) { + super(block, settings); + } + + @Override + public ActionResult useOnBlock(ItemUsageContext context) { + var x = super.useOnBlock(context); + if (x == ActionResult.CONSUME) { + if (context.getPlayer() instanceof ServerPlayerEntity player) { + var pos = Vec3d.ofCenter(context.getBlockPos().offset(context.getSide())); + var blockSoundGroup = this.getBlock().getDefaultState().getSoundGroup(); + player.networkHandler.sendPacket(new PlaySoundS2CPacket(Registries.SOUND_EVENT.getEntry(this.getPlaceSound(this.getBlock().getDefaultState())), SoundCategory.BLOCKS, pos.x, pos.y, pos.z, (blockSoundGroup.getVolume() + 1.0F) / 2.0F, blockSoundGroup.getPitch() * 0.8F, context.getPlayer().getRandom().nextLong())); + } + return ActionResult.SUCCESS; + } + return x; + } +} diff --git a/src/main/java/eu/pb4/cctpatch/mixin/poly/ServerPlayNetworkHandlerMixin.java b/src/main/java/eu/pb4/cctpatch/mixin/poly/ServerPlayNetworkHandlerMixin.java index ec4004a..d339289 100644 --- a/src/main/java/eu/pb4/cctpatch/mixin/poly/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/eu/pb4/cctpatch/mixin/poly/ServerPlayNetworkHandlerMixin.java @@ -1,5 +1,6 @@ package eu.pb4.cctpatch.mixin.poly; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import eu.pb4.cctpatch.impl.poly.gui.MapGui; import eu.pb4.sgui.virtual.VirtualScreenHandlerInterface; import net.minecraft.network.ClientConnection; @@ -14,6 +15,7 @@ import net.minecraft.server.network.ServerCommonNetworkHandler; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -22,6 +24,7 @@ import java.util.EnumSet; import java.util.Optional; +import java.util.Set; @Mixin(ServerPlayNetworkHandler.class) public abstract class ServerPlayNetworkHandlerMixin extends ServerCommonNetworkHandler { @@ -36,10 +39,16 @@ public ServerPlayNetworkHandlerMixin(MinecraftServer server, ClientConnection co @Shadow protected abstract void handleMessageChainException(MessageChain.MessageChainException exception); - @Shadow protected abstract void validateMessage(String message, Runnable callback); - @Shadow protected abstract Optional validateAcknowledgment(LastSeenMessageList.Acknowledgment acknowledgment); + @Shadow public abstract void syncWithPlayerPosition(); + + @Shadow private double lastTickX; + + @Shadow private double lastTickY; + + @Shadow private double lastTickZ; + @Inject(method = "onChatMessage", at = @At("HEAD"), cancellable = true) private void ccp_onChat(ChatMessageC2SPacket packet, CallbackInfo ci) { if (this.player.currentScreenHandler instanceof VirtualScreenHandlerInterface handler && handler.getGui() instanceof MapGui computerGui) { @@ -71,6 +80,28 @@ private void ccp_onChat(CommandExecutionC2SPacket packet, CallbackInfo ci) { } } + @WrapWithCondition(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;updatePositionAndAngles(DDDFF)V")) + private boolean ccp_allowMovement(ServerPlayerEntity instance, double x, double y, double z, float p, float yaw) { + if (this.player.currentScreenHandler instanceof VirtualScreenHandlerInterface handler && handler.getGui() instanceof MapGui computerGui) { + double l = instance.getX() - this.lastTickX; + double m = instance.getY() - this.lastTickY; + double n = instance.getZ() - this.lastTickZ; + this.player.getServerWorld().getChunkManager().updatePosition(this.player); + this.player.handleFall(l, m , n, player.isOnGround()); + this.player.setOnGround(player.isOnGround(), new Vec3d(l, m , n)); + this.syncWithPlayerPosition(); + return false; + } + return true; + } + + @Inject(method = "requestTeleport(DDDFFLjava/util/Set;)V", at = @At("HEAD"), cancellable = true) + private void ccp_noTeleport(double x, double y, double z, float yaw, float pitch, Set flags, CallbackInfo ci) { + if (this.player.currentScreenHandler instanceof VirtualScreenHandlerInterface handler && handler.getGui() instanceof MapGui computerGui) { + ci.cancel(); + } + } + @Inject(method = "onPlayerMove", at = @At("HEAD"), cancellable = true) private void ccp_onMove(PlayerMoveC2SPacket packet, CallbackInfo ci) { if (this.player.currentScreenHandler instanceof VirtualScreenHandlerInterface handler && handler.getGui() instanceof MapGui computerGui) { diff --git a/src/main/resources/cc-tweaked-polymer-patch.mixins.json b/src/main/resources/cc-tweaked-polymer-patch.mixins.json index de1b1da..068c3bc 100644 --- a/src/main/resources/cc-tweaked-polymer-patch.mixins.json +++ b/src/main/resources/cc-tweaked-polymer-patch.mixins.json @@ -5,7 +5,6 @@ "mixins": [ "ServerPlayNetworkHandlerAccessor", "TurtleModemAccessor", - "TurtleToolAccessor", "mod.PlatformHelperImplRegistryEntryImplMixin", "mod.ServerNetworkingMixin", "mod.block.GenericBlockModelMixin", @@ -20,6 +19,7 @@ "mod.ext.ServerInputStateMixin", "mod.ext.ServerMonitorMixin", "mod.ext.TerminalMixin", + "mod.item.AbstractComputerItemMixin", "mod.item.GenericItemMixin", "mod.item.ModRegistryCreativeTabsMixin", "mod.item.ModRegistryDataComponentsMixin",