Skip to content

Commit

Permalink
performance update
Browse files Browse the repository at this point in the history
  • Loading branch information
ToCraft committed Aug 16, 2024
1 parent de16ece commit 248d720
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_current.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: gradle/actions/setup-gradle@v4

- name: Build
run: ./gradlew check build --parallel
run: ./gradlew check build

- name: Setting mod version
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
cat $GITHUB_WORKSPACE/gradle.properties | grep ^mod_version= >> $GITHUB_ENV
- name: Build + Publish to Maven, Modrinth & CurseForge + Pack the ZIP for GH-Release
run: ./gradlew check build publish modrinth curseforge packTheMod --parallel
run: ./gradlew check build publish modrinth curseforge packTheMod
env:
MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }}
Expand All @@ -69,7 +69,7 @@ jobs:
- name: Extract Changelog for GitHub
run: ./gradlew extractNewestChangelog --parallel
run: ./gradlew extractNewestChangelog
- name: Create version data
run: |
cat $GITHUB_WORKSPACE/gradle.properties | grep ^archives_base_name= >> $GITHUB_ENV
Expand Down Expand Up @@ -100,6 +100,6 @@ jobs:
uses: gradle/actions/setup-gradle@v4

- name: Send Discord Message
run: ./gradlew discordRelease --parallel
run: ./gradlew discordRelease
env:
DISCORD_WEB_HOOK: ${{ secrets.DISCORD_WEB_HOOK }}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import tocraft.walkers.api.PlayerShapeChanger;
import tocraft.walkers.api.variant.ShapeType;

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

// TODO: Throw when no Player can be found
public class RemorphedCommand implements CommandEvents.CommandRegistration {
@Override
Expand Down Expand Up @@ -127,45 +130,68 @@ public void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBu
.then(Commands.argument("player", EntityArgument.players())
.then(Commands.argument("playerUUID", UuidArgument.uuid())
.executes(context -> {
PlayerProfile playerProfile = PlayerProfile.ofId(UuidArgument.getUuid(context, "playerUUID"));
removeSkin(context.getSource(), EntityArgument.getPlayer(context, "player"), playerProfile);
UUID playerUUID = UuidArgument.getUuid(context, "playerUUID");
ServerPlayer player = EntityArgument.getPlayer(context, "player");
CompletableFuture.runAsync(() -> {
PlayerProfile playerProfile = PlayerProfile.ofId(playerUUID);
if (playerProfile == null) {
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("skinshifter.invalid_player", playerUUID), true);
} else {
removeSkin(context.getSource(), player, playerProfile);
}
});
return 1;
}))
.then(Commands.argument("playerName", MessageArgument.message())
.executes(context -> {
String playerName = MessageArgument.getMessage(context, "playerName").getString();
PlayerProfile playerProfile = PlayerProfile.ofName(playerName);
if (playerProfile == null) {
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("skinshifter.invalid_player", playerName), true);
return 0;
}
removeSkin(context.getSource(), EntityArgument.getPlayer(context, "player"), playerProfile);
ServerPlayer player = EntityArgument.getPlayer(context, "player");
CompletableFuture.runAsync(() -> {
PlayerProfile playerProfile = PlayerProfile.ofName(playerName);
if (playerProfile == null) {
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("skinshifter.invalid_player", playerName), true);
} else {
removeSkin(context.getSource(), player, playerProfile);
}
});
return 1;
}))).build();

LiteralCommandNode<CommandSourceStack> addSkin = Commands.literal("addSkin")
.then(Commands.argument("player", EntityArgument.players())
.then(Commands.argument("playerUUID", UuidArgument.uuid())
.executes(context -> {
PlayerProfile playerProfile = PlayerProfile.ofId(UuidArgument.getUuid(context, "playerUUID"));
addSkin(context.getSource(), EntityArgument.getPlayer(context, "player"), playerProfile);
UUID playerUUID = UuidArgument.getUuid(context, "playerUUID");
ServerPlayer player = EntityArgument.getPlayer(context, "player");
CompletableFuture.runAsync(() -> {
PlayerProfile playerProfile = PlayerProfile.ofId(playerUUID);
if (playerProfile == null) {
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("skinshifter.invalid_player", playerUUID), true);
} else {
addSkin(context.getSource(), player, playerProfile);
}
});
return 1;
}))
.then(Commands.argument("playerName", MessageArgument.message())
.executes(context -> {
String playerName = MessageArgument.getMessage(context, "playerName").getString();
PlayerProfile playerProfile = PlayerProfile.ofName(playerName);
if (playerProfile == null) {
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("skinshifter.invalid_player", playerName), true);
return 0;
}
addSkin(context.getSource(), EntityArgument.getPlayer(context, "player"), playerProfile);
ServerPlayer player = EntityArgument.getPlayer(context, "player");
CompletableFuture.runAsync(() -> {
PlayerProfile playerProfile = PlayerProfile.ofName(playerName);
if (playerProfile == null) {
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("skinshifter.invalid_player", playerName), true);
} else {
addSkin(context.getSource(), player, playerProfile);
}
});
return 1;
}))).build();

LiteralCommandNode<CommandSourceStack> clearSkins = Commands.literal("clearSkins")
.then(Commands.argument("player", EntityArgument.players()).executes(context -> {
clearSkins(context.getSource(), EntityArgument.getPlayer(context, "player"));
ServerPlayer player = EntityArgument.getPlayer(context, "player");
clearSkins(context.getSource(), player);
return 1;
})).build();

Expand All @@ -176,19 +202,30 @@ public void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBu
.then(Commands.argument("player", EntityArgument.players())
.then(Commands.argument("playerUUID", UuidArgument.uuid())
.executes(context -> {
PlayerProfile playerProfile = PlayerProfile.ofId(UuidArgument.getUuid(context, "playerUUID"));
hasSkin(context.getSource(), EntityArgument.getPlayer(context, "player"), playerProfile);
UUID playerUUID = UuidArgument.getUuid(context, "playerUUID");
ServerPlayer player = EntityArgument.getPlayer(context, "player");
CompletableFuture.runAsync(() -> {
PlayerProfile playerProfile = PlayerProfile.ofId(playerUUID);
if (playerProfile == null) {
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("skinshifter.invalid_player", playerUUID), true);
} else {
hasSkin(context.getSource(), player, playerProfile);
}
});
return 1;
}))
.then(Commands.argument("playerName", MessageArgument.message())
.executes(context -> {
String playerName = MessageArgument.getMessage(context, "playerName").getString();
PlayerProfile playerProfile = PlayerProfile.ofName(playerName);
if (playerProfile == null) {
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("skinshifter.invalid_player", playerName), true);
return 0;
}
hasSkin(context.getSource(), EntityArgument.getPlayer(context, "player"), playerProfile);
ServerPlayer player = EntityArgument.getPlayer(context, "player");
CompletableFuture.runAsync(() -> {
PlayerProfile playerProfile = PlayerProfile.ofName(playerName);
if (playerProfile == null) {
CCommandSourceStack.sendSuccess(context.getSource(), TComponent.translatable("skinshifter.invalid_player", playerName), true);
} else {
hasSkin(context.getSource(), player, playerProfile);
}
});
return 1;
}))).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

import com.mojang.authlib.GameProfile;
import dev.tocraft.skinshifter.SkinShifter;
import dev.tocraft.skinshifter.data.SkinCache;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tocraft.craftedcore.platform.PlayerProfile;

import java.util.UUID;

//#if MC>1201
import net.minecraft.client.resources.PlayerSkin;
//#else
//$$ import org.jetbrains.annotations.Nullable;
//#endif

@Environment(EnvType.CLIENT)
Expand All @@ -26,8 +24,8 @@ public class FakeClientPlayer extends AbstractClientPlayer {
public FakeClientPlayer(ClientLevel level, @NotNull PlayerProfile skinProfile) {
super(level, new GameProfile(skinProfile.id(), skinProfile.name()));
if (skinProfile.skin() != null) {
ResourceLocation skinId = SkinCache.getCustomSkinId(skinProfile.skin());
ResourceLocation capeId = SkinShifter.CONFIG.changeCape ? SkinCache.getCustomCapeId(skinProfile.cape()) : null;
ResourceLocation skinId = skinProfile.getSkinId();
ResourceLocation capeId = SkinShifter.CONFIG.changeCape ? skinProfile.getCapeId() : null;
PlayerSkin.Model model = skinProfile.isSlim() ? PlayerSkin.Model.SLIM : PlayerSkin.Model.WIDE;
this.skin = new PlayerSkin(skinId, skinProfile.skin().toString(), capeId, null, model, true);
} else {
Expand All @@ -51,9 +49,9 @@ public FakeClientPlayer(ClientLevel level, @NotNull PlayerProfile skinProfile) {
//$$ super(clientLevel, new GameProfile(skinProfile.id(), skinProfile.name()));
//$$
//$$ if (skinProfile.skin() != null) {
//$$ skinId = SkinCache.getCustomSkinId(skinProfile.skin());
//$$ skinId = skinProfile.getSkinId();
//$$ modelType = skinProfile.isSlim() ? "slim" : "default";
//$$ cloakId = SkinCache.getCustomCapeId(skinProfile.cape());
//$$ cloakId = skinProfile.getCapeId();
//$$ } else {
//$$ skinId = null;
//$$ modelType = null;
Expand Down
55 changes: 30 additions & 25 deletions common/src/main/java/tocraft/remorphed/screen/RemorphedScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public void init() {

CompletableFuture.runAsync(() -> {
populateUnlockedRenderEntities(minecraft.player);
populateUnlockedRenderPlayers(minecraft.player);

ShapeType<? extends LivingEntity> currentShape = ShapeType.from(PlayerShape.getCurrentShape(minecraft.player));

// handle favorites
Expand Down Expand Up @@ -119,6 +117,7 @@ else if (firstIsFav) {
}

if (Remorphed.foundSkinShifter) {
populateUnlockedRenderPlayers(minecraft.player);
UUID currentSkin = SkinShifter.getCurrentSkin(minecraft.player);

unlockedSkins.sort((first, second) -> {
Expand All @@ -143,30 +142,30 @@ else if (firstIsFav) {
}

populateShapeWidgets(unlockedShapes, unlockedSkins);
});

// implement search handler
searchBar.setResponder(text -> {
setFocused(searchBar);

// Only re-filter if the text contents changed
if (!lastSearchContents.equals(text)) {
((ScreenAccessor) this).getSelectables().removeIf(button -> button instanceof EntityWidget);
children().removeIf(button -> button instanceof EntityWidget);

List<ShapeType<?>> filteredShapes = unlockedShapes
.stream()
.filter(type -> text.isEmpty() || ShapeType.createTooltipText(renderEntities.get(type)).getString().toUpperCase().contains(text.toUpperCase()) || EntityType.getKey(type.getEntityType()).toString().toUpperCase().contains(text.toUpperCase()))
.toList();
List<PlayerProfile> filteredSkins = unlockedSkins
.stream()
.filter(skin -> text.isEmpty() || skin.name().toUpperCase().contains(text.toUpperCase()) || skin.id().toString().contains(text.toUpperCase()))
.toList();

populateShapeWidgets(filteredShapes, filteredSkins);
}
// implement search handler
searchBar.setResponder(text -> {
setFocused(searchBar);

// Only re-filter if the text contents changed
if (!lastSearchContents.equals(text)) {
((ScreenAccessor) this).getSelectables().removeIf(button -> button instanceof EntityWidget);
children().removeIf(button -> button instanceof EntityWidget);

List<ShapeType<?>> filteredShapes = unlockedShapes
.stream()
.filter(type -> text.isEmpty() || ShapeType.createTooltipText(renderEntities.get(type)).getString().toUpperCase().contains(text.toUpperCase()) || EntityType.getKey(type.getEntityType()).toString().toUpperCase().contains(text.toUpperCase()))
.toList();
List<PlayerProfile> filteredSkins = unlockedSkins
.stream()
.filter(skin -> text.isEmpty() || skin.name().toUpperCase().contains(text.toUpperCase()) || skin.id().toString().contains(text.toUpperCase()))
.toList();

populateShapeWidgets(filteredShapes, filteredSkins);
}

lastSearchContents = text;
lastSearchContents = text;
});
});
}

Expand Down Expand Up @@ -434,7 +433,13 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (mouseY < 35) {
return searchBar.mouseClicked(mouseX, mouseY, button) || helpButton.mouseClicked(mouseX, mouseY, button) || variantsButton.mouseClicked(mouseX, mouseY, button) || traitsButton.mouseClicked(mouseX, mouseY, button) || playerButton.mouseClicked(mouseX, mouseY, button) || specialShapeButton.mouseClicked(mouseX, mouseY, button);
} else {
return super.mouseClicked(mouseX, mouseY, button);
for (ShapeWidget shapeWidget : shapeWidgets) {
if (shapeWidget.mouseClicked(mouseX, mouseY, button)) {
this.setFocused(shapeWidget);
return true;
}
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tocraft.remorphed.screen.widget;

import dev.tocraft.skinshifter.SkinShifter;
import dev.tocraft.skinshifter.data.SkinCache;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
Expand All @@ -17,6 +16,7 @@
import tocraft.walkers.impl.PlayerDataProvider;
import tocraft.walkers.network.impl.SwapPackets;
import net.minecraft.client.gui.components.AbstractButton;
import java.util.concurrent.CompletableFuture;

//#if MC>=1201
import net.minecraft.client.gui.GuiGraphics;
Expand Down Expand Up @@ -59,9 +59,12 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float
//#endif
if (Remorphed.foundSkinShifter && SkinShifter.getCurrentSkin(player) != null) {
// still render own skin as icon when in another skin
PlayerProfile playerProfile = PlayerProfile.ofId(player.getUUID());
PlayerProfile playerProfile = PlayerProfile.getCachedProfile(player.getUUID());
if (playerProfile != null && playerProfile.skin() != null) {
skinLocation = SkinCache.getCustomSkinId(playerProfile.skin());
skinLocation = playerProfile.getSkinId();
} else {
// cache profile asynchronous
CompletableFuture.runAsync(() -> PlayerProfile.ofId(player.getUUID()));
}
}

Expand Down
4 changes: 2 additions & 2 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ tasks.withType<ProcessResources> {

loom {
forge {
mixinConfigs.add("skinshifter.mixins.json")
mixinConfigs.add("remorphed.mixins.json")
}
}

dependencies {
modApi("dev.tocraft:craftedcore-forge:${parent!!.name}-${rootProject.properties["craftedcore_version"]}")
modApi("dev.tocraft:walkers-forge:${parent!!.name}-${rootProject.properties["woodwalkers_version"]}")
modApi("dev.tocraft:skinshifter-forge:${parent!!.name}-${rootProject.properties["skinshifter_version"]}")
}
}
Loading

0 comments on commit 248d720

Please sign in to comment.