-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25844fb
commit becbcc5
Showing
6 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ain/java/club/mcams/carpet/mixin/rule/fakePlayerInteractLikeClient/BoatEntityInvoker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
94 changes: 94 additions & 0 deletions
94
...carpet/mixin/rule/fakePlayerInteractLikeClient/EntityPlayerActionPackActionTypeMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters