Repaired Teleportation

-included flow-math library in the jar file on "build"
-fix for public pockets' depthZeroLocation's calculation
-TeleportCommand got weakened a little
-Repaired Survival and inter-dimensional (non vanilla dimension)
teleporting
-Added some missing javadoc to utility classes
-Corrected transformLocationRandomly
-Made Location serializable
-Corrected mistake in commented out generation of and generated default
private and public pockets.

Todo:
-Loading a world with a generated pocket, crashes the game with an
infinite loop. Ergo, the registering of Pockets needs to be done
somewhere else than in their constructor.
This commit is contained in:
Mathijs Riezebos 2017-03-27 23:56:43 +02:00
parent 3b41149c16
commit 758e521443
34 changed files with 243 additions and 132 deletions

View file

@ -34,11 +34,16 @@ minecraft {
}
configurations {
includeInJar
embed
compile.extendsFrom(embed)
}
dependencies {
includeInJar 'com.flowpowered:flow-math:1.0.3'
compile configurations.includeInJar
embed 'com.flowpowered:flow-math:1.0.3'
}
jar {
from configurations.embed.collect { it.isDirectory() ? it : zipTree(it) }
}
processResources

View file

@ -185,9 +185,11 @@ public class PocketRegistry {
int shortenedZ = shortenedLocation.getPos().getZ();
int dimID = shortenedLocation.getDimensionID();
Location depthZeroLocation;
if (typeID != EnumPocketType.PRIVATE) {
if (typeID == EnumPocketType.DUNGEON) {
depthZeroLocation = DDRandomUtils.transformLocationRandomly(DDConfig.getOwCoordinateOffsetBase(), DDConfig.getOwCoordinateOffsetPower(), depth, origRiftLocation);
} else {
} else if (typeID == EnumPocketType.PUBLIC) {
depthZeroLocation = DDRandomUtils.transformLocationRandomly(DDConfig.getOwCoordinateOffsetBase(), DDConfig.getOwCoordinateOffsetPower(), 1, origRiftLocation);
} else { //PRIVATE
depthZeroLocation = origRiftLocation;
}

View file

@ -255,7 +255,7 @@ public class RiftRegistry {
if (destinationRift == null) {
DimDoors.warn(this.getClass(), "The rift that an entity is trying to teleport to seems to be null.");
}
return TeleportHelper.teleport(entity, destinationRift.getTeleportTargetLocation());
return TeleporterDimDoors.instance().teleport(entity, destinationRift.getTeleportTargetLocation());
}
//@todo are we ever going to use this method?

View file

@ -83,6 +83,7 @@ public class SchematicHandler {
}
}
}
//Schematic.TempGenerateDefaultSchematics();
}
private static List<PocketTemplate> loadTemplatesFromJson(String nameString, int maxPocketSize) { //depending on the "jSonType" value in the jSon, this might load several variations of a pocket at once, hence loadTemplate -->s<--

View file

@ -13,10 +13,10 @@ import java.util.List;
* Created by Jared Johnson on 1/26/2017.
*/
public class TeleportCommand extends CommandBase {
private final List aliases;
public TeleportCommand()
{
public TeleportCommand() {
aliases = new ArrayList();
aliases.add("dimteleport");
@ -43,8 +43,7 @@ public class TeleportCommand extends CommandBase {
int id = Integer.parseInt(args[0]);
if (sender instanceof EntityPlayerMP) {
server.getPlayerList().transferPlayerToDimension((EntityPlayerMP) sender, Integer.parseInt(args[0]), new TeleportHelper(new Location(id, 0,300,0)));
server.getPlayerList().transferPlayerToDimension((EntityPlayerMP) sender, Integer.parseInt(args[0]), TeleporterDimDoors.instance());
}
}
}

View file

@ -1,80 +0,0 @@
package com.zixiken.dimdoors.shared;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.DimDoors;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Teleporter;
import net.minecraft.world.WorldServer;
public class TeleportHelper extends Teleporter {
private final Location location;
public TeleportHelper(Location location) {//@todo make TeleportHelper static
super(location.getWorld());
this.location = location;
}
@Override
public void placeInPortal(Entity entityIn, float rotationYaw) {
BlockPos pos = location.getPos();
entityIn.setPositionAndUpdate(pos.getX() + .5, pos.getY() + .05, pos.getZ() + .5);
}
public static boolean teleport(Entity entity, Location newLocation) {
if (DimDoors.getDefWorld().isRemote) {
return false;
}
entity.timeUntilPortal = 50;
BlockPos newPos = newLocation.getPos();
int oldDimID = entity.dimension;
int newDimID = newLocation.getDimensionID();
WorldServer oldWorldServer = DimDoors.proxy.getWorldServer(oldDimID);
WorldServer newWorldServer = DimDoors.proxy.getWorldServer(newDimID);
//DimDoors.log(TeleportHelper.class, "Starting teleporting now:");
if (oldDimID == newDimID) {
if (entity instanceof EntityPlayer) {
DimDoors.log(TeleportHelper.class, "Teleporting Player within same dimension.");
EntityPlayerMP player = (EntityPlayerMP) entity;
//player.setLocationAndAngles(newPos.getX() + 0.5, newPos.getY() + 0.05, newPos.getZ() + 0.5, player.getRotationYawHead(), player.getRotatedYaw(Rotation.CLOCKWISE_180)); //@todo, instead of following line
player.setPositionAndUpdate(newPos.getX() + 0.5, newPos.getY() + 0.05, newPos.getZ() + 0.5);
player.world.updateEntityWithOptionalForce(player, false);
//player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
} else {
DimDoors.log(TeleportHelper.class, "Teleporting non-Player within same dimension.");
WorldServer world = (WorldServer) entity.world;
entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
entity.timeUntilPortal = 50;
world.resetUpdateEntityTick();
}
entity.timeUntilPortal = 50;
} else {
if (entity instanceof EntityPlayer) {
DimDoors.log(TeleportHelper.class, "Teleporting Player to new dimension.");
EntityPlayerMP player = (EntityPlayerMP) entity;
player.changeDimension(newDimID); //@todo, this only works for Vanilla dimensions, I've heard?
player.setPositionAndUpdate(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
player.world.updateEntityWithOptionalForce(player, false);
//player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
} else if (!entity.world.isRemote) {
DimDoors.log(TeleportHelper.class, "Teleporting non-Player to new dimension.");
entity.changeDimension(newDimID);
entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
oldWorldServer.resetUpdateEntityTick();
newWorldServer.resetUpdateEntityTick();
} else {
//does this statement ever get reached though?
return false;
}
entity.timeUntilPortal = 150;
}
return true;
//@todo set player angle in front of and facing away from the door
}
}

View file

@ -0,0 +1,143 @@
package com.zixiken.dimdoors.shared;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.DimDoors;
import java.util.EnumSet;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.play.server.SPacketChangeGameState;
import net.minecraft.network.play.server.SPacketEffect;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Teleporter;
import net.minecraft.world.WorldServer;
import net.minecraft.network.play.server.SPacketPlayerPosLook;
import net.minecraft.stats.AchievementList;
//ref: https://github.com/WayofTime/BloodMagic/blob/1.11/src/main/java/WayofTime/bloodmagic/ritual/portal/Teleports.java
public class TeleporterDimDoors extends Teleporter {
/**
* Teleporter isn't static, so TeleporterDimDoors can't be static, so we're
* using the the Singleton Design Pattern instead
*/
private static TeleporterDimDoors instance;
private TeleporterDimDoors(WorldServer world) {
super(world);
}
@Override
public boolean makePortal(Entity entity) {
return true;
}
@Override
public void removeStalePortalLocations(long worldTime) {
}
@Override
public boolean placeInExistingPortal(Entity entityIn, float rotationYaw) {
return true;
}
public static TeleporterDimDoors instance() {
if (instance == null) {
instance = new TeleporterDimDoors(DimDoors.proxy.getWorldServer(0));
}
return instance;
}
@Override
public void placeInPortal(Entity entity, float rotationYaw) {
}
public boolean teleport(Entity entity, Location location) { //@todo add float playerRotationYaw as a parameter
if (DimDoors.getDefWorld().isRemote) {
return false;
}
entity.timeUntilPortal = 50;
BlockPos newPos = location.getPos();
int oldDimID = entity.dimension;
int newDimID = location.getDimensionID();
//DimDoors.log(TeleportHelper.class, "Starting teleporting now:");
if (oldDimID == newDimID) {
if (entity instanceof EntityPlayer) {
DimDoors.log(TeleporterDimDoors.class, "Teleporting Player within same dimension.");
EntityPlayerMP player = (EntityPlayerMP) entity;
float playerRotationYaw = player.rotationYaw;
player.dismountRidingEntity();
((EntityPlayerMP) player).connection.setPlayerLocation(newPos.getX() + 0.5, newPos.getY() + 0.05, newPos.getZ() + 0.5, playerRotationYaw, player.rotationPitch, EnumSet.<SPacketPlayerPosLook.EnumFlags>noneOf(SPacketPlayerPosLook.EnumFlags.class));
//player.setRotationYawHead(f);
//player.world.updateEntityWithOptionalForce(player, false);
//player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
} else {
DimDoors.log(TeleporterDimDoors.class, "Teleporting non-Player within same dimension.");
WorldServer world = (WorldServer) entity.world;
entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
world.resetUpdateEntityTick();
}
entity.timeUntilPortal = 50;
} else {
WorldServer oldWorldServer = DimDoors.proxy.getWorldServer(oldDimID);
WorldServer newWorldServer = DimDoors.proxy.getWorldServer(newDimID);
if (entity instanceof EntityPlayer) {
DimDoors.log(TeleporterDimDoors.class, "Teleporting Player to new dimension.");
EntityPlayerMP player = (EntityPlayerMP) entity;
float playerRotationYaw = player.rotationYaw;
player.dismountRidingEntity();
processAchievements(player, newDimID);
player.mcServer.getPlayerList().transferPlayerToDimension(player, newDimID, this);
player.connection.sendPacket(new SPacketEffect(1032, BlockPos.ORIGIN, 0, false));
player.removeExperienceLevel(0); //update experience
player.setPlayerHealthUpdated(); //update health
//updating food seems inpossible
((EntityPlayerMP) player).connection.setPlayerLocation(newPos.getX() + 0.5, newPos.getY() + 0.05, newPos.getZ() + 0.5, playerRotationYaw, player.rotationPitch, EnumSet.<SPacketPlayerPosLook.EnumFlags>noneOf(SPacketPlayerPosLook.EnumFlags.class));
//player.setRotationYawHead(f);
//player.world.updateEntityWithOptionalForce(player, false);
//player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
} else if (!entity.world.isRemote) {
DimDoors.log(TeleporterDimDoors.class, "Teleporting non-Player to new dimension.");
entity.changeDimension(newDimID);
entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
oldWorldServer.resetUpdateEntityTick();
newWorldServer.resetUpdateEntityTick();
} else {
//does this statement ever get reached though?
return false;
}
entity.timeUntilPortal = 100;
}
return true;
//@todo set player angle in front of and facing away from the door
}
private void processAchievements(EntityPlayerMP player, int dimID) {
if (player.dimension == 1 && dimID == 1) {
player.world.removeEntity(player);
if (!player.playerConqueredTheEnd) {
player.playerConqueredTheEnd = true;
if (player.hasAchievement(AchievementList.THE_END2)) {
player.connection.sendPacket(new SPacketChangeGameState(4, 0.0F));
} else {
player.addStat(AchievementList.THE_END2);
player.connection.sendPacket(new SPacketChangeGameState(4, 1.0F));
}
}
} else if (player.dimension == 0 && dimID == 1) {
player.addStat(AchievementList.THE_END);
} else if (dimID == -1) {
player.addStat(AchievementList.PORTAL);
}
}
}

View file

@ -3,7 +3,7 @@ package com.zixiken.dimdoors.shared.items;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.RayTraceHelper;
import com.zixiken.dimdoors.shared.TeleportHelper;
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
import com.zixiken.dimdoors.shared.tileentities.TileEntityRift;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -63,7 +63,7 @@ public class ItemRiftBlade extends ItemSword {
return new ActionResult(teleportResult, stack);
} else if (RayTraceHelper.isLivingEntity(hit)) {
EnumActionResult teleportResult = TeleportHelper.teleport(player, new Location(world, hit.getBlockPos())) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL; //@todo teleport to a location 1 or 2 blocks distance from the entity
EnumActionResult teleportResult = TeleporterDimDoors.instance().teleport(player, new Location(world, hit.getBlockPos())) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL; //@todo teleport to a location 1 or 2 blocks distance from the entity
if (teleportResult == EnumActionResult.SUCCESS) {
stack.damageItem(1, player);
}

View file

@ -7,7 +7,7 @@ import com.zixiken.dimdoors.shared.PocketRegistry;
import com.zixiken.dimdoors.shared.blocks.BlockDimDoor;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.RiftRegistry;
import com.zixiken.dimdoors.shared.TeleportHelper;
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
import com.zixiken.dimdoors.shared.util.DDRandomUtils;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import java.util.Random;
@ -76,7 +76,7 @@ public class TileEntityDimDoor extends DDTileEntityBase {
}
Location tpLocation = RiftRegistry.Instance.getTeleportLocation(otherRiftID);
RiftRegistry.Instance.validatePlayerPocketEntry(entity, otherRiftID);
return TeleportHelper.teleport(entity, tpLocation); //@todo this seems to return false?
return TeleporterDimDoors.instance().teleport(entity, tpLocation); //@todo this seems to return false?
}
public void uponDoorPlacement(@Nullable TileEntity possibleOldRift) {

View file

@ -6,7 +6,7 @@
package com.zixiken.dimdoors.shared.tileentities;
import com.zixiken.dimdoors.shared.RiftRegistry;
import com.zixiken.dimdoors.shared.TeleportHelper;
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
import com.zixiken.dimdoors.shared.util.Location;
import net.minecraft.entity.Entity;
@ -25,6 +25,6 @@ public class TileEntityDimDoorChaos extends TileEntityDimDoor {
int otherRiftID = RiftRegistry.Instance.getRandomNonPersonalRiftID();
Location tpLocation = RiftRegistry.Instance.getTeleportLocation(otherRiftID);
RiftRegistry.Instance.validatePlayerPocketEntry(entity, otherRiftID);
return TeleportHelper.teleport(entity, tpLocation);
return TeleporterDimDoors.instance().teleport(entity, tpLocation);
}
}

View file

@ -8,7 +8,7 @@ package com.zixiken.dimdoors.shared.tileentities;
import com.zixiken.dimdoors.shared.EnumPocketType;
import com.zixiken.dimdoors.shared.PocketRegistry;
import com.zixiken.dimdoors.shared.RiftRegistry;
import com.zixiken.dimdoors.shared.TeleportHelper;
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraft.entity.Entity;
@ -38,7 +38,7 @@ public class TileEntityDimDoorPersonal extends TileEntityDimDoor {
} else {
return false;
}
return TeleportHelper.teleport(entity, tpLocation);
return TeleporterDimDoors.instance().teleport(entity, tpLocation);
}
}

View file

@ -3,7 +3,7 @@ package com.zixiken.dimdoors.shared.tileentities;
import com.zixiken.dimdoors.shared.Pocket;
import com.zixiken.dimdoors.shared.PocketRegistry;
import com.zixiken.dimdoors.shared.RiftRegistry;
import com.zixiken.dimdoors.shared.TeleportHelper;
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
import com.zixiken.dimdoors.shared.util.Location;
import net.minecraft.entity.Entity;
@ -11,17 +11,17 @@ public class TileEntityDimDoorWarp extends TileEntityDimDoor {
@Override
public boolean tryTeleport(Entity entity) {
Location teleportLocation;
Location tpLocation;
if (isPaired()) {
int otherRiftID = getPairedRiftID();
teleportLocation = RiftRegistry.Instance.getTeleportLocation(otherRiftID);
tpLocation = RiftRegistry.Instance.getTeleportLocation(otherRiftID);
RiftRegistry.Instance.validatePlayerPocketEntry(entity, otherRiftID);
} else if (!(this.isInPocket)) {
return false;
} else {
Pocket pocket = PocketRegistry.INSTANCE.getPocket(this.pocketID, this.getPocketType());
teleportLocation = pocket.getDepthZeroLocation();
tpLocation = pocket.getDepthZeroLocation();
}
return TeleportHelper.teleport(entity, teleportLocation);
return TeleporterDimDoors.instance().teleport(entity, tpLocation);
}
}

View file

@ -3,7 +3,7 @@ package com.zixiken.dimdoors.shared.tileentities;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
import com.zixiken.dimdoors.shared.RiftRegistry;
import com.zixiken.dimdoors.shared.TeleportHelper;
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
import com.zixiken.dimdoors.shared.util.Location;
import java.util.List;
import java.util.Random;
@ -157,6 +157,6 @@ public class TileEntityRift extends DDTileEntityBase implements ITickable {
}
Location tpLocation = RiftRegistry.Instance.getTeleportLocation(otherRiftID);
RiftRegistry.Instance.validatePlayerPocketEntry(entity, otherRiftID);
return TeleportHelper.teleport(entity, tpLocation); //@todo this seems to return false?
return TeleporterDimDoors.instance().teleport(entity, tpLocation); //@todo this seems to return false?
}
}

View file

@ -3,7 +3,7 @@ package com.zixiken.dimdoors.shared.tileentities;
import com.zixiken.dimdoors.shared.Pocket;
import com.zixiken.dimdoors.shared.PocketRegistry;
import com.zixiken.dimdoors.shared.RiftRegistry;
import com.zixiken.dimdoors.shared.TeleportHelper;
import com.zixiken.dimdoors.shared.TeleporterDimDoors;
import com.zixiken.dimdoors.shared.util.Location;
import java.util.Random;
import net.minecraft.entity.Entity;
@ -32,17 +32,17 @@ public class TileEntityTransTrapdoor extends DDTileEntityBase {
@Override
public boolean tryTeleport(Entity entity) {
Location teleportLocation;
Location tpLocation;
if (isPaired()) {
int otherRiftID = getPairedRiftID();
teleportLocation = RiftRegistry.Instance.getTeleportLocation(otherRiftID);
tpLocation = RiftRegistry.Instance.getTeleportLocation(otherRiftID);
RiftRegistry.Instance.validatePlayerPocketEntry(entity, otherRiftID);
} else if (!(this.isInPocket)) {
return false;
} else {
Pocket pocket = PocketRegistry.INSTANCE.getPocket(this.pocketID, this.getPocketType());
teleportLocation = pocket.getDepthZeroLocation();
tpLocation = pocket.getDepthZeroLocation();
}
return TeleportHelper.teleport(entity, teleportLocation);
return TeleporterDimDoors.instance().teleport(entity, tpLocation);
}
}

View file

@ -40,11 +40,11 @@ public class DDMathUtils {
/**
* Returns the sum of the values of all integer elements in an integer array
*
* @param intArray
* @param intArray the integers to calculate the sum of
* @param flag this flag is meant to check if all elements in the array must
* be positive, negative, or it doesn't matter
* be positive (0), negative(1), or it doesn't matter (anything else)
* @pre
* {@code flag == 0 || (flag == 1 && (\forall i; intArray.has(i); i >= 0)) || (flag == 2 && (\forall i; intArray.has(i); i <= 0))}
* {@code (flag != 0 && flag != 1) || (flag == 0 && (\forall i; intArray.has(i); i >= 0)) || (flag == 1 && (\forall i; intArray.has(i); i <= 0))}
* @throws IllegalArgumentException if precondition is violated
* @return {@code sum(i = 0; intArray.has(i); intArray[i]) }
*/
@ -53,6 +53,8 @@ public class DDMathUtils {
for (int i : intArray) { //check flag
if (flag == 0 && i < 0) { //
throw new IllegalArgumentException("all integers in array must be positive");
} else if (flag == 1 && i > 0) { //
throw new IllegalArgumentException("all integers in array must be negative");
}
r += i;
}

View file

@ -5,6 +5,7 @@
*/
package com.zixiken.dimdoors.shared.util;
import com.zixiken.dimdoors.DimDoors;
import java.util.Random;
import net.minecraft.util.EnumFacing;
@ -35,22 +36,27 @@ public class DDRandomUtils {
}
/**
* Hello world
* This method returns the sum of {@code base} and a random element of
* {@code transformations} the weight of each of the entries in
*
* @param base
* @param transformations
* @param weights
* @pre transformations.length = weights.length
* @param base the base value to transform from
* @param transformations the possible transformations
* @param weights the chance-weight of those transformations
* @pre {@code transformations.length = weights.length} && {@code (\forall i; intArray.has(i); i >= 0)}
* && {@code DDMathUtils.arraySum(weights, 1) > 0}
* @throws IllegalArgumentException if precondition is violated
* @return the sum of {@code base} and the value of an element in
* {@code transformations}
*/
public static int transformRandomly(int base, int[] transformations, int[] weights) {
if (transformations.length != weights.length) {
throw new IllegalArgumentException("pre was violated");
throw new IllegalArgumentException("pre was violated, transformations.length != weights.length");
}
Random random = new Random();
int weightSum = DDMathUtils.arraySum(weights, (short) 1);
int weightSum = DDMathUtils.arraySum(weights, (short) 0);
if (weightSum <= 0) {
throw new IllegalArgumentException("pre was violated, DDMathUtils.arraySum(weights, 1) <= 0");
}
int choice = random.nextInt(weightSum);
for (int i = 0; i < weights.length; i++) {
choice -= weights[i];
@ -62,17 +68,31 @@ public class DDRandomUtils {
}
/**
* This method returns a Location that is determined by offsetting
* origLocation in the x and z direction by a randomly positive or negative
* random integer value, both based on the formula:
* {@code randomInt((base * depth) ^ power)}
*
* @param base
* @param power
* @param depth
* @param origLocation
* @return
* @param base this value is configured in the config files of DimDoors
* @param power this value is configured in the config files of DimDoors
* @param depth this should be the depth of the newly generated dungeon
* pocket
* @pre {@code base > 0 && depth > 0 && power >= 0 && origLocation != null}
* @throws IllegalArgumentException if pre is violated
* @param origLocation the original location to offset from
* @return a Location for which the x and z coordinates have both been
* offset by random values between {@code -(base * depth) ^ power)} and
* {@code ((base * depth) ^ power)} and y and dimensionID are the same as
* {@code origLocation}'s
*/
public static Location transformLocationRandomly(int base, double power, int depth, Location origLocation) {
if (base <= 0 || depth <= 0 || power < 0 || origLocation == null) {
throw new IllegalArgumentException("pre was violated");
}
Random random = new Random();
int xOffset = (int) Math.pow(base * depth, power) * (random.nextBoolean() ? 1 : -1);
int zOffset = (int) Math.pow(base * depth, power) * (random.nextBoolean() ? 1 : -1);
DimDoors.log(DDRandomUtils.class, "base = " + base + ", power = " + power + ", depth = " + depth + " and power is " + Math.pow(base * depth, power));
int xOffset = random.nextInt((int) Math.pow(base * depth, power)) * (random.nextBoolean() ? 1 : -1);
int zOffset = random.nextInt((int) Math.pow(base * depth, power)) * (random.nextBoolean() ? 1 : -1);
return new Location(origLocation.getWorld(), origLocation.getPos().offset(EnumFacing.EAST, xOffset).offset(EnumFacing.SOUTH, zOffset));
}

View file

@ -1,6 +1,8 @@
package com.zixiken.dimdoors.shared.util;
import com.zixiken.dimdoors.DimDoors;
import java.io.Serializable;
import java.util.Objects;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -12,7 +14,7 @@ import net.minecraft.world.WorldServer;
*
* @author Robijnvogel
*/
public class Location {
public class Location implements Serializable {
private int dimensionID;
private BlockPos pos;
@ -22,7 +24,7 @@ public class Location {
}
public Location(World world, int x, int y, int z) {
this(world, new BlockPos(x,y,z));
this(world, new BlockPos(x, y, z));
}
public Location(int dimID, int x, int y, int z) {
@ -78,7 +80,24 @@ public class Location {
BlockPos blockPos = new BlockPos(x, y, z);
return new Location(worldID, blockPos);
}
@Override
public boolean equals(Object o) {
if (o == null || !(o instanceof Location)) {
return false;
}
Location other = (Location) o;
return other.dimensionID == this.dimensionID && other.pos.equals(this.pos);
}
@Override
public int hashCode() {
int hash = 5;
hash = 89 * hash + this.dimensionID;
hash = 89 * hash + Objects.hashCode(this.pos);
return hash;
}
@Override
public String toString() {
return "Location: dimID: " + this.dimensionID + " position: " + this.pos.toString();

View file

@ -443,11 +443,11 @@ public class Schematic {
|| y == 0 || y == maxbound - 1
|| z == 0 || z == maxbound - 1) {
schematic.blockData[x][y][z] = 1; //outer dim wall
} else if (DDMathUtils.withinDistanceOf(new int[]{x, y, z}, 6, new int[]{0, maxbound})) {
} else if (DDMathUtils.withinDistanceOf(new int[]{x, y, z}, 5, new int[]{0, maxbound})) {
if (z == 4 && x == (maxbound - 1) / 2 && y > 4 && y < 7) {
if (y == 5) {
schematic.blockData[x][y][z] = 3; //door bottom
} else {
} else { // y == 6
schematic.blockData[x][y][z] = 4; //door top
}
} else {