Search in sources :

Example 6 with AssemblyException

use of com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException in project Create by Creators-of-Create.

the class HighlightCommand method highlightAssemblyExceptionFor.

private static int highlightAssemblyExceptionFor(ServerPlayer player, CommandSourceStack source) {
    double distance = player.getAttribute(ForgeMod.REACH_DISTANCE.get()).getValue();
    Vec3 start = player.getEyePosition(1);
    Vec3 look = player.getViewVector(1);
    Vec3 end = start.add(look.x * distance, look.y * distance, look.z * distance);
    Level world = player.level;
    BlockHitResult ray = world.clip(new ClipContext(start, end, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player));
    if (ray.getType() == HitResult.Type.MISS) {
        sendMissMessage(source);
        return 0;
    }
    BlockPos pos = ray.getBlockPos();
    BlockEntity te = world.getBlockEntity(pos);
    if (!(te instanceof IDisplayAssemblyExceptions)) {
        sendMissMessage(source);
        return 0;
    }
    IDisplayAssemblyExceptions display = (IDisplayAssemblyExceptions) te;
    AssemblyException exception = display.getLastAssemblyException();
    if (exception == null) {
        sendMissMessage(source);
        return 0;
    }
    if (!exception.hasPosition()) {
        source.sendSuccess(new TextComponent("Can't highlight a specific position for this issue"), true);
        return Command.SINGLE_SUCCESS;
    }
    BlockPos p = exception.getPosition();
    String command = "/create highlight " + p.getX() + " " + p.getY() + " " + p.getZ();
    return player.server.getCommands().performCommand(source, command);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) AssemblyException(com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException) ClipContext(net.minecraft.world.level.ClipContext) Vec3(net.minecraft.world.phys.Vec3) IDisplayAssemblyExceptions(com.simibubi.create.content.contraptions.components.structureMovement.IDisplayAssemblyExceptions) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

AssemblyException (com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException)6 Direction (net.minecraft.core.Direction)5 BlockPos (net.minecraft.core.BlockPos)4 OrientedContraptionEntity (com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity)2 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)2 Vec3 (net.minecraft.world.phys.Vec3)2 IDisplayAssemblyExceptions (com.simibubi.create.content.contraptions.components.structureMovement.IDisplayAssemblyExceptions)1 CartAssemblerTileEntity (com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity)1 MountedContraption (com.simibubi.create.content.contraptions.components.structureMovement.mounted.MountedContraption)1 CapabilityMinecartController (com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController)1 MinecartController (com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController)1 GantryShaftTileEntity (com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 TextComponent (net.minecraft.network.chat.TextComponent)1 MinecartFurnace (net.minecraft.world.entity.vehicle.MinecartFurnace)1 ClipContext (net.minecraft.world.level.ClipContext)1 Level (net.minecraft.world.level.Level)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 BlockHitResult (net.minecraft.world.phys.BlockHitResult)1