Search in sources :

Example 1 with ISpeedContraption

use of com.teammoeg.frostedheart.util.ISpeedContraption in project FrostedHeart by TeamMoegMC.

the class MixinBlockBreakingMovementBehaviour method tickBreaker.

/**
 * @author khjxiaogu
 * @reason further repair breaking speed
 */
@Overwrite(remap = false)
public void tickBreaker(MovementContext context) {
    CompoundNBT data = context.data;
    if (context.world.isRemote)
        return;
    if (!data.contains("BreakingPos"))
        return;
    if (context.relativeMotion.equals(Vector3d.ZERO)) {
        context.stall = false;
        return;
    }
    int ticksUntilNextProgress = data.getInt("TicksUntilNextProgress");
    if (ticksUntilNextProgress-- > 0) {
        data.putInt("TicksUntilNextProgress", ticksUntilNextProgress);
        return;
    }
    World world = context.world;
    BlockPos breakingPos = NBTUtil.readBlockPos(data.getCompound("BreakingPos"));
    int destroyProgress = data.getInt("Progress");
    int id = data.getInt("BreakerId");
    BlockState stateToBreak = world.getBlockState(breakingPos);
    float blockHardness = stateToBreak.getBlockHardness(world, breakingPos);
    if (!canBreak(world, breakingPos, stateToBreak)) {
        if (destroyProgress != 0) {
            destroyProgress = 0;
            data.remove("Progress");
            data.remove("TicksUntilNextProgress");
            data.remove("BreakingPos");
            world.sendBlockBreakProgress(id, breakingPos, -1);
        }
        context.stall = false;
        return;
    }
    float breakSpeed;
    if (context.contraption instanceof ISpeedContraption)
        breakSpeed = MathHelper.clamp(Math.abs(((ISpeedContraption) context.contraption).getSpeed()) * 10, 2, 16000f);
    else
        breakSpeed = MathHelper.clamp(Math.abs(context.getAnimationSpeed()) / 500f, 1 / 128f, 16f);
    destroyProgress += MathHelper.clamp((int) (breakSpeed / blockHardness), 1, 10000 - destroyProgress);
    world.playSound(null, breakingPos, stateToBreak.getSoundType().getHitSound(), SoundCategory.NEUTRAL, .25f, 1);
    if (destroyProgress >= 10000) {
        world.sendBlockBreakProgress(id, breakingPos, -1);
        // break falling blocks from top to bottom
        BlockPos ogPos = breakingPos;
        BlockState stateAbove = world.getBlockState(breakingPos.up());
        while (stateAbove.getBlock() instanceof FallingBlock) {
            breakingPos = breakingPos.up();
            stateAbove = world.getBlockState(breakingPos.up());
        }
        stateToBreak = world.getBlockState(breakingPos);
        context.stall = false;
        if (shouldDestroyStartBlock(stateToBreak))
            BlockHelper.destroyBlock(context.world, breakingPos, 1f, stack -> this.dropItem(context, stack));
        onBlockBroken(context, ogPos, stateToBreak);
        ticksUntilNextProgress = -1;
        data.remove("Progress");
        data.remove("TicksUntilNextProgress");
        data.remove("BreakingPos");
        return;
    }
    ticksUntilNextProgress = (int) (blockHardness / breakSpeed);
    world.sendBlockBreakProgress(id, breakingPos, MathHelper.clamp((int) (destroyProgress / 1000), 1, 10));
    data.putInt("TicksUntilNextProgress", ticksUntilNextProgress);
    data.putInt("Progress", destroyProgress);
}
Also used : FallingBlock(net.minecraft.block.FallingBlock) World(net.minecraft.world.World) MovementBehaviour(com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour) ISpeedContraption(com.teammoeg.frostedheart.util.ISpeedContraption) CompoundNBT(net.minecraft.nbt.CompoundNBT) BlockPos(net.minecraft.util.math.BlockPos) Overwrite(org.spongepowered.asm.mixin.Overwrite) BlockHelper(com.simibubi.create.foundation.utility.BlockHelper) Vector3d(net.minecraft.util.math.vector.Vector3d) Mixin(org.spongepowered.asm.mixin.Mixin) FallingBlock(net.minecraft.block.FallingBlock) MathHelper(net.minecraft.util.math.MathHelper) BlockBreakingMovementBehaviour(com.simibubi.create.content.contraptions.components.actors.BlockBreakingMovementBehaviour) Shadow(org.spongepowered.asm.mixin.Shadow) MovementContext(com.simibubi.create.content.contraptions.components.structureMovement.MovementContext) BlockState(net.minecraft.block.BlockState) NBTUtil(net.minecraft.nbt.NBTUtil) SoundCategory(net.minecraft.util.SoundCategory) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT) ISpeedContraption(com.teammoeg.frostedheart.util.ISpeedContraption) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with ISpeedContraption

use of com.teammoeg.frostedheart.util.ISpeedContraption 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 3 with ISpeedContraption

use of com.teammoeg.frostedheart.util.ISpeedContraption 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)

Aggregations

ISpeedContraption (com.teammoeg.frostedheart.util.ISpeedContraption)3 Contraption (com.simibubi.create.content.contraptions.components.structureMovement.Contraption)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vector3d (net.minecraft.util.math.vector.Vector3d)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2 MatrixTransformStack (com.jozufozu.flywheel.util.transform.MatrixTransformStack)1 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 BlockBreakingMovementBehaviour (com.simibubi.create.content.contraptions.components.actors.BlockBreakingMovementBehaviour)1 MovementBehaviour (com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour)1 MovementContext (com.simibubi.create.content.contraptions.components.structureMovement.MovementContext)1 BlockHelper (com.simibubi.create.foundation.utility.BlockHelper)1 BlockState (net.minecraft.block.BlockState)1 FallingBlock (net.minecraft.block.FallingBlock)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 NBTUtil (net.minecraft.nbt.NBTUtil)1 SoundCategory (net.minecraft.util.SoundCategory)1 MathHelper (net.minecraft.util.math.MathHelper)1 World (net.minecraft.world.World)1 Mixin (org.spongepowered.asm.mixin.Mixin)1 Shadow (org.spongepowered.asm.mixin.Shadow)1