Disable movement

Update player's position
This commit is contained in:
samo_lego 2019-11-30 22:07:23 +01:00
parent 235d05b6df
commit 4187a855fb
4 changed files with 21 additions and 13 deletions

View File

@ -2,12 +2,12 @@
org.gradle.jvmargs=-Xmx1G org.gradle.jvmargs=-Xmx1G
# Fabric properties # Fabric properties
minecraft_version=1.15-pre2 minecraft_version=1.15-pre3
yarn_mappings=1.15-pre2+build.3 yarn_mappings=1.15-pre3+build.2
loader_version=0.7.1+build.173 loader_version=0.7.2+build.174
#Fabric api #Fabric api
fabric_version=0.4.16+build.268-1.15 fabric_version=0.4.18+build.271-1.15
# Mod Properties # Mod Properties
mod_version = 1.0.0 mod_version = 1.0.0

View File

@ -1,7 +1,10 @@
package org.samo_lego.simpleauth.event; package org.samo_lego.simpleauth.event;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.minecraft.client.network.packet.InventoryS2CPacket;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketEncoder;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.packet.ChatMessageC2SPacket; import net.minecraft.server.network.packet.ChatMessageC2SPacket;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
@ -32,19 +35,17 @@ public class AuthEventHandler {
SimpleAuth.authenticatedUsers.remove(player); SimpleAuth.authenticatedUsers.remove(player);
} }
// todo
public static ActionResult onPlayerChat(PlayerEntity player, ChatMessageC2SPacket chatMessageC2SPacket) { public static ActionResult onPlayerChat(PlayerEntity player, ChatMessageC2SPacket chatMessageC2SPacket) {
String msg = chatMessageC2SPacket.getChatMessage(); String msg = chatMessageC2SPacket.getChatMessage();
if(!SimpleAuth.authenticatedUsers.contains(player) && !(msg.startsWith("/login") || msg.startsWith("/register"))) { if(!SimpleAuth.authenticatedUsers.contains(player) && !msg.startsWith("/login") && !msg.startsWith("/register")) {
player.sendMessage(notAuthenticated); player.sendMessage(notAuthenticated);
return ActionResult.FAIL; return ActionResult.FAIL;
} }
return ActionResult.PASS; return ActionResult.PASS;
} }
//todo // Player movement
public static ActionResult onPlayerMove(PlayerEntity player) { public static ActionResult onPlayerMove(PlayerEntity player) {
if(!SimpleAuth.authenticatedUsers.contains(player)) { if(!SimpleAuth.authenticatedUsers.contains(player)) {
// TP player back?
return ActionResult.FAIL; return ActionResult.FAIL;
} }
return ActionResult.PASS; return ActionResult.PASS;

View File

@ -1,10 +1,12 @@
package org.samo_lego.simpleauth.mixin; package org.samo_lego.simpleauth.mixin;
import net.minecraft.client.network.packet.InventoryS2CPacket;
import net.minecraft.container.PlayerContainer; import net.minecraft.container.PlayerContainer;
import net.minecraft.entity.ItemEntity; import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.packet.UpdateSelectedSlotC2SPacket;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import org.samo_lego.simpleauth.event.item.DropItemCallback; import org.samo_lego.simpleauth.event.item.DropItemCallback;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
@ -20,7 +22,7 @@ public abstract class MixinPlayerEntity {
@Shadow @Final public PlayerContainer playerContainer; @Shadow @Final public PlayerContainer playerContainer;
// Thanks to PR https://github.com/FabricMC/fabric/pull/260 and AbusedLib https://github.com/abused/AbusedLib // Thanks to PR https://github.com/FabricMC/fabric/pull/260 and AbusedLib https://github.com/abused/AbusedLib
@Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At("HEAD"), cancellable = true) @Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At("INVOKE"), cancellable = true)
private void dropItem(ItemStack stack, boolean dropAtFeet, boolean saveThrower, CallbackInfoReturnable<ItemEntity> cir) { private void dropItem(ItemStack stack, boolean dropAtFeet, boolean saveThrower, CallbackInfoReturnable<ItemEntity> cir) {
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this; ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
ActionResult result = DropItemCallback.EVENT.invoker().onDropItem(player); ActionResult result = DropItemCallback.EVENT.invoker().onDropItem(player);
@ -28,8 +30,6 @@ public abstract class MixinPlayerEntity {
if (result == ActionResult.FAIL) { if (result == ActionResult.FAIL) {
// Canceling the item drop, as well as giving the items back to player (and updating inv with packet) // Canceling the item drop, as well as giving the items back to player (and updating inv with packet)
player.giveItemStack(stack); player.giveItemStack(stack);
player.inventory.updateItems();
playerContainer.sendContentUpdates(); playerContainer.sendContentUpdates();
cir.cancel(); cir.cancel();
} }

View File

@ -1,5 +1,9 @@
package org.samo_lego.simpleauth.mixin; package org.samo_lego.simpleauth.mixin;
import net.minecraft.client.network.packet.InventoryS2CPacket;
import net.minecraft.client.network.packet.PlayerSpawnPositionS2CPacket;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.Packet;
import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.packet.ChatMessageC2SPacket; import net.minecraft.server.network.packet.ChatMessageC2SPacket;
@ -14,11 +18,12 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ServerPlayNetworkHandler.class) @Mixin(ServerPlayNetworkHandler.class)
public class MixinServerPlayNetworkHandler { public abstract class MixinServerPlayNetworkHandler {
@Shadow @Shadow
public ServerPlayerEntity player; public ServerPlayerEntity player;
// TODO @Shadow public abstract void sendPacket(Packet<?> packet_1);
@Inject( @Inject(
method = "onChatMessage(Lnet/minecraft/server/network/packet/ChatMessageC2SPacket;)V", method = "onChatMessage(Lnet/minecraft/server/network/packet/ChatMessageC2SPacket;)V",
at = @At( at = @At(
@ -50,6 +55,8 @@ public class MixinServerPlayNetworkHandler {
private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket_1, CallbackInfo ci) { private void onPlayerMove(PlayerMoveC2SPacket playerMoveC2SPacket_1, CallbackInfo ci) {
ActionResult result = OnPlayerMoveCallback.EVENT.invoker().onPlayerMove(player); ActionResult result = OnPlayerMoveCallback.EVENT.invoker().onPlayerMove(player);
if (result == ActionResult.FAIL) { if (result == ActionResult.FAIL) {
// A bit ugly, I know. (we need to update player position)
player.teleport(player.getX(), player.getY(), player.getZ());
ci.cancel(); ci.cancel();
} }
} }