From cc5c8c8394703fd2447716ce40cfba6a4e9dae76 Mon Sep 17 00:00:00 2001 From: samolego <34912839+samolego@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:34:20 +0100 Subject: [PATCH] npc selections glow again --- .github/workflows/fabric-build.yml | 4 +- .github/workflows/fabric-release.yml | 6 +-- .github/workflows/forge-build.yml | 46 ------------------- .github/workflows/forge-release.yml | 45 ------------------ build.gradle | 5 +- .../samo_lego/taterzens/common/Taterzens.java | 1 - .../common/commands/PresetCommand.java | 2 +- .../common/commands/edit/MountCommand.java | 2 +- .../common/commands/edit/SkinCommand.java | 4 +- ...ServerPlayerMixinCast_ITaterzenEditor.java | 4 +- .../taterzens/common/npc/TaterzenNPC.java | 35 +++++++------- .../taterzens/common/platform/Platform.java | 19 ++++---- .../taterzens/fabric/gui/EditorGUI.java | 2 +- .../fabric/platform/FabricPlatform.java | 2 +- 14 files changed, 42 insertions(+), 135 deletions(-) delete mode 100644 .github/workflows/forge-build.yml delete mode 100644 .github/workflows/forge-release.yml diff --git a/.github/workflows/fabric-build.yml b/.github/workflows/fabric-build.yml index 1c7f34a62..50a0bb823 100644 --- a/.github/workflows/fabric-build.yml +++ b/.github/workflows/fabric-build.yml @@ -37,10 +37,10 @@ jobs: if: ${{ runner.os != 'Windows' }} run: chmod +x ./gradlew - name: build - run: ./gradlew fabric:build + run: ./gradlew build - name: capture build artifacts if: ${{ runner.os == 'Linux' }} uses: actions/upload-artifact@v2 with: name: Artifacts - path: fabric/build/libs/ + path: build/libs/ diff --git a/.github/workflows/fabric-release.yml b/.github/workflows/fabric-release.yml index 01fe58d8f..a1a7dc9f1 100644 --- a/.github/workflows/fabric-release.yml +++ b/.github/workflows/fabric-release.yml @@ -32,16 +32,16 @@ jobs: run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew fabric:build --stacktrace + run: ./gradlew :build --stacktrace - name: Upload GitHub release uses: AButler/upload-release-assets@v2.0 with: - files: 'fabric/build/libs/*.jar' + files: 'build/libs/*.jar' repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Publish with Gradle - run: ./gradlew fabric:modrinth fabric:curseforge --stacktrace + run: ./gradlew modrinth curseforge --stacktrace env: CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }} MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} diff --git a/.github/workflows/forge-build.yml b/.github/workflows/forge-build.yml deleted file mode 100644 index a733ae9af..000000000 --- a/.github/workflows/forge-build.yml +++ /dev/null @@ -1,46 +0,0 @@ -# Automatically build the project and run any configured tests for every push -# and submitted pull request. This can help catch issues that only occur on -# certain platforms or Java versions, and provides a first line of defence -# against bad commits. - -name: Forge Build -on: [pull_request, push] - -jobs: - build: - strategy: - matrix: - # Use these Java versions - java: [17] # Latest version - # and run on both Linux and Windows - os: [ubuntu-20.04, windows-latest] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/cache@v2 - with: - path: | - ~/.gradle/loom-cache - ~/.gradle/caches - ~/.gradle/wrapper - key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - gradle- - - name: checkout repository - uses: actions/checkout@v2 - - name: validate gradle wrapper - uses: gradle/wrapper-validation-action@v1 - - name: setup jdk ${{ matrix.java }} - uses: actions/setup-java@v1 - with: - java-version: ${{ matrix.java }} - - name: make gradle wrapper executable - if: ${{ runner.os != 'Windows' }} - run: chmod +x ./gradlew - - name: build - run: ./gradlew forge:build - - name: capture build artifacts - if: ${{ runner.os == 'Linux' }} - uses: actions/upload-artifact@v2 - with: - name: Artifacts - path: forge/build/libs/ diff --git a/.github/workflows/forge-release.yml b/.github/workflows/forge-release.yml deleted file mode 100644 index eb75e97ec..000000000 --- a/.github/workflows/forge-release.yml +++ /dev/null @@ -1,45 +0,0 @@ -# Taken from Leuokcyte (https://github.com/NucleoidMC/leukocyte/blob/main/.github/workflows/release.yml) - -name: Forge Release - -on: - release: - types: - - published - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/cache@v2 - with: - path: | - ~/.gradle/loom-cache - ~/.gradle/caches - ~/.gradle/wrapper - key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - gradle- - - uses: actions/checkout@v2 - - name: Set up JDK - uses: actions/setup-java@v1 - with: - java-version: 17 - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - - name: Build and publish with Gradle - run: ./gradlew forge:build forge:curseforge forge:modrinth --stacktrace - env: - CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }} - MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} - CHANGELOG: ${{ github.event.release.body }} - - - name: Upload GitHub release - uses: AButler/upload-release-assets@v2.0 - with: - files: 'forge/build/libs/*-forge.jar' - repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/build.gradle b/build.gradle index b862ba2d2..36d9ba7e4 100644 --- a/build.gradle +++ b/build.gradle @@ -45,12 +45,13 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - // Dependencies + // Mod Dependencies + // Carpet Mod modCompileOnly("com.github.gnembon:fabric-carpet:${project.carpet_core_version}") // Disguiselib //modCompileOnly("xyz.nucleoid:disguiselib-fabric:${project.disguiselib_version}") - //modCompileOnly 'com.github.NucleoidMC:DisguiseLib:1.20.4-SNAPSHOT' + //modImplementation(include('com.github.NucleoidMC:DisguiseLib:90bf223196')) // Permission API modImplementation(include('me.lucko:fabric-permissions-api:0.1-SNAPSHOT')) diff --git a/src/main/java/org/samo_lego/taterzens/common/Taterzens.java b/src/main/java/org/samo_lego/taterzens/common/Taterzens.java index d22062062..849a2f9f2 100644 --- a/src/main/java/org/samo_lego/taterzens/common/Taterzens.java +++ b/src/main/java/org/samo_lego/taterzens/common/Taterzens.java @@ -87,7 +87,6 @@ public Taterzens(Platform platform) { LanguageUtil.setupLanguage(); PolymerEntityUtils.registerType(TATERZEN_TYPE.get()); - } /** diff --git a/src/main/java/org/samo_lego/taterzens/common/commands/PresetCommand.java b/src/main/java/org/samo_lego/taterzens/common/commands/PresetCommand.java index 7986ea644..5adcd643b 100644 --- a/src/main/java/org/samo_lego/taterzens/common/commands/PresetCommand.java +++ b/src/main/java/org/samo_lego/taterzens/common/commands/PresetCommand.java @@ -60,7 +60,7 @@ private static int loadTaterzenFromPreset(CommandContext con ((ITaterzenEditor) source.getPlayerOrException()).selectNpc(taterzenNPC); - taterzenNPC.sendProfileUpdates(); + taterzenNPC.broadcastProfileUpdates(); source.sendSuccess(() -> successText("taterzens.command.preset.import.success", filename), diff --git a/src/main/java/org/samo_lego/taterzens/common/commands/edit/MountCommand.java b/src/main/java/org/samo_lego/taterzens/common/commands/edit/MountCommand.java index 95f4d2a4b..24b830232 100644 --- a/src/main/java/org/samo_lego/taterzens/common/commands/edit/MountCommand.java +++ b/src/main/java/org/samo_lego/taterzens/common/commands/edit/MountCommand.java @@ -48,7 +48,7 @@ public static int mountTaterzen(CommandContext context) thro taterzen.startRiding(finalToMount, true); feedbackText = successText("taterzens.command.mount", taterzen.getName().getString(), finalToMount.getName().getString()); } - taterzen.sendProfileUpdates(); + taterzen.broadcastProfileUpdates(); src.sendSuccess(() -> feedbackText, false); }); } diff --git a/src/main/java/org/samo_lego/taterzens/common/commands/edit/SkinCommand.java b/src/main/java/org/samo_lego/taterzens/common/commands/edit/SkinCommand.java index e8f38ac10..5fa4772b7 100644 --- a/src/main/java/org/samo_lego/taterzens/common/commands/edit/SkinCommand.java +++ b/src/main/java/org/samo_lego/taterzens/common/commands/edit/SkinCommand.java @@ -120,7 +120,7 @@ private static int setCustomSkin(CommandContext context) thr skinTag.putString("signature", signature); taterzen.setSkinFromTag(skinTag); - taterzen.sendProfileUpdates(); + taterzen.broadcastProfileUpdates(); context.getSource().sendSuccess(() -> @@ -147,7 +147,7 @@ private static int copySkinLayers(CommandContext context) th Byte skinLayers = player.getEntityData().get(getPLAYER_MODE_CUSTOMISATION()); taterzen.setSkinLayers(skinLayers); - taterzen.sendProfileUpdates(); + taterzen.broadcastProfileUpdates(); source.sendSuccess(() -> successText("taterzens.command.skin.mirrored", taterzen.getName().getString()), false diff --git a/src/main/java/org/samo_lego/taterzens/common/mixin/player/ServerPlayerMixinCast_ITaterzenEditor.java b/src/main/java/org/samo_lego/taterzens/common/mixin/player/ServerPlayerMixinCast_ITaterzenEditor.java index 4d541db5b..69822326d 100644 --- a/src/main/java/org/samo_lego/taterzens/common/mixin/player/ServerPlayerMixinCast_ITaterzenEditor.java +++ b/src/main/java/org/samo_lego/taterzens/common/mixin/player/ServerPlayerMixinCast_ITaterzenEditor.java @@ -137,11 +137,11 @@ public boolean selectNpc(@Nullable TaterzenNPC npc) { this.selectedNpc = npc; if (npc != null) { - npc.sendProfileUpdates(); + npc.broadcastProfileUpdates(); } if (selectedNpc != null) { - selectedNpc.sendProfileUpdates(); + selectedNpc.broadcastProfileUpdates(); } return true; diff --git a/src/main/java/org/samo_lego/taterzens/common/npc/TaterzenNPC.java b/src/main/java/org/samo_lego/taterzens/common/npc/TaterzenNPC.java index 414a49bb9..9873a1c9d 100644 --- a/src/main/java/org/samo_lego/taterzens/common/npc/TaterzenNPC.java +++ b/src/main/java/org/samo_lego/taterzens/common/npc/TaterzenNPC.java @@ -1,6 +1,5 @@ package org.samo_lego.taterzens.common.npc; -import com.google.common.collect.Lists; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; @@ -578,14 +577,14 @@ public void setCustomName(Component name) { this.gameProfile = new GameProfile(this.getUUID(), profileName); if (skin != null) { this.setSkinFromTag(skin); - this.sendProfileUpdates(); + this.broadcastProfileUpdates(); } } /** * Updates Taterzen's {@link GameProfile} for others. */ - public void sendProfileUpdates() { + public void broadcastProfileUpdates() { if (this.level().isClientSide()) return; ServerChunkCache manager = (ServerChunkCache) this.level().getChunkSource(); @@ -610,7 +609,7 @@ public void applySkin(GameProfile texturesProfile) { setSkinFromTag(writeSkinToTag(texturesProfile)); // Sending updates - this.sendProfileUpdates(); + this.broadcastProfileUpdates(); } /** @@ -726,7 +725,7 @@ public void readAdditionalSaveData(CompoundTag tag) { ListTag pathTargets = (ListTag) npcTag.get("PathTargets"); if (pathTargets != null) { - if (pathTargets.size() > 0) { + if (!pathTargets.isEmpty()) { pathTargets.forEach(posTag -> { if (posTag instanceof CompoundTag pos) { BlockPos target = new BlockPos(pos.getInt("x"), pos.getInt("y"), pos.getInt("z")); @@ -739,7 +738,7 @@ public void readAdditionalSaveData(CompoundTag tag) { this.npcData.currentMoveTarget = npcTag.getInt("CurrentMoveTarget"); ListTag messages = (ListTag) npcTag.get("Messages"); - if (messages != null && messages.size() > 0) { + if (messages != null && !messages.isEmpty()) { messages.forEach(msgTag -> { CompoundTag msgCompound = (CompoundTag) msgTag; this.addMessage(TextUtil.fromNbtElement(msgCompound.get("Message")), msgCompound.getInt("Delay")); @@ -768,7 +767,7 @@ public void readAdditionalSaveData(CompoundTag tag) { // Profession initialising ListTag professions = (ListTag) npcTag.get("Professions"); - if (professions != null && professions.size() > 0) { + if (professions != null && !professions.isEmpty()) { professions.forEach(professionTag -> { CompoundTag professionCompound = (CompoundTag) professionTag; @@ -1884,17 +1883,17 @@ public EntityType getPolymerEntityType(ServerPlayer player) { @Override public void modifyRawTrackedData(List> data, ServerPlayer player, boolean initial) { // Change game profile + skin layers - } - - @Override - public List> getPolymerVisibleEquipment(List> items, ServerPlayer player) { - List> list = Lists.newArrayListWithCapacity(EquipmentSlot.values().length); - - for (var slot : EquipmentSlot.values()) { - list.add(Pair.of(slot, this.getItemBySlot(slot))); - } - - return list; + ((ITaterzenEditor) player).getSelectedNpc().ifPresent(npc -> { + if (this == npc && config.glowSelectedNpc) { + data.removeIf(value -> value.id() == 7); + // Modify Taterzen to have fake glowing effect for the player + var flags = this.entityData.get(Entity.DATA_SHARED_FLAGS_ID); + flags = (byte) (flags | 1 << Entity.FLAG_GLOWING); + + SynchedEntityData.DataValue glowingTag = SynchedEntityData.DataValue.create(Entity.DATA_SHARED_FLAGS_ID, flags); + data.add(glowingTag); + } + }); } @Override diff --git a/src/main/java/org/samo_lego/taterzens/common/platform/Platform.java b/src/main/java/org/samo_lego/taterzens/common/platform/Platform.java index e16d4b6a3..3ded14fe6 100644 --- a/src/main/java/org/samo_lego/taterzens/common/platform/Platform.java +++ b/src/main/java/org/samo_lego/taterzens/common/platform/Platform.java @@ -10,26 +10,26 @@ /** * Base class for platform implementations. */ -public abstract class Platform { +public interface Platform { /** * Gets the path to the directory where the config files are stored. * @return the path to the directory where the config files are stored. */ - public abstract Path getConfigDirPath(); + Path getConfigDirPath(); /** * Checks whether certain mod is loaded. * @param modId the mod id. * @return true if the mod is loaded, false otherwise. */ - public abstract boolean isModLoaded(String modId); + boolean isModLoaded(String modId); /** * Gets size of item registry. * @return size of item registry. */ - public abstract int getItemRegistrySize(); + int getItemRegistrySize(); /** * Checks for permission of provided command source. @@ -38,18 +38,17 @@ public abstract class Platform { * @param fallbackLevel the fallback level to use if the permission node is not set. * @return true if the command source has the permission node, false otherwise. */ - public abstract boolean checkPermission(CommandSourceStack source, String permissionNode, int fallbackLevel); + boolean checkPermission(CommandSourceStack source, String permissionNode, int fallbackLevel); /** * Registers the taterzen entity type. */ - public abstract void registerTaterzenType(); + void registerTaterzenType(); - public void openEditorGui(ServerPlayer player) { - } + void openEditorGui(ServerPlayer player); - public abstract void disguiseAs(TaterzenNPC taterzen, Entity entity); + void disguiseAs(TaterzenNPC taterzen, Entity entity); - public abstract void clearDisguise(TaterzenNPC taterzen); + void clearDisguise(TaterzenNPC taterzen); } diff --git a/src/main/java/org/samo_lego/taterzens/fabric/gui/EditorGUI.java b/src/main/java/org/samo_lego/taterzens/fabric/gui/EditorGUI.java index eff1bae12..8c47429ea 100644 --- a/src/main/java/org/samo_lego/taterzens/fabric/gui/EditorGUI.java +++ b/src/main/java/org/samo_lego/taterzens/fabric/gui/EditorGUI.java @@ -42,7 +42,7 @@ public static SimpleGui createCommandGui(ServerPlayer player, @Nullable SimpleGu CommandNode childNode = (CommandNode) parentNode.getChildren().toArray()[0]; if (childNode instanceof ArgumentCommandNode) { givenInput = false; - } else if (childNode.getChildren().size() > 0) { + } else if (!childNode.getChildren().isEmpty()) { currentCommandPath.add(parentNode.getName()); } else { break; diff --git a/src/main/java/org/samo_lego/taterzens/fabric/platform/FabricPlatform.java b/src/main/java/org/samo_lego/taterzens/fabric/platform/FabricPlatform.java index 45eba5bfb..6e1b804d8 100644 --- a/src/main/java/org/samo_lego/taterzens/fabric/platform/FabricPlatform.java +++ b/src/main/java/org/samo_lego/taterzens/fabric/platform/FabricPlatform.java @@ -24,7 +24,7 @@ import static org.samo_lego.taterzens.common.commands.NpcCommand.npcNode; import static org.samo_lego.taterzens.fabric.gui.EditorGUI.createCommandGui; -public class FabricPlatform extends Platform { +public class FabricPlatform implements Platform { private static final int REGISTRY_ITEMS_SIZE = ((AMappedRegistry) BuiltInRegistries.ITEM).getById().size();