-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add entity equipment, effects, and attributes to spawner #76
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
Draft
lonelyicer
wants to merge
3
commits into
main
Choose a base branch
from
feat/trial-spawner-entity-modifier
base: main
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.
Draft
Changes from all commits
Commits
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
65 changes: 65 additions & 0 deletions
65
src/generated/resources/data/mia/mia/trial_spawner/example_equipped_zombie.json
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,65 @@ | ||
| { | ||
| "base_mobs": 2, | ||
| "entity_tables": [ | ||
| { | ||
| "attribute_modifiers": [ | ||
| { | ||
| "amount": 0.5, | ||
| "attribute": "minecraft:generic.max_health", | ||
| "id": "mia:trial_spawner_health", | ||
| "operation": "add_multiplied_total" | ||
| } | ||
| ], | ||
| "effects": [ | ||
| { | ||
| "amplifier": 0, | ||
| "duration": -1, | ||
| "effect": "minecraft:fire_resistance" | ||
| } | ||
| ], | ||
| "entity": "minecraft:zombie", | ||
| "equipment": { | ||
| "chest": "minecraft:iron_chestplate", | ||
| "head": "minecraft:iron_helmet", | ||
| "mainhand": "minecraft:diamond_sword" | ||
| }, | ||
| "weight": 10 | ||
| }, | ||
| { | ||
| "attribute_modifiers": [ | ||
| { | ||
| "amount": 2.0, | ||
| "attribute": "minecraft:generic.attack_damage", | ||
| "id": "mia:trial_spawner_damage", | ||
| "operation": "add_value" | ||
| } | ||
| ], | ||
| "effects": [ | ||
| { | ||
| "amplifier": 1, | ||
| "duration": -1, | ||
| "effect": "minecraft:speed" | ||
| } | ||
| ], | ||
| "entity": "minecraft:skeleton", | ||
| "equipment": { | ||
| "head": "minecraft:chainmail_helmet", | ||
| "mainhand": "minecraft:bow" | ||
| }, | ||
| "weight": 5 | ||
| } | ||
| ], | ||
| "loot_tables": [ | ||
| { | ||
| "loot_table": "minecraft:chests/trial_chambers/reward_rare", | ||
| "weight": 10 | ||
| }, | ||
| { | ||
| "loot_table": "minecraft:chests/trial_chambers/reward_unique", | ||
| "weight": 3 | ||
| } | ||
| ], | ||
| "mobs_per_player": 1, | ||
| "spawn_per_tick": 1, | ||
| "spawn_range": 5 | ||
| } |
183 changes: 183 additions & 0 deletions
183
src/main/java/com/altnoir/mia/block/entity/renderer/AbyssSpawnerRenderer.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,183 @@ | ||
| package com.altnoir.mia.block.entity.renderer; | ||
|
|
||
| import com.altnoir.mia.block.entity.AbyssSpawnerBlockEntity; | ||
| import com.altnoir.mia.client.render.MiaRenderTypes; | ||
| import com.mojang.blaze3d.vertex.PoseStack; | ||
| import com.mojang.blaze3d.vertex.VertexConsumer; | ||
| import com.mojang.math.Axis; | ||
| import net.minecraft.client.renderer.LightTexture; | ||
| import net.minecraft.client.renderer.MultiBufferSource; | ||
| import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; | ||
| import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; | ||
| import net.minecraft.util.FastColor; | ||
| import net.minecraft.util.Mth; | ||
| import net.minecraft.util.RandomSource; | ||
| import org.joml.Matrix4f; | ||
| import org.joml.Vector3f; | ||
|
|
||
| public class AbyssSpawnerRenderer implements BlockEntityRenderer<AbyssSpawnerBlockEntity> { | ||
| private static final int SPHERE_SEGMENTS = 16; | ||
| private static final int SPHERE_RINGS = 12; | ||
| private static final float BASE_RADIUS = 0.25f; | ||
|
|
||
| private static final int CORE_COLOR = FastColor.ARGB32.color(230, 80, 20, 120); | ||
| private static final int OUTER_COLOR = FastColor.ARGB32.color(180, 120, 60, 180); | ||
|
|
||
| public AbyssSpawnerRenderer(BlockEntityRendererProvider.Context context) { | ||
| } | ||
|
|
||
| @Override | ||
| public void render(AbyssSpawnerBlockEntity blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, int packedOverlay) { | ||
| var level = blockEntity.getLevel(); | ||
| if (level == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (!blockEntity.hasValidPattern()) { | ||
| return; | ||
| } | ||
|
|
||
| var spawner = blockEntity.getAbyssSpawner(); | ||
| float time = (level.getGameTime() + partialTick) * 0.05f; | ||
|
|
||
| poseStack.pushPose(); | ||
| poseStack.translate(0.5, 0.5, 0.5); | ||
|
|
||
| double spin = Mth.lerp(partialTick, spawner.getOSpin(), spawner.getSpin()); | ||
| poseStack.mulPose(Axis.YP.rotationDegrees((float) spin)); | ||
|
|
||
| float bob = Mth.sin(time * 0.5f) * 0.05f; | ||
| poseStack.translate(0, bob, 0); | ||
|
|
||
| float pulse = 1.0f + Mth.sin(time * 2.0f) * 0.1f; | ||
| float radius = BASE_RADIUS * pulse; | ||
|
|
||
| renderDistortedSphere(poseStack, bufferSource, radius, time, packedLight); | ||
|
|
||
| poseStack.scale(1.3f, 1.3f, 1.3f); | ||
| renderGlowingSphere(poseStack, bufferSource, radius * 0.8f, time); | ||
|
|
||
| poseStack.popPose(); | ||
| } | ||
|
|
||
| private void renderDistortedSphere(PoseStack poseStack, MultiBufferSource bufferSource, float radius, float time, int packedLight) { | ||
| VertexConsumer buffer = bufferSource.getBuffer(MiaRenderTypes.ABYSS_ORB); | ||
| Matrix4f matrix = poseStack.last().pose(); | ||
|
|
||
| RandomSource random = RandomSource.create(42L); | ||
|
|
||
| for (int ring = 0; ring < SPHERE_RINGS; ring++) { | ||
| float theta1 = (float) Math.PI * ring / SPHERE_RINGS; | ||
| float theta2 = (float) Math.PI * (ring + 1) / SPHERE_RINGS; | ||
|
|
||
| for (int seg = 0; seg < SPHERE_SEGMENTS; seg++) { | ||
| float phi1 = 2.0f * (float) Math.PI * seg / SPHERE_SEGMENTS; | ||
| float phi2 = 2.0f * (float) Math.PI * (seg + 1) / SPHERE_SEGMENTS; | ||
|
|
||
| float distort1 = getDistortion(theta1, phi1, time, random); | ||
| float distort2 = getDistortion(theta2, phi1, time, random); | ||
| float distort3 = getDistortion(theta2, phi2, time, random); | ||
| float distort4 = getDistortion(theta1, phi2, time, random); | ||
|
|
||
| Vector3f p1 = spherePoint(theta1, phi1, radius * distort1); | ||
| Vector3f p2 = spherePoint(theta2, phi1, radius * distort2); | ||
| Vector3f p3 = spherePoint(theta2, phi2, radius * distort3); | ||
| Vector3f p4 = spherePoint(theta1, phi2, radius * distort4); | ||
|
|
||
| float v1 = (float) ring / SPHERE_RINGS; | ||
| float v2 = (float) (ring + 1) / SPHERE_RINGS; | ||
|
|
||
| int color1 = lerpColor(CORE_COLOR, OUTER_COLOR, v1); | ||
| int color2 = lerpColor(CORE_COLOR, OUTER_COLOR, v2); | ||
|
|
||
| addVertex(buffer, matrix, p1, color1, packedLight); | ||
| addVertex(buffer, matrix, p2, color2, packedLight); | ||
| addVertex(buffer, matrix, p3, color2, packedLight); | ||
|
|
||
| addVertex(buffer, matrix, p1, color1, packedLight); | ||
| addVertex(buffer, matrix, p3, color2, packedLight); | ||
| addVertex(buffer, matrix, p4, color1, packedLight); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void renderGlowingSphere(PoseStack poseStack, MultiBufferSource bufferSource, float radius, float time) { | ||
| VertexConsumer buffer = bufferSource.getBuffer(MiaRenderTypes.ABYSS_ORB_GLOW); | ||
| Matrix4f matrix = poseStack.last().pose(); | ||
|
|
||
| float glowPulse = Mth.sin(time * 3.0f) * 0.5f + 0.5f; | ||
| int glowAlpha = (int) (80 + glowPulse * 100); | ||
| int glowColor = FastColor.ARGB32.color(glowAlpha, 180, 80, 220); | ||
|
|
||
| for (int ring = 0; ring < SPHERE_RINGS / 2; ring++) { | ||
| float theta1 = (float) Math.PI * ring / (SPHERE_RINGS / 2); | ||
| float theta2 = (float) Math.PI * (ring + 1) / (SPHERE_RINGS / 2); | ||
|
|
||
| for (int seg = 0; seg < SPHERE_SEGMENTS / 2; seg++) { | ||
| float phi1 = 2.0f * (float) Math.PI * seg / (SPHERE_SEGMENTS / 2); | ||
| float phi2 = 2.0f * (float) Math.PI * (seg + 1) / (SPHERE_SEGMENTS / 2); | ||
|
|
||
| Vector3f p1 = spherePoint(theta1, phi1, radius); | ||
| Vector3f p2 = spherePoint(theta2, phi1, radius); | ||
| Vector3f p3 = spherePoint(theta2, phi2, radius); | ||
| Vector3f p4 = spherePoint(theta1, phi2, radius); | ||
|
|
||
| addVertex(buffer, matrix, p1, glowColor, LightTexture.FULL_BRIGHT); | ||
| addVertex(buffer, matrix, p2, glowColor, LightTexture.FULL_BRIGHT); | ||
| addVertex(buffer, matrix, p3, glowColor, LightTexture.FULL_BRIGHT); | ||
|
|
||
| addVertex(buffer, matrix, p1, glowColor, LightTexture.FULL_BRIGHT); | ||
| addVertex(buffer, matrix, p3, glowColor, LightTexture.FULL_BRIGHT); | ||
| addVertex(buffer, matrix, p4, glowColor, LightTexture.FULL_BRIGHT); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private float getDistortion(float theta, float phi, float time, RandomSource random) { | ||
| float noise = Mth.sin(theta * 5 + time) * Mth.cos(phi * 3 + time * 0.7f); | ||
| float secondary = Mth.sin(theta * 8 - time * 1.3f) * Mth.sin(phi * 6 + time * 0.5f); | ||
| return 1.0f + noise * 0.15f + secondary * 0.08f; | ||
| } | ||
|
|
||
| private Vector3f spherePoint(float theta, float phi, float radius) { | ||
| float x = radius * Mth.sin(theta) * Mth.cos(phi); | ||
| float y = radius * Mth.cos(theta); | ||
| float z = radius * Mth.sin(theta) * Mth.sin(phi); | ||
| return new Vector3f(x, y, z); | ||
| } | ||
|
|
||
| private void addVertex(VertexConsumer buffer, Matrix4f matrix, Vector3f pos, int color, int light) { | ||
| buffer.addVertex(matrix, pos.x, pos.y, pos.z) | ||
| .setColor(color) | ||
| .setLight(light); | ||
| } | ||
|
|
||
| private int lerpColor(int color1, int color2, float t) { | ||
| int a1 = FastColor.ARGB32.alpha(color1); | ||
| int r1 = FastColor.ARGB32.red(color1); | ||
| int g1 = FastColor.ARGB32.green(color1); | ||
| int b1 = FastColor.ARGB32.blue(color1); | ||
|
|
||
| int a2 = FastColor.ARGB32.alpha(color2); | ||
| int r2 = FastColor.ARGB32.red(color2); | ||
| int g2 = FastColor.ARGB32.green(color2); | ||
| int b2 = FastColor.ARGB32.blue(color2); | ||
|
|
||
| int a = (int) Mth.lerp(t, a1, a2); | ||
| int r = (int) Mth.lerp(t, r1, r2); | ||
| int g = (int) Mth.lerp(t, g1, g2); | ||
| int b = (int) Mth.lerp(t, b1, b2); | ||
|
|
||
| return FastColor.ARGB32.color(a, r, g, b); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean shouldRenderOffScreen(AbyssSpawnerBlockEntity blockEntity) { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public int getViewDistance() { | ||
| return 64; | ||
| } | ||
| } |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/altnoir/mia/client/render/MiaRenderTypes.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,44 @@ | ||
| package com.altnoir.mia.client.render; | ||
|
|
||
| import com.mojang.blaze3d.vertex.DefaultVertexFormat; | ||
| import com.mojang.blaze3d.vertex.VertexFormat; | ||
| import net.minecraft.client.renderer.RenderType; | ||
|
|
||
| public class MiaRenderTypes extends RenderType { | ||
|
|
||
| public MiaRenderTypes(String name, VertexFormat format, VertexFormat.Mode mode, int bufferSize, boolean affectsCrumbling, boolean sortOnUpload, Runnable setupState, Runnable clearState) { | ||
| super(name, format, mode, bufferSize, affectsCrumbling, sortOnUpload, setupState, clearState); | ||
| } | ||
|
|
||
| public static final RenderType ABYSS_ORB = create( | ||
| "mia_abyss_orb", | ||
| DefaultVertexFormat.POSITION_COLOR_LIGHTMAP, | ||
| VertexFormat.Mode.TRIANGLES, | ||
| 1536, | ||
| false, | ||
| true, | ||
| CompositeState.builder() | ||
| .setShaderState(POSITION_COLOR_LIGHTMAP_SHADER) | ||
| .setTransparencyState(TRANSLUCENT_TRANSPARENCY) | ||
| .setWriteMaskState(COLOR_DEPTH_WRITE) | ||
| .setCullState(NO_CULL) | ||
| .setDepthTestState(LEQUAL_DEPTH_TEST) | ||
| .createCompositeState(false) | ||
| ); | ||
|
|
||
| public static final RenderType ABYSS_ORB_GLOW = create( | ||
| "mia_abyss_orb_glow", | ||
| DefaultVertexFormat.POSITION_COLOR_LIGHTMAP, | ||
| VertexFormat.Mode.TRIANGLES, | ||
| 1536, | ||
| false, | ||
| true, | ||
| CompositeState.builder() | ||
| .setShaderState(POSITION_COLOR_LIGHTMAP_SHADER) | ||
| .setTransparencyState(ADDITIVE_TRANSPARENCY) | ||
| .setWriteMaskState(COLOR_WRITE) | ||
| .setCullState(NO_CULL) | ||
| .setDepthTestState(LEQUAL_DEPTH_TEST) | ||
| .createCompositeState(false) | ||
| ); | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.