Skip to content

Commit

Permalink
Fix the silly
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Mar 25, 2024
1 parent f59d2df commit b8e75a3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Mod Information
mod.version=0.6.1
mod.version=0.6.2
mod.name=cicada-lib
mod.maven_group = nl.enjarai
mod.target=[VERSIONED]
Expand Down
31 changes: 23 additions & 8 deletions src/main/java/nl/enjarai/cicada/mixin/PlayerEntityModelMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.Direction;
import nl.enjarai.cicada.Cicada;
import nl.enjarai.cicada.util.CapeHandler;
import nl.enjarai.cicada.util.SillyHairsModel;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.EnumSet;
import java.util.NoSuchElementException;

@Mixin(PlayerEntityModel.class)
public abstract class PlayerEntityModelMixin<T extends LivingEntity> extends BipedEntityModel<T> implements SillyHairsModel {
@Unique
@Nullable
private ModelPart sillyHairsLeft;
@Unique
@Nullable
private ModelPart sillyHairsRight;

public PlayerEntityModelMixin(ModelPart root) {
Expand All @@ -37,8 +41,13 @@ public PlayerEntityModelMixin(ModelPart root) {
)
)
private void initSillyHairs(ModelPart root, boolean thinArms, CallbackInfo ci) {
sillyHairsLeft = root.getChild("silly_hairs_left");
sillyHairsRight = root.getChild("silly_hairs_right");
try {
sillyHairsLeft = root.getChild("silly_hairs_left");
sillyHairsRight = root.getChild("silly_hairs_right");
} catch (NoSuchElementException e) {
// Fail quietly, this stuff is really not important
CapeHandler.sillyHairsFailed();
}
}

@Inject(
Expand Down Expand Up @@ -67,17 +76,23 @@ private static void textureSillyHairs(Dilation dilation, boolean slim, CallbackI
public void cicada_lib$renderSillyHairs(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, boolean right, float wobble) {
var sillyHairs = right ? sillyHairsRight : sillyHairsLeft;

sillyHairs.roll = wobble;
if (sillyHairs != null) {
sillyHairs.roll = wobble;

sillyHairs.render(matrices, vertices, light, overlay);
sillyHairs.render(matrices, vertices, light, overlay);
}
}

@Inject(
method = "setVisible",
at = @At("RETURN")
)
private void setSillyHairsVisible(boolean visible, CallbackInfo ci) {
sillyHairsLeft.visible = visible;
sillyHairsRight.visible = visible;
if (sillyHairsLeft != null) {
sillyHairsLeft.visible = visible;
}
if (sillyHairsRight != null) {
sillyHairsRight.visible = visible;
}
}
}
7 changes: 6 additions & 1 deletion src/main/java/nl/enjarai/cicada/util/CapeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public final class CapeHandler {

private static final ExecutorService capeExecutor = Executors.newFixedThreadPool(2);
private static final HashMap<UUID, CapeHandler> instances = new HashMap<>();
private static boolean sillyHairsFailed = false;

public static void shutdown() {
capeExecutor.shutdownNow();
Expand All @@ -54,6 +55,10 @@ private static HttpURLConnection getConnection(String url) throws IOException {
return connection;
}

public static void sillyHairsFailed() {
sillyHairsFailed = true;
}


public CapeHandler(GameProfile profile) {
uuid = profile.getId();
Expand All @@ -74,7 +79,7 @@ public boolean hasElytra() {
}

public boolean hasSillyHairs() {
return hasDecorations && meta.sillyHairs();
return !sillyHairsFailed && hasDecorations && meta.sillyHairs();
}

public boolean disableHeadOverlay() {
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"enjarai"
],
"contact": {
"homepage": "https://enjarai.nl/",
"sources": "https://github.com/enjarai/cicada-lib"
"homepage": "https://enjarai.dev/",
"sources": "https://github.com/enjarai/cicada-lib",
"issues": "https://github.com/enjarai/cicada-lib/issues"
},

"license": "MIT",
Expand Down

0 comments on commit b8e75a3

Please sign in to comment.