コード例 #1
0
ファイル: redstone.cpp プロジェクト: kiki64/mineserver
bool BlockRedstone::onPlace(User* user, int16_t newblock, int32_t x, int16_t y, int32_t z, int map, int8_t direction, int8_t posx, int8_t posy, int8_t posz)
{
  uint8_t block;
  uint8_t meta;

  if (!ServerInstance->map(map)->getBlock(x, y, z, &block, &meta))
  {
    revertBlock(user, x, y, z, map);
    return true;
  }

  /* Check block below allows blocks placed on top */
  if (!isBlockStackable(block))
  {
    revertBlock(user, x, y, z, map);
    return true;
  }

  /* move the x,y,z coords dependent upon placement direction */
  if (!translateDirection(&x, &y, &z, map, direction))
  {
    revertBlock(user, x, y, z, map);
    return true;
  }

  if (!isBlockEmpty(x, y, z, map))
  {
    revertBlock(user, x, y, z, map);
    return true;
  }

  newblock = 55;
  meta = 0;

  ServerInstance->map(map)->setBlock(x, y, z, char(newblock), meta);
  ServerInstance->map(map)->sendBlockChange(x, y, z, char(newblock), meta);

  ServerInstance->redstone(map)->addSimulation(vec(x,y,z));

  return false;
}
コード例 #2
0
ファイル: redstoneutil.cpp プロジェクト: chtisgit/mine152
bool BlockRedstoneUtil::onPlace(User* user, int16_t newblock, int32_t x, int16_t y, int32_t z, int map, int8_t direction)
{
	uint8_t block;
	uint8_t meta = 0;
	if (!ServerInstance->map(map)->getBlock(x, y, z, &block, &meta)) {
		revertBlock(user, x, y, z, map);
		return true;
	}

	/* Check block below allows blocks placed on top */
	if (!isBlockStackable(block)) {
		revertBlock(user, x, y, z, map);
		return true;
	}

	/* move the x,y,z coords dependent upon placement direction */
	if (!translateDirection(&x, &y, &z, map, direction)) {
		revertBlock(user, x, y, z, map);
		return true;
	}

	if (!isBlockEmpty(x, y, z, map)) {
		revertBlock(user, x, y, z, map);
		return true;
	}


	// Check that switch is placed on legal direction
	if ((newblock == BLOCK_STONE_BUTTON && (direction == BLOCK_TOP || direction == BLOCK_BOTTOM))
	        || ((newblock == BLOCK_STONE_PRESSURE_PLATE || newblock == BLOCK_WOODEN_PRESSURE_PLATE) && direction != BLOCK_TOP)) {
		revertBlock(user, x, y, z, map);
		return true;
	}

	// Set metadata for the position
	if (newblock == BLOCK_STONE_BUTTON || newblock == BLOCK_LEVER) {
		// Wall switch
		if (direction != BLOCK_TOP && direction != BLOCK_BOTTOM) {
			meta = direction;
		}
		// Ceiling lever
		else if (direction == BLOCK_BOTTOM) {
			int yaw = abs(int(user->pos.yaw)) % 360;
			if ((yaw > 45 && yaw <= 135) || (yaw > 225 && yaw <= 315)) {
				meta = 0x00;
			} else {
				meta = 0x07;
			}
		}
		// Floor lever
		else {
			int yaw = abs(int(user->pos.yaw)) % 360;
			if ((yaw > 45 && yaw <= 135) || (yaw > 225 && yaw <= 315)) {
				meta = 0x06;
			} else {
				meta = 0x05;
			}
		}
	}

	ServerInstance->map(map)->setBlock(x, y, z, char(newblock), meta);
	ServerInstance->map(map)->sendBlockChange(x, y, z, char(newblock), meta);

	return false;
}