Skip to content

Commit

Permalink
Merge pull request #276 from celestialfault/fix/holiday-jank
Browse files Browse the repository at this point in the history
Fix holiday theme-related rendering
  • Loading branch information
WildfireRomeo authored Dec 24, 2024
2 parents d1ed9ad + ebe2be7 commit 00d3ecd
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 54 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/wildfire/main/WildfireEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.wildfire.main.networking.WildfireSync;
import com.wildfire.render.GenderArmorLayer;
import com.wildfire.render.GenderLayer;
import com.wildfire.render.HolidayFeaturesRenderer;
import com.wildfire.render.RenderStateEntityCapture;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -56,7 +57,6 @@
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.PlayerEntityRenderer;
import net.minecraft.client.render.entity.model.ParrotEntityModel;
import net.minecraft.client.render.entity.state.PlayerEntityRenderState;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.client.util.math.MatrixStack;
Expand Down Expand Up @@ -213,6 +213,7 @@ private static void registerRenderLayers(EntityType<? extends LivingEntity> enti
if(entityRenderer instanceof PlayerEntityRenderer playerRenderer) {
registrationHelper.register(new GenderLayer<>(playerRenderer));
registrationHelper.register(new GenderArmorLayer<>(playerRenderer, context.getEquipmentModelLoader(), context.getEquipmentRenderer()));
registrationHelper.register(new HolidayFeaturesRenderer(playerRenderer));
} else if(entityRenderer instanceof ArmorStandEntityRenderer armorStandRenderer) {
registrationHelper.register(new GenderArmorLayer<>(armorStandRenderer, context.getEquipmentModelLoader(), context.getEquipmentRenderer()));
}
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/com/wildfire/main/WildfireHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.wildfire.api.WildfireAPI;
import com.wildfire.main.config.FloatConfigKey;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.render.block.entity.ChestBlockEntityRenderer;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.ItemStack;
import com.wildfire.api.impl.GenderArmor;
Expand All @@ -36,7 +35,6 @@
import net.minecraft.util.TriState;
import net.minecraft.util.math.MathHelper;

import java.util.Calendar;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Function;

Expand Down Expand Up @@ -102,10 +100,4 @@ public static String getModVersion(String modId) {
public static boolean onClient() {
return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
}

//Returns true when within the Christmas date(s). Taken from the Chest entity renderer
public static boolean isAroundChristmas() {
Calendar calendar = Calendar.getInstance();
return calendar.get(Calendar.MONTH) + 1 == 12 && calendar.get(Calendar.DATE) >= 24 && calendar.get(Calendar.DATE) <= 26;
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/wildfire/main/entitydata/PlayerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public PlayerConfig(UUID uuid) {
this.cfg.setDefault(Configuration.VOICE_PITCH);

this.cfg.setDefault(Configuration.HOLIDAY_THEMES);

// Real players always have a UUID of version 4; if this isn't the case, then this is undeniably
// an NPC player entity.
if(uuid.version() != 4) this.holidayThemes = false;
}

// this shouldn't ever be called on players, but just to be safe, override with a noop.
Expand Down
45 changes: 0 additions & 45 deletions src/main/java/com/wildfire/render/GenderLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,17 @@
package com.wildfire.render;

import com.wildfire.api.IGenderArmor;
import com.wildfire.main.WildfireEventHandler;
import com.wildfire.main.config.Configuration;
import com.wildfire.main.config.GlobalConfig;
import com.wildfire.main.entitydata.Breasts;
import com.wildfire.main.WildfireGender;
import com.wildfire.main.WildfireHelper;
import com.wildfire.main.entitydata.EntityConfig;
import com.wildfire.main.entitydata.PlayerConfig;
import com.wildfire.physics.BreastPhysics;
import com.wildfire.render.WildfireModelRenderer.BreastModelBox;
import com.wildfire.render.WildfireModelRenderer.OverlayModelBox;
import com.wildfire.render.WildfireModelRenderer.PositionTextureVertex;

import java.lang.Math;
import java.util.Calendar;
import java.util.Objects;
import java.util.function.Consumer;

Expand All @@ -58,8 +54,6 @@
import org.jetbrains.annotations.Nullable;
import org.joml.*;

import static com.wildfire.main.WildfireHelper.isAroundChristmas;

@Environment(EnvType.CLIENT)
public class GenderLayer<S extends BipedEntityRenderState, M extends BipedEntityModel<S>> extends FeatureRenderer<S, M> {

Expand All @@ -70,8 +64,6 @@ public class GenderLayer<S extends BipedEntityRenderState, M extends BipedEntity

private final FeatureRendererContext<S, M> context;

private boolean isChristmas = isAroundChristmas();

private float preBreastSize, preBreastOffsetZ;
private Breasts breasts;
protected ItemStack armorStack;
Expand All @@ -85,24 +77,12 @@ public class GenderLayer<S extends BipedEntityRenderState, M extends BipedEntity
rBreastWear = new OverlayModelBox(false, 64, 64, 21, 34, 0, 0.0F, 0F, 4, 5, 3, 0.0F, false);
}

private ModelPart santaHat;
public GenderLayer(FeatureRendererContext<S, M> render) {
super(render);
this.context = render;
// this can't be static or final as we need the ability to resize this during render time
lBreast = new BreastModelBox(64, 64, 16, 17, -4F, 0.0F, 0F, 4, 5, 4, 0.0F, false);
rBreast = new BreastModelBox(64, 64, 20, 17, 0, 0.0F, 0F, 4, 5, 4, 0.0F, false);

TexturedModelData data = getSantaHat();
santaHat = data.createModel();
}

private static TexturedModelData getSantaHat() {
Dilation dilation = new Dilation(0.75f);
ModelData modelData = new ModelData();
ModelPartData modelPartData = modelData.getRoot();
modelPartData.addChild("santa_hat", ModelPartBuilder.create().uv(0, 0).cuboid(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, dilation), ModelTransform.NONE);
return TexturedModelData.of(modelData, 32, 32);
}

/**
Expand Down Expand Up @@ -160,31 +140,6 @@ public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsume
} catch(Exception e) {
WildfireGender.LOGGER.error("Failed to render breast layer", e);
}

//Santa hat (if holiday themes are enabled)
if(isChristmas && entityConfig instanceof PlayerConfig plrConfig && plrConfig.hasHolidayThemes()) {
try {
int overlay = LivingEntityRenderer.getOverlay(state, 0);
RenderLayer hatRenderType = RenderLayer.getEntityTranslucent(Identifier.of(WildfireGender.MODID, "textures/santa_hat.png"));
if (hatRenderType == null) return;
VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(hatRenderType);

if (state.baby) {
matrixStack.scale(state.ageScale, state.ageScale, state.ageScale);
matrixStack.translate(0f, 0.75f, 0f);
}

ModelPart mPart = getContextModel().head;
matrixStack.translate(mPart.pivotX * 0.0625f, mPart.pivotY * 0.0625f, mPart.pivotZ * 0.0625f);
if (mPart.roll != 0.0F || mPart.yaw != 0.0F || mPart.pitch != 0.0F) {
matrixStack.multiply(new Quaternionf().rotationZYX(mPart.roll, mPart.yaw, mPart.pitch));
}

santaHat.render(matrixStack, vertexConsumer, light, overlay);
} catch (Exception e) {
WildfireGender.LOGGER.error("Failed to render breast layer", e);
}
}
}

/**
Expand Down
98 changes: 98 additions & 0 deletions src/main/java/com/wildfire/render/HolidayFeaturesRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Wildfire's Female Gender Mod is a female gender mod created for Minecraft.
* Copyright (C) 2023-present WildfireRomeo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.wildfire.render;

import com.wildfire.main.WildfireGender;
import net.minecraft.client.model.*;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.client.render.entity.state.PlayerEntityRenderState;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import org.joml.Quaternionf;

import java.util.Calendar;

public class HolidayFeaturesRenderer extends FeatureRenderer<PlayerEntityRenderState, PlayerEntityModel> {
private final ModelPart santaHat;

private static final Identifier SANTA_HAT = Identifier.of(WildfireGender.MODID, "textures/santa_hat.png");
private static final boolean christmas = isAroundChristmas();

public HolidayFeaturesRenderer(FeatureRendererContext<PlayerEntityRenderState, PlayerEntityModel> context) {
super(context);
santaHat = createSantaHat().createModel();
}

@Override
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, PlayerEntityRenderState state, float limbAngle, float limbDistance) {
var entity = ((RenderStateEntityCapture)state).getEntity();
if(entity == null) return;
var config = WildfireGender.getPlayerById(entity.getUuid());
if(config == null || !config.hasHolidayThemes()) return;

renderSantaHat(state, matrices, vertexConsumers, light);
}

private void renderSantaHat(PlayerEntityRenderState state, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light) {
if(!christmas) return;

matrixStack.push();
try {
int overlay = LivingEntityRenderer.getOverlay(state, 0);
RenderLayer hatRenderType = RenderLayer.getEntityTranslucent(SANTA_HAT);
if(hatRenderType == null) return;
VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(hatRenderType);

if(state.baby) {
matrixStack.scale(state.ageScale, state.ageScale, state.ageScale);
matrixStack.translate(0f, 0.75f, 0f);
}

ModelPart mPart = getContextModel().head;
matrixStack.translate(mPart.pivotX * 0.0625f, mPart.pivotY * 0.0625f, mPart.pivotZ * 0.0625f);
if(mPart.roll != 0.0F || mPart.yaw != 0.0F || mPart.pitch != 0.0F) {
matrixStack.multiply(new Quaternionf().rotationZYX(mPart.roll, mPart.yaw, mPart.pitch));
}

santaHat.render(matrixStack, vertexConsumer, light, overlay);
} catch(Exception e) {
WildfireGender.LOGGER.error("Failed to render breast layer", e);
}
matrixStack.pop();
}

private static TexturedModelData createSantaHat() {
Dilation dilation = new Dilation(0.75f);
ModelData modelData = new ModelData();
ModelPartData modelPartData = modelData.getRoot();
modelPartData.addChild("santa_hat", ModelPartBuilder.create().uv(0, 0).cuboid(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, dilation), ModelTransform.NONE);
return TexturedModelData.of(modelData, 32, 32);
}

public static boolean isAroundChristmas() {
Calendar calendar = Calendar.getInstance();
return calendar.get(Calendar.MONTH) == Calendar.DECEMBER && calendar.get(Calendar.DATE) >= 24 && calendar.get(Calendar.DATE) <= 26;
}
}

0 comments on commit 00d3ecd

Please sign in to comment.