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;
}
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);
}
Aggregations