Skip to content

Commit

Permalink
Merge pull request #59 from cdqtzrc/fabric/1.21
Browse files Browse the repository at this point in the history
修复服务端无法启动
  • Loading branch information
Gu-ZT committed Jun 26, 2024
2 parents cbb3e1f + 789c58a commit 650c127
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
25 changes: 25 additions & 0 deletions src/main/java/dev/dubhe/gugle/carpet/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dev.dubhe.gugle.carpet.mixin;

import dev.dubhe.gugle.carpet.GcaSetting;
import net.minecraft.client.player.RemotePlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Entity.class)
public class EntityMixin {
@SuppressWarnings("ConstantValue")
@Inject(method = "interact", at = @At("HEAD"), cancellable = true)
private void interact(Player player, InteractionHand interactionHand, CallbackInfoReturnable<InteractionResult> cir) {
// 在客户端中,玩家可以与客户端的被交互玩家交互并返回PASS,这时交互玩家手上如果拿着可以使用的物品,则物品会被使用
// 所以如果判断被交互实体是客户端玩家,返回SUCCESS
if ((Object) this instanceof RemotePlayer && (GcaSetting.openFakePlayerInventory || GcaSetting.openFakePlayerEnderChest)) {
cir.setReturnValue(InteractionResult.SUCCESS);
}
}
}
5 changes: 0 additions & 5 deletions src/main/java/dev/dubhe/gugle/carpet/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import dev.dubhe.gugle.carpet.tools.FakePlayerEnderChestContainer;
import dev.dubhe.gugle.carpet.tools.FakePlayerInventoryContainer;
import dev.dubhe.gugle.carpet.tools.FakePlayerInventoryMenu;
import net.minecraft.client.player.RemotePlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.SimpleMenuProvider;
Expand Down Expand Up @@ -44,10 +43,6 @@ private InteractionResult interactOn(Entity entity, Player player, InteractionHa
if (entity instanceof EntityPlayerMPFake fakePlayer) {
// 打开物品栏
return this.openInventory(player, fakePlayer);
} else if (entity instanceof RemotePlayer) {
// 在客户端中,玩家可以与客户端的被交互玩家交互并返回PASS,这时交互玩家手上如果拿着可以使用的物品,则物品会被使用
// 所以如果判断被交互实体是客户端玩家,返回SUCCESS
return InteractionResult.SUCCESS;
}
return original.call(entity, player, hand);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/gca.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"server": [
],
"client": [
"EntityMixin",
"ServerPlayerMixin"
],
"injectors": {
Expand Down

0 comments on commit 650c127

Please sign in to comment.