diff --git a/build.gradle b/build.gradle index fea6f3cd..32332a05 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/src/main/java/com/zixiken/dimdoors/shared/PocketRegistry.java b/src/main/java/com/zixiken/dimdoors/shared/PocketRegistry.java index f6969c7f..ea6e6157 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/PocketRegistry.java +++ b/src/main/java/com/zixiken/dimdoors/shared/PocketRegistry.java @@ -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; } diff --git a/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java b/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java index 656af377..9b5858de 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java +++ b/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java @@ -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? diff --git a/src/main/java/com/zixiken/dimdoors/shared/SchematicHandler.java b/src/main/java/com/zixiken/dimdoors/shared/SchematicHandler.java index 7e738be7..4bce61a3 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/SchematicHandler.java +++ b/src/main/java/com/zixiken/dimdoors/shared/SchematicHandler.java @@ -83,6 +83,7 @@ public class SchematicHandler { } } } + //Schematic.TempGenerateDefaultSchematics(); } private static List 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<-- diff --git a/src/main/java/com/zixiken/dimdoors/shared/TeleportCommand.java b/src/main/java/com/zixiken/dimdoors/shared/TeleportCommand.java index 02c7a518..ec06c25d 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/TeleportCommand.java +++ b/src/main/java/com/zixiken/dimdoors/shared/TeleportCommand.java @@ -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()); } } } diff --git a/src/main/java/com/zixiken/dimdoors/shared/TeleportHelper.java b/src/main/java/com/zixiken/dimdoors/shared/TeleportHelper.java deleted file mode 100644 index 9ad3844e..00000000 --- a/src/main/java/com/zixiken/dimdoors/shared/TeleportHelper.java +++ /dev/null @@ -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 - } -} diff --git a/src/main/java/com/zixiken/dimdoors/shared/TeleporterDimDoors.java b/src/main/java/com/zixiken/dimdoors/shared/TeleporterDimDoors.java new file mode 100644 index 00000000..628c4850 --- /dev/null +++ b/src/main/java/com/zixiken/dimdoors/shared/TeleporterDimDoors.java @@ -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.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.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); + } + } +} diff --git a/src/main/java/com/zixiken/dimdoors/shared/items/ItemRiftBlade.java b/src/main/java/com/zixiken/dimdoors/shared/items/ItemRiftBlade.java index 07a2a4f2..8296708d 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/items/ItemRiftBlade.java +++ b/src/main/java/com/zixiken/dimdoors/shared/items/ItemRiftBlade.java @@ -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); } diff --git a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoor.java b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoor.java index facd38ca..a843468f 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoor.java +++ b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoor.java @@ -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) { diff --git a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoorChaos.java b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoorChaos.java index bf271f4d..e8694ab0 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoorChaos.java +++ b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoorChaos.java @@ -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); } } diff --git a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoorPersonal.java b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoorPersonal.java index aa723738..c0cf90cf 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoorPersonal.java +++ b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoorPersonal.java @@ -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); } } diff --git a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoorWarp.java b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoorWarp.java index ee3863bc..c8ba4dca 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoorWarp.java +++ b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityDimDoorWarp.java @@ -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); } } diff --git a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityRift.java b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityRift.java index d691ef65..5d24ddf5 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityRift.java +++ b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityRift.java @@ -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? } } diff --git a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityTransTrapdoor.java b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityTransTrapdoor.java index f3a13041..2f106531 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityTransTrapdoor.java +++ b/src/main/java/com/zixiken/dimdoors/shared/tileentities/TileEntityTransTrapdoor.java @@ -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); } } diff --git a/src/main/java/com/zixiken/dimdoors/shared/util/DDMathUtils.java b/src/main/java/com/zixiken/dimdoors/shared/util/DDMathUtils.java index 1abb67d9..40dc90e2 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/util/DDMathUtils.java +++ b/src/main/java/com/zixiken/dimdoors/shared/util/DDMathUtils.java @@ -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; } diff --git a/src/main/java/com/zixiken/dimdoors/shared/util/DDRandomUtils.java b/src/main/java/com/zixiken/dimdoors/shared/util/DDRandomUtils.java index 34045aa7..9356fcf1 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/util/DDRandomUtils.java +++ b/src/main/java/com/zixiken/dimdoors/shared/util/DDRandomUtils.java @@ -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)); } diff --git a/src/main/java/com/zixiken/dimdoors/shared/util/Location.java b/src/main/java/com/zixiken/dimdoors/shared/util/Location.java index d2fe1e12..bf00fe7c 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/util/Location.java +++ b/src/main/java/com/zixiken/dimdoors/shared/util/Location.java @@ -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(); diff --git a/src/main/java/com/zixiken/dimdoors/shared/util/Schematic.java b/src/main/java/com/zixiken/dimdoors/shared/util/Schematic.java index 181a6476..32eec969 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/util/Schematic.java +++ b/src/main/java/com/zixiken/dimdoors/shared/util/Schematic.java @@ -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 { diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_0.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_0.schem index 87f2f501..55b7adf9 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_0.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_0.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_1.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_1.schem index 54061266..7ac33bac 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_1.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_1.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_2.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_2.schem index 078477c2..71a38d9b 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_2.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_2.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_3.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_3.schem index 24559ac7..f031ec61 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_3.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_3.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_4.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_4.schem index 8ab60e0e..6903022f 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_4.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_4.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_5.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_5.schem index 7b8f79ed..0f355d10 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_5.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_5.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_6.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_6.schem index b0f6b223..1a82f5b2 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_6.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_6.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_7.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_7.schem index bfc61241..5de760b4 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_7.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPrivate_7.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_0.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_0.schem index 52f72e4b..a4f709f2 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_0.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_0.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_1.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_1.schem index 0ee2dca7..270b3c99 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_1.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_1.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_2.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_2.schem index 9e1ced2a..89f24c34 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_2.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_2.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_3.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_3.schem index 77e47873..4132b315 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_3.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_3.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_4.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_4.schem index 8205ee02..ebba234b 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_4.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_4.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_5.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_5.schem index e3d15a0e..b03c0ade 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_5.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_5.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_6.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_6.schem index 73d8374a..dbd9a240 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_6.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_6.schem differ diff --git a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_7.schem b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_7.schem index 193a21e6..226a3501 100644 Binary files a/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_7.schem and b/src/main/resources/assets/dimdoors/pockets/schematic/defaultPublic_7.schem differ