Skip to content

Commit

Permalink
Merge branch 'feature-multi' into nyan-work/dev
Browse files Browse the repository at this point in the history
Signed-off-by: Hendrix-Shen <[email protected]>
  • Loading branch information
Hendrix-Shen committed Jul 29, 2023
2 parents 6510223 + ff1d317 commit ce1635c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 34 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ Operation command: `/pca`

## Dependencies

| Dependency | Download |
|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| MagicLib | [CurseForge](https://www.curseforge.com/minecraft/mc-mods/magiclib) &#124; [GitHub](https://github.com/Hendrix-Shen/MagicLib) &#124; [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
Expand Down
8 changes: 5 additions & 3 deletions README_ZH_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

## 依赖

| 依赖 | 下载 |
|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| MagicLib | [CurseForge](https://www.curseforge.com/minecraft/mc-mods/magiclib) &#124; [GitHub](https://github.com/Hendrix-Shen/MagicLib) &#124; [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)
Expand Down
1 change: 1 addition & 0 deletions fabricWrapper/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"environment": "*",
"depends": {
"carpet": "*",
"fabric": "*",
"magiclib": ">=${magiclib_dependency}",
"minecraft": ${minecraft_dependency}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
}

0 comments on commit ce1635c

Please sign in to comment.