Skip to content

Commit

Permalink
fix: rat item rendering reading from uninitialised hat texture array
Browse files Browse the repository at this point in the history
  • Loading branch information
williambl committed Oct 3, 2024
1 parent c20bae2 commit 2ed3b05
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class PartyHatFeatureRenderer extends GeoLayerRenderer<RatEntity> {
public static final Set<RatEntity.Type> DISALLOWED_TYPES = Sets.immutableEnumSet(RatEntity.Type.RAT_KID, RatEntity.Type.BIGGIE_CHEESE, RatEntity.Type.REMY);
public static Identifier[] TEXTURES;
private static Identifier[] TEXTURES;

private final PartyHatEntityRenderer partyHatEntityRenderer;

Expand All @@ -28,13 +28,7 @@ public PartyHatFeatureRenderer(IGeoRenderer<RatEntity> entityRendererIn, PartyHa
@Override
public void render(MatrixStack matrixStackIn, VertexConsumerProvider bufferIn, int packedLightIn, RatEntity ratEntity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
if (RatsMischiefUtils.IS_BIRTHDAY && !DISALLOWED_TYPES.contains(ratEntity.getRatType())) {
if (TEXTURES == null) {
TEXTURES = new Identifier[RatEntity.PartyHat.values().length];
for (RatEntity.PartyHat hat : RatEntity.PartyHat.values()) {
TEXTURES[hat.ordinal()] = new Identifier(RatsMischief.MOD_ID, "textures/entity/birthday_hats/" + hat.toString().toLowerCase() + ".png");
}
}
Identifier hatTexture = TEXTURES[ratEntity.getPartyHat().ordinal()];
Identifier hatTexture = getTexture(ratEntity.getPartyHat());
this.partyHatEntityRenderer.render(this.getEntityModel().getModel(this.getEntityModel().getModelResource(ratEntity)),
ratEntity,
partialTicks,
Expand All @@ -45,4 +39,14 @@ public void render(MatrixStack matrixStackIn, VertexConsumerProvider bufferIn, i
packedLightIn, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);
}
}

public static Identifier getTexture(RatEntity.PartyHat partyHat) {
if (TEXTURES == null) {
TEXTURES = new Identifier[RatEntity.PartyHat.values().length];
for (RatEntity.PartyHat hat : RatEntity.PartyHat.values()) {
TEXTURES[hat.ordinal()] = new Identifier(RatsMischief.MOD_ID, "textures/entity/birthday_hats/" + hat.toString().toLowerCase() + ".png");
}
}
return TEXTURES[partyHat.ordinal()];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void render(RatItem animatable, MatrixStack matrices, VertexConsumerProvi
&& stack.getNbt().getCompound(RatsMischief.MOD_ID).contains("rat")
&& stack.getNbt().getCompound(RatsMischief.MOD_ID).getCompound("rat").contains("PartyHat")) {
String hat = stack.getNbt().getCompound(RatsMischief.MOD_ID).getCompound("rat").getString("PartyHat");
Identifier hatTexture = PartyHatFeatureRenderer.TEXTURES[RatEntity.PartyHat.valueOf(hat).ordinal()];
Identifier hatTexture = PartyHatFeatureRenderer.getTexture(RatEntity.PartyHat.valueOf(hat));

MinecraftClient.getInstance().getTextureManager().bindTexture(hatTexture);
this.render(model, animatable, 0.0F, RenderLayer.getEntityCutout(hatTexture), matrices, bufferSource, null, packedLight, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public ArmorFeatureRendererMixin(FeatureRendererContext<T, M> context) {
if (context instanceof PlayerEntityRendererWrapper playerWrapper) {
this.slim = playerWrapper.mischief$isSlim();
}
this.leggingsModel = new PlayerEntityModel<>(wrapper.getContext().getPart(RatsMischiefClient.RAT_MASTER_ARMOR_INNER_LAYER), false);
this.playerModel = new PlayerEntityModel<>(wrapper.getContext().getPart(this.slim ? RatsMischiefClient.RAT_MASTER_ARMOR_OUTER_LAYER_SLIM : RatsMischiefClient.RAT_MASTER_ARMOR_OUTER_LAYER), this.slim);
this.leggingsModel = new PlayerEntityModel<>(wrapper.mischief$getContext().getPart(RatsMischiefClient.RAT_MASTER_ARMOR_INNER_LAYER), false);
this.playerModel = new PlayerEntityModel<>(wrapper.mischief$getContext().getPart(this.slim ? RatsMischiefClient.RAT_MASTER_ARMOR_OUTER_LAYER_SLIM : RatsMischiefClient.RAT_MASTER_ARMOR_OUTER_LAYER), this.slim);
}
}

Expand Down

0 comments on commit 2ed3b05

Please sign in to comment.