当前位置: 首页>>代码示例>>Java>>正文


Java ITurtleAccess.consumeFuel方法代码示例

本文整理汇总了Java中dan200.computercraft.api.turtle.ITurtleAccess.consumeFuel方法的典型用法代码示例。如果您正苦于以下问题:Java ITurtleAccess.consumeFuel方法的具体用法?Java ITurtleAccess.consumeFuel怎么用?Java ITurtleAccess.consumeFuel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dan200.computercraft.api.turtle.ITurtleAccess的用法示例。


在下文中一共展示了ITurtleAccess.consumeFuel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: teleportTo

import dan200.computercraft.api.turtle.ITurtleAccess; //导入方法依赖的package包/类
@LuaFunction
@MultiReturn
public Object[] teleportTo(int x, int y, int z) {
    // look for the Turtle above
    final ITurtleAccess turtle = TurtleUtil.getITurtle(worldObj, xCoord, yCoord + 1, zCoord);
    // if there was a turtle
    if (turtle != null) {
        // make sure it can teleport there
        if (!worldObj.isAirBlock(x, y, z)) {
            return new Object[]{false, "Teleport failed"};
        }
        // check there is enough fuel to teleport
        int requiredFuel = requiredFuelInternal(turtle, x, y, z);
        if (requiredFuel > turtle.getFuelLevel()) {
            return new Object[]{false, "Not enough fuel"};
        }
        // consume the fuel and teleport the Turtle
        turtle.consumeFuel(requiredFuel);
        turtle.teleportTo(worldObj, x, y, z);
        // show teleport particles and play teleport sounds at both sides
        doTeleportFX(new ChunkCoordinates(x, y, z));
        return new Object[]{true};
    }
    // no turtle
    return new Object[]{false, "No Turtle found above the teleport"};
}
 
开发者ID:theoriginalbit,项目名称:MoarPeripherals,代码行数:27,代码来源:TileTurtleTeleport.java

示例2: callMethod

import dan200.computercraft.api.turtle.ITurtleAccess; //导入方法依赖的package包/类
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException {
	if (!Config.enableTurtleTeleporter)
		throw new LuaException("Turtle teleporters have been disabled");
	if (method == 0 || method == 1) {
		if (arguments.length > 0 && !(arguments[0] instanceof Double))
			throw new LuaException("Bad argument #1 (expected number)");
		int index = arguments.length > 0 ? (int)Math.floor((Double)arguments[0]) - 1 : 0;
		if (index < 0 || index >= getMaxLinks())
			throw new LuaException("Bad link "+(index+1)+" (expected 1-"+getMaxLinks()+")");
		if (index >= links.size())
			throw new LuaException("No such link");
		LinkData link = links.get(index);
		if (link == null)
			throw new LuaException("No such link");
		TileEntity te = worldObj.getTileEntity(xCoord + Facing.offsetsXForSide[getBlockMetadata()], yCoord + Facing.offsetsYForSide[getBlockMetadata()], zCoord + Facing.offsetsZForSide[getBlockMetadata()]);
		try {
			if (ReflectionHelper.getTurtle(te) == null)
				throw new LuaException("No turtle in front");
		}catch (Exception e) {
			throw new LuaException("No turtle in front");
		}
		World destWorld = MinecraftServer.getServer().worldServerForDimension(link.linkDim);
		if (destWorld == null)
			throw new LuaException("Destination world missing");
		TileEntity dest = destWorld.getTileEntity(link.link.posX, link.link.posY, link.link.posZ);
		if (!(dest instanceof TileEntityTeleporter))
			throw new LuaException("Destination is not a teleporter");
		TileEntityTeleporter teleporter = (TileEntityTeleporter)dest;
		int linkToX = link.link.posX + Facing.offsetsXForSide[teleporter.getBlockMetadata()];
		int linkToY = link.link.posY + Facing.offsetsYForSide[teleporter.getBlockMetadata()];
		int linkToZ = link.link.posZ + Facing.offsetsZForSide[teleporter.getBlockMetadata()];
		if ((destWorld.blockExists(linkToX,linkToY,linkToZ) && !destWorld.isAirBlock(linkToX,linkToY,linkToZ)) || linkToY < 0 || linkToY > 254) //TODO: improve Block.blocksList[id] == null || Block.blocksList[id].isAirBlock(world, x, y, z) || Block.blocksList[id] instanceof BlockFluid || Block.blocksList[id] instanceof BlockSnow || Block.blocksList[id] instanceof BlockTallGrass;
			throw new LuaException("Destination obstructed");
		int xdif = Math.abs(xCoord - link.link.posX);
		int ydif = Math.abs(yCoord - link.link.posY);
		int zdif = Math.abs(zCoord - link.link.posZ);
		ITurtleAccess turtle = null;
		try {
			turtle = ReflectionHelper.getTurtle(te);
		}catch (Exception ignored) {}
		if (!turtle.consumeFuel(Math.abs((int)Math.ceil((xdif + ydif + zdif) * (Math.abs(worldObj.provider.dimensionId - destWorld.provider.dimensionId) + 1) * Config.teleporterPenalty))))
			throw new LuaException("Not enough fuel");
		boolean result = turtle.teleportTo(destWorld, linkToX, linkToY, linkToZ);
		destWorld.markBlockForUpdate(linkToX,linkToY,linkToZ);
		worldObj.markBlockForUpdate(xCoord + Facing.offsetsXForSide[getBlockMetadata()], yCoord + Facing.offsetsYForSide[getBlockMetadata()], zCoord + Facing.offsetsZForSide[getBlockMetadata()]);
		destWorld.notifyBlockChange(linkToX,linkToY,linkToZ, te.blockType);
		worldObj.notifyBlockChange(xCoord + Facing.offsetsXForSide[getBlockMetadata()], yCoord + Facing.offsetsYForSide[getBlockMetadata()], zCoord + Facing.offsetsZForSide[getBlockMetadata()], null);
		if (result) {
			//int flag = worldObj.provider.dimensionId != destWorld.provider.dimensionId ? 1 : 0;
			//onTeleport((byte)flag);TODO
			//teleporter.onTeleport((byte)flag);
		}
		return new Object[]{result};
	}else if (method == 2) {
		HashMap<Integer, Object> map1 = new HashMap<Integer,Object>();
		for (int i = 0; i < links.size(); i++) {
			HashMap<String,Object> map2 = new HashMap<String,Object>();
			map2.put("dim", links.get(i).linkDim);
			map2.put("x", links.get(i).link.posX);
			map2.put("y", links.get(i).link.posY);
			map2.put("z", links.get(i).link.posZ);
			map2.put("name", name);
			map1.put(i, map2.clone());
		}
		return new Object[]{map1};
	}else if (method == 3) {
		if (!(arguments.length >= 1) || !(arguments[0] instanceof String))
			throw new LuaException("Bad argument #1 (expected string)");
		this.name = (String) arguments[0];
		return new Object[]{name};
	}
	return new Object[0];
}
 
开发者ID:austinv11,项目名称:PeripheralsPlusPlus,代码行数:75,代码来源:TileEntityTeleporter.java


注:本文中的dan200.computercraft.api.turtle.ITurtleAccess.consumeFuel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。