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