Skip to content
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

fix: rat item rendering reading from uninitialised hat texture array #158

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading