Search in sources :

Example 1 with EnumAddonSlot

use of buildcraft.core.marker.volume.EnumAddonSlot in project BuildCraft by BuildCraft.

the class ItemMarkerConnector method onItemRightClickVolumeBoxes.

private EnumActionResult onItemRightClickVolumeBoxes(World world, EntityPlayer player) {
    if (world.isRemote) {
        return EnumActionResult.PASS;
    }
    WorldSavedDataVolumeBoxes volumeBoxes = WorldSavedDataVolumeBoxes.get(world);
    VolumeBox currentEditing = volumeBoxes.getCurrentEditing(player);
    Vec3d start = player.getPositionVector().addVector(0, player.getEyeHeight(), 0);
    Vec3d end = start.add(player.getLookVec().scale(4));
    Pair<VolumeBox, EnumAddonSlot> selectingVolumeBoxAndSlot = EnumAddonSlot.getSelectingVolumeBoxAndSlot(player, volumeBoxes.volumeBoxes);
    VolumeBox addonVolumeBox = selectingVolumeBoxAndSlot.getLeft();
    EnumAddonSlot addonSlot = selectingVolumeBoxAndSlot.getRight();
    if (addonVolumeBox != null && addonSlot != null) {
        if (addonVolumeBox.addons.containsKey(addonSlot) && addonVolumeBox.getLockTargetsStream().noneMatch(target -> target instanceof Lock.Target.TargetAddon && ((Lock.Target.TargetAddon) target).slot == addonSlot)) {
            if (player.isSneaking()) {
                addonVolumeBox.addons.get(addonSlot).onRemoved();
                addonVolumeBox.addons.remove(addonSlot);
                volumeBoxes.markDirty();
            } else {
                addonVolumeBox.addons.get(addonSlot).onPlayerRightClick(player);
                volumeBoxes.markDirty();
            }
        }
    } else if (player.isSneaking()) {
        if (currentEditing == null) {
            for (Iterator<VolumeBox> iterator = volumeBoxes.volumeBoxes.iterator(); iterator.hasNext(); ) {
                VolumeBox volumeBox = iterator.next();
                if (volumeBox.box.getBoundingBox().calculateIntercept(start, end) != null) {
                    if (volumeBox.getLockTargetsStream().noneMatch(Lock.Target.TargetResize.class::isInstance)) {
                        volumeBox.addons.values().forEach(Addon::onRemoved);
                        iterator.remove();
                        volumeBoxes.markDirty();
                        return EnumActionResult.SUCCESS;
                    } else {
                        return EnumActionResult.FAIL;
                    }
                }
            }
        } else {
            currentEditing.cancelEditing();
            volumeBoxes.markDirty();
            return EnumActionResult.SUCCESS;
        }
    } else {
        if (currentEditing == null) {
            VolumeBox bestVolumeBox = null;
            double bestDist = Double.MAX_VALUE;
            BlockPos editing = null;
            for (VolumeBox volumeBox : volumeBoxes.volumeBoxes.stream().filter(box -> box.getLockTargetsStream().noneMatch(Lock.Target.TargetResize.class::isInstance)).collect(Collectors.toList())) {
                for (BlockPos p : PositionUtil.getCorners(volumeBox.box.min(), volumeBox.box.max())) {
                    RayTraceResult ray = new AxisAlignedBB(p).calculateIntercept(start, end);
                    if (ray != null) {
                        double dist = ray.hitVec.distanceTo(start);
                        if (bestDist > dist) {
                            bestDist = dist;
                            bestVolumeBox = volumeBox;
                            editing = p;
                        }
                    }
                }
            }
            if (bestVolumeBox != null) {
                bestVolumeBox.setPlayer(player);
                BlockPos min = bestVolumeBox.box.min();
                BlockPos max = bestVolumeBox.box.max();
                BlockPos held = min;
                if (editing.getX() == min.getX()) {
                    held = VecUtil.replaceValue(held, EnumFacing.Axis.X, max.getX());
                }
                if (editing.getY() == min.getY()) {
                    held = VecUtil.replaceValue(held, EnumFacing.Axis.Y, max.getY());
                }
                if (editing.getZ() == min.getZ()) {
                    held = VecUtil.replaceValue(held, EnumFacing.Axis.Z, max.getZ());
                }
                bestVolumeBox.setHeldDistOldMinOldMax(held, Math.max(1.5, bestDist + 0.5), bestVolumeBox.box.min(), bestVolumeBox.box.max());
                volumeBoxes.markDirty();
                return EnumActionResult.SUCCESS;
            }
        } else {
            currentEditing.confirmEditing();
            volumeBoxes.markDirty();
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.FAIL;
}
Also used : Addon(buildcraft.core.marker.volume.Addon) PositionUtil(buildcraft.lib.misc.PositionUtil) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumHand(net.minecraft.util.EnumHand) ItemBC_Neptune(buildcraft.lib.item.ItemBC_Neptune) WorldSavedDataVolumeBoxes(buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) ImmutableList(com.google.common.collect.ImmutableList) Pair(org.apache.commons.lang3.tuple.Pair) Vec3d(net.minecraft.util.math.Vec3d) EnumAddonSlot(buildcraft.core.marker.volume.EnumAddonSlot) LineSkewResult(buildcraft.lib.misc.PositionUtil.LineSkewResult) VecUtil(buildcraft.lib.misc.VecUtil) MarkerSubCache(buildcraft.lib.marker.MarkerSubCache) Iterator(java.util.Iterator) VolumeBox(buildcraft.core.marker.volume.VolumeBox) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) ActionResult(net.minecraft.util.ActionResult) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) Lock(buildcraft.core.marker.volume.Lock) MarkerCache(buildcraft.lib.marker.MarkerCache) Line(buildcraft.lib.misc.PositionUtil.Line) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) VolumeBox(buildcraft.core.marker.volume.VolumeBox) WorldSavedDataVolumeBoxes(buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes) RayTraceResult(net.minecraft.util.math.RayTraceResult) EnumAddonSlot(buildcraft.core.marker.volume.EnumAddonSlot) Vec3d(net.minecraft.util.math.Vec3d) Lock(buildcraft.core.marker.volume.Lock) Iterator(java.util.Iterator) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

Addon (buildcraft.core.marker.volume.Addon)1 EnumAddonSlot (buildcraft.core.marker.volume.EnumAddonSlot)1 Lock (buildcraft.core.marker.volume.Lock)1 VolumeBox (buildcraft.core.marker.volume.VolumeBox)1 WorldSavedDataVolumeBoxes (buildcraft.core.marker.volume.WorldSavedDataVolumeBoxes)1 ItemBC_Neptune (buildcraft.lib.item.ItemBC_Neptune)1 MarkerCache (buildcraft.lib.marker.MarkerCache)1 MarkerSubCache (buildcraft.lib.marker.MarkerSubCache)1 PositionUtil (buildcraft.lib.misc.PositionUtil)1 Line (buildcraft.lib.misc.PositionUtil.Line)1 LineSkewResult (buildcraft.lib.misc.PositionUtil.LineSkewResult)1 VecUtil (buildcraft.lib.misc.VecUtil)1 ImmutableList (com.google.common.collect.ImmutableList)1 Iterator (java.util.Iterator)1 Collectors (java.util.stream.Collectors)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 EnumFacing (net.minecraft.util.EnumFacing)1