-
-
Notifications
You must be signed in to change notification settings - Fork 15
Render Tree arboretum #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Lazzzzz
wants to merge
2
commits into
bernie-g:master
Choose a base branch
from
Lazzzzz:Tree-render-arboretum
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/main/java/software/bernie/techarium/client/particles/ArboretumParticles.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| package software.bernie.techarium.client.particles; | ||
|
|
||
| import com.mojang.blaze3d.vertex.IVertexBuilder; | ||
|
|
||
| import net.minecraft.client.particle.IAnimatedSprite; | ||
| import net.minecraft.client.particle.IParticleFactory; | ||
| import net.minecraft.client.particle.IParticleRenderType; | ||
| import net.minecraft.client.particle.Particle; | ||
| import net.minecraft.client.particle.SpriteTexturedParticle; | ||
| import net.minecraft.client.renderer.ActiveRenderInfo; | ||
| import net.minecraft.client.world.ClientWorld; | ||
| import net.minecraft.particles.BasicParticleType; | ||
| import net.minecraft.util.math.MathHelper; | ||
| import net.minecraft.util.math.vector.Quaternion; | ||
| import net.minecraft.util.math.vector.Vector3d; | ||
| import net.minecraft.util.math.vector.Vector3f; | ||
| import net.minecraftforge.api.distmarker.Dist; | ||
| import net.minecraftforge.api.distmarker.OnlyIn; | ||
|
|
||
| public class ArboretumParticles extends SpriteTexturedParticle { | ||
|
|
||
| float particleMaxScale = 1; | ||
|
|
||
| public ArboretumParticles(ClientWorld world, double posX, double posY, double posZ, double red, | ||
| double green, double blue) { | ||
| super(world, posX, posY, posZ, red, green, blue); | ||
| xd = (random.nextFloat() - 0.5f) / 50f; | ||
| yd = random.nextFloat() / 50f; | ||
| zd = (random.nextFloat() - 0.5f) / 50f; | ||
| particleMaxScale = Math.max(random.nextFloat() / 120f, 0.0085f); | ||
| quadSize = particleMaxScale; | ||
| bCol = (float) blue; | ||
| gCol = (float) green; | ||
| rCol = (float) red; | ||
| setLifetime(100); | ||
| hasPhysics = true; | ||
| } | ||
|
|
||
| @Override | ||
| public void render(IVertexBuilder builder, ActiveRenderInfo renderInfo, float partialTicks) { | ||
| if (isAlive()) { | ||
| Vector3d vec3d = renderInfo.getPosition(); | ||
| float f = (float) (MathHelper.lerp((double) partialTicks, this.xo, this.x) - vec3d.x()); | ||
| float f1 = (float) (MathHelper.lerp((double) partialTicks, this.yo, this.y) - vec3d.y()); | ||
| float f2 = (float) (MathHelper.lerp((double) partialTicks, this.zo, this.z) - vec3d.z()); | ||
| Quaternion quaternion; | ||
| if (this.roll == 0.0F) { | ||
| quaternion = renderInfo.rotation(); | ||
| } else { | ||
| quaternion = new Quaternion(renderInfo.rotation()); | ||
| float f3 = MathHelper.lerp(partialTicks, this.oRoll, this.roll); | ||
| quaternion.mul(Vector3f.ZP.rotation(f3)); | ||
| } | ||
|
|
||
| Vector3f vector3f1 = new Vector3f(-1.0F, -1.0F, 0.0F); | ||
| vector3f1.transform(quaternion); | ||
| Vector3f[] avector3f = new Vector3f[] { new Vector3f(-1.0F, -1.0F, 0.0F), new Vector3f(-1.0F, 1.0F, 0.0F), | ||
| new Vector3f(1.0F, 1.0F, 0.0F), new Vector3f(1.0F, -1.0F, 0.0F) }; | ||
| float f4 = this.quadSize; | ||
|
|
||
| for (int i = 0; i < 4; ++i) { | ||
| Vector3f vector3f = avector3f[i]; | ||
| vector3f.transform(quaternion); | ||
| vector3f.mul(f4); | ||
| vector3f.add(f, f1, f2); | ||
| } | ||
|
|
||
| float f7 = this.getU0(); | ||
| float f8 = this.getU1(); | ||
| float f5 = this.getV0(); | ||
| float f6 = this.getV1(); | ||
| int j = this.getLightColor(partialTicks); | ||
| alpha = getGlowBrightness(); | ||
| builder.vertex((double) avector3f[0].x(), (double) avector3f[0].y(), (double) avector3f[0].z()) | ||
| .uv(f8, f6).color(this.rCol, this.gCol, this.bCol, this.alpha) | ||
| .uv2(j).endVertex(); | ||
| builder.vertex((double) avector3f[1].x(), (double) avector3f[1].y(), (double) avector3f[1].z()) | ||
| .uv(f8, f5).color(this.rCol, this.gCol, this.bCol, this.alpha) | ||
| .uv2(j).endVertex(); | ||
| builder.vertex((double) avector3f[2].x(), (double) avector3f[2].y(), (double) avector3f[2].z()) | ||
| .uv(f7, f5).color(this.rCol, this.gCol, this.bCol, this.alpha) | ||
| .uv2(j).endVertex(); | ||
| builder.vertex((double) avector3f[3].x(), (double) avector3f[3].y(), (double) avector3f[3].z()) | ||
| .uv(f7, f6).color(this.rCol, this.gCol, this.bCol, this.alpha) | ||
| .uv2(j).endVertex(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void tick() { | ||
| float percentAge = 1 - (float) age / (float) getLifetime(); | ||
| quadSize = (float) (particleMaxScale * percentAge); | ||
| yd += -0.001f; | ||
| super.tick(); | ||
|
|
||
| } | ||
|
|
||
| public float getGlowBrightness() { | ||
| return 1 - (float) age / (float) getLifetime(); | ||
| } | ||
|
|
||
| @Override | ||
| public IParticleRenderType getRenderType() { | ||
| return IParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; | ||
| } | ||
|
|
||
| @Override | ||
| public int getLightColor(float partialTicks) { | ||
| int i = super.getLightColor(partialTicks); | ||
| int j = 240; | ||
| int k = i >> 16 & 255; | ||
| return 240 | k << 16; | ||
| } | ||
|
|
||
| @OnlyIn(Dist.CLIENT) | ||
| public static class Factory implements IParticleFactory<BasicParticleType> { | ||
| private final IAnimatedSprite sprites; | ||
|
|
||
| public Factory(IAnimatedSprite sprite) { | ||
| this.sprites = sprite; | ||
| } | ||
|
|
||
| @Override | ||
| public Particle createParticle(BasicParticleType typeIn, ClientWorld worldIn, double x, double y, double z, | ||
| double xSpeed, double ySpeed, double zSpeed) { | ||
| ArboretumParticles particle = new ArboretumParticles(worldIn, x, y, z, xSpeed, ySpeed, zSpeed); | ||
| particle.pickSprite(sprites); | ||
| return particle; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...main/java/software/bernie/techarium/client/tile/render/arboretum/ArboretumTreeRender.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package software.bernie.techarium.client.tile.render.arboretum; | ||
|
|
||
| import com.mojang.blaze3d.matrix.MatrixStack; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import net.minecraft.block.Block; | ||
| import net.minecraft.block.Blocks; | ||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.client.renderer.IRenderTypeBuffer; | ||
| import net.minecraft.util.math.BlockPos; | ||
| import net.minecraftforge.client.model.data.EmptyModelData; | ||
| import software.bernie.techarium.registry.ParticlesRegistry; | ||
| import software.bernie.techarium.tile.arboretum.ArboretumTile; | ||
|
|
||
| public class ArboretumTreeRender { | ||
|
|
||
| @Getter | ||
| private static ArboretumTreeRender instance = new ArboretumTreeRender(); | ||
|
|
||
| @Getter | ||
| @Setter | ||
| private Block log = Blocks.OAK_LOG; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| private Block leaves = Blocks.OAK_LEAVES; | ||
|
|
||
| private float scale = 0; | ||
|
|
||
| public void renderTree(MatrixStack stack, IRenderTypeBuffer renderTypeBuffer, int packedLightIn, int packedOverlayIn, float partialTicks, float craftPercent) { | ||
| scale = craftPercent / 10f; | ||
| stack.translate(-scale/2f, 0.8, -scale/2f); | ||
| stack.scale(scale, scale, scale); | ||
|
|
||
| renderLogGrow(stack, renderTypeBuffer, packedLightIn, packedOverlayIn, partialTicks, craftPercent); | ||
| renderLeavesGrow(stack, renderTypeBuffer, packedLightIn, packedOverlayIn, partialTicks, craftPercent); | ||
| } | ||
|
|
||
| private void renderLogGrow(MatrixStack stack, IRenderTypeBuffer renderTypeBuffer, int packedLightIn, int packedOverlayIn, float partialTicks, float craftPercent) { | ||
| for (float i = 0; i < (float) 6f * craftPercent; i++) { | ||
| stack.pushPose(); | ||
| stack.translate(0, i, 0); | ||
| Minecraft.getInstance().getBlockRenderer().renderBlock(log.defaultBlockState(), stack, renderTypeBuffer, packedLightIn, packedOverlayIn, EmptyModelData.INSTANCE); | ||
| stack.popPose(); | ||
| } | ||
| } | ||
|
|
||
| private void renderLeavesGrow(MatrixStack stack, IRenderTypeBuffer renderTypeBuffer, int packedLightIn, int packedOverlayIn, float partialTicks, float craftPercent) { | ||
| if (craftPercent < 0.25) | ||
| return; | ||
|
|
||
| for (int i = -1; i <= 1; i++) { | ||
| for (int j = -1; j <= 1; j++) { | ||
| for (int k = 0; k < 2; k++) { | ||
| if (k == 1) { | ||
| if ((i == -1 && j == -1) || (i == 1 && j == -1) || (i == 1 && j == 1) || (i == -1 && j == 1)) | ||
| continue; | ||
| } | ||
| stack.pushPose(); | ||
| stack.translate(i, k + (float) 6f * craftPercent, j); | ||
| Minecraft.getInstance().getBlockRenderer().renderBlock(leaves.defaultBlockState(), stack, renderTypeBuffer, packedLightIn, packedOverlayIn, EmptyModelData.INSTANCE); | ||
| stack.popPose(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (craftPercent < 0.5) | ||
| return; | ||
|
|
||
| int radius = (int) (2.5f * Math.min(1, ((craftPercent * 2f) - 1f) + 0.1f)); | ||
|
|
||
| for (int i = -radius; i <= radius; i++) { | ||
| for (int j = -radius; j <= radius; j++) { | ||
| for (int k = -2; k < 0; k++) { | ||
| if (i == 0 && j == 0) continue; | ||
| stack.pushPose(); | ||
| stack.translate(i, k + (float) 6f * craftPercent, j); | ||
| Minecraft.getInstance().getBlockRenderer().renderBlock(leaves.defaultBlockState(), stack, renderTypeBuffer, packedLightIn, packedOverlayIn, EmptyModelData.INSTANCE); | ||
| stack.popPose(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting