Search in sources :

Example 6 with IAreaProvider

use of buildcraft.api.core.IAreaProvider 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 7 with IAreaProvider

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

the class TileFiller method onPlacedBy.

@Override
public void onPlacedBy(EntityLivingBase placer, ItemStack stack) {
    super.onPlacedBy(placer, stack);
    if (world.isRemote) {
        return;
    }
    IBlockState blockState = world.getBlockState(pos);
    WorldSavedDataVolumeBoxes volumeBoxes = WorldSavedDataVolumeBoxes.get(world);
    BlockPos offsetPos = pos.offset(blockState.getValue(BlockBCBase_Neptune.PROP_FACING).getOpposite());
    VolumeBox volumeBox = volumeBoxes.getVolumeBoxAt(offsetPos);
    TileEntity tile = world.getTileEntity(offsetPos);
    if (volumeBox != null) {
        addon = (AddonFillerPlanner) volumeBox.addons.values().stream().filter(AddonFillerPlanner.class::isInstance).findFirst().orElse(null);
        if (addon != null) {
            volumeBox.locks.add(new Lock(new Lock.Cause.CauseBlock(pos, blockState.getBlock()), new Lock.Target.TargetAddon(addon.getSlot()), new Lock.Target.TargetRemove(), new Lock.Target.TargetResize(), new Lock.Target.TargetUsedByMachine(Lock.Target.TargetUsedByMachine.EnumType.STRIPES_WRITE)));
            volumeBoxes.markDirty();
            addon.updateBuildingInfo();
            markerBox = false;
        } else {
            box.reset();
            box.setMin(volumeBox.box.min());
            box.setMax(volumeBox.box.max());
            volumeBox.locks.add(new Lock(new Lock.Cause.CauseBlock(pos, blockState.getBlock()), new Lock.Target.TargetRemove(), new Lock.Target.TargetResize(), new Lock.Target.TargetUsedByMachine(Lock.Target.TargetUsedByMachine.EnumType.STRIPES_WRITE)));
            volumeBoxes.markDirty();
            markerBox = false;
        }
    } else if (tile instanceof IAreaProvider) {
        IAreaProvider provider = (IAreaProvider) tile;
        box.reset();
        box.setMin(provider.min());
        box.setMax(provider.max());
        provider.removeFromWorld();
    }
    updateBuildingInfo();
    sendNetworkUpdate(NET_RENDER_DATA);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) VolumeBox(buildcraft.core.marker.volume.VolumeBox) AddonFillerPlanner(buildcraft.builders.addon.AddonFillerPlanner) WorldSavedDataVolumeBoxes(buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes) Lock(buildcraft.core.marker.volume.Lock) TileEntity(net.minecraft.tileentity.TileEntity) IAreaProvider(buildcraft.api.core.IAreaProvider) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IAreaProvider (buildcraft.api.core.IAreaProvider)7 TileEntity (net.minecraft.tileentity.TileEntity)4 BlockPos (net.minecraft.util.math.BlockPos)4 Lock (buildcraft.core.marker.volume.Lock)2 VolumeBox (buildcraft.core.marker.volume.VolumeBox)2 WorldSavedDataVolumeBoxes (buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes)2 IBlockState (net.minecraft.block.state.IBlockState)2 EnumFacing (net.minecraft.util.EnumFacing)2 IPathProvider (buildcraft.api.core.IPathProvider)1 AddonFillerPlanner (buildcraft.builders.addon.AddonFillerPlanner)1 DefaultAreaProvider (buildcraft.core.DefaultAreaProvider)1 Blueprint (buildcraft.core.blueprints.Blueprint)1 BptBuilderBlueprint (buildcraft.core.blueprints.BptBuilderBlueprint)1 VolumeConnection (buildcraft.core.marker.VolumeConnection)1 VolumeSubCache (buildcraft.core.marker.VolumeSubCache)1 TileMarkerVolume (buildcraft.core.tile.TileMarkerVolume)1 Box (buildcraft.lib.misc.data.Box)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1