Search in sources :

Example 1 with IPathProvider

use of buildcraft.api.core.IPathProvider in project BuildCraft by BuildCraft.

the class TileBuilder method initialize.

@Override
public void initialize() {
    super.initialize();
    if (worldObj.isRemote) {
        return;
    }
    if (initNBT != null) {
        iterateBpt(true);
        if (initNBT.hasKey("iterator")) {
            BlockPos expectedTo = NBTUtilBC.readBlockPos(initNBT.getTag("iterator"));
            while (!done && currentBuilder != null && currentPathIterator != null) {
                BlockPos bi = new BlockPos((int) currentPathIterator.ix, (int) currentPathIterator.iy, (int) currentPathIterator.iz);
                if (bi.equals(expectedTo)) {
                    break;
                }
                iterateBpt(true);
            }
        }
        if (currentBuilder != null) {
            currentBuilder.loadBuildStateToNBT(initNBT.getCompoundTag("builderState"), this);
        }
        initNBT = null;
    }
    box.kind = Kind.STRIPES;
    for (EnumFacing face : EnumFacing.values()) {
        TileEntity tile = worldObj.getTileEntity(pos.offset(face));
        if (tile instanceof IPathProvider) {
            path = ((IPathProvider) tile).getPath();
            ((IPathProvider) tile).removeFromWorld();
            break;
        }
    }
    if (path != null && pathLasers.size() == 0) {
        createLasersForPath();
        sendNetworkUpdate();
    }
    iterateBpt(false);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPathProvider(buildcraft.api.core.IPathProvider) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with IPathProvider

use of buildcraft.api.core.IPathProvider in project BuildCraft by BuildCraft.

the class ItemMapLocation method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (world.isRemote) {
        return EnumActionResult.PASS;
    }
    ItemStack stack = StackUtil.asNonNull(player.getHeldItem(hand));
    if (MapLocationType.getFromStack(stack) != MapLocationType.CLEAN) {
        return EnumActionResult.FAIL;
    }
    ItemStack modified = stack;
    if (stack.getCount() > 1) {
        modified = stack.copy();
        stack.setCount(stack.getCount() - 1);
        modified.setCount(1);
    }
    TileEntity tile = world.getTileEntity(pos);
    NBTTagCompound cpt = NBTUtilBC.getItemData(modified);
    if (tile instanceof IPathProvider) {
        List<BlockPos> path = ((IPathProvider) tile).getPath();
        if (path.size() > 1 && path.get(0).equals(path.get(path.size() - 1))) {
            MapLocationType.PATH_REPEATING.setToStack(stack);
        } else {
            MapLocationType.PATH.setToStack(stack);
        }
        NBTTagList pathNBT = new NBTTagList();
        for (BlockPos posInPath : path) {
            pathNBT.appendTag(NBTUtilBC.writeBlockPos(posInPath));
        }
        cpt.setTag("path", pathNBT);
    } else if (tile instanceof IAreaProvider) {
        MapLocationType.AREA.setToStack(modified);
        IAreaProvider areaTile = (IAreaProvider) tile;
        cpt.setInteger("xMin", areaTile.min().getX());
        cpt.setInteger("yMin", areaTile.min().getY());
        cpt.setInteger("zMin", areaTile.min().getZ());
        cpt.setInteger("xMax", areaTile.max().getX());
        cpt.setInteger("yMax", areaTile.max().getY());
        cpt.setInteger("zMax", areaTile.max().getZ());
    } else {
        MapLocationType.SPOT.setToStack(modified);
        cpt.setByte("side", (byte) side.getIndex());
        cpt.setInteger("x", pos.getX());
        cpt.setInteger("y", pos.getY());
        cpt.setInteger("z", pos.getZ());
    }
    return EnumActionResult.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagList(net.minecraft.nbt.NBTTagList) IAreaProvider(buildcraft.api.core.IAreaProvider) IPathProvider(buildcraft.api.core.IPathProvider) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IPathProvider

use of buildcraft.api.core.IPathProvider in project BuildCraft by BuildCraft.

the class TileBuilder method onPlacedBy.

@Override
public void onPlacedBy(EntityLivingBase placer, ItemStack stack) {
    super.onPlacedBy(placer, stack);
    EnumFacing facing = world.getBlockState(pos).getValue(BlockBCBase_Neptune.PROP_FACING);
    TileEntity inFront = world.getTileEntity(pos.offset(facing.getOpposite()));
    if (inFront instanceof IPathProvider) {
        IPathProvider provider = (IPathProvider) inFront;
        ImmutableList<BlockPos> copiedPath = ImmutableList.copyOf(provider.getPath());
        if (copiedPath.size() >= 2) {
            path = copiedPath;
            provider.removeFromWorld();
        }
    }
    updateBasePoses();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPathProvider(buildcraft.api.core.IPathProvider) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IPathProvider (buildcraft.api.core.IPathProvider)3 TileEntity (net.minecraft.tileentity.TileEntity)3 BlockPos (net.minecraft.util.math.BlockPos)3 EnumFacing (net.minecraft.util.EnumFacing)2 IAreaProvider (buildcraft.api.core.IAreaProvider)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1