Skip to content

Commit

Permalink
Fix all caching issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
IMB11 committed Jun 29, 2024
1 parent ef90987 commit e9963d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,11 @@ public int getHeight() {

skinModelButton = new CyclingButtonWidget.Builder<String>(Text::of)
.values("classic", "slim")
.build(0, 0, 192, 20, Text.translatable("skinshuffle.edit.source.skin_model"));
.build(0, 0, 192, 20, Text.translatable("skinshuffle.edit.source.skin_model"), (widget, val) -> {
SkinPreset preset = PresetEditScreen.this.preset;
preset.getSkin().setModel(val);
PresetEditScreen.this.entity = new DummyClientPlayerEntity(null, UUID.randomUUID(), preset.getSkin().getTexture(), preset.getSkin().getModel());
});

if (currentSourceType != null) {
gridAdder.add(new CyclingButtonWidget<>(0,
Expand Down Expand Up @@ -386,17 +390,16 @@ private void loadSkin() {
};

preset.setSkin(skin);

// Wait 1 sec before refreshing the entity to prevent flickering.
CompletableFuture.runAsync(() -> {
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
PresetEditScreen.this.entity = new DummyClientPlayerEntity(null, UUID.randomUUID(), skin.getTexture(), skin.getModel());
}, Util.getIoWorkerExecutor());
skin.getTexture();
}

CompletableFuture.runAsync(() -> {
while(preset.getSkin().isLoading()) {
Thread.onSpinWait();
}

PresetEditScreen.this.entity = new DummyClientPlayerEntity(null, UUID.randomUUID(), preset.getSkin().getTexture(), preset.getSkin().getModel());
}, Util.getIoWorkerExecutor());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@
import net.minecraft.client.util.GlfwUtil;
import net.minecraft.entity.LivingEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Util;
import nl.enjarai.cicada.api.cursed.DummyClientPlayerEntity;

import java.util.UUID;
import java.util.concurrent.CompletableFuture;

public abstract class PresetWidget<S extends CarouselScreen> extends AbstractCardWidget<S> {
protected final SkinPreset skinPreset;
protected VariableSpruceButtonWidget editButton;
protected VariableSpruceButtonWidget copyButton;
protected VariableSpruceButtonWidget deleteButton;
private final boolean showButtons;
protected boolean hasRefreshed = false;
protected LivingEntity entity;
protected double scaleFactor;

Expand All @@ -59,6 +60,15 @@ public PresetWidget(S parent, SkinPreset skinPreset) {

this.skinPreset = skinPreset;
this.entity = new DummyClientPlayerEntity(null, UUID.randomUUID(), skinPreset.getSkin().getTexture(), skinPreset.getSkin().getModel());

CompletableFuture.runAsync(() -> {
while(skinPreset.getSkin().isLoading()) {
Thread.onSpinWait();
}

this.entity = new DummyClientPlayerEntity(null, UUID.randomUUID(), skinPreset.getSkin().getTexture(), skinPreset.getSkin().getModel());
}, Util.getIoWorkerExecutor());

this.showButtons = true;

if (showButtons) {
Expand Down Expand Up @@ -132,11 +142,6 @@ protected void renderBackground(DrawContext graphics, int mouseX, int mouseY, fl
protected void renderWidget(DrawContext graphics, int mouseX, int mouseY, float delta) {
super.renderWidget(graphics, mouseX, mouseY, delta);

if(!hasRefreshed) {
hasRefreshed = true;
refreshEntity();
}

var margin = this.client.textRenderer.fontHeight / 2;
var name = this.skinPreset.getName() != null ? this.skinPreset.getName() : "Unnamed Preset";
var nameWidth = this.client.textRenderer.getWidth(name);
Expand Down

0 comments on commit e9963d2

Please sign in to comment.