Skip to content

Commit

Permalink
✅ fakePlayerInteractLikeClient
Browse files Browse the repository at this point in the history
  • Loading branch information
1024-byteeeee committed Aug 21, 2024
1 parent 25844fb commit becbcc5
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/club/mcams/carpet/AmsServerSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ public class AmsServerSettings {
@Rule(categories = {AMS, FEATURE, SURVIVAL})
public static boolean softObsidian = false;

@Rule(categories = {AMS, FEATURE, BUGFIX})
public static boolean fakePlayerInteractLikeClient = false;

/*
* 区块加载规则
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package club.mcams.carpet.mixin.rule.fakePlayerInteractLikeClient;

import net.minecraft.entity.vehicle.BoatEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(BoatEntity.class)
public interface BoatEntityInvoker {
@Accessor("ticksUnderwater")
float getTicksUnderwater();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* This file is part of the Carpet AMS Addition project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 A Minecraft Server and contributors
*
* Carpet AMS Addition is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Carpet AMS Addition is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Carpet AMS Addition. If not, see <https://www.gnu.org/licenses/>.
*/

package club.mcams.carpet.mixin.rule.fakePlayerInteractLikeClient;

import club.mcams.carpet.AmsServerSettings;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;

import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.entity.vehicle.MinecartEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.Vec3d;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@SuppressWarnings("PatternVariableCanBeUsed")
@Mixin(targets = "carpet.helpers.EntityPlayerActionPack$ActionType$1")
public abstract class EntityPlayerActionPackActionTypeMixin {
@WrapOperation(
method = "execute(Lnet/minecraft/server/network/ServerPlayerEntity;Lcarpet/helpers/EntityPlayerActionPack$Action;)Z",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/Entity;interactAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"
)
)
private ActionResult onInteractAt(Entity instance, PlayerEntity player, Vec3d hitPos, Hand hand, Operation<ActionResult> original) {
//有一部分是直接在interact里面进行一些操作,所以先call一遍
ActionResult originalResult = original.call(instance, player, hitPos, hand);
if (AmsServerSettings.fakePlayerInteractLikeClient) {
if (instance instanceof ArmorStandEntity) {
ArmorStandEntity stand = (ArmorStandEntity) instance;
ItemStack handItem = player.getStackInHand(hand);
if (!stand.isMarker() && handItem.getItem() != Items.NAME_TAG && !player.isSpectator()) {
//1.21之类的版本应改为SUCCESS_SERVER,但是就这里而言应该效果一致
return ActionResult.CONSUME;
}
}
}
return originalResult;
}

@WrapOperation(
method = "execute(Lnet/minecraft/server/network/ServerPlayerEntity;Lcarpet/helpers/EntityPlayerActionPack$Action;)Z",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/network/ServerPlayerEntity;interact(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"
)
)
private ActionResult onInteract(ServerPlayerEntity player, Entity entity, Hand hand, Operation<ActionResult> original) {
//有一部分是直接在interact里面进行一些操作,所以先call一遍
ActionResult originalResult = original.call(player, entity, hand);
if (AmsServerSettings.fakePlayerInteractLikeClient) {
if (entity instanceof BoatEntity) {
BoatEntity boat = (BoatEntity) entity;
if (!player.shouldCancelInteraction() && ((BoatEntityInvoker) boat).getTicksUnderwater() < 60.0F) {
return ActionResult.SUCCESS;
}
} else if (entity instanceof MinecartEntity) {
MinecartEntity minecart = (MinecartEntity) entity;
if (!player.shouldCancelInteraction() && !minecart.hasPassengers()) {
return ActionResult.SUCCESS;
}
}
}
return originalResult;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/amscarpet.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"rule.experimentalContentCheckDisabled.ToggleableFeatureMixin",
"rule.extinguishedCampfire_campfireSmokeParticleDisabled.CampfireBlockMixin",
"rule.fakePeace.AbstractBlockStateMixin",
"rule.fakePlayerInteractLikeClient.BoatEntityInvoker",
"rule.fakePlayerInteractLikeClient.EntityPlayerActionPackActionTypeMixin",
"rule.fakePlayerNoScoreboardCounter.PlayerEntityMixin",
"rule.fakePlayerPickUpController.ItemEntityMixin",
"rule.fancyFakePlayerName.CarpetMod_PlayerCommandMixin",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/carpetamsaddition/lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ carpetamsaddition:
desc: Change the hardness of obsidian and crying obsidian to end stone
extra:
'0': 'Requires client support'
fakePlayerInteractLikeClient:
desc: Fix some cases that fake player interact differently from the client

# 计划刻催熟规则:
scheduledRandomTickCactus:
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ carpetamsaddition:
desc: 改变黑曜石与哭泣的黑曜石的硬度使其和末地石一致
extra:
'0': '需要客户端支持'
fakePlayerInteractLikeClient:
name: 假人交互同步客户端行为
desc: 修复几个假人和盔甲架、矿车、船在特定情况下与客户端相应行为结果不一样的问题

# 计划刻催熟规则:
scheduledRandomTickCactus:
Expand Down

0 comments on commit becbcc5

Please sign in to comment.