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-08-31 13:39:52 +02:00
|
|
|
import net.minecraft.util.MathHelper;
|
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;
|
2013-08-31 13:39:52 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.DDTeleporter;
|
2013-07-16 23:52:26 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
|
2013-08-31 13:39:52 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
2013-02-18 03:46:16 +01:00
|
|
|
|
|
|
|
public class BlockDimWallPerm extends Block
|
|
|
|
{
|
2013-08-31 13:39:52 +02:00
|
|
|
private static final Random random = new Random();
|
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-31 13:39:52 +02:00
|
|
|
public void onEntityWalking(World world, int x, int y, int z, Entity entity)
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
2013-08-31 13:39:52 +02:00
|
|
|
if (!world.isRemote && world.provider.dimensionId == properties.LimboDimensionID)
|
2013-06-14 01:01:54 +02:00
|
|
|
{
|
2013-08-29 08:14:24 +02:00
|
|
|
World overworld = DimensionManager.getWorld(0);
|
|
|
|
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;
|
2013-08-31 13:39:52 +02:00
|
|
|
int rangeLimit = properties.LimboReturnRange / 2;
|
|
|
|
int destinationX = x + MathHelper.getRandomIntegerInRange(random, -rangeLimit, rangeLimit);
|
|
|
|
int destinationZ = z + MathHelper.getRandomIntegerInRange(random, -rangeLimit, rangeLimit);
|
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
|
2013-08-31 13:39:52 +02:00
|
|
|
destinationX = destinationX + (destinationX >> 4);
|
|
|
|
destinationZ = destinationZ + (destinationZ >> 4);
|
2013-06-14 01:01:54 +02:00
|
|
|
|
2013-08-31 13:39:52 +02:00
|
|
|
int destinationY = yCoordHelper.getFirstUncovered(overworld, destinationX, 63, destinationZ, true);
|
2013-06-16 07:44:05 +02:00
|
|
|
|
2013-08-31 13:39:52 +02:00
|
|
|
//FIXME: Shouldn't we make the player's destination safe BEFORE teleporting him?!
|
|
|
|
//player.setPositionAndUpdate( x, y, z );
|
|
|
|
Point4D destination = new Point4D(destinationX, destinationY, destinationZ, 0);
|
2013-09-01 15:21:27 +02:00
|
|
|
DDTeleporter.teleportEntity(player, destination);
|
2013-08-29 08:14:24 +02:00
|
|
|
|
2013-08-31 13:39:52 +02:00
|
|
|
//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-31 13:39:52 +02:00
|
|
|
overworld.setBlockToAir(destinationX, destinationY, destinationZ);
|
|
|
|
overworld.setBlockToAir(destinationX, destinationY + 1, destinationZ);
|
2013-08-18 23:13:23 +02:00
|
|
|
|
2013-08-31 13:39:52 +02:00
|
|
|
for (int xc = -3; xc < 4; xc++)
|
2013-03-29 02:34:38 +01:00
|
|
|
{
|
2013-08-31 13:39:52 +02:00
|
|
|
for (int zc = -3; zc < 4; zc++)
|
2013-03-29 02:34:38 +01:00
|
|
|
{
|
2013-08-31 13:39:52 +02:00
|
|
|
if (Math.abs(xc) + Math.abs(zc) < random.nextInt(3) + 2 ||
|
|
|
|
Math.abs(xc) + Math.abs(zc) < random.nextInt(3) + 3)
|
2013-03-29 02:34:38 +01:00
|
|
|
{
|
2013-08-31 13:39:52 +02:00
|
|
|
overworld.setBlock(destinationX + xc, destinationY - 1, destinationZ + zc, properties.LimboBlockID);
|
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...
|
2013-08-31 13:39:52 +02:00
|
|
|
player.setPositionAndUpdate( destinationX, destinationY, destinationZ );
|
2013-08-29 08:14:24 +02:00
|
|
|
player.fallDistance = 0;
|
2013-06-14 01:01:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-18 03:46:16 +01:00
|
|
|
}
|