diff --git a/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/StevenDimDoors/mod_pocketDim/EventHookContainer.java index abdeafb8..132a1610 100644 --- a/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -1,18 +1,13 @@ package StevenDimDoors.mod_pocketDim; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChunkCoordinates; -import net.minecraft.util.DamageSource; import net.minecraftforge.client.event.sound.SoundLoadEvent; -import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.EventPriority; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingFallEvent; -import net.minecraftforge.event.entity.player.PlayerDropsEvent; import net.minecraftforge.event.world.WorldEvent; import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.core.PocketManager; @@ -74,15 +69,17 @@ public class EventHookContainer public boolean LivingDeathEvent(LivingDeathEvent event) { Entity entity = event.entity; - if(entity instanceof EntityPlayer&&entity.worldObj.provider instanceof PocketProvider && this.properties.LimboEnabled) + if (entity instanceof EntityPlayer && entity.worldObj.provider instanceof PocketProvider + && properties.LimboEnabled) { - if(!this.properties.LimboReturnsInventoryEnabled) + EntityPlayer player = (EntityPlayer) entity; + if (!properties.LimboReturnsInventoryEnabled) { - ((EntityPlayer)entity).inventory.clearInventory(-1, -1); + player.inventory.clearInventory(-1, -1); } - ChunkCoordinates coords = LimboProvider.getLimboSkySpawn(entity.worldObj.rand); - DDTeleporter.teleportEntity(entity, new Point4D(coords.posX,coords.posY,coords.posZ,mod_pocketDim.properties.LimboDimensionID)); - ((EntityLiving) entity).setEntityHealth(20); + ChunkCoordinates coords = LimboProvider.getLimboSkySpawn(player.worldObj.rand); + DDTeleporter.teleportEntity(player, new Point4D(coords.posX, coords.posY, coords.posZ, mod_pocketDim.properties.LimboDimensionID)); + player.setEntityHealth(player.getMaxHealth()); event.setCanceled(true); return false; } diff --git a/StevenDimDoors/mod_pocketDim/PlayerRespawnTracker.java b/StevenDimDoors/mod_pocketDim/PlayerRespawnTracker.java deleted file mode 100644 index 2a4f57ea..00000000 --- a/StevenDimDoors/mod_pocketDim/PlayerRespawnTracker.java +++ /dev/null @@ -1,47 +0,0 @@ - - -package StevenDimDoors.mod_pocketDim; - - -import net.minecraft.entity.item.EntityItem; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemArmor; -import cpw.mods.fml.common.IPlayerTracker; - - -public class PlayerRespawnTracker implements IPlayerTracker -{ - private final DDProperties properties; - - public PlayerRespawnTracker(DDProperties properties) - { - this.properties = properties; - } - - @Override - public void onPlayerLogin(EntityPlayer player) { - // TODO Auto-generated method stub - - } - - @Override - public void onPlayerLogout(EntityPlayer player) { - // TODO Auto-generated method stub - - } - - @Override - public void onPlayerChangedDimension(EntityPlayer player) { - // TODO Auto-generated method stub - - } - - @Override - public void onPlayerRespawn(EntityPlayer player) { - // TODO Auto-generated method stub - - } - - -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/blocks/DDoorBase.java b/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java similarity index 85% rename from StevenDimDoors/mod_pocketDim/blocks/DDoorBase.java rename to StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java index b51f08c1..a23dac62 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/DDoorBase.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java @@ -8,7 +8,6 @@ import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Icon; @@ -21,25 +20,22 @@ import StevenDimDoors.mod_pocketDim.DDProperties; 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; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class DDoorBase extends BlockContainer implements IDDoorLogic +public abstract class BaseDimDoor extends BlockContainer implements IDimDoor { - protected static DDProperties properties = null; + protected final DDProperties properties; private Icon blockIconBottom; - public DDoorBase(int par1, Material material) + public BaseDimDoor(int blockID, Material material, DDProperties properties) { - super(par1, material); + super(blockID, material); - if (properties == null) - properties = DDProperties.instance(); + this.properties = properties; } public void registerIcons(IconRegister par1IconRegister) @@ -54,63 +50,63 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic this.enterDimDoor(world, x, y, z, entity); } - public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { boolean shouldOpen=true; //System.out.println(String.valueOf(par1World.getBlockMetadata(par2, par3, par4))); - if(par5EntityPlayer.inventory.getCurrentItem()!=null) + if(player.inventory.getCurrentItem()!=null) { - if(par5EntityPlayer.inventory.getCurrentItem().getItem() == mod_pocketDim.itemRiftBlade) + if(player.inventory.getCurrentItem().getItem() == mod_pocketDim.itemRiftBlade) { shouldOpen = false; - if (!par1World.isRemote && par1World.getBlockId(par2, par3-1, par4) == this.blockID) + if (!world.isRemote && world.getBlockId(x, y-1, z) == this.blockID) { - int var12 = (int) (MathHelper.floor_double((double)((par5EntityPlayer.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); + int var12 = (int) (MathHelper.floor_double((double)((player.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); - if (par1World.getBlockMetadata(par2, par3-1, par4) == var12) + if (world.getBlockMetadata(x, y-1, z) == var12) { var12 = BlockRotator.transformMetadata(var12, 1, this.blockID); } - par1World.setBlockMetadataWithNotify(par2, par3-1, par4, var12, 2); + world.setBlockMetadataWithNotify(x, y-1, z, var12, 2); } - if (!par1World.isRemote && par1World.getBlockId(par2, par3+1, par4) == this.blockID) + if (!world.isRemote && world.getBlockId(x, y+1, z) == this.blockID) { - int var12 = (int) (MathHelper.floor_double((double)((par5EntityPlayer.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); - if(par1World.getBlockMetadata(par2, par3, par4)==var12) + int var12 = (int) (MathHelper.floor_double((double)((player.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); + if(world.getBlockMetadata(x, y, z)==var12) { var12 = BlockRotator.transformMetadata(var12, 1, this.blockID); } - par1World.setBlockMetadataWithNotify(par2, par3, par4, var12, 2); + world.setBlockMetadataWithNotify(x, y, z, var12, 2); } - par1World.playAuxSFXAtEntity(par5EntityPlayer, 1001, par2, par3, par4, 0); + world.playAuxSFXAtEntity(player, 1001, x, y, z, 0); - if (!shouldOpen && !par1World.isRemote) + if (!shouldOpen && !world.isRemote) { - par5EntityPlayer.inventory.getCurrentItem().damageItem(5, par5EntityPlayer); + player.inventory.getCurrentItem().damageItem(5, player); } } } if(shouldOpen) { - int var10 = this.getFullMetadata(par1World, par2, par3, par4); + int var10 = this.getFullMetadata(world, x, y, z); int var11 = var10 & 7; var11 ^= 4; if ((var10 & 8) == 0) { - par1World.setBlockMetadataWithNotify(par2, par3, par4, var11,2); - par1World.markBlockRangeForRenderUpdate(par2, par3, par4, par2, par3, par4); + world.setBlockMetadataWithNotify(x, y, z, var11,2); + world.markBlockRangeForRenderUpdate(x, y, z, x, y, z); } else { - par1World.setBlockMetadataWithNotify(par2, par3 - 1, par4, var11,2); - par1World.markBlockRangeForRenderUpdate(par2, par3 - 1, par4, par2, par3, par4); + world.setBlockMetadataWithNotify(x, y - 1, z, var11,2); + world.markBlockRangeForRenderUpdate(x, y - 1, z, x, y, z); } - par1World.playAuxSFXAtEntity(par5EntityPlayer, 1003, par2, par3, par4, 0); + world.playAuxSFXAtEntity(player, 1003, x, y, z, 0); return true; } else @@ -158,11 +154,11 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic this.updateAttachedTile(world, x, y, z); } - @SideOnly(Side.CLIENT) /** * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side */ + @SideOnly(Side.CLIENT) public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { if(par1IBlockAccess.getBlockId(par2, par3-1, par4) == this.blockID) @@ -177,7 +173,7 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic //Called to update the render information on the tile entity. Could probably implement a data watcher, //but this works fine and is more versatile I think. - public DDoorBase updateAttachedTile(World world, int x, int y, int z) + public BaseDimDoor updateAttachedTile(World world, int x, int y, int z) { TileEntity tile = world.getBlockTileEntity(x, y, z); if (tile instanceof TileEntityDimDoor) @@ -200,11 +196,18 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic tile.orientation = this.getFullMetadata(par1World, par2, par3, par4) & 7; } + public boolean isDoorOpen(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) + { + return (this.getFullMetadata(par1IBlockAccess, par2, par3, par4) & 4) != 0; + } + + @Override public boolean isOpaqueCube() { return false; } + @Override public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { int var5 = this.getFullMetadata(par1IBlockAccess, par2, par3, par4); @@ -214,6 +217,7 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic /** * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) */ + @Override public boolean renderAsNormalBlock() { return false; @@ -222,16 +226,18 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic /** * The type of render function that is called for this block */ + @Override public int getRenderType() { return 7; } - @SideOnly(Side.CLIENT) /** * Returns the bounding box of the wired rectangular prism to render. */ + @Override + @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4) { this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); @@ -251,6 +257,7 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic /** * Updates the blocks bounds based on its current state. Args: world, x, y, z */ + @Override public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { this.setDoorRotation(this.getFullMetadata(par1IBlockAccess, par2, par3, par4)); @@ -264,11 +271,6 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic return this.getFullMetadata(par1IBlockAccess, par2, par3, par4) & 3; } - public boolean isDoorOpen(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) - { - return (this.getFullMetadata(par1IBlockAccess, par2, par3, par4) & 4) != 0; - } - private void setDoorRotation(int par1) { float var2 = 0.1875F; @@ -354,6 +356,7 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic /** * Called when the block is clicked by a player. Args: x, y, z, entityPlayer */ + @Override public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) { // System.out.println(this.getFullMetadata(par1World, par2, par3, par4)%4); @@ -363,6 +366,7 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are * their own) Args: x, y, z, neighbor blockID */ + @Override public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) { int var6 = par1World.getBlockMetadata(par2, par3, par4); @@ -425,6 +429,7 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit. Args: world, * x, y, z, startVec, endVec */ + @Override public MovingObjectPosition collisionRayTrace(World par1World, int par2, int par3, int par4, Vec3 par5Vec3, Vec3 par6Vec3) { this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); @@ -434,6 +439,7 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic /** * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z */ + @Override public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) { return par3 >= 255 ? false : par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) && super.canPlaceBlockAt(par1World, par2, par3, par4) && super.canPlaceBlockAt(par1World, par2, par3 + 1, par4); @@ -443,6 +449,7 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic * Returns the mobility information of the block, 0 = free, 1 = can't push but can move over, 2 = total immobility * and stop pistons */ + @Override public int getMobilityFlag() { return 2; @@ -473,15 +480,17 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic return var7 & 7 | (var6 ? 8 : 0) | (var9 ? 16 : 0); } - @SideOnly(Side.CLIENT) /** * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) */ + @Override + @SideOnly(Side.CLIENT) public int idPicked(World par1World, int par2, int par3, int par4) { return this.getDrops(); } + @Override public int idDropped(int par1, Random par2Random, int par3) { return (par1 & 8) != 0 ? 0 : (getDrops()); @@ -490,6 +499,7 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic /** * Called when the block is attempted to be harvested */ + @Override public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer) { if (par6EntityPlayer.capabilities.isCreativeMode && (par5 & 8) != 0 && par1World.getBlockId(par2, par3 - 1, par4) == this.blockID) @@ -501,8 +511,7 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic @Override public TileEntity createNewTileEntity(World world) { - TileEntity tile = new TileEntityDimDoor(); - return tile; + return new TileEntityDimDoor(); } @Override @@ -523,12 +532,7 @@ public class DDoorBase extends BlockContainer implements IDDoorLogic } } } - - @Override - public void placeDimDoor(World world, int x, int y, int z) - { - // TODO Auto-generated method stub - } + @Override public int getDrops() { diff --git a/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java b/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java index b2ba41cd..9b59b8b9 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java @@ -1,41 +1,20 @@ package StevenDimDoors.mod_pocketDim.blocks; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.Icon; -import net.minecraft.util.MathHelper; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; -import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -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; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; -import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -public class DimensionalDoor extends DDoorBase implements IDDoorLogic +public class DimensionalDoor extends BaseDimDoor { - public DimensionalDoor(int par1, Material material) + public DimensionalDoor(int blockID, Material material, DDProperties properties) { - super(par1, material); - // TODO Auto-generated constructor stub + super(blockID, material, properties); } @Override diff --git a/StevenDimDoors/mod_pocketDim/blocks/IDDoorLogic.java b/StevenDimDoors/mod_pocketDim/blocks/IDimDoor.java similarity index 90% rename from StevenDimDoors/mod_pocketDim/blocks/IDDoorLogic.java rename to StevenDimDoors/mod_pocketDim/blocks/IDimDoor.java index 6d459edc..6ebe0127 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/IDDoorLogic.java +++ b/StevenDimDoors/mod_pocketDim/blocks/IDimDoor.java @@ -3,7 +3,7 @@ package StevenDimDoors.mod_pocketDim.blocks; import net.minecraft.entity.Entity; import net.minecraft.world.World; -public interface IDDoorLogic +public interface IDimDoor { public void enterDimDoor(World world, int x, int y, int z, Entity entity); diff --git a/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java b/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java index d9b00d4a..e0d7c1d1 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java @@ -1,29 +1,22 @@ package StevenDimDoors.mod_pocketDim.blocks; -import java.util.Random; - import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; -import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -public class TransientDoor extends DDoorBase implements IDDoorLogic +public class TransientDoor extends BaseDimDoor { - public TransientDoor(int blockID, Material material) + public TransientDoor(int blockID, Material material, DDProperties properties) { - super(blockID, material); + super(blockID, material, properties); } @Override @@ -54,28 +47,32 @@ public class TransientDoor extends DDoorBase implements IDDoorLogic { NewDimData dimension = PocketManager.getDimensionData(world); DimLink link = dimension.getLink(x, y, z); - if (link == null&&dimension.isPocketDimension()) + if (link == null && dimension.isPocketDimension()) { dimension.createLink(x, y, z, LinkTypes.SAFE_EXIT); } } } + @Override public int getDrops() { return 0; } - + + @Override public boolean isCollidable() { return false; } + @Override public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) { return null; } + @Override public int getRenderType() { return 8; diff --git a/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java b/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java index 155520c6..77d283d1 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java @@ -1,28 +1,18 @@ package StevenDimDoors.mod_pocketDim.blocks; import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.entity.Entity; import net.minecraft.item.Item; -import net.minecraft.util.Icon; -import net.minecraft.util.MathHelper; -import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -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; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -public class UnstableDoor extends DDoorBase implements IDDoorLogic +public class UnstableDoor extends BaseDimDoor { - public UnstableDoor(int par1, Material material) + public UnstableDoor(int blockID, Material material, DDProperties properties) { - super(par1, material); + super(blockID, material, properties); } @Override diff --git a/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java b/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java index 960fc33d..4e4c4b47 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java @@ -1,29 +1,19 @@ package StevenDimDoors.mod_pocketDim.blocks; -import java.util.Random; - import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.entity.Entity; import net.minecraft.item.Item; -import net.minecraft.util.Icon; -import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -public class WarpDoor extends DDoorBase implements IDDoorLogic +public class WarpDoor extends BaseDimDoor { - private Icon blockIconBottom; - - public WarpDoor(int blockID, Material material) + public WarpDoor(int blockID, Material material, DDProperties properties) { - super(blockID, material); + super(blockID, material, properties); } @Override @@ -33,7 +23,7 @@ public class WarpDoor extends DDoorBase implements IDDoorLogic { NewDimData dimension = PocketManager.getDimensionData(world); DimLink link = dimension.getLink(x, y, z); - if (link == null&&dimension.isPocketDimension()) + if (link == null && dimension.isPocketDimension()) { dimension.createLink(x, y, z, LinkTypes.SAFE_EXIT); } @@ -45,6 +35,4 @@ public class WarpDoor extends DDoorBase implements IDDoorLogic { return Item.doorWood.itemID; } - - } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index c0d9b379..b2e63889 100644 --- a/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -18,6 +18,11 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; +import StevenDimDoors.mod_pocketDim.Point3D; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; +import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; +import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.world.PocketBuilder; import cpw.mods.fml.common.registry.GameRegistry; @@ -472,19 +477,63 @@ public class DDTeleporter return false; } - private static boolean generateSafeExit(NewDimData target, DimLink link, DDProperties properties) + private static boolean generateSafeExit(NewDimData destinationDim, 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. + // are fixed to match the source (mostly - may be shifted a little), + // but the Y coordinate is chosen by searching for a safe location + // to place the door. - // FIXME: Add code here! - return false; + // 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 goes down. If a player is near the bottom + // of the map, the search goes up. If a safe destination cannot be + // found, then we return false and the source-side door slams shut. + + Point3D destination; + Point4D source = link.source(); + World world = PocketManager.loadDimension(destinationDim.id()); + if (world == null) + { + return false; + } + + boolean searchDown = (source.getY() >= world.getActualHeight() / 2); + destination = yCoordHelper.findSafeCube(world, source.getX(), source.getY() - 2, source.getZ(), searchDown); + if (destination == null) + { + destination = yCoordHelper.findSafeCube(world, source.getX(), source.getY() - 2, source.getZ(), !searchDown); + } + if (destination != null) + { + // Set up a 3x3 platform at the destination + int x = destination.getX(); + int y = destination.getY(); + int z = destination.getZ(); + for (int dx = -1; dx <= 1; dx++) + { + for (int dz = -1; dz <= 1; dz++) + { + world.setBlock(x + dx, y, z + dz, properties.FabricBlockID); + } + } + + // Create a reverse link for returning + NewDimData sourceDim = PocketManager.getDimensionData(link.source().getDimension()); + DimLink reverse = destinationDim.createLink(x, y + 2, z, LinkTypes.REVERSE); + sourceDim.setDestination(reverse, source.getX(), source.getY(), source.getZ()); + + // Set up the warp door at the destination + int orientation = getDestinationOrientation(source, properties); + orientation = BlockRotator.transformMetadata(orientation, 2, properties.WarpDoorID); + ItemDimensionalDoor.placeDoorBlock(world, x, y + 1, z, orientation, mod_pocketDim.warpDoor); + + // Complete the link to the destination + // This comes last so the destination isn't set unless everything else works first + destinationDim.setDestination(link, x, y + 2, z); + } + + return (destination != null); } } diff --git a/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java b/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java index 1574634e..d912b464 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java @@ -2,8 +2,10 @@ package StevenDimDoors.mod_pocketDim.helpers; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; +import StevenDimDoors.mod_pocketDim.Point3D; public class yCoordHelper { @@ -67,6 +69,76 @@ public class yCoordHelper material = block.blockMaterial; return (material.isLiquid() || !material.isReplaceable()); } + + public static Point3D findSafeCube(World world, int x, int startY, int z, boolean searchDown) + { + // Search for a 3x3x3 cube of air with blocks underneath + // We can also match against a 3x2x3 box with + // We shift the search area into the bounds of a chunk for the sake of simplicity, + // so that we don't need to worry about working across chunks. + + int localX = x < 0 ? (x % 16) + 16 : (x % 16); + int localZ = z < 0 ? (z % 16) + 16 : (z % 16); + int cornerX = x - localX; + int cornerZ = z - localZ; + localX = MathHelper.clamp_int(localX, 1, 14); + localZ = MathHelper.clamp_int(localZ, 1, 14); + + Chunk chunk = world.getChunkProvider().loadChunk(x >> 4, z >> 4); + + int layers = 0; + int height = world.getActualHeight(); + int y, dx, dz, blockID; + boolean filled; + Block block; + Point3D location = null; + + if (searchDown) + { + /*for (y = startY; y >= 0; y--) + { + blockID = chunk.getBlockID(localX, y, localZ); + + }*/ + } + else + { + // Check if a 3x3 layer of blocks is empty + // If we find a layer that contains replaceable blocks, it can + // serve as the base where we'll place the player and door. + for (y = Math.max(startY, 0); y < height; y++) + { + filled = false; + for (dx = -1; dx <= 1 && !filled; dx++) + { + for (dz = -1; dz <= 1 && !filled; dz++) + { + blockID = chunk.getBlockID(localX + dx, y, localZ + dz); + if (blockID != 0) + { + block = Block.blocksList[blockID]; + if (block != null && !block.blockMaterial.isReplaceable()) + { + filled = true; + } + layers = 0; + } + } + } + if (!filled) + { + layers++; + if (layers == 3) + { + location = new Point3D(localX + cornerX, y - 2, localZ + cornerZ); + break; + } + } + } + } + + return location; + } public static int adjustDestinationY(int y, int worldHeight, int entranceY, int dungeonHeight) { diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 487ffe3f..0dd64745 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -1,15 +1,11 @@ package StevenDimDoors.mod_pocketDim; -import java.util.ArrayList; -import java.util.HashMap; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityEggInfo; import net.minecraft.entity.EntityList; -import net.minecraft.entity.item.EntityItem; import net.minecraft.item.EnumToolMaterial; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -113,8 +109,6 @@ public class mod_pocketDim public static BiomeGenBase limboBiome; public static BiomeGenBase pocketBiome; - - public static PlayerRespawnTracker tracker; public static boolean isPlayerWearingGoogles = false; @@ -148,7 +142,6 @@ public class mod_pocketDim //Now do other stuff MinecraftForge.EVENT_BUS.register(new EventHookContainer(properties)); - tracker = new PlayerRespawnTracker(properties); riftGen = new GatewayGenerator(properties); } @@ -165,15 +158,15 @@ public class mod_pocketDim new RiftRegenerator(commonTickHandler); //No need to store the reference LimboDecay decay = new LimboDecay(commonTickHandler, properties); - transientDoor = (new TransientDoor(properties.TransientDoorID, Material.iron)).setHardness(1.0F) .setUnlocalizedName("transientDoor"); + transientDoor = new TransientDoor(properties.TransientDoorID, Material.iron, properties).setHardness(1.0F) .setUnlocalizedName("transientDoor"); - blockDimWall = (new BlockDimWall(properties.FabricBlockID, 0, Material.iron)).setLightValue(1.0F).setHardness(0.1F).setUnlocalizedName("blockDimWall"); + blockDimWall = new BlockDimWall(properties.FabricBlockID, 0, Material.iron).setLightValue(1.0F).setHardness(0.1F).setUnlocalizedName("blockDimWall"); blockDimWallPerm = (new BlockDimWallPerm(properties.PermaFabricBlockID, 0, Material.iron)).setLightValue(1.0F).setBlockUnbreakable().setResistance(6000000.0F).setUnlocalizedName("blockDimWallPerm"); - warpDoor = (new WarpDoor(properties.WarpDoorID, Material.wood)).setHardness(1.0F) .setUnlocalizedName("dimDoorWarp"); + warpDoor = new WarpDoor(properties.WarpDoorID, Material.wood, properties).setHardness(1.0F) .setUnlocalizedName("dimDoorWarp"); blockRift = (BlockRift) (new BlockRift(properties.RiftBlockID, 0, Material.air, properties).setHardness(1.0F) .setUnlocalizedName("rift")); - blockLimbo = (new BlockLimbo(properties.LimboBlockID, 15, Material.iron, properties.LimboDimensionID, decay).setHardness(.2F).setUnlocalizedName("BlockLimbo").setLightValue(.0F)); - unstableDoor = (new UnstableDoor(properties.UnstableDoorID, Material.iron).setHardness(.2F).setUnlocalizedName("chaosDoor").setLightValue(.0F) ); - dimensionalDoor = (DimensionalDoor) (new DimensionalDoor(properties.DimensionalDoorID, Material.iron)).setHardness(1.0F).setResistance(2000.0F) .setUnlocalizedName("dimDoor"); + blockLimbo = new BlockLimbo(properties.LimboBlockID, 15, Material.iron, properties.LimboDimensionID, decay).setHardness(.2F).setUnlocalizedName("BlockLimbo").setLightValue(.0F); + unstableDoor = (new UnstableDoor(properties.UnstableDoorID, Material.iron, properties).setHardness(.2F).setUnlocalizedName("chaosDoor").setLightValue(.0F) ); + dimensionalDoor = (DimensionalDoor) (new DimensionalDoor(properties.DimensionalDoorID, Material.iron, properties).setHardness(1.0F).setResistance(2000.0F) .setUnlocalizedName("dimDoor")); dimHatch = (new dimHatch(properties.TransTrapdoorID, 84, Material.iron)).setHardness(1.0F) .setUnlocalizedName("dimHatch"); // dimRail = (new DimRail(dimRailID, 88, false)).setHardness(.5F) .setUnlocalizedName("dimRail"); @@ -202,8 +195,6 @@ public class mod_pocketDim GameRegistry.registerBlock(blockDimWall, ItemBlockDimWall.class, "Fabric of Reality"); - GameRegistry.registerPlayerTracker(tracker); - DimensionManager.registerProviderType(properties.PocketProviderID, PocketProvider.class, false); DimensionManager.registerProviderType(properties.LimboProviderID, LimboProvider.class, false); DimensionManager.registerDimension(properties.LimboDimensionID, properties.LimboProviderID); diff --git a/StevenDimDoors/mod_pocketDim/world/LimboProvider.java b/StevenDimDoors/mod_pocketDim/world/LimboProvider.java index 4ddbc2b8..44d18435 100644 --- a/StevenDimDoors/mod_pocketDim/world/LimboProvider.java +++ b/StevenDimDoors/mod_pocketDim/world/LimboProvider.java @@ -181,6 +181,7 @@ public class LimboProvider extends WorldProvider return var5; } + @Override public ChunkCoordinates getRandomizedSpawnPoint() {