use of com.simibubi.create.content.schematics.block.LaunchedItem.ForBlockState in project Create by Creators-of-Create.
the class SchematicannonRenderer method renderLaunchedBlocks.
private static void renderLaunchedBlocks(SchematicannonTileEntity tileEntityIn, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
for (LaunchedItem launched : tileEntityIn.flyingBlocks) {
if (launched.ticksRemaining == 0)
continue;
// Calculate position of flying block
Vec3 start = Vec3.atLowerCornerOf(tileEntityIn.getBlockPos().offset(.5f, 1, .5f));
Vec3 target = Vec3.atLowerCornerOf(launched.target).add(-.5, 0, 1);
Vec3 distance = target.subtract(start);
double targetY = target.y - start.y;
double throwHeight = Math.sqrt(distance.lengthSqr()) * .6f + targetY;
Vec3 cannonOffset = distance.add(0, throwHeight, 0).normalize().scale(2);
start = start.add(cannonOffset);
float progress = ((float) launched.totalTicks - (launched.ticksRemaining + 1 - partialTicks)) / launched.totalTicks;
Vec3 blockLocationXZ = new Vec3(.5, .5, .5).add(target.subtract(start).scale(progress).multiply(1, 0, 1));
// Height is determined through a bezier curve
float t = progress;
double yOffset = 2 * (1 - t) * t * throwHeight + t * t * targetY;
Vec3 blockLocation = blockLocationXZ.add(0, yOffset + 1, 0).add(cannonOffset);
// Offset to position
ms.pushPose();
ms.translate(blockLocation.x, blockLocation.y, blockLocation.z);
ms.translate(.125f, .125f, .125f);
ms.mulPose(new Vector3f(0, 1, 0).rotationDegrees(360 * t));
ms.mulPose(new Vector3f(1, 0, 0).rotationDegrees(360 * t));
ms.translate(-.125f, -.125f, -.125f);
if (launched instanceof ForBlockState) {
// Render the Block
BlockState state;
if (launched instanceof ForBelt) {
// Render a shaft instead of the belt
state = AllBlocks.SHAFT.getDefaultState();
} else {
state = ((ForBlockState) launched).state;
}
float scale = .3f;
ms.scale(scale, scale, scale);
Minecraft.getInstance().getBlockRenderer().renderSingleBlock(state, ms, buffer, light, overlay, VirtualEmptyModelData.INSTANCE);
} else if (launched instanceof ForEntity) {
// Render the item
float scale = 1.2f;
ms.scale(scale, scale, scale);
Minecraft.getInstance().getItemRenderer().renderStatic(launched.stack, TransformType.GROUND, light, overlay, ms, buffer, 0);
}
ms.popPose();
// Render particles for launch
if (launched.ticksRemaining == launched.totalTicks && tileEntityIn.firstRenderTick) {
tileEntityIn.firstRenderTick = false;
for (int i = 0; i < 10; i++) {
Random r = tileEntityIn.getLevel().getRandom();
double sX = cannonOffset.x * .01f;
double sY = (cannonOffset.y + 1) * .01f;
double sZ = cannonOffset.z * .01f;
double rX = r.nextFloat() - sX * 40;
double rY = r.nextFloat() - sY * 40;
double rZ = r.nextFloat() - sZ * 40;
tileEntityIn.getLevel().addParticle(ParticleTypes.CLOUD, start.x + rX, start.y + rY, start.z + rZ, sX, sY, sZ);
}
}
}
}
Aggregations