Skip to content

Commit

Permalink
refactor: only use render type and stuff for evil whirlwinds
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed Dec 28, 2024
1 parent b2b8053 commit b611804
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void renderPost(RenderLevelStageEvent event) {


for (Iterator<Entity> iterator =
Iterators.filter(level.entitiesForRendering().iterator(), e -> e.getType() == AetherEntityTypes.WHIRLWIND.get() || e.getType() == AetherEntityTypes.EVIL_WHIRLWIND.get());
Iterators.filter(level.entitiesForRendering().iterator(), e -> e.getType() == AetherEntityTypes.EVIL_WHIRLWIND.get());
iterator.hasNext(); ) {
Entity entity = iterator.next();
if (dispatch.shouldRender(entity, frustum, x, y, z) || entity.hasIndirectPassenger(player)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import net.minecraft.resources.ResourceLocation;

public class ReduxRenderTypes {
public static RenderType whirlwind(ResourceLocation location, float u, float v) {
public static RenderType whirlwindParticleTranslucency(ResourceLocation location, float u, float v) {
return RenderType.create(
"whirlwind",
"whirlwind_post_translucency",
DefaultVertexFormat.NEW_ENTITY,
VertexFormat.Mode.QUADS,
1536,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.EventBusSubscriber.Bus;import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.zepalesque.redux.Redux;
import net.zepalesque.redux.client.renderer.entity.ReduxEvilWhirlwindRenderer;
import net.zepalesque.redux.client.renderer.entity.ReduxWhirlwindRenderer;
import net.zepalesque.redux.client.renderer.entity.model.WhirlwindModel;

Expand All @@ -29,7 +30,7 @@ public static void registerLayerDefinitions(EntityRenderersEvent.RegisterLayerDe
public static void registerEntityRenderers(EntityRenderersEvent.RegisterRenderers event) {
Redux.BLOCK_SETS.forEach(set -> set.registerRenderers(event));
event.registerEntityRenderer(AetherEntityTypes.WHIRLWIND.get(), ReduxWhirlwindRenderer::new);
event.registerEntityRenderer(AetherEntityTypes.EVIL_WHIRLWIND.get(), ReduxWhirlwindRenderer::new);
event.registerEntityRenderer(AetherEntityTypes.EVIL_WHIRLWIND.get(), ReduxEvilWhirlwindRenderer::new);
}

public static void registerAccessoryRenderers() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package net.zepalesque.redux.client.renderer.entity;

import com.aetherteam.aether.Aether;
import com.aetherteam.aether.entity.monster.AbstractWhirlwind;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.resources.ResourceLocation;
import net.zepalesque.redux.client.renderer.ReduxRenderTypes;
import net.zepalesque.redux.client.renderer.api.IPostRenderer;
import org.jetbrains.annotations.NotNull;

public class ReduxEvilWhirlwindRenderer<T extends AbstractWhirlwind> extends ReduxWhirlwindRenderer<T> implements IPostRenderer<T> {

private static final ResourceLocation EVIL_WHIRLWIND = ResourceLocation.fromNamespaceAndPath(Aether.MODID, "textures/entity/whirlwind/evil_whirlwind.png");

public ReduxEvilWhirlwindRenderer(EntityRendererProvider.Context context) {
super(context);
}

@Override
@NotNull
public ResourceLocation getTextureLocation(@NotNull T whirlwind) {
return EVIL_WHIRLWIND;
}

@Override
public void render(@NotNull T entity, float entityYaw, float partialTicks, @NotNull PoseStack poseStack, @NotNull MultiBufferSource buffer, int packedLight) {}

@Override
public void internalRender(@NotNull T entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) {
super.render(entity, entityYaw, partialTicks, poseStack, buffer, packedLight);
}

@Override
protected float xOffset(float tickCount) {
return tickCount * 0.015F;
}

@Override
protected void setupRotations(@NotNull AbstractWhirlwind entity, @NotNull PoseStack poseStack, float bob, float yBodyRot, float partialTick, float scale) {}

@Override
protected void scale(T livingEntity, PoseStack poseStack, float partialTickTime) {
poseStack.scale(1.25F, 1.25F, 1.25F);
}

@Override
protected RenderType renderType(ResourceLocation texture, float xOffset) {
return ReduxRenderTypes.whirlwindParticleTranslucency(texture, xOffset, 0.0F);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
Expand All @@ -16,12 +17,13 @@
import net.zepalesque.redux.client.renderer.api.IPostRenderer;
import net.zepalesque.redux.client.renderer.entity.model.WhirlwindModel;
import net.zepalesque.redux.config.ReduxConfig;
import net.zepalesque.zenith.util.lambda.Consumers;
import net.zepalesque.zenith.util.lambda.Functions;
import org.jetbrains.annotations.NotNull;

public class ReduxWhirlwindRenderer<T extends AbstractWhirlwind> extends LivingEntityRenderer<T, WhirlwindModel<T>> implements IPostRenderer<T> {
public class ReduxWhirlwindRenderer<T extends AbstractWhirlwind> extends LivingEntityRenderer<T, WhirlwindModel<T>> {

private static final ResourceLocation WHIRLWIND = ResourceLocation.fromNamespaceAndPath(Aether.MODID, "textures/entity/whirlwind/whirlwind.png");
private static final ResourceLocation EVIL_WHIRLWIND = ResourceLocation.fromNamespaceAndPath(Aether.MODID, "textures/entity/whirlwind/evil_whirlwind.png");

public ReduxWhirlwindRenderer(EntityRendererProvider.Context context) {
super(context, new WhirlwindModel<>(context.bakeLayer(ReduxRenderers.ModelLayers.WHIRLWIND)), 0.0F);
Expand All @@ -30,32 +32,29 @@ public ReduxWhirlwindRenderer(EntityRendererProvider.Context context) {
@Override
@NotNull
public ResourceLocation getTextureLocation(@NotNull T whirlwind) {
if (whirlwind.getType() == AetherEntityTypes.EVIL_WHIRLWIND.get()) return EVIL_WHIRLWIND;
else return WHIRLWIND;
return WHIRLWIND;
}

@Override
public void render(@NotNull T entity, float entityYaw, float partialTicks, @NotNull PoseStack poseStack, @NotNull MultiBufferSource buffer, int packedLight) {}

public void internalRender(@NotNull T entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) {
public void render(@NotNull T entity, float entityYaw, float partialTicks, @NotNull PoseStack poseStack, @NotNull MultiBufferSource buffer, int packedLight) {
if (ReduxConfig.CLIENT.improved_whirlwinds.get()) {
boolean isEvil = entity.getType() == AetherEntityTypes.EVIL_WHIRLWIND.get();
float age = this.getBob(entity, partialTicks);
VertexConsumer vertexconsumer = buffer.getBuffer(ReduxRenderTypes.whirlwind(getTextureLocation(entity), this.xOffset(age, isEvil) % 1.0F, 0.0F));
VertexConsumer vertexconsumer = buffer.getBuffer(renderType(getTextureLocation(entity), this.xOffset(age) % 1.0F));
poseStack.pushPose();
this.model.setupAnim(entity, 0.0F, 0.0F, age, 0.0F, 0.0F);
poseStack.mulPose(Axis.ZP.rotationDegrees(180.0F));

if (isEvil) poseStack.scale(1.25F, 1.25F, 1.25F);
this.scale(entity, poseStack, partialTicks);
this.model.renderToBuffer(poseStack, vertexconsumer, packedLight, OverlayTexture.NO_OVERLAY);
poseStack.popPose();
}
}


protected RenderType renderType(ResourceLocation texture, float xOffset) {
return RenderType.breezeWind(texture, xOffset, 0.0F);
}

private float xOffset(float tickCount, boolean isEvil) {
return tickCount * (isEvil ? 0.015F : 0.01F);
protected float xOffset(float tickCount) {
return tickCount * 0.1F;
}

@Override
Expand Down

0 comments on commit b611804

Please sign in to comment.