Search in sources :

Example 6 with Contraption

use of com.simibubi.create.content.contraptions.components.structureMovement.Contraption in project FrostedHeart by TeamMoegMC.

the class MixinDeployerMovementBehaviour method doTimer.

@Inject(method = "tick(Lcom/simibubi/create/content/contraptions/components/structureMovement/MovementContext;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundNBT;putInt(Ljava/lang/String;I)V", ordinal = 0), cancellable = true)
public void doTimer(MovementContext m, CallbackInfo cbi) {
    Contraption c = m.contraption;
    if (c instanceof ISpeedContraption) {
        int timer = m.data.getInt("Timer");
        timer += MathHelper.clamp(Math.abs(((ISpeedContraption) c).getSpeed()) * 10, 1, 2560);
        m.data.putInt("Timer", timer);
        cbi.cancel();
    }
}
Also used : ISpeedContraption(com.teammoeg.frostedheart.util.ISpeedContraption) Contraption(com.simibubi.create.content.contraptions.components.structureMovement.Contraption) ISpeedContraption(com.teammoeg.frostedheart.util.ISpeedContraption) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 7 with Contraption

use of com.simibubi.create.content.contraptions.components.structureMovement.Contraption in project FrostedHeart by TeamMoegMC.

the class DeployerActorInstanceMixin method beginFrame.

/**
 * @author khjxiaogu
 * @reason change speed of deployer animation
 */
@Overwrite(remap = false)
public void beginFrame() {
    double factor;
    if (context.contraption.stalled || context.position == null || context.data.contains("StationaryTimer")) {
        Contraption cont = context.contraption;
        // TODO: change to ModifyConstant
        if (cont instanceof ISpeedContraption) {
            factor = MathHelper.sin(AnimationTickHolder.getRenderTime() * .5f) * .05f + .45f;
        } else
            factor = MathHelper.sin(AnimationTickHolder.getRenderTime() * .5f) * .25f + .25f;
    } else {
        Vector3d center = VecHelper.getCenterOf(new BlockPos(context.position));
        double distance = context.position.distanceTo(center);
        double nextDistance = context.position.add(context.motion).distanceTo(center);
        factor = .5f - MathHelper.clamp(MathHelper.lerp(AnimationTickHolder.getPartialTicks(), distance, nextDistance), 0, 1);
    }
    Vector3d offset = Vector3d.copy(facing.getDirectionVec()).scale(factor);
    MatrixStack ms = new MatrixStack();
    MatrixTransformStack msr = MatrixTransformStack.of(ms);
    msr.translate(context.localPos).translate(offset);
    transformModel(msr, pole, hand, yRot, zRot, zRotPole);
}
Also used : ISpeedContraption(com.teammoeg.frostedheart.util.ISpeedContraption) Vector3d(net.minecraft.util.math.vector.Vector3d) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) BlockPos(net.minecraft.util.math.BlockPos) Contraption(com.simibubi.create.content.contraptions.components.structureMovement.Contraption) ISpeedContraption(com.teammoeg.frostedheart.util.ISpeedContraption) MatrixTransformStack(com.jozufozu.flywheel.util.transform.MatrixTransformStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 8 with Contraption

use of com.simibubi.create.content.contraptions.components.structureMovement.Contraption in project FrostedHeart by TeamMoegMC.

the class ContraptionCostUtils method setSpeedAndCollect.

public static void setSpeedAndCollect(AbstractContraptionEntity ace, float speed) {
    Contraption c = ace.getContraption();
    if (c instanceof ISpeedContraption) {
        ISpeedContraption isc = (ISpeedContraption) c;
        isc.setSpeed(speed);
        isc.contributeSpeed(speed);
    }
}
Also used : Contraption(com.simibubi.create.content.contraptions.components.structureMovement.Contraption)

Example 9 with Contraption

use of com.simibubi.create.content.contraptions.components.structureMovement.Contraption in project Create_Aeronautics by Eriksonnaren.

the class AirshipContraptionHandlerClient method rightClickingOnContraptionsGetsHandledLocally.

@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public static void rightClickingOnContraptionsGetsHandledLocally(InputEvent.ClickInputEvent event) {
    Minecraft mc = Minecraft.getInstance();
    ClientPlayerEntity player = mc.player;
    if (player == null)
        return;
    // return;
    if (mc.level == null)
        return;
    if (!event.isUseItem())
        return;
    Vector3d origin = RaycastHelper.getTraceOrigin(player);
    double reach = mc.gameMode.getPickRange();
    if (mc.hitResult != null && mc.hitResult.getLocation() != null)
        reach = Math.min(mc.hitResult.getLocation().distanceTo(origin), reach);
    Vector3d target = RaycastHelper.getTraceTarget(player, reach, origin);
    for (AirshipContraptionEntity contraptionEntity : mc.level.getEntitiesOfClass(AirshipContraptionEntity.class, new AxisAlignedBB(origin, target))) {
        Vector3d localOrigin = contraptionEntity.toLocalVector(origin, 1);
        Vector3d localTarget = contraptionEntity.toLocalVector(target, 1);
        Contraption contraption = contraptionEntity.getContraption();
        MutableObject<BlockRayTraceResult> mutableResult = new MutableObject<>();
        RaycastHelper.PredicateTraceResult predicateResult = RaycastHelper.rayTraceUntil(localOrigin, localTarget, p -> {
            Template.BlockInfo blockInfo = contraption.getBlocks().get(p);
            if (blockInfo == null)
                return false;
            BlockState state = blockInfo.state;
            VoxelShape raytraceShape = state.getShape(Minecraft.getInstance().level, BlockPos.ZERO.below());
            if (raytraceShape.isEmpty())
                return false;
            BlockRayTraceResult rayTrace = raytraceShape.clip(localOrigin, localTarget, p);
            if (rayTrace != null) {
                mutableResult.setValue(rayTrace);
                return true;
            }
            return false;
        });
        if (predicateResult == null || predicateResult.missed())
            return;
        BlockRayTraceResult rayTraceResult = mutableResult.getValue();
        Hand hand = event.getHand();
        Direction face = rayTraceResult.getDirection();
        BlockPos pos = rayTraceResult.getBlockPos();
        if (!contraptionEntity.handlePlayerInteraction2(player, pos, face, hand))
            return;
        AllPackets.channel.sendToServer(new ContraptionInteractionPacket(contraptionEntity, hand, pos, face));
        event.setCanceled(true);
        event.setSwingHand(false);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ContraptionInteractionPacket(com.simibubi.create.content.contraptions.components.structureMovement.sync.ContraptionInteractionPacket) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Contraption(com.simibubi.create.content.contraptions.components.structureMovement.Contraption) Minecraft(net.minecraft.client.Minecraft) Hand(net.minecraft.util.Hand) Direction(net.minecraft.util.Direction) Template(net.minecraft.world.gen.feature.template.Template) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) Vector3d(net.minecraft.util.math.vector.Vector3d) RaycastHelper(com.simibubi.create.foundation.utility.RaycastHelper) BlockPos(net.minecraft.util.math.BlockPos) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) MutableObject(org.apache.commons.lang3.mutable.MutableObject) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 10 with Contraption

use of com.simibubi.create.content.contraptions.components.structureMovement.Contraption in project Create_Aeronautics by Eriksonnaren.

the class RenderEvents method renderList.

/**
 * Renders block outline for contraptions
 */
/*public static void drawLine(VertexConsumer consumer, Matrix4f matrix, Vector3d vecA, Vector3d vecB, Vector3d normal, int r, int g, int b, int a)
    {
        consumer.vertex(matrix, (float)vecA.x, (float)vecA.y, (float)vecA.z).color(r, g, b, a).normal((float) normal.x, (float) normal.y, (float) normal.z).endVertex();
        consumer.vertex(matrix, (float)vecB.x, (float)vecB.y, (float)vecB.z).color(r, g, b, a).normal((float) normal.x, (float) normal.y, (float) normal.z).endVertex();
    }*/
@SubscribeEvent
public static void renderList(RenderWorldLastEvent event) {
    Minecraft mc = Minecraft.getInstance();
    mc.getProfiler().push("renderVehicleDebug");
    ClientPlayerEntity player = mc.player;
    if (player == null)
        return;
    Vector3d origin = RaycastHelper.getTraceOrigin(mc.player);
    double reach = mc.gameMode.getPickRange();
    if (mc.hitResult != null && mc.hitResult.getLocation() != null)
        reach = Math.max(mc.hitResult.getLocation().distanceTo(origin), reach);
    Vector3d target = RaycastHelper.getTraceTarget(mc.player, reach, origin);
    for (AirshipContraptionEntity contraptionEntity : mc.level.getEntitiesOfClass(AirshipContraptionEntity.class, new AxisAlignedBB(origin, target))) {
        Vector3d localOrigin = contraptionEntity.toLocalVector(origin, 1);
        Vector3d localTarget = contraptionEntity.toLocalVector(target, 1);
        Contraption contraption = contraptionEntity.getContraption();
        MutableObject<BlockRayTraceResult> mutableResult = new MutableObject<>();
        AtomicReference<VoxelShape> voxelShape = new AtomicReference();
        RaycastHelper.PredicateTraceResult predicateResult = RaycastHelper.rayTraceUntil(localOrigin, localTarget, p -> {
            Template.BlockInfo blockInfo = contraption.getBlocks().get(p);
            if (blockInfo == null)
                return false;
            BlockState state = blockInfo.state;
            VoxelShape raytraceShape = state.getShape(Minecraft.getInstance().level, BlockPos.ZERO.below());
            if (raytraceShape.isEmpty())
                return false;
            BlockRayTraceResult rayTrace = raytraceShape.clip(localOrigin, localTarget, p);
            if (rayTrace != null) {
                mutableResult.setValue(rayTrace);
                voxelShape.set(raytraceShape);
                return true;
            }
            return false;
        });
        if (predicateResult == null || predicateResult.missed())
            return;
        BlockRayTraceResult rayTraceResult = mutableResult.getValue();
        BlockPos blockPos = rayTraceResult.getBlockPos();
        renderBlockOutline(contraptionEntity, event.getMatrixStack(), voxelShape.get(), blockPos, event.getPartialTicks());
    }
    mc.getProfiler().pop();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) AtomicReference(java.util.concurrent.atomic.AtomicReference) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Contraption(com.simibubi.create.content.contraptions.components.structureMovement.Contraption) Minecraft(net.minecraft.client.Minecraft) Template(net.minecraft.world.gen.feature.template.Template) AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) BlockState(net.minecraft.block.BlockState) Vector3d(net.minecraft.util.math.vector.Vector3d) RaycastHelper(com.simibubi.create.foundation.utility.RaycastHelper) BlockPos(net.minecraft.util.math.BlockPos) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) MutableObject(org.apache.commons.lang3.mutable.MutableObject) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

Contraption (com.simibubi.create.content.contraptions.components.structureMovement.Contraption)11 BlockPos (net.minecraft.util.math.BlockPos)5 Vector3d (net.minecraft.util.math.vector.Vector3d)4 BlockState (net.minecraft.block.BlockState)3 RaycastHelper (com.simibubi.create.foundation.utility.RaycastHelper)2 ISpeedContraption (com.teammoeg.frostedheart.util.ISpeedContraption)2 Minecraft (net.minecraft.client.Minecraft)2 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)2 VoxelShape (net.minecraft.util.math.shapes.VoxelShape)2 Template (net.minecraft.world.gen.feature.template.Template)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 MutableObject (org.apache.commons.lang3.mutable.MutableObject)2 AirshipContraption (com.eriksonn.createaeronautics.contraptions.AirshipContraption)1 AirshipContraptionEntity (com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity)1 AirshipWorld (com.eriksonn.createaeronautics.dimension.AirshipWorld)1 MatrixTransformStack (com.jozufozu.flywheel.util.transform.MatrixTransformStack)1 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1