use of net.minecraft.world.phys.Vec3 in project Botania by VazkiiMods.
the class BoltParticleOptions method generate.
public List<BoltQuads> generate() {
Random random = new Random();
List<BoltQuads> quads = new ArrayList<>();
Vec3 diff = end.subtract(start);
float totalDistance = (float) diff.length();
for (int i = 0; i < count; i++) {
Queue<BoltInstructions> drawQueue = new ArrayDeque<>();
drawQueue.add(new BoltInstructions(start, 0, Vec3.ZERO, null, false));
while (!drawQueue.isEmpty()) {
BoltInstructions data = drawQueue.poll();
Vec3 perpendicularDist = data.perpendicularDist();
float progress = data.progress() + (1F / segments) * (1 - renderInfo.parallelNoise + random.nextFloat() * renderInfo.parallelNoise * 2);
Vec3 segmentEnd;
float segmentDiffScale = renderInfo.spreadFunction.getMaxSpread(progress);
if (progress >= 1 && segmentDiffScale <= 0) {
segmentEnd = end;
} else {
float maxDiff = renderInfo.spreadFactor * segmentDiffScale * totalDistance;
Vec3 randVec = findRandomOrthogonalVector(diff, random);
double rand = renderInfo.randomFunction.getRandom(random);
perpendicularDist = renderInfo.segmentSpreader.getSegmentAdd(perpendicularDist, randVec, maxDiff, segmentDiffScale, progress, rand);
// new vector is original + current progress through segments + perpendicular change
segmentEnd = start.add(diff.scale(progress)).add(perpendicularDist);
}
float boltSize = size * (0.5F + (1 - progress) * 0.5F);
Pair<BoltQuads, QuadCache> quadData = createQuads(data.cache(), data.start(), segmentEnd, boltSize);
quads.add(quadData.getLeft());
if (progress >= 1) {
// break if we've reached the defined end point
break;
} else if (!data.isBranch()) {
// continue the bolt if this is the primary (non-branch) segment
drawQueue.add(new BoltInstructions(segmentEnd, progress, perpendicularDist, quadData.getRight(), false));
} else if (random.nextFloat() < renderInfo.branchContinuationFactor) {
// branch continuation
drawQueue.add(new BoltInstructions(segmentEnd, progress, perpendicularDist, quadData.getRight(), true));
}
while (random.nextFloat() < renderInfo.branchInitiationFactor * (1 - progress)) {
// branch initiation (probability decreases as progress increases)
drawQueue.add(new BoltInstructions(segmentEnd, progress, perpendicularDist, quadData.getRight(), true));
}
}
}
return quads;
}
use of net.minecraft.world.phys.Vec3 in project Botania by VazkiiMods.
the class BoltParticleOptions method createQuads.
private Pair<BoltQuads, QuadCache> createQuads(@Nullable QuadCache cache, Vec3 startPos, Vec3 end, float size) {
Vec3 diff = end.subtract(startPos);
Vec3 rightAdd = diff.cross(new Vec3(0.5, 0.5, 0.5)).normalize().scale(size);
Vec3 backAdd = diff.cross(rightAdd).normalize().scale(size);
Vec3 rightAddSplit = rightAdd.scale(0.5F);
Vec3 start = cache != null ? cache.prevEnd() : startPos;
Vec3 startRight = cache != null ? cache.prevEndRight() : start.add(rightAdd);
Vec3 startBack = cache != null ? cache.prevEndBack() : start.add(rightAddSplit).add(backAdd);
Vec3 endRight = end.add(rightAdd);
Vec3 endBack = end.add(rightAddSplit).add(backAdd);
BoltQuads quads = new BoltQuads();
quads.addQuad(start, end, endRight, startRight);
quads.addQuad(startRight, endRight, end, start);
quads.addQuad(startRight, endRight, endBack, startBack);
quads.addQuad(startBack, endBack, endRight, startRight);
return Pair.of(quads, new QuadCache(end, endRight, endBack));
}
use of net.minecraft.world.phys.Vec3 in project Botania by VazkiiMods.
the class BoltRenderer method onWorldRenderLast.
public static void onWorldRenderLast(Camera camera, float partialTicks, PoseStack ps, RenderBuffers buffers) {
ps.pushPose();
// here we translate based on the inverse position of the client viewing camera to get back to 0, 0, 0
Vec3 camVec = camera.getPosition();
ps.translate(-camVec.x, -camVec.y, -camVec.z);
var bufferSource = buffers.bufferSource();
BoltRenderer.INSTANCE.render(partialTicks, ps, bufferSource);
bufferSource.endBatch(RenderHelper.LIGHTNING);
ps.popPose();
}
use of net.minecraft.world.phys.Vec3 in project Botania by VazkiiMods.
the class FXSparkle method wiggleAround.
// [VanillaCopy] Entity.moveTowardClosestSpace with tweaks
private void wiggleAround(double x, double y, double z) {
BlockPos blockpos = new BlockPos(x, y, z);
Vec3 Vector3d = new Vec3(x - (double) blockpos.getX(), y - (double) blockpos.getY(), z - (double) blockpos.getZ());
BlockPos.MutableBlockPos blockpos$mutable = new BlockPos.MutableBlockPos();
Direction direction = Direction.UP;
double d0 = Double.MAX_VALUE;
for (Direction direction1 : new Direction[] { Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST, Direction.UP }) {
blockpos$mutable.set(blockpos).move(direction1);
if (!this.level.getBlockState(blockpos$mutable).isCollisionShapeFullBlock(this.level, blockpos$mutable)) {
double d1 = Vector3d.get(direction1.getAxis());
double d2 = direction1.getAxisDirection() == Direction.AxisDirection.POSITIVE ? 1.0D - d1 : d1;
if (d2 < d0) {
d0 = d2;
direction = direction1;
}
}
}
// Botania - made multiplier and add both smaller
float f = this.random.nextFloat() * 0.05F + 0.025F;
float f1 = (float) direction.getAxisDirection().getStep();
// Botania - Randomness in other axes as well
float secondary = (random.nextFloat() - random.nextFloat()) * 0.1F;
float secondary2 = (random.nextFloat() - random.nextFloat()) * 0.1F;
if (direction.getAxis() == Direction.Axis.X) {
xd = (double) (f1 * f);
yd = secondary;
zd = secondary2;
} else if (direction.getAxis() == Direction.Axis.Y) {
xd = secondary;
yd = (double) (f1 * f);
zd = secondary2;
} else if (direction.getAxis() == Direction.Axis.Z) {
xd = secondary;
yd = secondary2;
zd = (double) (f1 * f);
}
}
use of net.minecraft.world.phys.Vec3 in project Botania by VazkiiMods.
the class TileEntityGeneratingFlower method tickFlower.
@Override
public void tickFlower() {
super.tickFlower();
if (getLevel().isClientSide) {
double particleChance = 1F - (double) getMana() / (double) getMaxMana() / 3.5F;
int color = getColor();
float red = (color >> 16 & 0xFF) / 255F;
float green = (color >> 8 & 0xFF) / 255F;
float blue = (color & 0xFF) / 255F;
if (Math.random() > particleChance) {
Vec3 offset = getLevel().getBlockState(getBlockPos()).getOffset(getLevel(), getBlockPos());
double x = getBlockPos().getX() + offset.x;
double y = getBlockPos().getY() + offset.y;
double z = getBlockPos().getZ() + offset.z;
BotaniaAPI.instance().sparkleFX(getLevel(), x + 0.3 + Math.random() * 0.5, y + 0.5 + Math.random() * 0.5, z + 0.3 + Math.random() * 0.5, red, green, blue, (float) Math.random(), 5);
}
}
emptyManaIntoCollector();
}
Aggregations