diff --git a/README.md b/README.md index c8d74c9..ff8f469 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,11 @@ Operation command: `/pca` ## Dependencies -| Dependency | Download | -|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| MagicLib | [CurseForge](https://www.curseforge.com/minecraft/mc-mods/magiclib) | [GitHub](https://github.com/Hendrix-Shen/MagicLib) | [Modrinth](https://modrinth.com/mod/magiclib) | +| Dependency | Link1 | Link2 | Link3 | +|------------|---------------------------------------------------------------------|----------------------------------------------------|-------------------------------------------------| +| Carpet | [CurseForge](https://www.curseforge.com/minecraft/mc-mods/carpet) | [GitHub](https://github.com/gnembon/fabric-carpet) | [Modrinth](https://modrinth.com/mod/carpet) | +| Fabric API | [CurseForge](https://www.curseforge.com/minecraft/mc-mods/fabric) | [GitHub](https://github.com/FabricMC/fabric) | [Modrinth](https://modrinth.com/mod/fabric-api) | +| MagicLib | [CurseForge](https://www.curseforge.com/minecraft/mc-mods/magiclib) | [GitHub](https://github.com/Hendrix-Shen/MagicLib) | [Modrinth](https://modrinth.com/mod/magiclib) | ## Rule List ## autoTrade diff --git a/README_ZH_CN.md b/README_ZH_CN.md index 3131d10..5b39ba4 100644 --- a/README_ZH_CN.md +++ b/README_ZH_CN.md @@ -18,9 +18,11 @@ ## 依赖 -| 依赖 | 下载 | -|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| MagicLib | [CurseForge](https://www.curseforge.com/minecraft/mc-mods/magiclib) | [GitHub](https://github.com/Hendrix-Shen/MagicLib) | [Modrinth](https://modrinth.com/mod/magiclib) | +| 依赖 | 链接1 | 链接2 | 链接3 | +|------------|---------------------------------------------------------------------|----------------------------------------------------|-------------------------------------------------| +| Carpet | [CurseForge](https://www.curseforge.com/minecraft/mc-mods/carpet) | [GitHub](https://github.com/gnembon/fabric-carpet) | [Modrinth](https://modrinth.com/mod/carpet) | +| Fabric API | [CurseForge](https://www.curseforge.com/minecraft/mc-mods/fabric) | [GitHub](https://github.com/FabricMC/fabric) | [Modrinth](https://modrinth.com/mod/fabric-api) | +| MagicLib | [CurseForge](https://www.curseforge.com/minecraft/mc-mods/magiclib) | [GitHub](https://github.com/Hendrix-Shen/MagicLib) | [Modrinth](https://modrinth.com/mod/magiclib) | ## 规则列表 ## 自动交易 (autoTrade) diff --git a/fabricWrapper/src/main/resources/fabric.mod.json b/fabricWrapper/src/main/resources/fabric.mod.json index 418c100..bf38097 100644 --- a/fabricWrapper/src/main/resources/fabric.mod.json +++ b/fabricWrapper/src/main/resources/fabric.mod.json @@ -22,6 +22,7 @@ "environment": "*", "depends": { "carpet": "*", + "fabric": "*", "magiclib": ">=${magiclib_dependency}", "minecraft": ${minecraft_dependency} }, diff --git a/src/main/java/com/plusls/carpet/mixin/rule/playerSit/MixinServerPlayer.java b/src/main/java/com/plusls/carpet/mixin/rule/playerSit/MixinServerPlayer.java index f6920f6..f07af28 100644 --- a/src/main/java/com/plusls/carpet/mixin/rule/playerSit/MixinServerPlayer.java +++ b/src/main/java/com/plusls/carpet/mixin/rule/playerSit/MixinServerPlayer.java @@ -3,6 +3,7 @@ import com.mojang.authlib.GameProfile; import com.plusls.carpet.PluslsCarpetAdditionSettings; import com.plusls.carpet.util.rule.playerSit.SitEntity; +import net.minecraft.Util; import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; import net.minecraft.server.level.ServerPlayer; @@ -13,6 +14,7 @@ import org.spongepowered.asm.mixin.Intrinsic; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -44,7 +46,9 @@ public MixinServerPlayer(Level level, BlockPos blockPos, float f, GameProfile ga @Shadow public ServerGamePacketListenerImpl connection; + @Unique private int pca$sneakTimes = 0; + @Unique private long pca$lastSneakTime = 0; @Override @@ -65,43 +69,50 @@ public void setShiftKeyDown(boolean sneaking) { ), cancellable = true ) - private void preSetShiftKeyDown(boolean sneaking, CallbackInfo ci) { - if (!PluslsCarpetAdditionSettings.playerSit || (sneaking && this.isShiftKeyDown())) { + private void customSetShiftKeyDownCheck(boolean sneaking, CallbackInfo ci) { + if (!PluslsCarpetAdditionSettings.playerSit) { return; } if (sneaking) { - long nowTime = System.currentTimeMillis(); - if (nowTime - this.pca$lastSneakTime < 200 && this.pca$sneakTimes == 0) { + long nowTime = Util.getMillis(); + + // Every sneak interval must not be over 0.2s + if (nowTime - this.pca$lastSneakTime > 200) { + this.pca$sneakTimes = 0; + } else { + // Block input update for 0.2s after player sit ci.cancel(); } - super.setShiftKeyDown(true); - if (this.onGround() && nowTime - this.pca$lastSneakTime < 200) { - this.pca$sneakTimes += 1; - if (this.pca$sneakTimes == 3) { - ArmorStand armorStandEntity = new ArmorStand(this.getLevelCompat(), this.getX(), this.getY() - 0.16, this.getZ()); - ((SitEntity) armorStandEntity).pca$setSitEntity(true); - this.getLevelCompat().addFreshEntity(armorStandEntity); - this.setShiftKeyDown(false); - this.startRiding(armorStandEntity); - this.pca$sneakTimes = 0; - } - } else { - this.pca$sneakTimes = 1; + + if (this.onGround()) { + this.pca$sneakTimes++; } + this.pca$lastSneakTime = nowTime; - } else { - super.setShiftKeyDown(false); - // 同步潜行状态到客户端 - // 如果不同步的话客户端会认为仍在潜行,从而碰撞箱的高度会计算错误 - if (this.pca$sneakTimes == 0 && this.connection != null) { - //#if MC > 11902 - this.connection.send(new ClientboundSetEntityDataPacket(this.getId(), this.getEntityData().getNonDefaultValues())); - //#else - //$$ this.connection.send(new ClientboundSetEntityDataPacket(this.getId(), this.getEntityData(), true)); - //#endif + + if (this.pca$sneakTimes > 2) { + ArmorStand armorStandEntity = new ArmorStand(this.getLevelCompat(), this.getX(), this.getY() - 0.16, this.getZ()); + ((SitEntity) armorStandEntity).pca$setSitEntity(true); + this.getLevelCompat().addFreshEntity(armorStandEntity); + this.setShiftKeyDown(false); + + if (this.connection != null) { + this.connection.send(new ClientboundSetEntityDataPacket( + this.getId(), + //#if MC > 11902 + this.getEntityData().getNonDefaultValues() + //#else + //$$ this.getEntityData(), + //$$ true + //#endif + )); + } + + this.startRiding(armorStandEntity); + this.pca$sneakTimes = 0; + ci.cancel(); } } - ci.cancel(); } }