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);
}
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();
}
}
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);
}
Aggregations