Nether portal rescue working.
This commit is contained in:
parent
cbe720198c
commit
6cda3d7d08
|
@ -1,5 +1,7 @@
|
|||
package org.samo_lego.simpleauth.event;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
|
||||
|
@ -8,10 +10,12 @@ import net.minecraft.text.LiteralText;
|
|||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.samo_lego.simpleauth.SimpleAuth;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import static net.minecraft.block.NetherPortalBlock.AXIS;
|
||||
import static net.minecraft.util.math.Direction.Axis.Z;
|
||||
|
||||
/**
|
||||
* This class will take care of actions players try to do,
|
||||
|
@ -25,9 +29,80 @@ public class AuthEventHandler {
|
|||
return new LiteralText(SimpleAuth.config.lang.notAuthenticated);
|
||||
}
|
||||
|
||||
private static Text successfulPortalRescue = new LiteralText(SimpleAuth.config.lang.successfulPortalRescue);
|
||||
|
||||
// Player joining the server
|
||||
public static void onPlayerJoin(ServerPlayerEntity player) {
|
||||
SimpleAuth.deauthenticatePlayer(player);
|
||||
|
||||
// Tries to rescue player from nether portal
|
||||
if(SimpleAuth.config.main.tryPortalRescue && player.getBlockState().getBlock().equals(Blocks.NETHER_PORTAL)) {
|
||||
boolean wasSuccessful = false;
|
||||
|
||||
BlockState portalState = player.getBlockState();
|
||||
World world = player.getEntityWorld();
|
||||
|
||||
double x = player.getX();
|
||||
double y = player.getY();
|
||||
double z = player.getZ();
|
||||
|
||||
if(portalState.get(AXIS) == Z) {
|
||||
// Player should be put to eastern or western block
|
||||
if( // Checking towards east
|
||||
world.getBlockState(new BlockPos(x + 1, y, z)).isAir() &&
|
||||
world.getBlockState(new BlockPos(x + 1, y + 1, z)).isAir() &&
|
||||
(
|
||||
world.getBlockState(new BlockPos(x + 1, y - 1, z)).isOpaque() ||
|
||||
world.getBlockState(new BlockPos(x + 1, y - 1, z)).hasSolidTopSurface(world, new BlockPos(x + 1, y - 1, z), player)
|
||||
)
|
||||
) {
|
||||
x++; // Towards east
|
||||
wasSuccessful = true;
|
||||
}
|
||||
|
||||
else if( // Checking towards south
|
||||
world.getBlockState(new BlockPos(x - 1, y, z)).isAir() &&
|
||||
world.getBlockState(new BlockPos(x - 1, y + 1, z)).isAir() &&
|
||||
(
|
||||
world.getBlockState(new BlockPos(x - 1, y - 1, z)).isOpaque() ||
|
||||
world.getBlockState(new BlockPos(x - 1, y - 1, z)).hasSolidTopSurface(world, new BlockPos(x - 1, y - 1, z), player)
|
||||
)
|
||||
) {
|
||||
x--; // Towards south
|
||||
wasSuccessful = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Player should be put to northern or southern block
|
||||
if( // Checking towards south
|
||||
world.getBlockState(new BlockPos(x, y, z + 1)).isAir() &&
|
||||
world.getBlockState(new BlockPos(x, y + 1, z + 1)).isAir() &&
|
||||
(
|
||||
world.getBlockState(new BlockPos(x, y - 1, z + 1)).isOpaque() ||
|
||||
world.getBlockState(new BlockPos(x, y - 1, z + 1)).hasSolidTopSurface(world, new BlockPos(x, y - 1, z + 1), player)
|
||||
)
|
||||
) {
|
||||
z++; // Towards south
|
||||
wasSuccessful = true;
|
||||
}
|
||||
|
||||
else if( // Checking towards north
|
||||
world.getBlockState(new BlockPos(x, y, z - 1)).isAir() &&
|
||||
world.getBlockState(new BlockPos(x, y + 1, z - 1)).isAir() &&
|
||||
(
|
||||
world.getBlockState(new BlockPos(x, y - 1, z - 1)).isOpaque() ||
|
||||
world.getBlockState(new BlockPos(x, y - 1, z - 1)).hasSolidTopSurface(world, new BlockPos(x, y - 1, z - 1), player)
|
||||
)
|
||||
) {
|
||||
z--; // Towards north
|
||||
wasSuccessful = true;
|
||||
}
|
||||
}
|
||||
if(wasSuccessful) {
|
||||
player.teleport(x, y, z);
|
||||
player.sendMessage(successfulPortalRescue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Player chatting
|
||||
|
|
|
@ -1,61 +1,19 @@
|
|||
package org.samo_lego.simpleauth.mixin;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.server.PlayerManager;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.samo_lego.simpleauth.SimpleAuth;
|
||||
import org.samo_lego.simpleauth.event.entity.player.PlayerJoinServerCallback;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static net.minecraft.block.NetherPortalBlock.AXIS;
|
||||
import static net.minecraft.util.math.Direction.Axis.Z;
|
||||
|
||||
@Mixin(PlayerManager.class)
|
||||
public abstract class MixinPlayerManager {
|
||||
|
||||
@Inject(method = "onPlayerConnect", at = @At("RETURN"))
|
||||
private void onPlayerConnect(ClientConnection clientConnection, ServerPlayerEntity serverPlayerEntity, CallbackInfo ci) {
|
||||
PlayerJoinServerCallback.EVENT.invoker().onPlayerJoin(serverPlayerEntity);
|
||||
if(SimpleAuth.config.main.tryPortalRescue && serverPlayerEntity.getBlockState().getBlock().equals(Blocks.NETHER_PORTAL)) { //((MixinEntity) serverPlayerEntity).inNetherPortal()
|
||||
// Tries to rescue player from nether portal
|
||||
// Teleport - serverPlayerEntity.getBlockState().isOpaque();
|
||||
BlockState portalState = serverPlayerEntity.getBlockState();
|
||||
BlockPos portalBlockPos = serverPlayerEntity.getBlockPos();
|
||||
|
||||
World world = serverPlayerEntity.getEntityWorld();
|
||||
|
||||
double x = serverPlayerEntity.getX();
|
||||
double y = serverPlayerEntity.getY();
|
||||
double z = serverPlayerEntity.getZ();
|
||||
|
||||
if(portalState.get(AXIS) == Z) {
|
||||
// Player should be put to eastern or western block
|
||||
System.out.println("(W/E is ok) Position " + serverPlayerEntity.getBlockPos().toString());
|
||||
}
|
||||
else {
|
||||
// Player should be put to northern or southern block
|
||||
System.out.println("(N/S is ok) Position " + serverPlayerEntity.getBlockPos().toString());
|
||||
System.out.println("Feet: " + serverPlayerEntity.getEntityWorld().getBlockState(new BlockPos(x, y, z + 1)).isAir());
|
||||
System.out.println("Head: " + serverPlayerEntity.getEntityWorld().getBlockState(new BlockPos(x, y + 1, z + 1)).isAir());
|
||||
System.out.println("Ground: " + serverPlayerEntity.getEntityWorld().getBlockState(new BlockPos(x, y -1, z + 1)).isOpaque());
|
||||
if(
|
||||
world.getBlockState(new BlockPos(x, y, z + 1)).isAir() &&
|
||||
world.getBlockState(new BlockPos(x, y + 1, z + 1)).isAir() &&
|
||||
(world.getBlockState(new BlockPos(x, y - 1, z + 1)).isOpaque() || world.getBlockState(new BlockPos(x, y - 1, z + 1)).hasSolidTopSurface(world,new BlockPos(x, y - 1, z + 1), serverPlayerEntity))
|
||||
) {
|
||||
System.out.println("+z je ok");
|
||||
z++;
|
||||
}
|
||||
}
|
||||
serverPlayerEntity.teleport(x, y, z);
|
||||
System.out.println("TPying on x:" + x+ ", y: " +y + ", z:" + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ public class AuthConfig {
|
|||
public String userdataUpdated = "§aUserdata updated.";
|
||||
public String accountDeleted = "§aYour account was successfully deleted!";
|
||||
public String configurationReloaded = "§aConfiguration file was reloaded successfully.";
|
||||
public String successfulPortalRescue = "§aYou were rescued from nether portal successfully!";
|
||||
}
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Gson gson = new GsonBuilder()
|
||||
|
|
Loading…
Reference in New Issue