parent
b9f82195b4
commit
a644572c7b
9 changed files with 105 additions and 38 deletions
|
@ -1,7 +1,6 @@
|
|||
package org.dimdev.dimdoors.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import org.dimdev.dimdoors.util.TeleportUtil;
|
||||
|
||||
import net.minecraft.command.argument.DimensionArgumentType;
|
||||
import net.minecraft.command.argument.Vec3ArgumentType;
|
||||
|
@ -32,8 +31,8 @@ public class DimTeleportCommand {
|
|||
}
|
||||
|
||||
private static int teleport(ServerPlayerEntity player, ServerWorld dimension, Vec3d pos) {
|
||||
TeleportUtil.teleport(player, dimension, pos, 0);
|
||||
player.moveToWorld(dimension);
|
||||
player.setPos(pos.x, pos.y, pos.z);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
55
src/main/java/org/dimdev/dimdoors/mixin/EntityMixin.java
Normal file
55
src/main/java/org/dimdev/dimdoors/mixin/EntityMixin.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package org.dimdev.dimdoors.mixin;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.dimdev.dimdoors.util.EntityExtensions;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.world.TeleportTarget;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
public class EntityMixin implements EntityExtensions {
|
||||
@Shadow
|
||||
public World world;
|
||||
@Unique
|
||||
private boolean dimdoors_readyToTeleport = false;
|
||||
private TeleportTarget dimdoors_teleportTarget = null;
|
||||
|
||||
@Inject(at = @At("HEAD"), cancellable = true, method = "getTeleportTarget")
|
||||
public void interceptTeleportTarget(ServerWorld destination, CallbackInfoReturnable<TeleportTarget> cir) {
|
||||
if (destination.getRegistryKey().getValue().getNamespace().equals("dimdoors")) {
|
||||
if (this.dimdoors_isReadyToTeleport()) {
|
||||
cir.setReturnValue(Objects.requireNonNull(this.dimdoors_teleportTarget));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(at = @At("TAIL"), method = "moveToWorld")
|
||||
public void cleanup(ServerWorld destination, CallbackInfoReturnable<TeleportTarget> cir) {
|
||||
this.dimdoors_teleportTarget = null;
|
||||
this.dimdoors_setReadyToTeleport(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dimdoors_isReadyToTeleport() {
|
||||
return this.dimdoors_readyToTeleport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dimdoors_setReadyToTeleport(boolean value) {
|
||||
this.dimdoors_readyToTeleport = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dimdoors_setTeleportTarget(TeleportTarget target) {
|
||||
this.dimdoors_teleportTarget = target;
|
||||
}
|
||||
}
|
|
@ -53,7 +53,8 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD
|
|||
}
|
||||
if (!entity.getEntityWorld().isClient) {
|
||||
if (ModDimensions.LIMBO_DIMENSION != null) {
|
||||
TeleportUtil.teleportToLimbo(entity);
|
||||
Entity newEntity = entity.moveToWorld(ModDimensions.LIMBO_DIMENSION);
|
||||
newEntity.setPos(this.location.getX(), this.location.getY(), this.location.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ public class LimboTarget extends VirtualTarget implements EntityTarget {
|
|||
@Override
|
||||
public boolean receiveEntity(Entity entity, float yawOffset) {
|
||||
TeleportUtil.teleport(entity, ModDimensions.LIMBO_DIMENSION, entity.getPos(), yawOffset);
|
||||
//FabricDimensions.teleport(entity, entity.getServer().getWorld(LIMBO));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,11 @@ package org.dimdev.dimdoors.rift.targets;
|
|||
import java.util.UUID;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
|
||||
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
||||
import org.dimdev.dimdoors.rift.registry.RiftRegistry;
|
||||
import org.dimdev.dimdoors.util.EntityUtils;
|
||||
import org.dimdev.dimdoors.util.Location;
|
||||
import org.dimdev.dimdoors.util.RGBA;
|
||||
import org.dimdev.dimdoors.util.TeleportUtil;
|
||||
import org.dimdev.dimdoors.world.ModDimensions;
|
||||
import org.dimdev.dimdoors.world.pocket.Pocket;
|
||||
import org.dimdev.dimdoors.world.pocket.PocketRegistry;
|
||||
|
@ -18,11 +16,8 @@ import org.dimdev.dimdoors.world.pocket.PrivatePocketData;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
|
||||
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
|
||||
|
||||
//import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PrivatePocketExitTarget extends VirtualTarget implements EntityTarget {
|
||||
public static final Codec<PrivatePocketExitTarget> CODEC = Codec.unit(PrivatePocketExitTarget::new);
|
||||
public static final RGBA COLOR = new RGBA(0, 1, 0, 1);
|
||||
|
@ -47,7 +42,7 @@ public class PrivatePocketExitTarget extends VirtualTarget implements EntityTarg
|
|||
} else {
|
||||
EntityUtils.chat(entity, new TranslatableText("rifts.destinations.private_pocket_exit.rift_has_closed"));
|
||||
}
|
||||
TeleportUtil.teleportToLimbo(entity);
|
||||
//FabricDimensions.teleport(entity, entity.getServer().getWorld(ModDimensions.LIMBO));
|
||||
return false;
|
||||
} else {
|
||||
((EntityTarget) destLoc.getBlockEntity()).receiveEntity(entity, yawOffset);
|
||||
|
|
|
@ -27,16 +27,18 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.world.Heightmap;
|
||||
|
||||
public class RandomTarget extends VirtualTarget { // TODO: Split into DungeonTarget subclass
|
||||
public static final Codec<RandomTarget> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
Codec.FLOAT.fieldOf("newRiftWeight").forGetter(target -> target.newRiftWeight),
|
||||
Codec.DOUBLE.fieldOf("weightMaximum").forGetter(location -> location.weightMaximum),
|
||||
Codec.DOUBLE.fieldOf("coordFactor").forGetter(location -> location.coordFactor),
|
||||
Codec.DOUBLE.fieldOf("positiveDepthFactor").forGetter(location -> location.positiveDepthFactor),
|
||||
Codec.DOUBLE.fieldOf("negativeDepthFactor").forGetter(location -> location.negativeDepthFactor),
|
||||
Codec.INT_STREAM.comapFlatMap(a -> DataResult.success(a.boxed().collect(Collectors.toSet())), a -> a.stream().mapToInt(Integer::intValue)).fieldOf("acceptedGroups").forGetter(target -> target.acceptedGroups),
|
||||
Codec.BOOL.fieldOf("noLink").forGetter(target -> target.noLink),
|
||||
Codec.BOOL.fieldOf("noLinkBack").forGetter(target -> target.noLinkBack)
|
||||
).apply(instance, RandomTarget::new));
|
||||
public static final Codec<RandomTarget> CODEC = RecordCodecBuilder.create(instance -> {
|
||||
return instance.group(
|
||||
Codec.FLOAT.fieldOf("newRiftWeight").forGetter(target -> target.newRiftWeight),
|
||||
Codec.DOUBLE.fieldOf("weightMaximum").forGetter(location -> location.weightMaximum),
|
||||
Codec.DOUBLE.fieldOf("coordFactor").forGetter(location -> location.coordFactor),
|
||||
Codec.DOUBLE.fieldOf("positiveDepthFactor").forGetter(location -> location.positiveDepthFactor),
|
||||
Codec.DOUBLE.fieldOf("negativeDepthFactor").forGetter(location -> location.negativeDepthFactor),
|
||||
Codec.INT_STREAM.comapFlatMap(a -> DataResult.success(a.boxed().collect(Collectors.toSet())), a -> a.stream().mapToInt(Integer::intValue)).fieldOf("acceptedGroups").forGetter(target -> target.acceptedGroups),
|
||||
Codec.BOOL.fieldOf("noLink").forGetter(target -> target.noLink),
|
||||
Codec.BOOL.fieldOf("noLinkBack").forGetter(target -> target.noLinkBack)
|
||||
).apply(instance, RandomTarget::new);
|
||||
});
|
||||
|
||||
protected float newRiftWeight;
|
||||
protected double weightMaximum;
|
||||
|
|
11
src/main/java/org/dimdev/dimdoors/util/EntityExtensions.java
Normal file
11
src/main/java/org/dimdev/dimdoors/util/EntityExtensions.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package org.dimdev.dimdoors.util;
|
||||
|
||||
import net.minecraft.world.TeleportTarget;
|
||||
|
||||
public interface EntityExtensions {
|
||||
boolean dimdoors_isReadyToTeleport();
|
||||
|
||||
void dimdoors_setReadyToTeleport(boolean value);
|
||||
|
||||
void dimdoors_setTeleportTarget(TeleportTarget target);
|
||||
}
|
|
@ -13,10 +13,13 @@ import net.minecraft.util.registry.RegistryKey;
|
|||
import net.minecraft.world.World;
|
||||
|
||||
public class Location {
|
||||
public static final Codec<Location> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
World.CODEC.fieldOf("world").forGetter(location -> location.world),
|
||||
BlockPos.CODEC.fieldOf("pos").forGetter(location -> location.pos)
|
||||
).apply(instance, Location::new));
|
||||
public static final Codec<Location> CODEC = RecordCodecBuilder.create(instance -> {
|
||||
return instance.group(World.CODEC.fieldOf("world").forGetter(location -> {
|
||||
return location.world;
|
||||
}), BlockPos.CODEC.fieldOf("pos").forGetter(location -> {
|
||||
return location.pos;
|
||||
})).apply(instance, Location::new);
|
||||
});
|
||||
|
||||
public final RegistryKey<World> world;
|
||||
public final BlockPos pos;
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
package org.dimdev.dimdoors.util;
|
||||
|
||||
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
|
||||
import org.dimdev.dimdoors.world.ModDimensions;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.TeleportTarget;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public final class TeleportUtil {
|
||||
public static void teleport(Entity entity, World world, BlockPos pos, int yawOffset) {
|
||||
if (world.isClient) {
|
||||
|
@ -27,18 +23,22 @@ public final class TeleportUtil {
|
|||
throw new UnsupportedOperationException("Only supported on ServerWorld");
|
||||
}
|
||||
|
||||
FabricDimensions.teleport(entity, (ServerWorld) world, new TeleportTarget(pos, Vec3d.ZERO, entity.getYaw(1.0F) + yawOffset, entity.getPitch(1.0F)));
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
((ServerPlayerEntity) entity).teleport((ServerWorld) world, pos.x, pos.y, pos.z, entity.getYaw(1.0F) + yawOffset, entity.getPitch(1.0F));
|
||||
} else if (entity.world.getRegistryKey().equals(world.getRegistryKey())) {
|
||||
entity.setPos(pos.x, pos.y, pos.z);
|
||||
entity.setYaw(entity.yaw + yawOffset);
|
||||
} else {
|
||||
EntityUtils.prepareTeleportation(entity, pos, yawOffset);
|
||||
entity.moveToWorld((ServerWorld) world);
|
||||
}
|
||||
}
|
||||
|
||||
public static void teleport(Entity entity, Location location) {
|
||||
teleport(entity, DimensionalDoorsInitializer.getWorld(location.world), location.pos, 0);
|
||||
public static void teleport(ServerPlayerEntity player, Location location) {
|
||||
teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, 0);
|
||||
}
|
||||
|
||||
public static void teleport(Entity entity, RotatedLocation location) {
|
||||
teleport(entity, DimensionalDoorsInitializer.getWorld(location.world), location.pos, (int) location.yaw);
|
||||
}
|
||||
|
||||
public static void teleportToLimbo(Entity entity) {
|
||||
teleport(entity, ModDimensions.LIMBO_DIMENSION, entity.getPos().multiply(1.0 / ModDimensions.LIMBO_DIMENSION.getDimension().getCoordinateScale()), 0);
|
||||
public static void teleport(ServerPlayerEntity player, RotatedLocation location) {
|
||||
teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, (int) location.yaw);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue