Fixed limbo! now limbo rifts teleport you into the last rift you went throuhg, if u went through a rift, otherwise it teleports you to the place you did /dimteleport from.
This commit is contained in:
parent
18f974e6c8
commit
41cacff88d
6 changed files with 80 additions and 4 deletions
|
@ -1,9 +1,12 @@
|
||||||
package org.dimdev.dimdoors.block;
|
package org.dimdev.dimdoors.block;
|
||||||
|
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
|
import org.dimdev.dimdoors.api.util.Location;
|
||||||
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
|
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
|
||||||
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
|
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
|
||||||
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
|
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
|
||||||
|
import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
@ -65,6 +68,10 @@ public class DimensionalPortalBlock extends Block implements RiftProvider<Entran
|
||||||
|
|
||||||
world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState());
|
world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState());
|
||||||
((DetachedRiftBlockEntity) world.getBlockEntity(pos)).setData(rift.getData());
|
((DetachedRiftBlockEntity) world.getBlockEntity(pos)).setData(rift.getData());
|
||||||
|
|
||||||
|
DimensionalRegistry.getRiftRegistry().setOverworldRift(entity.getUuid(), new Location((ServerWorld) world, pos));
|
||||||
|
LOGGER.log(Level.INFO, "Set overworld rift location");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockState rotate(BlockState state, BlockRotation rotation) {
|
public BlockState rotate(BlockState state, BlockRotation rotation) {
|
||||||
|
|
|
@ -2,12 +2,19 @@ package org.dimdev.dimdoors.block.entity;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
|
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
|
||||||
|
import org.dimdev.dimdoors.api.util.Location;
|
||||||
import org.dimdev.dimdoors.block.CoordinateTransformerBlock;
|
import org.dimdev.dimdoors.block.CoordinateTransformerBlock;
|
||||||
import org.dimdev.dimdoors.block.RiftProvider;
|
import org.dimdev.dimdoors.block.RiftProvider;
|
||||||
import org.dimdev.dimdoors.api.client.DefaultTransformation;
|
import org.dimdev.dimdoors.api.client.DefaultTransformation;
|
||||||
import org.dimdev.dimdoors.api.client.Transformer;
|
import org.dimdev.dimdoors.api.client.Transformer;
|
||||||
|
import org.dimdev.dimdoors.item.DimensionalDoorItem;
|
||||||
import org.dimdev.dimdoors.item.RiftKeyItem;
|
import org.dimdev.dimdoors.item.RiftKeyItem;
|
||||||
import org.dimdev.dimdoors.pockets.DefaultDungeonDestinations;
|
import org.dimdev.dimdoors.pockets.DefaultDungeonDestinations;
|
||||||
import org.dimdev.dimdoors.rift.registry.Rift;
|
import org.dimdev.dimdoors.rift.registry.Rift;
|
||||||
|
@ -34,9 +41,11 @@ import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
|
||||||
|
|
||||||
public class EntranceRiftBlockEntity extends RiftBlockEntity {
|
public class EntranceRiftBlockEntity extends RiftBlockEntity {
|
||||||
private static final EscapeTarget ESCAPE_TARGET = new EscapeTarget(true);
|
private static final EscapeTarget ESCAPE_TARGET = new EscapeTarget(true);
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
private boolean locked;
|
private boolean locked;
|
||||||
|
|
||||||
public EntranceRiftBlockEntity(BlockPos pos, BlockState state) {
|
public EntranceRiftBlockEntity(BlockPos pos, BlockState state) {
|
||||||
|
@ -57,6 +66,8 @@ public class EntranceRiftBlockEntity extends RiftBlockEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean teleport(Entity entity) {
|
public boolean teleport(Entity entity) {
|
||||||
|
//Sets the location where the player should be teleported back to if they are in limbo and try to escape, to be the netrance of the rift that took them into dungeons.
|
||||||
|
|
||||||
if (this.isLocked()) {
|
if (this.isLocked()) {
|
||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
ItemStack stack = ((LivingEntity) entity).getStackInHand(((LivingEntity) entity).getActiveHand());
|
ItemStack stack = ((LivingEntity) entity).getStackInHand(((LivingEntity) entity).getActiveHand());
|
||||||
|
@ -89,7 +100,13 @@ public class EntranceRiftBlockEntity extends RiftBlockEntity {
|
||||||
BlockState state = this.getWorld().getBlockState(this.getPos());
|
BlockState state = this.getWorld().getBlockState(this.getPos());
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
Vec3d targetPos = Vec3d.ofCenter(this.pos).add(Vec3d.of(this.getOrientation().getOpposite().getVector()).multiply(DimensionalDoorsInitializer.getConfig().getGeneralConfig().teleportOffset + 0.5));
|
Vec3d targetPos = Vec3d.ofCenter(this.pos).add(Vec3d.of(this.getOrientation().getOpposite().getVector()).multiply(DimensionalDoorsInitializer.getConfig().getGeneralConfig().teleportOffset + 0.5));
|
||||||
|
/*
|
||||||
|
Unused code that needs to be edited if there are other ways to get to limbo
|
||||||
|
But if it is only dimteleport and going through rifts then this code isn't nessecary
|
||||||
|
if(DimensionalRegistry.getRiftRegistry().getOverworldRift(entity.getUuid()) == null) {
|
||||||
|
DimensionalRegistry.getRiftRegistry().setOverworldRift(entity.getUuid(), new Location(World.OVERWORLD, ((ServerPlayerEntity)entity).getSpawnPointPosition()));
|
||||||
|
}
|
||||||
|
*/
|
||||||
if (block instanceof CoordinateTransformerBlock) {
|
if (block instanceof CoordinateTransformerBlock) {
|
||||||
CoordinateTransformerBlock transformer = (CoordinateTransformerBlock) block;
|
CoordinateTransformerBlock transformer = (CoordinateTransformerBlock) block;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.dimdev.dimdoors.command;
|
||||||
import com.mojang.brigadier.Command;
|
import com.mojang.brigadier.Command;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.arguments.FloatArgumentType;
|
import com.mojang.brigadier.arguments.FloatArgumentType;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import org.dimdev.dimdoors.api.util.Location;
|
||||||
import org.dimdev.dimdoors.api.util.TeleportUtil;
|
import org.dimdev.dimdoors.api.util.TeleportUtil;
|
||||||
import org.dimdev.dimdoors.api.util.math.MathUtil;
|
import org.dimdev.dimdoors.api.util.math.MathUtil;
|
||||||
|
|
||||||
|
@ -15,6 +17,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.EulerAngle;
|
import net.minecraft.util.math.EulerAngle;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry;
|
||||||
|
|
||||||
public class DimTeleportCommand {
|
public class DimTeleportCommand {
|
||||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||||
|
@ -51,6 +54,9 @@ public class DimTeleportCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int teleport(Entity entity, ServerWorld dimension, Vec3d pos, EulerAngle angle) {
|
private static int teleport(Entity entity, ServerWorld dimension, Vec3d pos, EulerAngle angle) {
|
||||||
|
if(entity instanceof PlayerEntity) {
|
||||||
|
DimensionalRegistry.getRiftRegistry().setOverworldRift(entity.getUuid(), new Location((ServerWorld) entity.getEntityWorld(), entity.getBlockPos()));
|
||||||
|
}
|
||||||
TeleportUtil.teleport(entity, dimension, pos, angle, entity.getVelocity());
|
TeleportUtil.teleport(entity, dimension, pos, angle, entity.getVelocity());
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,12 @@ import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.util.NbtType;
|
import net.fabricmc.fabric.api.util.NbtType;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.NbtElement;
|
import net.minecraft.nbt.NbtElement;
|
||||||
import net.minecraft.nbt.NbtList;
|
import net.minecraft.nbt.NbtList;
|
||||||
import net.minecraft.util.Pair;
|
import net.minecraft.util.Pair;
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dimdev.dimdoors.api.util.GraphUtils;
|
import org.dimdev.dimdoors.api.util.GraphUtils;
|
||||||
|
@ -33,7 +35,9 @@ public class RiftRegistry {
|
||||||
protected Map<UUID, PlayerRiftPointer> lastPrivatePocketEntrances = new HashMap<>(); // Player UUID -> last rift used to exit pocket
|
protected Map<UUID, PlayerRiftPointer> lastPrivatePocketEntrances = new HashMap<>(); // Player UUID -> last rift used to exit pocket
|
||||||
protected Map<UUID, PlayerRiftPointer> lastPrivatePocketExits = new HashMap<>(); // Player UUID -> last rift used to enter pocket
|
protected Map<UUID, PlayerRiftPointer> lastPrivatePocketExits = new HashMap<>(); // Player UUID -> last rift used to enter pocket
|
||||||
protected Map<UUID, PlayerRiftPointer> overworldRifts = new HashMap<>(); // Player UUID -> rift used to exit the overworld
|
protected Map<UUID, PlayerRiftPointer> overworldRifts = new HashMap<>(); // Player UUID -> rift used to exit the overworld
|
||||||
|
//I know this is sorta hacky, but overworldRifts can't be set for some reason it doesn't think that the rift location exists.
|
||||||
|
//TODO: Fix this shit so that u can use overworldRifts instead of overworldLocations. NVM this is better cause we can teleport to locations that aren't rifts.
|
||||||
|
protected Map<UUID, Location> overworldLocations = new HashMap<>();
|
||||||
public static RiftRegistry fromNbt(Map<RegistryKey<World>, PocketDirectory> pocketRegistry, NbtCompound nbt) {
|
public static RiftRegistry fromNbt(Map<RegistryKey<World>, PocketDirectory> pocketRegistry, NbtCompound nbt) {
|
||||||
// Read rifts in this dimension
|
// Read rifts in this dimension
|
||||||
|
|
||||||
|
@ -354,14 +358,27 @@ public class RiftRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getOverworldRift(UUID playerUUID) {
|
public Location getOverworldRift(UUID playerUUID) {
|
||||||
|
/*
|
||||||
PlayerRiftPointer entrancePointer = this.overworldRifts.get(playerUUID);
|
PlayerRiftPointer entrancePointer = this.overworldRifts.get(playerUUID);
|
||||||
Rift rift = (Rift) GraphUtils.followPointer(this.graph, entrancePointer);
|
Rift rift = (Rift) GraphUtils.followPointer(this.graph, entrancePointer);
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
if (rift == null) {
|
||||||
|
LOGGER.log(Level.ERROR, "rift is null for getOverworldRift");
|
||||||
|
} else {
|
||||||
|
LOGGER.log(Level.INFO, "rift location " + rift.getLocation().getWorld() + " and pos " + rift.getLocation().pos.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
return rift != null ? rift.getLocation() : null;
|
return rift != null ? rift.getLocation() : null;
|
||||||
|
*/
|
||||||
|
return overworldLocations.get(playerUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOverworldRift(UUID playerUUID, Location rift) {
|
public void setOverworldRift(UUID playerUUID, Location rift) {
|
||||||
LOGGER.debug("Setting last used overworld rift for " + playerUUID + " at " + rift);
|
/*
|
||||||
|
LOGGER.log(Level.INFO, "Setting last used overworld rift for " + playerUUID + " at " + rift.getWorld() + " pos at " + rift.getBlockPos());
|
||||||
this.setPlayerRiftPointer(playerUUID, rift, this.overworldRifts);
|
this.setPlayerRiftPointer(playerUUID, rift, this.overworldRifts);
|
||||||
|
*/
|
||||||
|
overworldLocations.put(playerUUID, rift);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Rift> getRifts() {
|
public Collection<Rift> getRifts() {
|
||||||
|
|
|
@ -47,6 +47,8 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
|
||||||
UUID uuid = entity.getUuid();
|
UUID uuid = entity.getUuid();
|
||||||
if (uuid != null) {
|
if (uuid != null) {
|
||||||
Location destLoc = DimensionalRegistry.getRiftRegistry().getOverworldRift(uuid);
|
Location destLoc = DimensionalRegistry.getRiftRegistry().getOverworldRift(uuid);
|
||||||
|
//This right here is changed to work with a slightly diff system where we just store where we want to player to go, after they leave limbo.
|
||||||
|
/*
|
||||||
if (destLoc != null && destLoc.getBlockEntity() instanceof RiftBlockEntity || this.canEscapeLimbo) {
|
if (destLoc != null && destLoc.getBlockEntity() instanceof RiftBlockEntity || this.canEscapeLimbo) {
|
||||||
Location location = VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, entity.getBlockPos())).projectToWorld(false);
|
Location location = VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, entity.getBlockPos())).projectToWorld(false);
|
||||||
TeleportUtil.teleport(entity, location.getWorld(), location.getBlockPos(), relativeAngle, relativeVelocity);
|
TeleportUtil.teleport(entity, location.getWorld(), location.getBlockPos(), relativeAngle, relativeVelocity);
|
||||||
|
@ -60,6 +62,22 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
|
||||||
TeleportUtil.teleport(entity, ModDimensions.LIMBO_DIMENSION, new BlockPos(this.location.getX(), this.location.getY(), this.location.getZ()), relativeAngle, relativeVelocity);
|
TeleportUtil.teleport(entity, ModDimensions.LIMBO_DIMENSION, new BlockPos(this.location.getX(), this.location.getY(), this.location.getZ()), relativeAngle, relativeVelocity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
if(destLoc != null && this.canEscapeLimbo) {
|
||||||
|
Location location = VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, destLoc.pos)).projectToWorld(false);
|
||||||
|
TeleportUtil.teleport(entity, location.getWorld(), location.getBlockPos(), relativeAngle, relativeVelocity);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (destLoc == null) {
|
||||||
|
chat(entity, new TranslatableText("rifts.destinations.escape.did_not_use_rift"));
|
||||||
|
} else {
|
||||||
|
chat(entity, new TranslatableText("rifts.destinations.escape.rift_has_closed"));
|
||||||
|
}
|
||||||
|
if (ModDimensions.LIMBO_DIMENSION != null) {
|
||||||
|
TeleportUtil.teleport(entity, ModDimensions.LIMBO_DIMENSION, new BlockPos(this.location.getX(), this.location.getY(), this.location.getZ()), relativeAngle, relativeVelocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false; // No escape info for that entity
|
return false; // No escape info for that entity
|
||||||
|
|
|
@ -89,9 +89,20 @@ public class VirtualLocation {
|
||||||
float spread = DimensionalDoorsInitializer.getConfig().getGeneralConfig().depthSpreadFactor * this.depth;
|
float spread = DimensionalDoorsInitializer.getConfig().getGeneralConfig().depthSpreadFactor * this.depth;
|
||||||
int newX = (int) (this.x + spread * 2 * (Math.random() - 0.5));
|
int newX = (int) (this.x + spread * 2 * (Math.random() - 0.5));
|
||||||
int newZ = (int) (this.z + spread * 2 * (Math.random() - 0.5));
|
int newZ = (int) (this.z + spread * 2 * (Math.random() - 0.5));
|
||||||
BlockPos pos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, new BlockPos(newX, 0, newZ));
|
//BlockPos pos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, new BlockPos(newX, 1, newZ));
|
||||||
|
BlockPos pos = getTopPos(world, new BlockPos(newX, 255, newZ));
|
||||||
return new Location(world, pos);
|
return new Location(world, pos);
|
||||||
}
|
}
|
||||||
|
private static BlockPos getTopPos(World world, BlockPos pos) {
|
||||||
|
while(world.getBlockState(pos).isAir()) {
|
||||||
|
pos = pos.down();
|
||||||
|
}
|
||||||
|
while(world.getBlockState(pos).isSolidBlock(world, pos)) {
|
||||||
|
pos = pos.up();
|
||||||
|
}
|
||||||
|
pos = pos.up(2);
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
public RegistryKey<World> getWorld() {
|
public RegistryKey<World> getWorld() {
|
||||||
return this.world;
|
return this.world;
|
||||||
|
|
Loading…
Reference in a new issue