Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fabric/1.21.x' into fabric/1.21.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Oct 16, 2024
2 parents 7beb5d9 + 410a1fd commit 98ff846
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 35 deletions.
25 changes: 0 additions & 25 deletions src/main/java/dev/dubhe/gugle/carpet/mixin/EntityMixin.java

This file was deleted.

31 changes: 24 additions & 7 deletions src/main/java/dev/dubhe/gugle/carpet/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@Mixin(Player.class)
abstract class PlayerMixin {
@Unique
Player gca$self = (Player) (Object) this;
private final Player gca$self = (Player) (Object) this;

@Inject(method = "tick", at = @At("RETURN"))
private void tick(CallbackInfo ci) {
Expand All @@ -40,16 +40,35 @@ private void tick(CallbackInfo ci) {

@WrapOperation(method = "interactOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;interact(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResult;"))
private InteractionResult interactOn(Entity entity, Player player, InteractionHand hand, Operation<InteractionResult> original) {
// 此处不能直接使用entity instanceof EntityPlayerMPFake
// 第一次entity instanceof Player是为了排除掉非玩家实体,避免影响非玩家实体的交互逻辑,第二次instanceof在interact方法中,用来判断交互玩家是否为假玩家
// 在服务端,entity instanceof Player可能是多余的
// 但是在客户端中,如果直接entity instanceof EntityPlayerMPFake,那么在右键假玩家时,客户端并不知道当前交互的玩家是不是假玩家
// 因此右键交互时可能会应用玩家手中的物品功能,例如使用熔岩桶右键玩家时可能在假玩家位置放置岩浆,使用风弹右键玩家时可能发射风弹
// 所以客户端在交互前要先判断一下当前交互的实体是不是玩家,这用来防止意外的使用物品功能
// 尽管这带来了一些新的问题,例如玩家飞行时不能对着玩家使用烟花,不能对着玩家吃食物,但是这相比意外使用物品是小问题
if (entity instanceof Player interactPlayer && (GcaSetting.openFakePlayerInventory || GcaSetting.openFakePlayerEnderChest)) {
return interact(interactPlayer, player, hand, original);
}
return original.call(entity, player, hand);
}

@Unique
private InteractionResult interact(Player entity, Player player, InteractionHand hand, Operation<InteractionResult> original) {
InteractionResult result;
if (entity instanceof EntityPlayerMPFake fakePlayer) {
// 打开物品栏
return this.openInventory(player, fakePlayer);
result = this.openInventory(player, fakePlayer);
} else {
// 怎么判断一个客户端玩家是不是假玩家?
return InteractionResult.SUCCESS;
}
return original.call(entity, player, hand);
return result == InteractionResult.PASS ? original.call(entity, player, hand) : result;
}

@Unique
private InteractionResult openInventory(Player player, EntityPlayerMPFake fakePlayer) {
SimpleMenuProvider provider = null;
SimpleMenuProvider provider;
if (player.isShiftKeyDown()) {
// 打开末影箱
if (GcaSetting.openFakePlayerEnderChest) {
Expand Down Expand Up @@ -79,9 +98,7 @@ private InteractionResult openInventory(Player player, EntityPlayerMPFake fakePl
),
ComponentTranslate.trans("gca.player.inventory", fakePlayer.getDisplayName())
);
}

if (provider == null) {
} else {
return InteractionResult.PASS;
}
player.openMenu(provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.component.ItemContainerContents;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -38,12 +37,13 @@ private static void replenishment(@NotNull ItemStack itemStack, NonNullList<Item
eachItem.setCount(0);
}
break;
} else if (eachItem.is(Items.SHULKER_BOX)) {
} else if (eachItem.has(DataComponents.CONTAINER)) {
int result = pickItemFromBox(eachItem, itemStack, half);
if (result == 0) {
continue;
}
itemStack.grow(result);
return;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/gca.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"server": [
],
"client": [
"EntityMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 98ff846

Please sign in to comment.