From e8e0cdf8ad6932abcb556359771885b3d691279f Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 5 Sep 2013 00:15:48 -0400 Subject: [PATCH 01/11] Minor Changes Made minor changes to LinkTypes for clarity. Removed removeRift() from PocketManager since it wasn't used by anything and because it shouldn't contain rift removal code anyway. --- .../mod_pocketDim/core/LinkTypes.java | 18 ++++++------- .../mod_pocketDim/core/PocketManager.java | 27 ------------------- 2 files changed, 9 insertions(+), 36 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/core/LinkTypes.java b/StevenDimDoors/mod_pocketDim/core/LinkTypes.java index 5e64aff..cce9f9c 100644 --- a/StevenDimDoors/mod_pocketDim/core/LinkTypes.java +++ b/StevenDimDoors/mod_pocketDim/core/LinkTypes.java @@ -5,17 +5,17 @@ public class LinkTypes private LinkTypes() { } public static final int ENUM_MIN = 0; - public static final int ENUM_MAX = 8; + public static final int ENUM_MAX = 7; public static final int CLIENT_SIDE = -1337; + // WARNING: Don't modify these values carelessly or you'll risk breaking links in existing worlds! public static final int NORMAL = 0; - public static final int LIMBO = 1; - public static final int POCKET = 2; - public static final int DUNGEON = 3; - public static final int RANDOM = 4; - public static final int DUNGEON_EXIT = 5; - public static final int SAFE_EXIT = 6; - public static final int UNSAFE_EXIT = 7; - public static final int RANDOM_DUNGEON = 8; + public static final int POCKET = 1; + public static final int DUNGEON = 2; + public static final int RANDOM = 3; + public static final int DUNGEON_EXIT = 4; + public static final int SAFE_EXIT = 5; + public static final int UNSAFE_EXIT = 6; + public static final int RANDOM_DUNGEON = 7; } diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index a03a7b9..a6365f7 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -6,15 +6,11 @@ import java.io.File; import java.io.IOException; import java.util.HashMap; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.helpers.Compactor; import StevenDimDoors.mod_pocketDim.helpers.DeleteFolder; -import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.watcher.ClientDimData; import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource; @@ -286,29 +282,6 @@ public class PocketManager } } - public static boolean removeRift(World world, int x, int y, int z, int range, EntityPlayer player, ItemStack item) - { - //Function called by rift tile entities and the rift remover to find and spread between rifts. - //Does not actually unregister the rift data, see deleteRift for that. - - NewDimData dimension = getDimensionData(world); - DimLink nearest = dimension.findNearestRift(world, range, x, y, z); - - if (nearest != null) - { - Point4D location = nearest.source(); - TileEntity tileEntity = world.getBlockTileEntity(location.getX(), location.getY(), location.getZ()); - if (tileEntity != null) - { - TileEntityRift riftEntity = (TileEntityRift) tileEntity; - riftEntity.shouldClose = true; - item.damageItem(1, player); - return true; - } - } - return false; - } - public static NewDimData registerDimension(World world) { return registerDimension(world.provider.dimensionId, null, false, false); -- 2.39.5 From b4cb8f8610d6b41688c140d1a20a1ea652211040 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 5 Sep 2013 02:12:59 -0400 Subject: [PATCH 02/11] Fixed Rift Remover Fixed the Rift Remover item. --- .../mod_pocketDim/items/itemRiftRemover.java | 153 +++++++++++------- 1 file changed, 98 insertions(+), 55 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java b/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java index 02e8ed3..c3759ac 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java +++ b/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java @@ -5,79 +5,122 @@ import java.util.List; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.MathHelper; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; +import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class itemRiftRemover extends Item { - public itemRiftRemover(int par1, Material par2Material) - { - super(par1); - this.setMaxStackSize(1); - this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); - this.setMaxDamage(5); - this.hasSubtypes = true; - } - - public void registerIcons(IconRegister par1IconRegister) - { - this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName()); - } - - public static MovingObjectPosition getBlockTarget(World par1World, EntityPlayer par2EntityPlayer, boolean par3) - { - float var4 = 1.0F; - float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4; - float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4; - double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)var4; - double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par2EntityPlayer.yOffset; - double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)var4; - Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11); - float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI); - float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI); - float var16 = -MathHelper.cos(-var5 * 0.017453292F); - float var17 = MathHelper.sin(-var5 * 0.017453292F); - float var18 = var15 * var16; - float var20 = var14 * var16; - double var21 = 5.0D; - if (par2EntityPlayer instanceof EntityPlayerMP) - { - var21 = 6; - } - Vec3 var23 = var13.addVector((double)var18 * var21, (double)var17 * var21, (double)var20 * var21); - return par1World.rayTraceBlocks_do_do(var13, var23, true, false); - } + public itemRiftRemover(int itemID, Material par2Material) + { + super(itemID); + this.setMaxStackSize(1); + this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); + this.setMaxDamage(4); + } - public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) - { - MovingObjectPosition hit = getBlockTarget(par3EntityPlayer.worldObj, par3EntityPlayer, false); + public void registerIcons(IconRegister par1IconRegister) + { + this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName()); + } + + @Override + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) + { + // We invoke PlayerControllerMP.onPlayerRightClick() from here so that Minecraft + // will invoke onItemUseFirst() on the client side. We'll tell it to pass the + // request to the server, which will make sure that rift-related changes are + // reflected on the server. + + if (!world.isRemote) + { + return stack; + } + + MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(world, player, true); if (hit != null) { - if (PocketManager.removeRift(par2World, hit.blockX, hit.blockY, hit.blockZ, 1, par3EntityPlayer, par1ItemStack)) + int hx = hit.blockX; + int hy = hit.blockY; + int hz = hit.blockZ; + NewDimData dimension = PocketManager.getDimensionData(world); + DimLink link = dimension.getLink(hx, hy, hz); + if (world.getBlockId(hx, hy, hz) == mod_pocketDim.blockRift.blockID && link != null && + player.canPlayerEdit(hx, hy, hz, 0, stack)) { - par3EntityPlayer.worldObj.playSoundAtEntity(par3EntityPlayer,"mods.DimDoors.sfx.riftClose", 0.8f, 1); + // Invoke onPlayerRightClick() + FMLClientHandler.instance().getClient().playerController.onPlayerRightClick( + player, world, stack, hx, hy, hz, hit.sideHit, hit.hitVec); } } - return par1ItemStack; - } - - /** - * allows items to add custom lines of information to the mouseover description - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + return stack; + } + + @Override + public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) + { + // We want to use onItemUseFirst() here so that this code will run on the server side, + // so we don't need the client to send link-related updates to the server. Still, + // check whether we have a rift in sight before passing the request over. + + // On integrated servers, the link won't be removed immediately because of the rift + // removal animation. That means we'll have a chance to check for the link before + // it's deleted. Otherwise the Rift Remover's durability wouldn't drop. + + NewDimData dimension = PocketManager.getDimensionData(world); + DimLink link = dimension.getLink(x, y, z); + if (world.getBlockId(x, y, z) == mod_pocketDim.blockRift.blockID && link != null && + player.canPlayerEdit(x, y, z, side, stack)) + { + // Tell the rift's tile entity to do its removal animation + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + if (tileEntity != null && tileEntity instanceof TileEntityRift) + { + ((TileEntityRift) tileEntity).shouldClose = true; + } + else if (!world.isRemote) + { + // Only set the block to air on the server side so that we don't + // tell the server to remove the rift block before it can use the + // Rift Remover. Otherwise, it won't know to reduce durability. + world.setBlockToAir(x, y, z); + } + if (world.isRemote) + { + // Tell the server about this + return false; + } + else + { + if (!player.capabilities.isCreativeMode) + { + stack.damageItem(1, player); + } + player.sendChatToPlayer("Clink! Damaged!"); + player.worldObj.playSoundAtEntity(player, "mods.DimDoors.sfx.riftClose", 0.8f, 1); + } + } + return true; + } + + /** + * allows items to add custom lines of information to the mouseover description + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) @SideOnly(Side.CLIENT) - @Override - public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) - { + @Override + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) + { par3List.add("Use near exposed rift"); par3List.add("to remove it and"); par3List.add("any nearby rifts."); -- 2.39.5 From 6a816bbca79eea7fb60c0a4841b0866364699106 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 5 Sep 2013 11:04:48 -0400 Subject: [PATCH 03/11] Minor Change Removed a debug message from the Rift Remover. --- StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java | 1 - 1 file changed, 1 deletion(-) diff --git a/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java b/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java index c3759ac..201ffcb 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java +++ b/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java @@ -106,7 +106,6 @@ public class itemRiftRemover extends Item { stack.damageItem(1, player); } - player.sendChatToPlayer("Clink! Damaged!"); player.worldObj.playSoundAtEntity(player, "mods.DimDoors.sfx.riftClose", 0.8f, 1); } } -- 2.39.5 From 22b7ed147a7bdea52da923b37764c92a226553d6 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 5 Sep 2013 11:13:14 -0400 Subject: [PATCH 04/11] Fixed Bug in PocketManager Fixed a bug in PocketManager - I had forgotten to raise the dimension creation event when needed. --- StevenDimDoors/mod_pocketDim/core/PocketManager.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index a6365f7..aa3b549 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -309,6 +309,8 @@ public class PocketManager InnerDimData dimension = new InnerDimData(dimensionID, parent, isPocket, isDungeon, linkWatcher); dimensionData.put(dimensionID, dimension); + dimWatcher.onCreated(new ClientDimData(dimension)); + return dimension; } -- 2.39.5 From 1138f6733eef74bd277a6c36d0eae6d2ed20d9d6 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 5 Sep 2013 11:36:59 -0400 Subject: [PATCH 05/11] Cleaned Up Code Changed calls to canPlayerEdit() to pass hit.sideHit data with the request. Also renamed several variables to make the code clearer. Removed a custom implementation of the ray tracing call in BaseItemDoor - we can use the built-in call from Minecraft there. --- .../mod_pocketDim/items/BaseItemDoor.java | 42 ++++--------------- .../mod_pocketDim/items/ItemRiftBlade.java | 19 ++++----- .../items/ItemRiftSignature.java | 2 +- .../items/ItemStabilizedRiftSignature.java | 2 +- .../mod_pocketDim/items/itemRiftRemover.java | 2 +- 5 files changed, 19 insertions(+), 48 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java b/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java index 9517b95..e084b1f 100644 --- a/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java +++ b/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java @@ -6,12 +6,10 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemDoor; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; @@ -41,12 +39,12 @@ public abstract class BaseItemDoor extends ItemDoor public abstract void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4); @Override - public abstract boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10); + public abstract boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ); - public static boolean tryItemUse(Block doorBlock, ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, boolean requireLink, boolean reduceStack) + public static boolean tryItemUse(Block doorBlock, ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, boolean requireLink, boolean reduceStack) { - //FIXME: Without any sort of this documentation, this condition is like magic -_- ~SenseiKiwi - if (par7 == 1 && !world.isRemote) + // Only place doors on top of blocks - check if we're targeting the top side + if (side == 1 && !world.isRemote) { int blockID = world.getBlockId(x, y, z); if (blockID != 0) @@ -58,7 +56,7 @@ public abstract class BaseItemDoor extends ItemDoor } if (canPlace(world, x, y, z) && canPlace(world, x, y + 1, z) && - player.canPlayerEdit(x, y, z, par7, stack) && player.canPlayerEdit(x, y + 1, z, par7, stack) && + player.canPlayerEdit(x, y, z, side, stack) && player.canPlayerEdit(x, y + 1, z, side, stack) && (!requireLink || PocketManager.getLink(x, y + 1, z, world) != null)) { int orientation = MathHelper.floor_double((double) ((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; @@ -74,31 +72,6 @@ public abstract class BaseItemDoor extends ItemDoor return false; } - @Override - public final MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3) - { - float var4 = 1.0F; - float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4; - float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4; - double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)var4; - double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par2EntityPlayer.yOffset; - double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)var4; - Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11); - float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI); - float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI); - float var16 = -MathHelper.cos(-var5 * 0.017453292F); - float var17 = MathHelper.sin(-var5 * 0.017453292F); - float var18 = var15 * var16; - float var20 = var14 * var16; - double var21 = 5.0D; - if (par2EntityPlayer instanceof EntityPlayerMP) - { - var21 = 4; - } - Vec3 var23 = var13.addVector((double) var18 * var21, (double)var17 * var21, (double)var20 * var21); - return par1World.rayTraceBlocks_do_do(var13, var23, true, false); - } - @Override public abstract ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player); @@ -109,7 +82,7 @@ public abstract class BaseItemDoor extends ItemDoor return false; } - MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(player.worldObj, player, false); + MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(player.worldObj, player, true); if (hit != null) { if (world.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.RiftBlockID) @@ -120,9 +93,8 @@ public abstract class BaseItemDoor extends ItemDoor int x = hit.blockX; int y = hit.blockY; int z = hit.blockZ; - int par7 = 0; - if (player.canPlayerEdit(x, y, z, par7, item) && player.canPlayerEdit(x, y - 1, z, par7, item)) + if (player.canPlayerEdit(x, y, z, hit.sideHit, item) && player.canPlayerEdit(x, y - 1, z, hit.sideHit, item)) { if (canPlace(world, x, y, z) && canPlace(world, x, y - 1, z)) { diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java index ba49480..4de21ce 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java @@ -224,20 +224,19 @@ public class ItemRiftBlade extends ItemSword { if (PocketManager.getLink(hit.blockX, hit.blockY, hit.blockZ, world) != null) { - Block var11 = mod_pocketDim.transientDoor; - int par4 = hit.blockX; - int par5 = hit.blockY; - int par6 = hit.blockZ; - int par7 = 0; + Block block = mod_pocketDim.transientDoor; + int x = hit.blockX; + int y = hit.blockY; + int z = hit.blockZ; - if (player.canPlayerEdit(par4, par5, par6, par7, stack) && player.canPlayerEdit(par4, par5 + 1, par6, par7, stack)&&!world.isRemote) + if (player.canPlayerEdit(x, y, z, hit.sideHit, stack) && player.canPlayerEdit(x, y + 1, z, hit.sideHit, stack) && !world.isRemote) { - int var12 = MathHelper.floor_double((double)((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; + int orientation = MathHelper.floor_double((double)((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - if (BaseItemDoor.canPlace(world, par4, par5, par6) && - BaseItemDoor.canPlace(world, par4, par5 - 1, par6)) + if (BaseItemDoor.canPlace(world, x, y, z) && + BaseItemDoor.canPlace(world, x, y - 1, z)) { - ItemDimensionalDoor.placeDoorBlock(world, par4, par5 - 1, par6, var12, var11); + ItemDimensionalDoor.placeDoorBlock(world, x, y - 1, z, orientation, block); player.worldObj.playSoundAtEntity(player,"mods.DimDoors.sfx.riftDoor", 0.6f, 1); stack.damageItem(10, player); } diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java index 05b1f51..b4003fe 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java @@ -60,7 +60,7 @@ public class ItemRiftSignature extends Item //We don't check for replaceable blocks. The user can deal with that. <_< y += 2; //Increase y by 2 to place the rift at head level - if (!player.canPlayerEdit(x, y, z, 0, stack)) + if (!player.canPlayerEdit(x, y, z, side, stack)) { return true; } diff --git a/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index 0a20abb..0e37b6b 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -40,7 +40,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature // We don't check for replaceable blocks. The user can deal with that. <_< y += 2; //Increase y by 2 to place the rift at head level - if (!player.canPlayerEdit(x, y, z, 0, stack)) + if (!player.canPlayerEdit(x, y, z, side, stack)) { return true; } diff --git a/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java b/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java index 201ffcb..a0256ad 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java +++ b/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java @@ -56,7 +56,7 @@ public class itemRiftRemover extends Item NewDimData dimension = PocketManager.getDimensionData(world); DimLink link = dimension.getLink(hx, hy, hz); if (world.getBlockId(hx, hy, hz) == mod_pocketDim.blockRift.blockID && link != null && - player.canPlayerEdit(hx, hy, hz, 0, stack)) + player.canPlayerEdit(hx, hy, hz, hit.sideHit, stack)) { // Invoke onPlayerRightClick() FMLClientHandler.instance().getClient().playerController.onPlayerRightClick( -- 2.39.5 From a82c7ce4c258dee2af0a73a60473ba2a1f9e2b4f Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 5 Sep 2013 16:19:05 -0400 Subject: [PATCH 06/11] Minor Changes Made minor changes to ItemRiftBlade to clarify our code. Had to update mod_pocketDim to use ItemRiftBlade's new constructor after changing it slightly. --- .../mod_pocketDim/items/ItemRiftBlade.java | 12 ++++++------ StevenDimDoors/mod_pocketDim/mod_pocketDim.java | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java index 4de21ce..9fc3115 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java @@ -28,9 +28,9 @@ import cpw.mods.fml.relauncher.SideOnly; public class ItemRiftBlade extends ItemSword { - private static DDProperties properties = null; + private final DDProperties properties; - public ItemRiftBlade(int itemID, EnumToolMaterial material) + public ItemRiftBlade(int itemID, EnumToolMaterial material, DDProperties properties) { super(itemID, material); @@ -38,10 +38,10 @@ public class ItemRiftBlade extends ItemSword this.setMaxStackSize(1); this.setMaxDamage(500); this.hasSubtypes = false; - if (properties == null) - properties = DDProperties.instance(); + this.properties = properties; } + @Override @SideOnly(Side.CLIENT) public boolean isFull3D() { @@ -272,9 +272,9 @@ public class ItemRiftBlade extends ItemSword @Override public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, - int z, int par7, float par8, float par9, float par10) + int z, int side, float hitX, float hitY, float hitZ) { - if (BaseItemDoor.tryItemUse(mod_pocketDim.transientDoor, stack, player, world, x, y, z, par7, true, false)) + if (BaseItemDoor.tryItemUse(mod_pocketDim.transientDoor, stack, player, world, x, y, z, side, true, false)) { world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftDoor", 0.6f, 1); return true; diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 4ab5058..c395c11 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -185,7 +185,7 @@ public class mod_pocketDim itemRiftRemover = (new itemRiftRemover(properties.RiftRemoverItemID, Material.wood)).setUnlocalizedName("itemRiftRemover"); itemStableFabric = (new ItemStableFabric(properties.StableFabricItemID, 0)).setUnlocalizedName("itemStableFabric"); itemChaosDoor = (new ItemUnstableDoor(properties.UnstableDoorItemID, Material.iron)).setUnlocalizedName("itemChaosDoor"); - itemRiftBlade = (new ItemRiftBlade(properties.RiftBladeItemID, EnumToolMaterial.GOLD)).setUnlocalizedName("ItemRiftBlade"); + itemRiftBlade = (new ItemRiftBlade(properties.RiftBladeItemID, EnumToolMaterial.GOLD, properties)).setUnlocalizedName("ItemRiftBlade"); itemStabilizedLinkSignature = (new ItemStabilizedRiftSignature(properties.StabilizedRiftSignatureItemID)).setUnlocalizedName("itemStabilizedRiftSig"); mod_pocketDim.limboBiome= (new BiomeGenLimbo(properties.LimboBiomeID)); -- 2.39.5 From 64cc95f92b3fe03779c3de0522e53c02c7a7808b Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 5 Sep 2013 16:24:01 -0400 Subject: [PATCH 07/11] Deleted DimUpdatePacket Deleted DimUpdatePacket since it's not used for anything and the file is essentially empty. --- .../mod_pocketDim/DimUpdatePacket.java | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 StevenDimDoors/mod_pocketDim/DimUpdatePacket.java diff --git a/StevenDimDoors/mod_pocketDim/DimUpdatePacket.java b/StevenDimDoors/mod_pocketDim/DimUpdatePacket.java deleted file mode 100644 index daed1ea..0000000 --- a/StevenDimDoors/mod_pocketDim/DimUpdatePacket.java +++ /dev/null @@ -1,17 +0,0 @@ -package StevenDimDoors.mod_pocketDim; - - -public class DimUpdatePacket -{ - - public DimUpdatePacket(int dim) - { - - } - - - - - - -} \ No newline at end of file -- 2.39.5 From 1dfa5817bf6cb734c2b2c658b65ad364e27c09a7 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 5 Sep 2013 16:31:32 -0400 Subject: [PATCH 08/11] Moved DDTeleporter Moved DDTeleporter to the mod_pocketDim.core package. It seemed reasonable given that DDTeleporter is closely tied to how Dimensional Doors works. It controls the most critical feature for all items - teleportation - and handles routing requests to initialize link destinations. --- StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java | 2 +- StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java | 2 +- StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java | 2 +- StevenDimDoors/mod_pocketDim/{ => core}/DDTeleporter.java | 6 ++---- StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java | 2 +- StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java | 2 +- 6 files changed, 7 insertions(+), 9 deletions(-) rename StevenDimDoors/mod_pocketDim/{ => core}/DDTeleporter.java (98%) diff --git a/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java b/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java index 5789fb3..f5e34ae 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java @@ -12,8 +12,8 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.DDTeleporter; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import StevenDimDoors.mod_pocketDim.util.Point4D; diff --git a/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java b/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java index 95de79d..83b64f4 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java @@ -18,8 +18,8 @@ import net.minecraft.util.Vec3; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.DDTeleporter; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; diff --git a/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java b/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java index c1fe83c..cc847cc 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java @@ -10,8 +10,8 @@ import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.DDTeleporter; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; diff --git a/StevenDimDoors/mod_pocketDim/DDTeleporter.java b/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java similarity index 98% rename from StevenDimDoors/mod_pocketDim/DDTeleporter.java rename to StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index 97aae3f..f973e38 100644 --- a/StevenDimDoors/mod_pocketDim/DDTeleporter.java +++ b/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -1,4 +1,4 @@ -package StevenDimDoors.mod_pocketDim; +package StevenDimDoors.mod_pocketDim.core; import java.util.Random; @@ -16,9 +16,7 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; -import StevenDimDoors.mod_pocketDim.core.DimLink; -import StevenDimDoors.mod_pocketDim.core.LinkTypes; -import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.world.PocketBuilder; import cpw.mods.fml.common.registry.GameRegistry; diff --git a/StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java b/StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java index a190039..26057b4 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java +++ b/StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java @@ -3,7 +3,7 @@ package StevenDimDoors.mod_pocketDim.ticking; import java.util.ArrayList; import java.util.EnumSet; -import StevenDimDoors.mod_pocketDim.DDTeleporter; +import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; diff --git a/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java b/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java index 2fed8ab..71ba77a 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java +++ b/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java @@ -13,7 +13,7 @@ import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.DDTeleporter; +import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.PocketProvider; -- 2.39.5 From 3ce380ad5e108460d241f23890c574a66995554d Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 5 Sep 2013 18:13:05 -0400 Subject: [PATCH 09/11] Fixed Unstable Doors Added code so that the links for Unstable Doors are handled properly by DDTeleporter. Hurray! Also cleaned up some unused imports in the BiomeGen classes and removed the RANDOM_DUNGEON link type - it was meant for the dd-rift command but there is no need for it anymore. --- .../mod_pocketDim/core/DDTeleporter.java | 53 ++++++++++++++++++- .../mod_pocketDim/core/LinkTypes.java | 3 +- .../mod_pocketDim/world/BiomeGenLimbo.java | 3 -- .../mod_pocketDim/world/BiomeGenPocket.java | 2 - 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index f973e38..4ff768b 100644 --- a/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -1,5 +1,6 @@ package StevenDimDoors.mod_pocketDim.core; +import java.util.ArrayList; import java.util.Random; import net.minecraft.entity.Entity; @@ -344,8 +345,20 @@ public class DDTeleporter return; } - entity = teleportEntity(entity, link.destination()); - entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F); + if (link.linkType() == LinkTypes.RANDOM) + { + Point4D randomDestination = getRandomDestination(); + if (randomDestination != null) + { + entity = teleportEntity(entity, randomDestination); + entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F); + } + } + else + { + entity = teleportEntity(entity, link.destination()); + entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F); + } } private static boolean initializeDestination(DimLink link, DDProperties properties) @@ -366,9 +379,45 @@ public class DDTeleporter case LinkTypes.POCKET: return PocketBuilder.generateNewPocket(link, properties); case LinkTypes.NORMAL: + case LinkTypes.RANDOM: return true; default: throw new IllegalArgumentException("link has an unrecognized link type."); } } + + private static Point4D getRandomDestination() + { + // Our aim is to return a point near a random link's source + // so that a link of type RANDOM can teleport a player there. + + // Restrictions: + // 1. Ignore links with their source inside a pocket dimension. + // 2. Ignore links with link type RANDOM. + + ArrayList matches = new ArrayList(); + for (NewDimData dimension : PocketManager.getDimensions()) + { + if (!dimension.isPocketDimension()) + { + for (DimLink link : dimension.getAllLinks()) + { + if (link.linkType() != LinkTypes.RANDOM) + { + matches.add(link.source()); + } + } + } + } + + // Pick a random point, if any is available + if (!matches.isEmpty()) + { + return matches.get( random.nextInt(matches.size()) ); + } + else + { + return null; + } + } } diff --git a/StevenDimDoors/mod_pocketDim/core/LinkTypes.java b/StevenDimDoors/mod_pocketDim/core/LinkTypes.java index cce9f9c..9cebd37 100644 --- a/StevenDimDoors/mod_pocketDim/core/LinkTypes.java +++ b/StevenDimDoors/mod_pocketDim/core/LinkTypes.java @@ -5,7 +5,7 @@ public class LinkTypes private LinkTypes() { } public static final int ENUM_MIN = 0; - public static final int ENUM_MAX = 7; + public static final int ENUM_MAX = 6; public static final int CLIENT_SIDE = -1337; @@ -17,5 +17,4 @@ public class LinkTypes public static final int DUNGEON_EXIT = 4; public static final int SAFE_EXIT = 5; public static final int UNSAFE_EXIT = 6; - public static final int RANDOM_DUNGEON = 7; } diff --git a/StevenDimDoors/mod_pocketDim/world/BiomeGenLimbo.java b/StevenDimDoors/mod_pocketDim/world/BiomeGenLimbo.java index 4b8fd1d..b60eabe 100644 --- a/StevenDimDoors/mod_pocketDim/world/BiomeGenLimbo.java +++ b/StevenDimDoors/mod_pocketDim/world/BiomeGenLimbo.java @@ -1,9 +1,6 @@ package StevenDimDoors.mod_pocketDim.world; -import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; -import net.minecraft.entity.monster.EntitySpider; import net.minecraft.world.biome.BiomeGenBase; -import net.minecraft.world.biome.SpawnListEntry; public class BiomeGenLimbo extends BiomeGenBase { diff --git a/StevenDimDoors/mod_pocketDim/world/BiomeGenPocket.java b/StevenDimDoors/mod_pocketDim/world/BiomeGenPocket.java index 3fe0c57..e9dbdb7 100644 --- a/StevenDimDoors/mod_pocketDim/world/BiomeGenPocket.java +++ b/StevenDimDoors/mod_pocketDim/world/BiomeGenPocket.java @@ -1,8 +1,6 @@ package StevenDimDoors.mod_pocketDim.world; -import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; import net.minecraft.world.biome.BiomeGenBase; -import net.minecraft.world.biome.SpawnListEntry; public class BiomeGenPocket extends BiomeGenBase { -- 2.39.5 From 03660699cfe83ae3ca3bd640bf605277274f4898 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 5 Sep 2013 21:03:11 -0400 Subject: [PATCH 10/11] Minor Changes Cleaned up our code related to initializing dimensions. Removed redundant instances of that code and instead created a function: PocketManager.loadDimension() - to centralize all uses of that logic. Added LinkTypes.REVERSE to represent links leading back out of pockets through their entrances. That distinction might prove critical in the future when we support resetting dungeons. --- .../mod_pocketDim/core/DDTeleporter.java | 26 ++++++++++--------- .../mod_pocketDim/core/LinkTypes.java | 3 ++- .../mod_pocketDim/core/PocketManager.java | 17 ++++++++++++ .../dungeon/DungeonSchematic.java | 2 +- .../mod_pocketDim/world/PocketBuilder.java | 24 +++-------------- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index 4ff768b..57c1dcd 100644 --- a/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -192,12 +192,7 @@ public class DDTeleporter if (difDest) { // Destination isn't loaded? Then we need to load it. - newWorld = DimensionManager.getWorld(destination.getDimension()); - if (newWorld == null) - { - DimensionManager.initDimension(destination.getDimension()); - newWorld = DimensionManager.getWorld(destination.getDimension()); - } + newWorld = PocketManager.loadDimension(destination.getDimension()); } else { @@ -230,10 +225,10 @@ public class DDTeleporter oldWorld.getPlayerManager().removePlayer(player); newWorld.getPlayerManager().addPlayer(player); - player.theItemInWorldManager.setWorld((WorldServer)newWorld); + player.theItemInWorldManager.setWorld(newWorld); // Synchronize with the server so the client knows what time it is and what it's holding. - player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, (WorldServer)newWorld); + player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, newWorld); player.mcServer.getConfigurationManager().syncPlayerInventory(player); for(Object potionEffect : player.getActivePotionEffects()) { @@ -304,7 +299,7 @@ public class DDTeleporter DDTeleporter.placeInPortal(entity, newWorld, destination, properties); return entity; } - + /** * Primary function used to teleport the player using doors. Performs numerous null checks, and also generates the destination door/pocket if it has not done so already. * Also ensures correct orientation relative to the door. @@ -347,7 +342,7 @@ public class DDTeleporter if (link.linkType() == LinkTypes.RANDOM) { - Point4D randomDestination = getRandomDestination(); + Point4D randomDestination = prepareRandomDestination(); if (randomDestination != null) { entity = teleportEntity(entity, randomDestination); @@ -364,6 +359,7 @@ public class DDTeleporter private static boolean initializeDestination(DimLink link, DDProperties properties) { //FIXME: Change this later to support rooms that have been wiped and must be regenerated. + //We might need to implement regeneration for REVERSE links as well. if (link.hasDestination()) { return true; @@ -378,7 +374,13 @@ public class DDTeleporter return PocketBuilder.generateNewDungeonPocket(link, properties); case LinkTypes.POCKET: return PocketBuilder.generateNewPocket(link, properties); + case LinkTypes.SAFE_EXIT: + case LinkTypes.DUNGEON_EXIT: + return ; + case LinkTypes.UNSAFE_EXIT: + return ; case LinkTypes.NORMAL: + case LinkTypes.REVERSE: case LinkTypes.RANDOM: return true; default: @@ -386,9 +388,9 @@ public class DDTeleporter } } - private static Point4D getRandomDestination() + private static Point4D prepareRandomDestination() { - // Our aim is to return a point near a random link's source + // Our aim is to return a random link's source point // so that a link of type RANDOM can teleport a player there. // Restrictions: diff --git a/StevenDimDoors/mod_pocketDim/core/LinkTypes.java b/StevenDimDoors/mod_pocketDim/core/LinkTypes.java index 9cebd37..f7424b5 100644 --- a/StevenDimDoors/mod_pocketDim/core/LinkTypes.java +++ b/StevenDimDoors/mod_pocketDim/core/LinkTypes.java @@ -5,7 +5,7 @@ public class LinkTypes private LinkTypes() { } public static final int ENUM_MIN = 0; - public static final int ENUM_MAX = 6; + public static final int ENUM_MAX = 7; public static final int CLIENT_SIDE = -1337; @@ -17,4 +17,5 @@ public class LinkTypes public static final int DUNGEON_EXIT = 4; public static final int SAFE_EXIT = 5; public static final int UNSAFE_EXIT = 6; + public static final int REVERSE = 7; } diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index aa3b549..105843b 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.util.HashMap; import net.minecraft.world.World; +import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.helpers.Compactor; @@ -281,6 +282,22 @@ public class PocketManager isSaving = false; } } + + public static WorldServer loadDimension(int id) + { + WorldServer world = DimensionManager.getWorld(id); + if (world == null) + { + DimensionManager.initDimension(id); + world = DimensionManager.getWorld(id); + } + else if (world.provider == null) + { + DimensionManager.initDimension(id); + world = DimensionManager.getWorld(id); + } + return world; + } public static NewDimData registerDimension(World world) { diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index d61f64e..e33a455 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -285,7 +285,7 @@ public class DungeonSchematic extends Schematic { private static void createEntranceReverseLink(NewDimData dimension, Point3D pocketCenter, DimLink entryLink) { - DimLink reverseLink = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ(), LinkTypes.NORMAL); + DimLink reverseLink = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ(), LinkTypes.REVERSE); Point4D destination = entryLink.source(); NewDimData prevDim = PocketManager.getDimensionData(destination.getDimension()); prevDim.setDestination(reverseLink, destination.getX(), destination.getY(), destination.getZ()); diff --git a/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java b/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java index d76e9b6..0f2d42f 100644 --- a/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java +++ b/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java @@ -61,17 +61,8 @@ public class PocketBuilder NewDimData dimension = PocketManager.registerPocket(parent, true); //Load a world - World world = DimensionManager.getWorld(dimension.id()); + World world = PocketManager.loadDimension(dimension.id()); - if (world == null) - { - DimensionManager.initDimension(dimension.id()); - world = DimensionManager.getWorld(dimension.id()); - } - if (world != null && world.provider == null) - { - DimensionManager.initDimension(dimension.id()); - } if (world == null || world.provider == null) { System.err.println("Could not initialize dimension for a dungeon!"); @@ -282,17 +273,8 @@ public class PocketBuilder NewDimData dimension = PocketManager.registerPocket(parent, false); //Load a world - World world = DimensionManager.getWorld(dimension.id()); + World world = PocketManager.loadDimension(dimension.id()); - if (world == null) - { - DimensionManager.initDimension(dimension.id()); - world = DimensionManager.getWorld(dimension.id()); - } - if (world != null && world.provider == null) - { - DimensionManager.initDimension(dimension.id()); - } if (world == null || world.provider == null) { System.err.println("Could not initialize dimension for a pocket!"); @@ -305,7 +287,7 @@ public class PocketBuilder int orientation = getDoorOrientation(source, properties); //Place a link leading back out of the pocket - DimLink reverseLink = dimension.createLink(source.getX(), destinationY, source.getZ(), LinkTypes.NORMAL); + DimLink reverseLink = dimension.createLink(source.getX(), destinationY, source.getZ(), LinkTypes.REVERSE); parent.setDestination(reverseLink, source.getX(), source.getY(), source.getZ()); //Build the actual pocket area -- 2.39.5 From b795c411be782e36e5323b96785b9ff890f90e6e Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 5 Sep 2013 22:43:11 -0400 Subject: [PATCH 11/11] Added Support for Missing Link Types Added functions for generating destinations for some link types that we hadn't included yet - player-made exits, trapdoors, and dungeon exits. The player-made and dungeon exits still don't generate anything, but there's a single function where we can write up the code: DDTeleporter.generateSafeExit(). Also added some simple code for listing root dimensions in PocketManager. None of this has been tested yet! --- .../mod_pocketDim/core/DDTeleporter.java | 99 +++++++++++++++---- .../mod_pocketDim/core/PocketManager.java | 17 ++++ 2 files changed, 99 insertions(+), 17 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index 57c1dcd..c0d9b37 100644 --- a/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -25,6 +25,7 @@ import cpw.mods.fml.common.registry.GameRegistry; public class DDTeleporter { private static final Random random = new Random(); + private static int END_DIMENSION_ID = 1; public static int cooldown = 0; private DDTeleporter() { } @@ -342,7 +343,7 @@ public class DDTeleporter if (link.linkType() == LinkTypes.RANDOM) { - Point4D randomDestination = prepareRandomDestination(); + Point4D randomDestination = getRandomDestination(); if (randomDestination != null) { entity = teleportEntity(entity, randomDestination); @@ -358,16 +359,16 @@ public class DDTeleporter private static boolean initializeDestination(DimLink link, DDProperties properties) { - //FIXME: Change this later to support rooms that have been wiped and must be regenerated. - //We might need to implement regeneration for REVERSE links as well. + // FIXME: Change this later to support rooms that have been wiped and must be regenerated. + // FIXME: Add code for restoring the destination-side door. + // We might need to implement regeneration for REVERSE links as well. + if (link.hasDestination()) { return true; } - //Check the destination type and respond accordingly - //FIXME: Add missing link types. - //FIXME: Add code for restoring the destination-side door. + // Check the destination type and respond accordingly switch (link.linkType()) { case LinkTypes.DUNGEON: @@ -375,10 +376,11 @@ public class DDTeleporter case LinkTypes.POCKET: return PocketBuilder.generateNewPocket(link, properties); case LinkTypes.SAFE_EXIT: + return generateSafeExit(link, properties); case LinkTypes.DUNGEON_EXIT: - return ; + return generateDungeonExit(link, properties); case LinkTypes.UNSAFE_EXIT: - return ; + return generateUnsafeExit(link); case LinkTypes.NORMAL: case LinkTypes.REVERSE: case LinkTypes.RANDOM: @@ -387,8 +389,8 @@ public class DDTeleporter throw new IllegalArgumentException("link has an unrecognized link type."); } } - - private static Point4D prepareRandomDestination() + + private static Point4D getRandomDestination() { // Our aim is to return a random link's source point // so that a link of type RANDOM can teleport a player there. @@ -397,17 +399,17 @@ public class DDTeleporter // 1. Ignore links with their source inside a pocket dimension. // 2. Ignore links with link type RANDOM. + // Iterate over the root dimensions. Pocket dimensions cannot be roots. + // Don't just pick a random root and a random link within that root + // because we want to have unbiased selection among all links. ArrayList matches = new ArrayList(); - for (NewDimData dimension : PocketManager.getDimensions()) + for (NewDimData dimension : PocketManager.getRootDimensions()) { - if (!dimension.isPocketDimension()) + for (DimLink link : dimension.getAllLinks()) { - for (DimLink link : dimension.getAllLinks()) + if (link.linkType() != LinkTypes.RANDOM) { - if (link.linkType() != LinkTypes.RANDOM) - { - matches.add(link.source()); - } + matches.add(link.source()); } } } @@ -422,4 +424,67 @@ public class DDTeleporter return null; } } + + private static boolean generateUnsafeExit(DimLink link) + { + // An unsafe exit teleports the user to exactly the same coordinates + // as the link source, except located at the dimension's root dimension. + // This is very risky, as we make no effort to clear an air pocket or + // place a platform at the destination. We also don't place a reverse + // link at the destination, so it's a one-way trip. Good luck! + + // To avoid loops, don't generate a destination if the player is + // already in a non-pocket dimension. + + NewDimData current = PocketManager.getDimensionData(link.source.getDimension()); + if (current.isPocketDimension()) + { + Point4D source = link.source(); + current.root().setDestination(link, source.getX(), source.getY(), source.getZ()); + return true; + } + else + { + return false; + } + } + + private static boolean generateSafeExit(DimLink link, DDProperties properties) + { + NewDimData current = PocketManager.getDimensionData(link.source.getDimension()); + return generateSafeExit(current.root(), link, properties); + } + + private static boolean generateDungeonExit(DimLink link, DDProperties properties) + { + // A dungeon exit acts the same as a safe exit, but has the chance of + // taking the user to any non-pocket dimension, excluding Limbo and The End. + + ArrayList roots = PocketManager.getRootDimensions(); + for (int attempts = 0; attempts < 10; attempts++) + { + NewDimData selection = roots.get( random.nextInt(roots.size()) ); + if (selection.id() != END_DIMENSION_ID && selection.id() != properties.LimboDimensionID) + { + return generateSafeExit(selection, link, properties); + } + } + return false; + } + + private static boolean generateSafeExit(NewDimData target, DimLink link, DDProperties properties) + { + // A safe exit attempts to place a Warp Door in a dimension with + // some precautions to protect the player. The X and Z coordinates + // are fixed to match the source, but the Y coordinate is chosen by + // searching for a safe location to place the door. The direction of + // the vertical search is away from the map boundary closest to + // the source Y. In other words, if a player is really high up, the + // search proceeds down. If a player is near the bottom of the map, + // the search proceeds up. If a safe destination cannot be found, + // then we return false and the source-side door slams shut. + + // FIXME: Add code here! + return false; + } } diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 105843b..eda8947 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -4,6 +4,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import net.minecraft.world.World; @@ -97,6 +98,7 @@ public class PocketManager private static volatile boolean isSaving = false; private static final UpdateWatcherProxy linkWatcher = new UpdateWatcherProxy(); private static final UpdateWatcherProxy dimWatcher = new UpdateWatcherProxy(); + private static ArrayList rootDimensions = null; //HashMap that maps all the dimension IDs registered with DimDoors to their DD data. private static HashMap dimensionData = null; @@ -123,6 +125,7 @@ public class PocketManager isLoading = true; dimensionData = new HashMap(); + rootDimensions = new ArrayList(); //Register Limbo DDProperties properties = DDProperties.instance(); @@ -326,6 +329,10 @@ public class PocketManager InnerDimData dimension = new InnerDimData(dimensionID, parent, isPocket, isDungeon, linkWatcher); dimensionData.put(dimensionID, dimension); + if (!dimension.isPocketDimension()) + { + rootDimensions.add(dimension); + } dimWatcher.onCreated(new ClientDimData(dimension)); return dimension; @@ -336,6 +343,9 @@ public class PocketManager // No need to raise events here since this code should only run on the client side // getDimensionData() always handles root dimensions properly, even if the weren't defined before + // SenseiKiwi: I'm a little worried about how getDimensionData will raise + // an event when it creates any root dimensions... Needs checking later. + InnerDimData root = (InnerDimData) getDimensionData(rootID); InnerDimData dimension; @@ -381,6 +391,12 @@ public class PocketManager return dimensionData.values(); } + @SuppressWarnings("unchecked") + public static ArrayList getRootDimensions() + { + return (ArrayList) rootDimensions.clone(); + } + public static void unload() { if (!isLoaded) @@ -391,6 +407,7 @@ public class PocketManager save(); unregisterPockets(); dimensionData = null; + rootDimensions = null; isLoaded = false; } -- 2.39.5