Make local/relative destinations when possible

This commit is contained in:
Runemoro 2018-03-29 01:14:36 -04:00
parent b87a810d2c
commit 4c484166dc
5 changed files with 33 additions and 5 deletions

View file

@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.dimdev.ddutils.RotatedLocation; import org.dimdev.ddutils.RotatedLocation;
import org.dimdev.dimdoors.shared.blocks.ModBlocks; import org.dimdev.dimdoors.shared.blocks.ModBlocks;
import org.dimdev.dimdoors.shared.rifts.DestinationMaker;
import org.dimdev.dimdoors.shared.rifts.destinations.GlobalDestination; import org.dimdev.dimdoors.shared.rifts.destinations.GlobalDestination;
import org.dimdev.dimdoors.shared.sound.ModSounds; import org.dimdev.dimdoors.shared.sound.ModSounds;
import org.dimdev.dimdoors.shared.tileentities.TileEntityFloatingRift; import org.dimdev.dimdoors.shared.tileentities.TileEntityFloatingRift;
@ -70,7 +71,7 @@ public class ItemRiftSignature extends Item {
World sourceWorld = target.getLocation().getWorld(); World sourceWorld = target.getLocation().getWorld();
sourceWorld.setBlockState(target.getLocation().getPos(), ModBlocks.RIFT.getDefaultState()); sourceWorld.setBlockState(target.getLocation().getPos(), ModBlocks.RIFT.getDefaultState());
TileEntityFloatingRift rift1 = (TileEntityFloatingRift) target.getLocation().getTileEntity(); TileEntityFloatingRift rift1 = (TileEntityFloatingRift) target.getLocation().getTileEntity();
rift1.setDestination(new GlobalDestination(new Location(world, pos))); rift1.setDestination(DestinationMaker.relativeIfPossible(target.getLocation(), new Location(world, pos)));
rift1.setTeleportTargetRotation(target.getYaw(), 0); // setting pitch to 0 because player is always facing down to place rift rift1.setTeleportTargetRotation(target.getYaw(), 0); // setting pitch to 0 because player is always facing down to place rift
rift1.register(); rift1.register();
} }
@ -78,7 +79,7 @@ public class ItemRiftSignature extends Item {
// Place a rift at the target point // Place a rift at the target point
world.setBlockState(pos, ModBlocks.RIFT.getDefaultState()); world.setBlockState(pos, ModBlocks.RIFT.getDefaultState());
TileEntityFloatingRift rift2 = (TileEntityFloatingRift) world.getTileEntity(pos); TileEntityFloatingRift rift2 = (TileEntityFloatingRift) world.getTileEntity(pos);
rift2.setDestination(new GlobalDestination(target.getLocation())); rift2.setDestination(DestinationMaker.relativeIfPossible(new Location(world, pos), target.getLocation()));
rift2.setTeleportTargetRotation(player.rotationYaw, 0); rift2.setTeleportTargetRotation(player.rotationYaw, 0);
rift2.register(); rift2.register();

View file

@ -17,6 +17,7 @@ import org.dimdev.ddutils.Location;
import org.dimdev.dimdoors.DimDoors; import org.dimdev.dimdoors.DimDoors;
import org.dimdev.ddutils.RotatedLocation; import org.dimdev.ddutils.RotatedLocation;
import org.dimdev.dimdoors.shared.blocks.ModBlocks; import org.dimdev.dimdoors.shared.blocks.ModBlocks;
import org.dimdev.dimdoors.shared.rifts.DestinationMaker;
import org.dimdev.dimdoors.shared.rifts.destinations.GlobalDestination; import org.dimdev.dimdoors.shared.rifts.destinations.GlobalDestination;
import org.dimdev.dimdoors.shared.sound.ModSounds; import org.dimdev.dimdoors.shared.sound.ModSounds;
import org.dimdev.dimdoors.shared.tileentities.TileEntityFloatingRift; import org.dimdev.dimdoors.shared.tileentities.TileEntityFloatingRift;
@ -77,7 +78,7 @@ public class ItemStabilizedRiftSignature extends Item { // TODO: common supercla
// Place a rift at the source point // Place a rift at the source point
world.setBlockState(pos, ModBlocks.RIFT.getDefaultState()); world.setBlockState(pos, ModBlocks.RIFT.getDefaultState());
TileEntityFloatingRift rift2 = (TileEntityFloatingRift) world.getTileEntity(pos); TileEntityFloatingRift rift2 = (TileEntityFloatingRift) world.getTileEntity(pos);
rift2.setDestination(new GlobalDestination(target.getLocation())); rift2.setDestination(DestinationMaker.relativeIfPossible(new Location(world, pos), target.getLocation()));
rift2.setTeleportTargetRotation(player.rotationYaw, 0); rift2.setTeleportTargetRotation(player.rotationYaw, 0);
rift2.register(); rift2.register();

View file

@ -0,0 +1,25 @@
package org.dimdev.dimdoors.shared.rifts;
import net.minecraft.util.math.Vec3i;
import org.dimdev.ddutils.Location;
import org.dimdev.dimdoors.shared.rifts.destinations.GlobalDestination;
import org.dimdev.dimdoors.shared.rifts.destinations.LocalDestination;
import org.dimdev.dimdoors.shared.rifts.destinations.RelativeDestination;
public final class DestinationMaker {
public static RiftDestination localIfPossible(Location from, Location to) {
if (from.getDim() != to.getDim()) {
return new GlobalDestination(to);
} else {
return new LocalDestination(to.getPos());
}
}
public static RiftDestination relativeIfPossible(Location from, Location to) {
if (from.getDim() != to.getDim()) {
return new GlobalDestination(to);
} else {
return new RelativeDestination(new Vec3i(to.getX() - from.getX(), to.getY() - from.getY(), to.getZ() - from.getZ()));
}
}
}

View file

@ -169,7 +169,7 @@ import java.util.Set;
private static void linkRifts(Location from, Location to) { private static void linkRifts(Location from, Location to) {
TileEntityRift tileEntityFrom = (TileEntityRift) from.getTileEntity(); TileEntityRift tileEntityFrom = (TileEntityRift) from.getTileEntity();
TileEntityRift tileEntityTo = (TileEntityRift) to.getTileEntity(); TileEntityRift tileEntityTo = (TileEntityRift) to.getTileEntity();
tileEntityFrom.setDestination(new GlobalDestination(to)); // TODO: local if possible tileEntityFrom.setDestination(DestinationMaker.localIfPossible(from, to));
tileEntityFrom.markDirty(); tileEntityFrom.markDirty();
if (tileEntityTo.getProperties() != null) { if (tileEntityTo.getProperties() != null) {
tileEntityTo.getProperties().linksRemaining--; tileEntityTo.getProperties().linksRemaining--;

View file

@ -5,6 +5,7 @@ import net.minecraft.nbt.NBTTagCompound;
import org.dimdev.ddutils.Location; import org.dimdev.ddutils.Location;
import org.dimdev.ddutils.RGBA; import org.dimdev.ddutils.RGBA;
import org.dimdev.ddutils.RotatedLocation; import org.dimdev.ddutils.RotatedLocation;
import org.dimdev.dimdoors.shared.rifts.DestinationMaker;
import org.dimdev.dimdoors.shared.rifts.RiftDestination; import org.dimdev.dimdoors.shared.rifts.RiftDestination;
public abstract class RestoringDestination extends RiftDestination { public abstract class RestoringDestination extends RiftDestination {
@ -27,7 +28,7 @@ public abstract class RestoringDestination extends RiftDestination {
Location linkTarget = makeLinkTarget(loc, entity); Location linkTarget = makeLinkTarget(loc, entity);
if (linkTarget != null) { if (linkTarget != null) {
wrappedDestination = new GlobalDestination(linkTarget); wrappedDestination = DestinationMaker.localIfPossible(loc.getLocation(), linkTarget);
wrappedDestination.register(loc.getLocation()); wrappedDestination.register(loc.getLocation());
wrappedDestination.teleport(loc, entity); wrappedDestination.teleport(loc, entity);