2013-04-17 02:48:49 +02:00
|
|
|
package StevenDimDoors.mod_pocketDim.blocks;
|
2013-02-18 03:46:16 +01:00
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
2013-03-29 23:19:27 +01:00
|
|
|
import net.minecraft.client.renderer.texture.IconRegister;
|
2013-02-18 03:46:16 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-06-16 07:44:05 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2013-02-18 03:46:16 +01:00
|
|
|
import net.minecraft.world.World;
|
2013-08-29 08:14:24 +02:00
|
|
|
import net.minecraftforge.common.DimensionManager;
|
2013-07-16 23:52:26 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.DDProperties;
|
|
|
|
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
2013-08-29 08:14:24 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.core.IDimLink;
|
|
|
|
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
2013-07-16 23:52:26 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
|
2013-02-18 03:46:16 +01:00
|
|
|
|
|
|
|
public class BlockDimWallPerm extends Block
|
|
|
|
{
|
2013-06-14 01:01:54 +02:00
|
|
|
private static DDProperties properties = null;
|
2013-02-18 03:46:16 +01:00
|
|
|
|
2013-04-17 02:48:49 +02:00
|
|
|
public BlockDimWallPerm(int i, int j, Material par2Material)
|
2013-02-18 03:46:16 +01:00
|
|
|
{
|
2013-06-14 01:01:54 +02:00
|
|
|
super(i, Material.ground);
|
2013-07-16 09:00:57 +02:00
|
|
|
this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab);
|
2013-06-14 01:01:54 +02:00
|
|
|
if (properties == null)
|
|
|
|
properties = DDProperties.instance();
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|
2013-03-29 23:19:27 +01:00
|
|
|
|
|
|
|
public void registerIcons(IconRegister par1IconRegister)
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
2013-07-16 09:00:57 +02:00
|
|
|
this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2());
|
2013-06-14 01:01:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int quantityDropped(Random par1Random)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-16 09:00:57 +02:00
|
|
|
|
2013-06-14 01:01:54 +02:00
|
|
|
public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Only matters if the player is in limbo, acts to teleport the player from limbo back to dim 0
|
|
|
|
*/
|
2013-08-29 08:14:24 +02:00
|
|
|
public void onEntityWalking(World par1World, int par2, int par3, int par4, Entity entity)
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
if (!par1World.isRemote && par1World.provider.dimensionId == properties.LimboDimensionID)
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
|
|
|
Random rand = new Random();
|
|
|
|
|
2013-08-29 08:14:24 +02:00
|
|
|
IDimLink link = PocketManager.getRandomLinkData(false);
|
|
|
|
if (link == null)
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
2013-08-23 10:12:56 +02:00
|
|
|
link =new NewLinkData(0,0,0,0);
|
2013-06-14 01:01:54 +02:00
|
|
|
}
|
2013-08-18 23:13:23 +02:00
|
|
|
link.destDimID = 0;
|
|
|
|
link.locDimID = par1World.provider.dimensionId;
|
2013-08-29 08:14:24 +02:00
|
|
|
World overworld = DimensionManager.getWorld(0);
|
2013-06-14 01:01:54 +02:00
|
|
|
|
2013-08-29 08:14:24 +02:00
|
|
|
if (overworld == null)
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
DimensionManager.initDimension(0);
|
|
|
|
overworld = DimensionManager.getWorld(0);
|
2013-06-14 01:01:54 +02:00
|
|
|
}
|
2013-08-29 08:14:24 +02:00
|
|
|
|
|
|
|
if (overworld != null && entity instanceof EntityPlayerMP)
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
EntityPlayer player = (EntityPlayer) entity;
|
|
|
|
player.fallDistance = 0;
|
|
|
|
int x = (link.destXCoord + rand.nextInt(properties.LimboReturnRange) - properties.LimboReturnRange/2);
|
|
|
|
int z = (link.destZCoord + rand.nextInt(properties.LimboReturnRange) - properties.LimboReturnRange/2);
|
2013-06-14 01:01:54 +02:00
|
|
|
|
|
|
|
//make sure I am in the middle of a chunk, and not on a boundary, so it doesn't load the chunk next to me
|
|
|
|
x = x + (x >> 4);
|
|
|
|
z = z + (z >> 4);
|
|
|
|
|
2013-08-18 23:13:23 +02:00
|
|
|
int y = yCoordHelper.getFirstUncovered(0, x, 63, z, true);
|
2013-06-16 07:44:05 +02:00
|
|
|
|
2013-08-29 08:14:24 +02:00
|
|
|
player.setPositionAndUpdate( x, y, z );
|
2013-06-14 01:01:54 +02:00
|
|
|
//this complicated chunk teleports the player back to the overworld at some random location. Looks funky becaue it has to load the chunk
|
2013-08-18 23:13:23 +02:00
|
|
|
link.destXCoord = x;
|
|
|
|
link.destYCoord = y;
|
|
|
|
link.destZCoord = z;
|
2013-08-29 08:14:24 +02:00
|
|
|
PocketManager.teleportEntity(par1World, player, link);
|
|
|
|
|
|
|
|
player.setPositionAndUpdate( x, y, z );
|
2013-06-14 01:01:54 +02:00
|
|
|
|
2013-08-18 23:13:23 +02:00
|
|
|
// Make absolutely sure the player doesn't spawn inside blocks, though to be honest this shouldn't ever have to be a problem...
|
2013-08-29 08:14:24 +02:00
|
|
|
overworld.setBlockToAir(x, y, z);
|
|
|
|
overworld.setBlockToAir(x, y + 1, z);
|
2013-08-18 23:13:23 +02:00
|
|
|
|
2013-06-14 01:01:54 +02:00
|
|
|
int i=x;
|
2013-08-18 23:13:23 +02:00
|
|
|
int j=y;
|
2013-06-14 01:01:54 +02:00
|
|
|
int k=z;
|
|
|
|
|
|
|
|
for(int xc=-3;xc<4;xc++)
|
2013-03-29 02:34:38 +01:00
|
|
|
{
|
|
|
|
for(int zc=-3;zc<4;zc++)
|
|
|
|
{
|
|
|
|
for(int yc=0;yc<200;yc++)
|
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
if (yc==0)
|
2013-03-29 02:34:38 +01:00
|
|
|
{
|
|
|
|
if(Math.abs(xc)+Math.abs(zc)<rand.nextInt(3)+2)
|
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
overworld.setBlock(i+xc, j-1+yc, k+zc, properties.LimboBlockID);
|
2013-03-29 02:34:38 +01:00
|
|
|
}
|
|
|
|
else if(Math.abs(xc)+Math.abs(zc)<rand.nextInt(3)+3)
|
|
|
|
|
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
overworld.setBlock(i+xc, j-1+yc, k+zc, properties.LimboBlockID,2,0);
|
2013-03-29 02:34:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2013-06-14 01:01:54 +02:00
|
|
|
|
2013-08-29 08:14:24 +02:00
|
|
|
//FIXME: Why do we do this repeatedly? We also set the fall distance at the start...
|
|
|
|
player.setPositionAndUpdate( x, y, z );
|
|
|
|
player.fallDistance = 0;
|
2013-06-14 01:01:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|