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 ;
2013-06-16 07:44:05 +02:00
import cpw.mods.fml.common.FMLCommonHandler ;
2013-06-16 09:40:46 +02:00
import StevenDimDoors.mod_pocketDim.BlankTeleporter ;
2013-06-14 01:01:54 +02:00
import StevenDimDoors.mod_pocketDim.DDProperties ;
2013-04-17 02:48:49 +02:00
import StevenDimDoors.mod_pocketDim.LinkData ;
import StevenDimDoors.mod_pocketDim.mod_pocketDim ;
2013-06-10 23:03:52 +02:00
import StevenDimDoors.mod_pocketDim.helpers.dimHelper ;
2013-05-09 21:28:32 +02:00
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper ;
2013-04-17 02:48:49 +02:00
2013-02-18 03:46:16 +01:00
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 ;
import net.minecraft.server.management.ServerConfigurationManager ;
2013-02-18 03:46:16 +01:00
import net.minecraft.world.World ;
2013-06-16 07:44:05 +02:00
import net.minecraft.world.WorldServer ;
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 ) ;
setTickRandomly ( true ) ;
// this.setCreativeTab(CreativeTabs.tabBlock);
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
{
this . blockIcon = par1IconRegister . registerIcon ( mod_pocketDim . modid + " : " + this . getUnlocalizedName2 ( ) . replace ( " perm " , " " ) ) ;
}
public int quantityDropped ( Random par1Random )
{
return 0 ;
}
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
* /
public void onEntityWalking ( World par1World , int par2 , int par3 , int par4 , Entity par5Entity )
{
if ( ! par1World . isRemote & & par1World . provider . dimensionId = = properties . LimboDimensionID )
{
Random rand = new Random ( ) ;
LinkData link = dimHelper . instance . getRandomLinkData ( false ) ;
if ( link = = null )
{
link = new LinkData ( 0 , 0 , 0 , 0 ) ;
}
if ( dimHelper . getWorld ( 0 ) = = null )
{
dimHelper . initDimension ( 0 ) ;
}
2013-06-16 07:44:05 +02:00
if ( dimHelper . getWorld ( 0 ) ! = null & & par5Entity instanceof EntityPlayerMP )
2013-06-14 01:01:54 +02:00
{
int x = ( link . destXCoord + rand . nextInt ( properties . LimboReturnRange ) - properties . LimboReturnRange / 2 ) ;
int z = ( link . destZCoord + rand . nextInt ( properties . LimboReturnRange ) - properties . LimboReturnRange / 2 ) ;
//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 ) ;
int y = yCoordHelper . getFirstUncovered ( 0 , x , 63 , z ) ;
2013-06-16 07:44:05 +02:00
EntityPlayer . class . cast ( par5Entity ) . 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-06-16 07:44:05 +02:00
2013-06-16 09:40:46 +02:00
FMLCommonHandler . instance ( ) . getMinecraftServerInstance ( ) . getConfigurationManager ( ) . transferPlayerToDimension ( ( EntityPlayerMP ) par5Entity , 0 , new BlankTeleporter ( ( WorldServer ) par5Entity . worldObj ) ) ;
2013-06-16 07:44:05 +02:00
//dimHelper.instance.teleportToPocket(par1World, new LinkData(par1World.provider.dimensionId,0,x,y,z,link.locXCoord,link.locYCoord,link.locZCoord,link.isLocPocket,0),
// EntityPlayer.class.cast(par5Entity));
2013-06-14 01:01:54 +02:00
EntityPlayer . class . cast ( par5Entity ) . setPositionAndUpdate ( x , y , z ) ;
//makes sure they can breath when they teleport
dimHelper . getWorld ( 0 ) . setBlock ( x , y , z , 0 ) ;
int i = x ;
int j = y - 1 ;
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-05-09 23:16:27 +02:00
if ( yc = = 0 )
2013-03-29 02:34:38 +01:00
{
2013-06-14 01:01:54 +02:00
2013-03-29 02:34:38 +01:00
if ( Math . abs ( xc ) + Math . abs ( zc ) < rand . nextInt ( 3 ) + 2 )
{
2013-06-14 01:01:54 +02:00
dimHelper . getWorld ( 0 ) . 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-06-14 01:01:54 +02:00
dimHelper . getWorld ( 0 ) . 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-03-29 02:34:38 +01:00
{
2013-06-14 11:20:51 +02:00
EntityPlayer . class . cast ( par5Entity ) . setPositionAndUpdate ( x , y , z ) ;
2013-06-15 10:19:08 +02:00
EntityPlayer . class . cast ( par5Entity ) . fallDistance = 0 ;
2013-03-29 02:34:38 +01:00
}
2013-06-16 07:44:05 +02:00
2013-06-14 01:01:54 +02:00
}
}
}
2013-02-18 03:46:16 +01:00
}