Search in sources :

Example 6 with Axis

use of net.minecraft.util.Direction.Axis in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAIHurtByTarget method getPathComplexity.

private static int getPathComplexity(Path path) {
    if (path.getNodeCount() == 0) {
        return 0;
    }
    int pathComplexity = 0;
    Axis prevPrevPrevAxis = null;
    Axis prevPrevAxis = null;
    Axis prevAxis = null;
    int prevX = path.getNode(0).x;
    int prevZ = path.getNode(0).z;
    for (int i = 0; i < path.getNodeCount(); i++) {
        PathPoint point = path.getNode(i);
        int x = point.x;
        int z = point.z;
        Axis axis;
        if (x != prevX) {
            axis = Axis.X;
        } else if (z != prevZ) {
            axis = Axis.Z;
        } else {
            axis = Axis.Y;
        }
        if (prevAxis == axis && prevAxis != prevPrevAxis && prevPrevAxis == prevPrevPrevAxis) {
            pathComplexity++;
        }
        prevPrevPrevAxis = prevPrevAxis;
        prevPrevAxis = prevAxis;
        prevAxis = axis;
        prevX = x;
        prevZ = z;
    }
    return pathComplexity;
}
Also used : PathPoint(net.minecraft.pathfinding.PathPoint) PathPoint(net.minecraft.pathfinding.PathPoint) Axis(net.minecraft.util.Direction.Axis)

Example 7 with Axis

use of net.minecraft.util.Direction.Axis in project Mekanism by mekanism.

the class ModuleFarmingUnit method stripLogsAOE.

private ActionResultType stripLogsAOE(ItemUseContext context) {
    PlayerEntity player = context.getPlayer();
    if (player == null || player.isShiftKeyDown()) {
        // Skip if we don't have a player, or they are sneaking
        return ActionResultType.PASS;
    }
    int diameter = farmingRadius.get().getRadius();
    if (diameter == 0) {
        // If we don't have any blocks we are going to want to do, then skip it
        return ActionResultType.PASS;
    }
    ItemStack stack = context.getItemInHand();
    IEnergyContainer energyContainer = StorageUtils.getEnergyContainer(stack, 0);
    if (energyContainer == null) {
        return ActionResultType.FAIL;
    }
    FloatingLong energy = energyContainer.getEnergy();
    FloatingLong energyUsage = MekanismConfig.gear.mekaToolEnergyUsageAxe.get();
    if (energy.smallerThan(energyUsage)) {
        // Fail if we don't have enough energy or using the item failed
        return ActionResultType.FAIL;
    }
    World world = context.getLevel();
    BlockPos pos = context.getClickedPos();
    BlockState clickedState = world.getBlockState(pos);
    BlockState strippedState = clickedState.getToolModifiedState(world, pos, player, stack, ToolType.AXE);
    if (strippedState == null) {
        // Skip stripping the blocks if the one we clicked cannot be stripped
        return ActionResultType.PASS;
    } else if (world.isClientSide) {
        return ActionResultType.SUCCESS;
    }
    Axis axis = clickedState.getValue(RotatedPillarBlock.AXIS);
    // Process the block we interacted with initially and play the sound
    world.setBlock(pos, strippedState, BlockFlags.DEFAULT_AND_RERENDER);
    world.playSound(null, pos, SoundEvents.AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
    Direction side = context.getClickedFace();
    FloatingLong energyUsed = energyUsage.copy();
    Vector3d offset = Vector3d.atLowerCornerOf(side.getNormal()).scale(0.44);
    for (BlockPos newPos : getStrippingArea(pos, side, (diameter - 1) / 2)) {
        if (pos.equals(newPos)) {
            // Skip the source position as it is free, and we manually handled it before the loop
            continue;
        } else if (energyUsed.add(energyUsage).greaterThan(energy)) {
            break;
        }
        // Check to make that the result we would get from stripping the other block is the same as the one we got on the initial block we interacted with
        // Also make sure that it is on the same axis as the block we initially clicked
        BlockState state = world.getBlockState(newPos);
        if (strippedState == state.getToolModifiedState(world, newPos, player, stack, ToolType.AXE) && axis == state.getValue(RotatedPillarBlock.AXIS)) {
            // Some of the below methods don't behave properly when the BlockPos is mutable, so now that we are onto ones where it may actually
            // matter we make sure to get an immutable instance of newPos
            newPos = newPos.immutable();
            // Add energy cost
            energyUsed = energyUsed.plusEqual(energyUsage);
            // Replace the block. Note it just directly sets it (in the same way that AxeItem does).
            world.setBlock(newPos, strippedState, BlockFlags.DEFAULT_AND_RERENDER);
            world.playSound(null, pos, SoundEvents.AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
            Mekanism.packetHandler.sendToAllTracking(new PacketLightningRender(LightningPreset.TOOL_AOE, Objects.hash(pos, newPos), Vector3d.atCenterOf(pos).add(offset), Vector3d.atCenterOf(newPos).add(offset), 10), world, pos);
        }
    }
    energyContainer.extract(energyUsed, Action.EXECUTE, AutomationType.MANUAL);
    return ActionResultType.SUCCESS;
}
Also used : FloatingLong(mekanism.api.math.FloatingLong) IEnergyContainer(mekanism.api.energy.IEnergyContainer) BlockState(net.minecraft.block.BlockState) PacketLightningRender(mekanism.common.network.to_client.PacketLightningRender) Vector3d(net.minecraft.util.math.vector.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) Direction(net.minecraft.util.Direction) Axis(net.minecraft.util.Direction.Axis) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 8 with Axis

use of net.minecraft.util.Direction.Axis in project Create_Aeronautics by Eriksonnaren.

the class RotationPropagatorMixin method isLargeToLargeGear.

private static boolean isLargeToLargeGear(BlockState from, BlockState to, BlockPos diff) {
    if (ICogWheel.isLargeCog(from) && ICogWheel.isLargeCog(to)) {
        Axis fromAxis = (Axis) from.getValue(BlockStateProperties.AXIS);
        Axis toAxis = (Axis) to.getValue(BlockStateProperties.AXIS);
        if (fromAxis == toAxis) {
            return false;
        } else {
            Axis[] var5 = Axis.values();
            int var6 = var5.length;
            for (int var7 = 0; var7 < var6; ++var7) {
                Axis axis = var5[var7];
                int axisDiff = axis.choose(diff.getX(), diff.getY(), diff.getZ());
                if (axis != fromAxis && axis != toAxis) {
                    if (axisDiff != 0) {
                        return false;
                    }
                } else if (axisDiff == 0) {
                    return false;
                }
            }
            return true;
        }
    } else {
        return false;
    }
}
Also used : Axis(net.minecraft.util.Direction.Axis)

Aggregations

Axis (net.minecraft.util.Direction.Axis)8 BlockState (net.minecraft.block.BlockState)4 Direction (net.minecraft.util.Direction)4 BlockPos (net.minecraft.util.math.BlockPos)4 World (net.minecraft.world.World)2 IRotate (com.simibubi.create.content.contraptions.base.IRotate)1 SpeedControllerBlock (com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerBlock)1 CogWheelBlock (com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock)1 EncasedBeltBlock (com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock)1 HashMap (java.util.HashMap)1 Nullable (javax.annotation.Nullable)1 IEnergyContainer (mekanism.api.energy.IEnergyContainer)1 FloatingLong (mekanism.api.math.FloatingLong)1 PacketLightningRender (mekanism.common.network.to_client.PacketLightningRender)1 Block (net.minecraft.block.Block)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 PathPoint (net.minecraft.pathfinding.PathPoint)1 AxisDirection (net.minecraft.util.Direction.AxisDirection)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1