Fix on_player_rides being called from the wrong thread
This commit is contained in:
1 parent
c9b90ab766
commit
1e6860fdd9
1 file changed
+24
-31
@@ -1,6 +1,5 @@
|
|||||||
package carpet.mixins;
|
package carpet.mixins;
|
||||||
|
|
||||||
import carpet.fakes.EntityInterface;
|
|
||||||
import net.minecraft.network.protocol.game.ServerboundChatCommandPacket;
|
import net.minecraft.network.protocol.game.ServerboundChatCommandPacket;
|
||||||
import net.minecraft.world.entity.player.Input;
|
import net.minecraft.world.entity.player.Input;
|
||||||
import net.minecraft.world.item.crafting.RecipeManager;
|
import net.minecraft.world.item.crafting.RecipeManager;
|
||||||
@@ -48,22 +47,37 @@ import net.minecraft.world.InteractionHand;
|
|||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
|
||||||
|
|
||||||
@Mixin(ServerGamePacketListenerImpl.class)
|
@Mixin(ServerGamePacketListenerImpl.class)
|
||||||
public class ServerGamePacketListenerImpl_scarpetEventsMixin
|
public class ServerGamePacketListenerImpl_scarpetEventsMixin
|
||||||
{
|
{
|
||||||
@Shadow public ServerPlayer player;
|
@Shadow public ServerPlayer player;
|
||||||
|
|
||||||
@Inject(method = "handlePlayerInput", at = @At("HEAD"))
|
|
||||||
private void checkMoves(ServerboundPlayerInputPacket p, CallbackInfo ci)
|
|
||||||
|
@Inject(method = "handlePlayerInput", at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/server/level/ServerPlayer;setLastClientInput(Lnet/minecraft/world/entity/player/Input;)V"
|
||||||
|
))
|
||||||
|
private void checkMovement(ServerboundPlayerInputPacket packet, CallbackInfo ci)
|
||||||
{
|
{
|
||||||
// todo this may not ride on the right thread moment, so needs to be checked
|
Input input = packet.input();
|
||||||
|
|
||||||
Input input = p.input();
|
// sneak events
|
||||||
|
boolean wasDown = player.isShiftKeyDown();
|
||||||
if (player.getVehicle() != null && !((EntityInterface)player.getVehicle()).isPermanentVehicle()) // won't since that method makes sure its not null
|
boolean isDown = input.shift();
|
||||||
player.setShiftKeyDown(p.input().shift());
|
if (wasDown != isDown)
|
||||||
|
{
|
||||||
|
if (isDown)
|
||||||
|
{
|
||||||
|
PLAYER_STARTS_SNEAKING.onPlayerEvent(player);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PLAYER_STOPS_SNEAKING.onPlayerEvent(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ride event, which should check for mount?
|
||||||
if (PLAYER_RIDES.isNeeded() && (input.jump() || input.shift() || input.forward() || input.backward() || input.left() || input.right()))
|
if (PLAYER_RIDES.isNeeded() && (input.jump() || input.shift() || input.forward() || input.backward() || input.left() || input.right()))
|
||||||
{
|
{
|
||||||
PLAYER_RIDES.onMountControls(player, input.left() == input.right() ? 0 : (input.left() ? -1 : 1 ), input.forward() == input.backward() ? 0 : (input.forward() ? 1 : -1), input.jump(), input.shift());
|
PLAYER_RIDES.onMountControls(player, input.left() == input.right() ? 0 : (input.left() ? -1 : 1 ), input.forward() == input.backward() ? 0 : (input.forward() ? 1 : -1), input.jump(), input.shift());
|
||||||
@@ -180,27 +194,6 @@ public class ServerGamePacketListenerImpl_scarpetEventsMixin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "handlePlayerInput", at = @At(
|
|
||||||
value = "INVOKE",
|
|
||||||
target = "Lnet/minecraft/server/level/ServerPlayer;setLastClientInput(Lnet/minecraft/world/entity/player/Input;)V"
|
|
||||||
))
|
|
||||||
private void onStartSneaking(ServerboundPlayerInputPacket serverboundPlayerInputPacket, CallbackInfo ci)
|
|
||||||
{
|
|
||||||
boolean wasDown = player.isShiftKeyDown();
|
|
||||||
boolean isDown = serverboundPlayerInputPacket.input().shift();
|
|
||||||
if (wasDown != isDown)
|
|
||||||
{
|
|
||||||
if (isDown)
|
|
||||||
{
|
|
||||||
PLAYER_STARTS_SNEAKING.onPlayerEvent(player);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PLAYER_STOPS_SNEAKING.onPlayerEvent(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "handlePlayerCommand", at = @At(
|
@Inject(method = "handlePlayerCommand", at = @At(
|
||||||
value = "INVOKE",
|
value = "INVOKE",
|
||||||
target = "Lnet/minecraft/server/level/ServerPlayer;setSprinting(Z)V",
|
target = "Lnet/minecraft/server/level/ServerPlayer;setSprinting(Z)V",
|
||||||
|
|||||||
Reference in new issue
Block a user