Skip to content

Instantly share code, notes, and snippets.

@Pwootage
Created July 11, 2011 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pwootage/1075302 to your computer and use it in GitHub Desktop.
Save Pwootage/1075302 to your computer and use it in GitHub Desktop.
Push a block
if (hitBlock != null)
{
blockID = world.getBlockID(hitBlock.x, hitBlock.y, hitBlock.z);
pushid = 12;
iceid = 79;
triggerid = 201;
if (blockID == pushid)
{
if (world.getBlockID(hitBlock.x, hitBlock.y-1, hitBlock.z) == iceid)
{
dirx = 0;
dirz = 0;
x = hitBlock.x;
y = hitBlock.y;
z = hitBlock.z;
foundEnd = false;
block = 0;
floor = 0;
ppos = player.getPosition();
diffx = hitBlock.x-ppos.x;
diffz = hitBlock.z-ppos.z;
absx = Math.abs(diffx);
absz = Math.abs(diffz);
if (absx > absz)
{
dirx = diffx/absx;
}
else
{
dirz = diffz/absz;
}
if (dirx != 0)
{
while (!foundEnd)
{
x += dirx;
block = world.getBlockID(x,y,z);
floor = world.getBlockID(x,y-1,z);
if (block != 0)
{
foundEnd = true
}
if (floor != iceid && floor != triggerid)
{
foundEnd = true;
}
}
if (floor == 0 && block == 0)
{
}
else
{
x -= dirx;
}
world.setBlockID(hitBlock.x, hitBlock.y, hitBlock.z, 0);
world.setBlockID(x, y, z, pushid);
}
else if (dirz != 0)
{
while (!foundEnd)
{
z += dirz;
block = world.getBlockID(x,y,z);
floor = world.getBlockID(x,y-1,z);
if (block != 0)
{
foundEnd = true
}
if (floor != iceid && floor != triggerid)
{
foundEnd = true;
}
}
if (floor == 0 && block == 0)
{
}
else
{
z -= dirz;
}
world.setBlockID(hitBlock.x, hitBlock.y, hitBlock.z, 0);
world.setBlockID(x, y, z, pushid);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment