Tweaked teleportation

Changes to be committed:
	modified:   src/main/java/org/dimdev/dimdoors/block/DimensionalPortalBlock.java
	modified:   src/main/java/org/dimdev/dimdoors/rift/targets/EscapeTarget.java
	modified:   src/main/java/org/dimdev/dimdoors/rift/targets/VirtualTarget.java
	modified:   src/main/java/org/dimdev/dimdoors/util/TeleportUtil.java
This commit is contained in:
SD 2020-10-02 16:52:56 +05:30
parent e40a396a9f
commit 1b286ccdda
No known key found for this signature in database
GPG key ID: E36B57EE08544BC5
4 changed files with 38 additions and 21 deletions

View file

@ -1,11 +1,15 @@
package org.dimdev.dimdoors.block;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import org.dimdev.dimdoors.util.TeleportUtil;
import org.dimdev.dimdoors.world.ModDimensions;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
@ -29,4 +33,15 @@ public class DimensionalPortalBlock extends Block implements RiftProvider<Entran
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.ENTITYBLOCK_ANIMATED;
}
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
if (world.isClient) {
return;
}
if (ModDimensions.isLimboDimension(entity.getEntityWorld())) {
TeleportUtil.teleport(entity, DimensionalDoorsInitializer.getWorld(World.OVERWORLD), entity.getPos().subtract(0, entity.getPos().y, 0).add(0, 384, 0), 0);
}
super.onEntityCollision(state, world, pos, entity);
}
}

View file

@ -35,7 +35,7 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
chat(entity, new TranslatableText("rifts.destinations.escape.not_in_pocket_dim"));
return false;
}
if (ModDimensions.isLimboDimension(entity.world) && !canEscapeLimbo) {
if (ModDimensions.isLimboDimension(entity.world) && !this.canEscapeLimbo) {
chat(entity, new TranslatableText("rifts.destinations.escape.cannot_escape_limbo"));
return false;
}
@ -43,7 +43,7 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
UUID uuid = entity.getUuid();
if (uuid != null) {
Location destLoc = RiftRegistry.instance().getOverworldRift(uuid);
if (destLoc != null && destLoc.getBlockEntity() instanceof RiftBlockEntity || canEscapeLimbo) {
if (destLoc != null && destLoc.getBlockEntity() instanceof RiftBlockEntity || this.canEscapeLimbo) {
Location location = VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, entity.getBlockPos())).projectToWorld(false);
TeleportUtil.teleport(entity, location.getWorld(), location.getBlockPos(), 0);
} else {
@ -54,8 +54,8 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
}
if (!entity.getEntityWorld().isClient) {
if (ModDimensions.LIMBO_DIMENSION != null) {
entity.moveToWorld(ModDimensions.LIMBO_DIMENSION);
entity.setPos(location.getX(), location.getY(), location.getZ());
Entity newEntity = entity.moveToWorld(ModDimensions.LIMBO_DIMENSION);
newEntity.setPos(this.location.getX(), this.location.getY(), this.location.getZ());
}
}
}

View file

@ -41,13 +41,13 @@ public abstract class VirtualTarget implements Target {
}
public RGBA getColor() {
return getType().getColor();
return this.getType().getColor();
}
public boolean equals(Object o) {
return o instanceof VirtualTarget &&
((VirtualTarget) o).canEqual(this) &&
(location == null ? ((VirtualTarget) o).location == null : ((Object) location).equals(((VirtualTarget) o).location));
(this.location == null ? ((VirtualTarget) o).location == null : ((Object) this.location).equals(((VirtualTarget) o).location));
}
protected boolean canEqual(Object other) {
@ -55,7 +55,7 @@ public abstract class VirtualTarget implements Target {
}
public int hashCode() {
return 59 + (location == null ? 43 : location.hashCode());
return 59 + (this.location == null ? 43 : this.location.hashCode());
}
public void setLocation(Location location) {
@ -67,18 +67,18 @@ public abstract class VirtualTarget implements Target {
}
public interface VirtualTargetType<T extends VirtualTarget> {
public VirtualTargetType<RandomTarget> AVAILABLE_LINK = register("available_link", RandomTarget.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<EscapeTarget> ESCAPE = register("escape", EscapeTarget.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<GlobalReference> GLOBAL = register("global", GlobalReference.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<LimboTarget> LIMBO = register("limbo", LimboTarget.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<LocalReference> LOCAL = register("local", LocalReference.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<PublicPocketTarget> PUBLIC_POCKET = register("public_pocket", PublicPocketTarget.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<PocketEntranceMarker> POCKET_ENTRANCE = register("pocket_entrance", PocketEntranceMarker.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<PocketExitMarker> POCKET_EXIT = register("pocket_exit", PocketExitMarker.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<PrivatePocketTarget> PRIVATE = register("private", PrivatePocketTarget.CODEC, PrivatePocketExitTarget.COLOR);
public VirtualTargetType<PrivatePocketExitTarget> PRIVATE_POCKET_EXIT = register("private_pocket_exit", PrivatePocketExitTarget.CODEC, PrivatePocketExitTarget.COLOR);
public VirtualTargetType<RelativeReference> RELATIVE = register("relative", RelativeReference.CODEC, VirtualTarget.COLOR);
public VirtualTargetType<NoneTarget> NONE = register("none", NoneTarget.CODEC, COLOR);
VirtualTargetType<RandomTarget> AVAILABLE_LINK = register("available_link", RandomTarget.CODEC, VirtualTarget.COLOR);
VirtualTargetType<EscapeTarget> ESCAPE = register("escape", EscapeTarget.CODEC, VirtualTarget.COLOR);
VirtualTargetType<GlobalReference> GLOBAL = register("global", GlobalReference.CODEC, VirtualTarget.COLOR);
VirtualTargetType<LimboTarget> LIMBO = register("limbo", LimboTarget.CODEC, VirtualTarget.COLOR);
VirtualTargetType<LocalReference> LOCAL = register("local", LocalReference.CODEC, VirtualTarget.COLOR);
VirtualTargetType<PublicPocketTarget> PUBLIC_POCKET = register("public_pocket", PublicPocketTarget.CODEC, VirtualTarget.COLOR);
VirtualTargetType<PocketEntranceMarker> POCKET_ENTRANCE = register("pocket_entrance", PocketEntranceMarker.CODEC, VirtualTarget.COLOR);
VirtualTargetType<PocketExitMarker> POCKET_EXIT = register("pocket_exit", PocketExitMarker.CODEC, VirtualTarget.COLOR);
VirtualTargetType<PrivatePocketTarget> PRIVATE = register("private", PrivatePocketTarget.CODEC, PrivatePocketExitTarget.COLOR);
VirtualTargetType<PrivatePocketExitTarget> PRIVATE_POCKET_EXIT = register("private_pocket_exit", PrivatePocketExitTarget.CODEC, PrivatePocketExitTarget.COLOR);
VirtualTargetType<RelativeReference> RELATIVE = register("relative", RelativeReference.CODEC, VirtualTarget.COLOR);
VirtualTargetType<NoneTarget> NONE = register("none", NoneTarget.CODEC, COLOR);
Codec<T> codec();

View file

@ -2,6 +2,8 @@ package org.dimdev.dimdoors.util;
import java.util.Objects;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import net.minecraft.entity.Entity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
@ -33,10 +35,10 @@ public final class TeleportUtil {
}
public static void teleport(ServerPlayerEntity player, Location location) {
teleport(player, WorldUtil.getWorld(location.world), location.pos, 0);
teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, 0);
}
public static void teleport(ServerPlayerEntity player, RotatedLocation location) {
teleport(player, WorldUtil.getWorld(location.world), location.pos, (int) location.yaw);
teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, (int) location.yaw);
}
}