Search in sources :

Example 41 with Vec3i

use of net.minecraft.util.math.Vec3i in project GregTech by GregTechCEu.

the class ToolDrillLarge method findOppositeCorner.

private static BlockPos findOppositeCorner(int max, BlockPos corner, EnumFacing facing) {
    Vec3i rightVec = RelativeDirection.RIGHT.applyVec3i(facing);
    Vec3i forwardVec = RelativeDirection.FRONT.applyVec3i(facing);
    Vec3i upVec = RelativeDirection.UP.applyVec3i(facing);
    return corner.add(multiplyVec(rightVec, max - 1)).add(multiplyVec(forwardVec, max - 1)).add(multiplyVec(upVec, max - 1));
}
Also used : Vec3i(net.minecraft.util.math.Vec3i)

Example 42 with Vec3i

use of net.minecraft.util.math.Vec3i in project Blockus by Brandcraf06.

the class WoodenBarrelBlockEntity method playSound.

void playSound(BlockState state, SoundEvent soundEvent) {
    Vec3i vec3i = state.get(BarrelBlock.FACING).getVector();
    double d = (double) this.pos.getX() + 0.5D + (double) vec3i.getX() / 2.0D;
    double e = (double) this.pos.getY() + 0.5D + (double) vec3i.getY() / 2.0D;
    double f = (double) this.pos.getZ() + 0.5D + (double) vec3i.getZ() / 2.0D;
    this.world.playSound(null, d, e, f, soundEvent, SoundCategory.BLOCKS, 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F);
}
Also used : Vec3i(net.minecraft.util.math.Vec3i)

Example 43 with Vec3i

use of net.minecraft.util.math.Vec3i in project baritone by cabaletta.

the class MovementFall method updateState.

@Override
public MovementState updateState(MovementState state) {
    super.updateState(state);
    if (state.getStatus() != MovementStatus.RUNNING) {
        return state;
    }
    BlockPos playerFeet = ctx.playerFeet();
    Rotation toDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations());
    Rotation targetRotation = null;
    Block destBlock = ctx.world().getBlockState(dest).getBlock();
    boolean isWater = destBlock == Blocks.WATER || destBlock == Blocks.FLOWING_WATER;
    if (!isWater && willPlaceBucket() && !playerFeet.equals(dest)) {
        if (!InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER)) || ctx.world().provider.isNether()) {
            return state.setStatus(MovementStatus.UNREACHABLE);
        }
        if (ctx.player().posY - dest.getY() < ctx.playerController().getBlockReachDistance() && !ctx.player().onGround) {
            ctx.player().inventory.currentItem = ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER);
            targetRotation = new Rotation(toDest.getYaw(), 90.0F);
            if (ctx.isLookingAt(dest) || ctx.isLookingAt(dest.down())) {
                state.setInput(Input.CLICK_RIGHT, true);
            }
        }
    }
    if (targetRotation != null) {
        state.setTarget(new MovementTarget(targetRotation, true));
    } else {
        state.setTarget(new MovementTarget(toDest, false));
    }
    if (playerFeet.equals(dest) && (ctx.player().posY - playerFeet.getY() < 0.094 || isWater)) {
        // 0.094 because lilypads
        if (isWater) {
            // only match water, not flowing water (which we cannot pick up with a bucket)
            if (InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
                ctx.player().inventory.currentItem = ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
                if (ctx.player().motionY >= 0) {
                    return state.setInput(Input.CLICK_RIGHT, true);
                } else {
                    return state;
                }
            } else {
                if (ctx.player().motionY >= 0) {
                    return state.setStatus(MovementStatus.SUCCESS);
                }
            // don't else return state; we need to stay centered because this water might be flowing under the surface
            }
        } else {
            return state.setStatus(MovementStatus.SUCCESS);
        }
    }
    // we are moving to the 0.5 center not the edge (like if we were falling on a ladder)
    Vec3d destCenter = VecUtils.getBlockPosCenter(dest);
    if (Math.abs(ctx.player().posX + ctx.player().motionX - destCenter.x) > 0.1 || Math.abs(ctx.player().posZ + ctx.player().motionZ - destCenter.z) > 0.1) {
        if (!ctx.player().onGround && Math.abs(ctx.player().motionY) > 0.4) {
            state.setInput(Input.SNEAK, true);
        }
        state.setInput(Input.MOVE_FORWARD, true);
    }
    Vec3i avoid = Optional.ofNullable(avoid()).map(EnumFacing::getDirectionVec).orElse(null);
    if (avoid == null) {
        avoid = src.subtract(dest);
    } else {
        double dist = Math.abs(avoid.getX() * (destCenter.x - avoid.getX() / 2.0 - ctx.player().posX)) + Math.abs(avoid.getZ() * (destCenter.z - avoid.getZ() / 2.0 - ctx.player().posZ));
        if (dist < 0.6) {
            state.setInput(Input.MOVE_FORWARD, true);
        } else if (!ctx.player().onGround) {
            state.setInput(Input.SNEAK, false);
        }
    }
    if (targetRotation == null) {
        Vec3d destCenterOffset = new Vec3d(destCenter.x + 0.125 * avoid.getX(), destCenter.y, destCenter.z + 0.125 * avoid.getZ());
        state.setTarget(new MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), destCenterOffset, ctx.playerRotations()), false));
    }
    return state;
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) Rotation(baritone.api.utils.Rotation) MovementTarget(baritone.pathing.movement.MovementState.MovementTarget) Vec3d(net.minecraft.util.math.Vec3d)

Example 44 with Vec3i

use of net.minecraft.util.math.Vec3i in project baritone by cabaletta.

the class SelCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    Action action = Action.getByName(args.getString());
    if (action == null) {
        throw new CommandInvalidTypeException(args.consumed(), "an action");
    }
    if (action == Action.POS1 || action == Action.POS2) {
        if (action == Action.POS2 && pos1 == null) {
            throw new CommandInvalidStateException("Set pos1 first before using pos2");
        }
        BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
        BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
        args.requireMax(0);
        if (action == Action.POS1) {
            pos1 = pos;
            logDirect("Position 1 has been set");
        } else {
            manager.addSelection(pos1, pos);
            pos1 = null;
            logDirect("Selection added");
        }
    } else if (action == Action.CLEAR) {
        args.requireMax(0);
        pos1 = null;
        logDirect(String.format("Removed %d selections", manager.removeAllSelections().length));
    } else if (action == Action.UNDO) {
        args.requireMax(0);
        if (pos1 != null) {
            pos1 = null;
            logDirect("Undid pos1");
        } else {
            ISelection[] selections = manager.getSelections();
            if (selections.length < 1) {
                throw new CommandInvalidStateException("Nothing to undo!");
            } else {
                pos1 = manager.removeSelection(selections[selections.length - 1]).pos1();
                logDirect("Undid pos2");
            }
        }
    } else if (action == Action.SET || action == Action.WALLS || action == Action.SHELL || action == Action.CLEARAREA || action == Action.REPLACE) {
        BlockOptionalMeta type = action == Action.CLEARAREA ? new BlockOptionalMeta(Blocks.AIR) : args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
        BlockOptionalMetaLookup replaces = null;
        if (action == Action.REPLACE) {
            args.requireMin(1);
            List<BlockOptionalMeta> replacesList = new ArrayList<>();
            replacesList.add(type);
            while (args.has(2)) {
                replacesList.add(args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE));
            }
            type = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
            replaces = new BlockOptionalMetaLookup(replacesList.toArray(new BlockOptionalMeta[0]));
        } else {
            args.requireMax(0);
        }
        ISelection[] selections = manager.getSelections();
        if (selections.length == 0) {
            throw new CommandInvalidStateException("No selections");
        }
        BetterBlockPos origin = selections[0].min();
        CompositeSchematic composite = new CompositeSchematic(0, 0, 0);
        for (ISelection selection : selections) {
            BetterBlockPos min = selection.min();
            origin = new BetterBlockPos(Math.min(origin.x, min.x), Math.min(origin.y, min.y), Math.min(origin.z, min.z));
        }
        for (ISelection selection : selections) {
            Vec3i size = selection.size();
            BetterBlockPos min = selection.min();
            ISchematic schematic = new FillSchematic(size.getX(), size.getY(), size.getZ(), type);
            if (action == Action.WALLS) {
                schematic = new WallsSchematic(schematic);
            } else if (action == Action.SHELL) {
                schematic = new ShellSchematic(schematic);
            } else if (action == Action.REPLACE) {
                schematic = new ReplaceSchematic(schematic, replaces);
            }
            composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z);
        }
        baritone.getBuilderProcess().build("Fill", composite, origin);
        logDirect("Filling now");
    } else if (action == Action.COPY) {
        BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
        BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
        args.requireMax(0);
        ISelection[] selections = manager.getSelections();
        if (selections.length < 1) {
            throw new CommandInvalidStateException("No selections");
        }
        BlockStateInterface bsi = new BlockStateInterface(ctx);
        BetterBlockPos origin = selections[0].min();
        CompositeSchematic composite = new CompositeSchematic(0, 0, 0);
        for (ISelection selection : selections) {
            BetterBlockPos min = selection.min();
            origin = new BetterBlockPos(Math.min(origin.x, min.x), Math.min(origin.y, min.y), Math.min(origin.z, min.z));
        }
        for (ISelection selection : selections) {
            Vec3i size = selection.size();
            BetterBlockPos min = selection.min();
            IBlockState[][][] blockstates = new IBlockState[size.getX()][size.getZ()][size.getY()];
            for (int x = 0; x < size.getX(); x++) {
                for (int y = 0; y < size.getY(); y++) {
                    for (int z = 0; z < size.getZ(); z++) {
                        blockstates[x][z][y] = bsi.get0(min.x + x, min.y + y, min.z + z);
                    }
                }
            }
            ISchematic schematic = new StaticSchematic() {

                {
                    states = blockstates;
                    x = size.getX();
                    y = size.getY();
                    z = size.getZ();
                }
            };
            composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z);
        }
        clipboard = composite;
        clipboardOffset = origin.subtract(pos);
        logDirect("Selection copied");
    } else if (action == Action.PASTE) {
        BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
        BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
        args.requireMax(0);
        if (clipboard == null) {
            throw new CommandInvalidStateException("You need to copy a selection first");
        }
        baritone.getBuilderProcess().build("Fill", clipboard, pos.add(clipboardOffset));
        logDirect("Building now");
    } else if (action == Action.EXPAND || action == Action.CONTRACT || action == Action.SHIFT) {
        args.requireExactly(3);
        TransformTarget transformTarget = TransformTarget.getByName(args.getString());
        if (transformTarget == null) {
            throw new CommandInvalidStateException("Invalid transform type");
        }
        EnumFacing direction = args.getDatatypeFor(ForEnumFacing.INSTANCE);
        int blocks = args.getAs(Integer.class);
        ISelection[] selections = manager.getSelections();
        if (selections.length < 1) {
            throw new CommandInvalidStateException("No selections found");
        }
        selections = transformTarget.transform(selections);
        for (ISelection selection : selections) {
            if (action == Action.EXPAND) {
                manager.expand(selection, direction, blocks);
            } else if (action == Action.CONTRACT) {
                manager.contract(selection, direction, blocks);
            } else {
                manager.shift(selection, direction, blocks);
            }
        }
        logDirect(String.format("Transformed %d selections", selections.length));
    }
}
Also used : CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) EnumFacing(net.minecraft.util.EnumFacing) ForEnumFacing(baritone.api.command.datatypes.ForEnumFacing) StaticSchematic(baritone.utils.schematic.StaticSchematic) BetterBlockPos(baritone.api.utils.BetterBlockPos) ISelection(baritone.api.selection.ISelection) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) RelativeBlockPos(baritone.api.command.datatypes.RelativeBlockPos) List(java.util.List) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) Vec3i(net.minecraft.util.math.Vec3i) BlockStateInterface(baritone.utils.BlockStateInterface) IBlockState(net.minecraft.block.state.IBlockState) BlockOptionalMetaLookup(baritone.api.utils.BlockOptionalMetaLookup) ForBlockOptionalMeta(baritone.api.command.datatypes.ForBlockOptionalMeta) BlockOptionalMeta(baritone.api.utils.BlockOptionalMeta)

Example 45 with Vec3i

use of net.minecraft.util.math.Vec3i in project fabric by FabricMC.

the class AoCalculator method computeFace.

/**
 * Computes smoothed brightness and Ao shading for four corners of a block face.
 * Outer block face is what you normally see and what you get get when second
 * parameter is true. Inner is light *within* the block and usually darker.
 * It is blended with the outer face for inset surfaces, but is also used directly
 * in vanilla logic for some blocks that aren't full opaque cubes.
 * Except for parameterization, the logic itself is practically identical to vanilla.
 */
private AoFaceData computeFace(Direction lightFace, boolean isOnBlockFace) {
    final int faceDataIndex = isOnBlockFace ? lightFace.getId() : lightFace.getId() + 6;
    final int mask = 1 << faceDataIndex;
    final AoFaceData result = faceData[faceDataIndex];
    if ((completionFlags & mask) == 0) {
        completionFlags |= mask;
        final ExtendedBlockView world = blockInfo.blockView;
        final BlockPos pos = blockInfo.blockPos;
        final BlockPos.Mutable lightPos = this.lightPos;
        final BlockPos.Mutable searchPos = this.searchPos;
        lightPos.set(isOnBlockFace ? pos.offset(lightFace) : pos);
        AoFace aoFace = AoFace.get(lightFace);
        searchPos.set(lightPos).setOffset(aoFace.neighbors[0]);
        final int light0 = brightnessFunc.applyAsInt(searchPos);
        final float ao0 = aoFunc.apply(searchPos);
        searchPos.set(lightPos).setOffset(aoFace.neighbors[1]);
        final int light1 = brightnessFunc.applyAsInt(searchPos);
        final float ao1 = aoFunc.apply(searchPos);
        searchPos.set(lightPos).setOffset(aoFace.neighbors[2]);
        final int light2 = brightnessFunc.applyAsInt(searchPos);
        final float ao2 = aoFunc.apply(searchPos);
        searchPos.set(lightPos).setOffset(aoFace.neighbors[3]);
        final int light3 = brightnessFunc.applyAsInt(searchPos);
        final float ao3 = aoFunc.apply(searchPos);
        // vanilla was further offsetting these in the direction of the light face
        // but it was actually mis-sampling and causing visible artifacts in certain situation
        // .setOffset(lightFace);
        searchPos.set(lightPos).setOffset(aoFace.neighbors[0]);
        if (!Indigo.FIX_SMOOTH_LIGHTING_OFFSET)
            searchPos.setOffset(lightFace);
        final boolean isClear0 = world.getBlockState(searchPos).getLightSubtracted(world, searchPos) == 0;
        // .setOffset(lightFace);
        searchPos.set(lightPos).setOffset(aoFace.neighbors[1]);
        if (!Indigo.FIX_SMOOTH_LIGHTING_OFFSET)
            searchPos.setOffset(lightFace);
        final boolean isClear1 = world.getBlockState(searchPos).getLightSubtracted(world, searchPos) == 0;
        // .setOffset(lightFace);
        searchPos.set(lightPos).setOffset(aoFace.neighbors[2]);
        if (!Indigo.FIX_SMOOTH_LIGHTING_OFFSET)
            searchPos.setOffset(lightFace);
        final boolean isClear2 = world.getBlockState(searchPos).getLightSubtracted(world, searchPos) == 0;
        // .setOffset(lightFace);
        searchPos.set(lightPos).setOffset(aoFace.neighbors[3]);
        if (!Indigo.FIX_SMOOTH_LIGHTING_OFFSET)
            searchPos.setOffset(lightFace);
        final boolean isClear3 = world.getBlockState(searchPos).getLightSubtracted(world, searchPos) == 0;
        // c = corner - values at corners of face
        int cLight0, cLight1, cLight2, cLight3;
        float cAo0, cAo1, cAo2, cAo3;
        // then we use values from the outwardly diagonal corner. (outwardly = position is one more away from light face)
        if (!isClear2 && !isClear0) {
            cAo0 = ao0;
            cLight0 = light0;
        } else {
            searchPos.set(lightPos).setOffset(aoFace.neighbors[0]).setOffset(aoFace.neighbors[2]);
            cAo0 = aoFunc.apply(searchPos);
            cLight0 = brightnessFunc.applyAsInt(searchPos);
        }
        if (!isClear3 && !isClear0) {
            cAo1 = ao0;
            cLight1 = light0;
        } else {
            searchPos.set(lightPos).setOffset(aoFace.neighbors[0]).setOffset(aoFace.neighbors[3]);
            cAo1 = aoFunc.apply(searchPos);
            cLight1 = brightnessFunc.applyAsInt(searchPos);
        }
        if (!isClear2 && !isClear1) {
            cAo2 = ao1;
            cLight2 = light1;
        } else {
            searchPos.set(lightPos).setOffset(aoFace.neighbors[1]).setOffset(aoFace.neighbors[2]);
            cAo2 = aoFunc.apply(searchPos);
            cLight2 = brightnessFunc.applyAsInt(searchPos);
        }
        if (!isClear3 && !isClear1) {
            cAo3 = ao1;
            cLight3 = light1;
        } else {
            searchPos.set(lightPos).setOffset(aoFace.neighbors[1]).setOffset(aoFace.neighbors[3]);
            cAo3 = aoFunc.apply(searchPos);
            cLight3 = brightnessFunc.applyAsInt(searchPos);
        }
        // If on block face or neighbor isn't occluding, "center" will be neighbor brightness
        // Doesn't use light pos because logic not based solely on this block's geometry
        int lightCenter;
        searchPos.set((Vec3i) pos).setOffset(lightFace);
        if (isOnBlockFace || !world.getBlockState(searchPos).isFullOpaque(world, searchPos)) {
            lightCenter = brightnessFunc.applyAsInt(searchPos);
        } else {
            lightCenter = brightnessFunc.applyAsInt(pos);
        }
        float aoCenter = aoFunc.apply(isOnBlockFace ? lightPos : pos);
        result.a0 = (ao3 + ao0 + cAo1 + aoCenter) * 0.25F;
        result.a1 = (ao2 + ao0 + cAo0 + aoCenter) * 0.25F;
        result.a2 = (ao2 + ao1 + cAo2 + aoCenter) * 0.25F;
        result.a3 = (ao3 + ao1 + cAo3 + aoCenter) * 0.25F;
        result.l0(meanBrightness(light3, light0, cLight1, lightCenter));
        result.l1(meanBrightness(light2, light0, cLight0, lightCenter));
        result.l2(meanBrightness(light2, light1, cLight2, lightCenter));
        result.l3(meanBrightness(light3, light1, cLight3, lightCenter));
    }
    return result;
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) BlockPos(net.minecraft.util.math.BlockPos) ExtendedBlockView(net.minecraft.world.ExtendedBlockView)

Aggregations

Vec3i (net.minecraft.util.math.Vec3i)161 BlockPos (net.minecraft.util.math.BlockPos)88 IBlockState (net.minecraft.block.state.IBlockState)29 Vec3d (net.minecraft.util.math.Vec3d)25 EnumFacing (net.minecraft.util.EnumFacing)18 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)15 Block (net.minecraft.block.Block)12 Entity (net.minecraft.entity.Entity)11 ArrayList (java.util.ArrayList)10 World (net.minecraft.world.World)10 TileEntity (net.minecraft.tileentity.TileEntity)8 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)7 HashSet (java.util.HashSet)6 Tessellator (net.minecraft.client.renderer.Tessellator)6 EntityEnderCrystal (net.minecraft.entity.item.EntityEnderCrystal)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 HashMap (java.util.HashMap)5 Random (java.util.Random)5 Direction (net.minecraft.util.math.Direction)5