934dcfde3d
Replaced several core classes from DD with new classes to enforce integrity checks. Rewriting everything that depended on those classes is a massive undertaking but it should simplify our code and prevent the many bugs we've seen lately. The rewrite isn't done yet, just committing my progress so far.
127 lines
3.8 KiB
Java
127 lines
3.8 KiB
Java
package StevenDimDoors.mod_pocketDim.blocks;
|
|
|
|
import java.util.Random;
|
|
|
|
import net.minecraft.block.Block;
|
|
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.entity.player.EntityPlayerMP;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.common.DimensionManager;
|
|
import StevenDimDoors.mod_pocketDim.DDProperties;
|
|
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
|
import StevenDimDoors.mod_pocketDim.core.IDimLink;
|
|
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
|
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
|
|
|
|
public class BlockDimWallPerm extends Block
|
|
{
|
|
private static DDProperties properties = null;
|
|
|
|
public BlockDimWallPerm(int i, int j, Material par2Material)
|
|
{
|
|
super(i, Material.ground);
|
|
this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab);
|
|
if (properties == null)
|
|
properties = DDProperties.instance();
|
|
}
|
|
|
|
public void registerIcons(IconRegister par1IconRegister)
|
|
{
|
|
this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2());
|
|
}
|
|
|
|
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 entity)
|
|
{
|
|
if (!par1World.isRemote && par1World.provider.dimensionId == properties.LimboDimensionID)
|
|
{
|
|
Random rand = new Random();
|
|
|
|
IDimLink link = PocketManager.getRandomLinkData(false);
|
|
if (link == null)
|
|
{
|
|
link =new NewLinkData(0,0,0,0);
|
|
}
|
|
link.destDimID = 0;
|
|
link.locDimID = par1World.provider.dimensionId;
|
|
World overworld = DimensionManager.getWorld(0);
|
|
|
|
if (overworld == null)
|
|
{
|
|
DimensionManager.initDimension(0);
|
|
overworld = DimensionManager.getWorld(0);
|
|
}
|
|
|
|
if (overworld != null && entity instanceof EntityPlayerMP)
|
|
{
|
|
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);
|
|
|
|
//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, true);
|
|
|
|
player.setPositionAndUpdate( x, y, z );
|
|
//this complicated chunk teleports the player back to the overworld at some random location. Looks funky becaue it has to load the chunk
|
|
link.destXCoord = x;
|
|
link.destYCoord = y;
|
|
link.destZCoord = z;
|
|
PocketManager.teleportEntity(par1World, player, link);
|
|
|
|
player.setPositionAndUpdate( x, y, z );
|
|
|
|
// Make absolutely sure the player doesn't spawn inside blocks, though to be honest this shouldn't ever have to be a problem...
|
|
overworld.setBlockToAir(x, y, z);
|
|
overworld.setBlockToAir(x, y + 1, z);
|
|
|
|
int i=x;
|
|
int j=y;
|
|
int k=z;
|
|
|
|
for(int xc=-3;xc<4;xc++)
|
|
{
|
|
for(int zc=-3;zc<4;zc++)
|
|
{
|
|
for(int yc=0;yc<200;yc++)
|
|
{
|
|
if (yc==0)
|
|
{
|
|
if(Math.abs(xc)+Math.abs(zc)<rand.nextInt(3)+2)
|
|
{
|
|
overworld.setBlock(i+xc, j-1+yc, k+zc, properties.LimboBlockID);
|
|
}
|
|
else if(Math.abs(xc)+Math.abs(zc)<rand.nextInt(3)+3)
|
|
|
|
{
|
|
overworld.setBlock(i+xc, j-1+yc, k+zc, properties.LimboBlockID,2,0);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//FIXME: Why do we do this repeatedly? We also set the fall distance at the start...
|
|
player.setPositionAndUpdate( x, y, z );
|
|
player.fallDistance = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|