aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/PistonExtensionTile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Minecraft.World/PistonExtensionTile.cpp')
-rw-r--r--Minecraft.World/PistonExtensionTile.cpp226
1 files changed, 123 insertions, 103 deletions
diff --git a/Minecraft.World/PistonExtensionTile.cpp b/Minecraft.World/PistonExtensionTile.cpp
index 1827ddde..25c5adb9 100644
--- a/Minecraft.World/PistonExtensionTile.cpp
+++ b/Minecraft.World/PistonExtensionTile.cpp
@@ -9,8 +9,8 @@ PistonExtensionTile::PistonExtensionTile(int id) : Tile(id, Material::piston,isS
// 4J added initialiser
overrideTopTexture = NULL;
- setSoundType(SOUND_STONE);
- setDestroyTime(0.5f);
+ setSoundType(SOUND_STONE);
+ setDestroyTime(0.5f);
}
void PistonExtensionTile::setOverrideTopTexture(Icon *overrideTopTexture)
@@ -23,49 +23,63 @@ void PistonExtensionTile::clearOverrideTopTexture()
this->overrideTopTexture = NULL;
}
+void PistonExtensionTile::playerWillDestroy(Level *level, int x, int y, int z, int data, shared_ptr<Player> player)
+{
+ if (player->abilities.instabuild)
+ {
+ int facing = getFacing(data);
+ int tile = level->getTile(x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing]);
+ if (tile == Tile::pistonBase_Id || tile == Tile::pistonStickyBase_Id)
+ {
+ level->removeTile(x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing]);
+ }
+ }
+ Tile::playerWillDestroy(level, x, y, z, data, player);
+}
+
void PistonExtensionTile::onRemove(Level *level, int x, int y, int z, int id, int data)
{
- Tile::onRemove(level, x, y, z, id, data);
- int facing = Facing::OPPOSITE_FACING[getFacing(data)];
- x += Facing::STEP_X[facing];
- y += Facing::STEP_Y[facing];
- z += Facing::STEP_Z[facing];
+ Tile::onRemove(level, x, y, z, id, data);
+ int facing = Facing::OPPOSITE_FACING[getFacing(data)];
+ x += Facing::STEP_X[facing];
+ y += Facing::STEP_Y[facing];
+ z += Facing::STEP_Z[facing];
- int t = level->getTile(x, y, z);
+ int t = level->getTile(x, y, z);
- if (t == Tile::pistonBase_Id || t == Tile::pistonStickyBase_Id)
+ if (t == Tile::pistonBase_Id || t == Tile::pistonStickyBase_Id)
{
- data = level->getData(x, y, z);
- if (PistonBaseTile::isExtended(data))
+ data = level->getData(x, y, z);
+ if (PistonBaseTile::isExtended(data))
{
- Tile::tiles[t]->spawnResources(level, x, y, z, data, 0);
- level->setTile(x, y, z, 0);
+ Tile::tiles[t]->spawnResources(level, x, y, z, data, 0);
+ level->removeTile(x, y, z);
- }
- }
+ }
+ }
}
Icon *PistonExtensionTile::getTexture(int face, int data)
{
- int facing = getFacing(data);
+ int facing = getFacing(data);
- if (face == facing)
+ if (face == facing)
{
- if (overrideTopTexture != NULL)
+ if (overrideTopTexture != NULL)
{
- return overrideTopTexture;
- }
- if ((data & STICKY_BIT) != 0)
+ return overrideTopTexture;
+ }
+ if ((data & STICKY_BIT) != 0)
{
return PistonBaseTile::getTexture(PistonBaseTile::PLATFORM_STICKY_TEX);
- }
- return PistonBaseTile::getTexture(PistonBaseTile::PLATFORM_TEX);
- }
- if (facing < 6 && face == Facing::OPPOSITE_FACING[facing])
+ }
+ return PistonBaseTile::getTexture(PistonBaseTile::PLATFORM_TEX);
+ }
+ if (facing < 6 && face == Facing::OPPOSITE_FACING[facing])
{
- return PistonBaseTile::getTexture(PistonBaseTile::PLATFORM_TEX);
- }
- return PistonBaseTile::getTexture(PistonBaseTile::EDGE_TEX); // edge and arms
+ return PistonBaseTile::getTexture(PistonBaseTile::PLATFORM_TEX);
+ }
+ return PistonBaseTile::getTexture(PistonBaseTile::EDGE_TEX); // edge and arms
}
void PistonExtensionTile::registerIcons(IconRegister *iconRegister)
@@ -105,98 +119,98 @@ int PistonExtensionTile::getResourceCount(Random *random)
void PistonExtensionTile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes, shared_ptr<Entity> source)
{
- int data = level->getData(x, y, z);
+ int data = level->getData(x, y, z);
- const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f;
- const float smallEdge1 = (8.0f - (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f;
- const float smallEdge2 = (8.0f + (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f;
- const float largeEdge1 = (8.0f - PistonBaseTile::PLATFORM_THICKNESS) / 16.0f;
- const float largeEdge2 = (8.0f + PistonBaseTile::PLATFORM_THICKNESS) / 16.0f;
+ const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f;
+ const float smallEdge1 = (8.0f - (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f;
+ const float smallEdge2 = (8.0f + (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f;
+ const float largeEdge1 = (8.0f - PistonBaseTile::PLATFORM_THICKNESS) / 16.0f;
+ const float largeEdge2 = (8.0f + PistonBaseTile::PLATFORM_THICKNESS) / 16.0f;
- switch (getFacing(data))
+ switch (getFacing(data))
{
- case Facing::DOWN:
- setShape(0, 0, 0, 1, thickness, 1);
- Tile::addAABBs(level, x, y, z, box, boxes, source);
- setShape(smallEdge1, thickness, smallEdge1, smallEdge2, 1, smallEdge2);
- Tile::addAABBs(level, x, y, z, box, boxes, source);
- break;
- case Facing::UP:
- setShape(0, 1 - thickness, 0, 1, 1, 1);
- Tile::addAABBs(level, x, y, z, box, boxes, source);
- setShape(smallEdge1, 0, smallEdge1, smallEdge2, 1 - thickness, smallEdge2);
- Tile::addAABBs(level, x, y, z, box, boxes, source);
- break;
- case Facing::NORTH:
- setShape(0, 0, 0, 1, 1, thickness);
- Tile::addAABBs(level, x, y, z, box, boxes, source);
- setShape(largeEdge1, smallEdge1, thickness, largeEdge2, smallEdge2, 1);
- Tile::addAABBs(level, x, y, z, box, boxes, source);
- break;
- case Facing::SOUTH:
- setShape(0, 0, 1 - thickness, 1, 1, 1);
- Tile::addAABBs(level, x, y, z, box, boxes, source);
- setShape(largeEdge1, smallEdge1, 0, largeEdge2, smallEdge2, 1 - thickness);
- Tile::addAABBs(level, x, y, z, box, boxes, source);
- break;
- case Facing::WEST:
- setShape(0, 0, 0, thickness, 1, 1);
- Tile::addAABBs(level, x, y, z, box, boxes, source);
- setShape(smallEdge1, largeEdge1, thickness, smallEdge2, largeEdge2, 1);
- Tile::addAABBs(level, x, y, z, box, boxes, source);
- break;
- case Facing::EAST:
- setShape(1 - thickness, 0, 0, 1, 1, 1);
- Tile::addAABBs(level, x, y, z, box, boxes, source);
- setShape(0, smallEdge1, largeEdge1, 1 - thickness, smallEdge2, largeEdge2);
- Tile::addAABBs(level, x, y, z, box, boxes, source);
- break;
- }
- setShape(0, 0, 0, 1, 1, 1);
+ case Facing::DOWN:
+ setShape(0, 0, 0, 1, thickness, 1);
+ Tile::addAABBs(level, x, y, z, box, boxes, source);
+ setShape(smallEdge1, thickness, smallEdge1, smallEdge2, 1, smallEdge2);
+ Tile::addAABBs(level, x, y, z, box, boxes, source);
+ break;
+ case Facing::UP:
+ setShape(0, 1 - thickness, 0, 1, 1, 1);
+ Tile::addAABBs(level, x, y, z, box, boxes, source);
+ setShape(smallEdge1, 0, smallEdge1, smallEdge2, 1 - thickness, smallEdge2);
+ Tile::addAABBs(level, x, y, z, box, boxes, source);
+ break;
+ case Facing::NORTH:
+ setShape(0, 0, 0, 1, 1, thickness);
+ Tile::addAABBs(level, x, y, z, box, boxes, source);
+ setShape(largeEdge1, smallEdge1, thickness, largeEdge2, smallEdge2, 1);
+ Tile::addAABBs(level, x, y, z, box, boxes, source);
+ break;
+ case Facing::SOUTH:
+ setShape(0, 0, 1 - thickness, 1, 1, 1);
+ Tile::addAABBs(level, x, y, z, box, boxes, source);
+ setShape(largeEdge1, smallEdge1, 0, largeEdge2, smallEdge2, 1 - thickness);
+ Tile::addAABBs(level, x, y, z, box, boxes, source);
+ break;
+ case Facing::WEST:
+ setShape(0, 0, 0, thickness, 1, 1);
+ Tile::addAABBs(level, x, y, z, box, boxes, source);
+ setShape(smallEdge1, largeEdge1, thickness, smallEdge2, largeEdge2, 1);
+ Tile::addAABBs(level, x, y, z, box, boxes, source);
+ break;
+ case Facing::EAST:
+ setShape(1 - thickness, 0, 0, 1, 1, 1);
+ Tile::addAABBs(level, x, y, z, box, boxes, source);
+ setShape(0, smallEdge1, largeEdge1, 1 - thickness, smallEdge2, largeEdge2);
+ Tile::addAABBs(level, x, y, z, box, boxes, source);
+ break;
+ }
+ setShape(0, 0, 0, 1, 1, 1);
}
void PistonExtensionTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param
{
- int data = (forceData == -1 ) ? level->getData(x, y, z) : forceData;
+ int data = (forceData == -1 ) ? level->getData(x, y, z) : forceData;
- const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f;
+ const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f;
- switch (getFacing(data))
+ switch (getFacing(data))
{
- case Facing::DOWN:
- setShape(0, 0, 0, 1, thickness, 1);
- break;
- case Facing::UP:
- setShape(0, 1 - thickness, 0, 1, 1, 1);
- break;
- case Facing::NORTH:
- setShape(0, 0, 0, 1, 1, thickness);
- break;
- case Facing::SOUTH:
- setShape(0, 0, 1 - thickness, 1, 1, 1);
- break;
- case Facing::WEST:
- setShape(0, 0, 0, thickness, 1, 1);
- break;
- case Facing::EAST:
- setShape(1 - thickness, 0, 0, 1, 1, 1);
- break;
- }
+ case Facing::DOWN:
+ setShape(0, 0, 0, 1, thickness, 1);
+ break;
+ case Facing::UP:
+ setShape(0, 1 - thickness, 0, 1, 1, 1);
+ break;
+ case Facing::NORTH:
+ setShape(0, 0, 0, 1, 1, thickness);
+ break;
+ case Facing::SOUTH:
+ setShape(0, 0, 1 - thickness, 1, 1, 1);
+ break;
+ case Facing::WEST:
+ setShape(0, 0, 0, thickness, 1, 1);
+ break;
+ case Facing::EAST:
+ setShape(1 - thickness, 0, 0, 1, 1, 1);
+ break;
+ }
}
void PistonExtensionTile::neighborChanged(Level *level, int x, int y, int z, int type)
{
- int facing = getFacing(level->getData(x, y, z));
- int tile = level->getTile(x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing]);
- if (tile != Tile::pistonBase_Id && tile != Tile::pistonStickyBase_Id)
+ int facing = getFacing(level->getData(x, y, z));
+ int tile = level->getTile(x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing]);
+ if (tile != Tile::pistonBase_Id && tile != Tile::pistonStickyBase_Id)
{
- level->setTile(x, y, z, 0);
- }
- else
+ level->removeTile(x, y, z);
+ }
+ else
{
- Tile::tiles[tile]->neighborChanged(level, x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing], type);
- }
+ Tile::tiles[tile]->neighborChanged(level, x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing], type);
+ }
}
int PistonExtensionTile::getFacing(int data)
@@ -206,5 +220,11 @@ int PistonExtensionTile::getFacing(int data)
int PistonExtensionTile::cloneTileId(Level *level, int x, int y, int z)
{
+ int data = level->getData(x, y, z);
+ if ((data & STICKY_BIT) != 0)
+ {
+ return Tile::pistonStickyBase_Id;
+ }
+ return Tile::pistonBase_Id;
return 0;
} \ No newline at end of file