Finishing portal rescue overhaul
This commit is contained in:
parent
c335e2233f
commit
b250a52426
|
@ -11,6 +11,8 @@ import net.minecraft.server.MinecraftServer;
|
|||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
@ -157,8 +159,16 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
|||
if(config.main.spawnOnJoin)
|
||||
teleportPlayer(player, false);
|
||||
|
||||
// Updating chunk if needed (if portal rescue action happened)
|
||||
if(deauthenticatedUsers.get(convertUuid(player)).wasInPortal)
|
||||
// Updating blocks if needed (if portal rescue action happened)
|
||||
if(deauthenticatedUsers.get(convertUuid(player)).wasInPortal) {
|
||||
World world = player.getEntityWorld();
|
||||
BlockPos pos = player.getBlockPos();
|
||||
|
||||
// Sending updates to portal blocks
|
||||
// This is technically not needed, but it cleans the "messed portal" on the client
|
||||
world.updateListeners(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
|
||||
world.updateListeners(pos.up(), world.getBlockState(pos.up()), world.getBlockState(pos.up()), 3);
|
||||
}
|
||||
|
||||
deauthenticatedUsers.remove(convertUuid(player));
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import net.minecraft.text.Text;
|
|||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.samo_lego.simpleauth.mixin.BlockUpdateS2CPacketAccess;
|
||||
import org.samo_lego.simpleauth.mixin.BlockUpdateS2CPacketAccessor;
|
||||
import org.samo_lego.simpleauth.storage.PlayerCache;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
@ -96,8 +96,10 @@ public class AuthEventHandler {
|
|||
else
|
||||
player.sendMessage(new LiteralText(config.lang.notRegistered), false);
|
||||
}
|
||||
else
|
||||
else {
|
||||
deauthenticatePlayer(player);
|
||||
playerCache = deauthenticatedUsers.get(uuid);
|
||||
}
|
||||
|
||||
if(config.main.spawnOnJoin)
|
||||
teleportPlayer(player, true);
|
||||
|
@ -105,23 +107,22 @@ public class AuthEventHandler {
|
|||
|
||||
// Tries to rescue player from nether portal
|
||||
if(config.main.tryPortalRescue && player.getBlockState().getBlock().equals(Blocks.NETHER_PORTAL)) {
|
||||
PlayerCache newPlayerCache = deauthenticatedUsers.get(uuid);
|
||||
BlockPos pos = player.getBlockPos();
|
||||
|
||||
// Faking portal blocks to be air
|
||||
BlockUpdateS2CPacket feetPacket = new BlockUpdateS2CPacket();
|
||||
((BlockUpdateS2CPacketAccess) feetPacket).setState(new BlockState(Blocks.AIR, null));
|
||||
((BlockUpdateS2CPacketAccess) feetPacket).setBlockPos(pos);
|
||||
((BlockUpdateS2CPacketAccessor) feetPacket).setState(new BlockState(Blocks.AIR, null));
|
||||
((BlockUpdateS2CPacketAccessor) feetPacket).setBlockPos(pos);
|
||||
player.networkHandler.sendPacket(feetPacket);
|
||||
|
||||
BlockUpdateS2CPacket headPacket = new BlockUpdateS2CPacket();
|
||||
((BlockUpdateS2CPacketAccess) headPacket).setState(new BlockState(Blocks.AIR, null));
|
||||
((BlockUpdateS2CPacketAccess) headPacket).setBlockPos(pos.up());
|
||||
((BlockUpdateS2CPacketAccessor) headPacket).setState(new BlockState(Blocks.AIR, null));
|
||||
((BlockUpdateS2CPacketAccessor) headPacket).setBlockPos(pos.up());
|
||||
player.networkHandler.sendPacket(headPacket);
|
||||
|
||||
// Teleporting player to the middle of the block
|
||||
player.teleport(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
|
||||
newPlayerCache.wasInPortal = true;
|
||||
playerCache.wasInPortal = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.Mixin;
|
|||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(BlockUpdateS2CPacket.class)
|
||||
public interface BlockUpdateS2CPacketAccess {
|
||||
public interface BlockUpdateS2CPacketAccessor {
|
||||
@Accessor("state")
|
||||
void setState(BlockState state);
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [],
|
||||
"server": [
|
||||
"BlockUpdateS2CPacketAccess",
|
||||
"BlockUpdateS2CPacketAccessor",
|
||||
"MixinPlayerEntity",
|
||||
"MixinPlayerManager",
|
||||
"MixinServerPlayNetworkHandler",
|
||||
|
|
Loading…
Reference in New Issue