Skip to content

Commit

Permalink
add lazilyDiffTarget task
Browse files Browse the repository at this point in the history
  • Loading branch information
supersaiyansubtlety committed Dec 4, 2024
1 parent 9595fd5 commit dfee3c2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected ProcessMappingsExtension applyImpl(@NotNull Project project) {
insertAutoGeneratedMappings.flatMap(AddProposedMappingsTask::getOutputMappings)
));

// TODO LATER move this to build/ once generate-diff.yml uses generateDiff
// TODO LATER move this to build/ once generate-diff.yml uses lazilyDiffTarget
task.getOutput().convention(this.getProjectDir().dir("namedSrc"));
}
);
Expand Down
41 changes: 36 additions & 5 deletions buildSrc/src/main/java/quilt/internal/plugin/TargetDiffPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.Task;
Expand All @@ -20,6 +21,7 @@
import quilt.internal.constants.Constants;
import quilt.internal.constants.Classifiers;
import quilt.internal.constants.Extensions;
import quilt.internal.constants.Groups;
import quilt.internal.extension.QuiltMappingsExtension;
import quilt.internal.decompile.javadoc.MappingsJavadocProvider;
import quilt.internal.plugin.abstraction.MappingsProjectPlugin;
Expand All @@ -40,15 +42,16 @@

import java.io.FileReader;
import java.io.IOException;
import java.util.Collections;

import static quilt.internal.constants.Constants.UNPICK_NAME;
import static quilt.internal.task.build.MappingsV2JarTask.JAR_MAPPINGS_PATH;

/**
* {@linkplain TaskContainer#register Registers} tasks that download the latest published Quilt Mappings for the current
* {@link QuiltMappingsExtension#getMinecraftVersion() minecraftVersion} so the
* {@value DiffTargetTask#DIFF_TARGET_TASK_NAME} task can {@value DiffDirectoriesTask#DIFF_COMMAND}
* them with this project's mappings.
* {@value DiffTargetTask#DIFF_TARGET_TASK_NAME} (or {@value #LAZILY_DIFF_TARGET_TASK_NAME}) task can
* {@value DiffDirectoriesTask#DIFF_COMMAND} them with this project's mappings.
* <p>
* The generated {@value DiffDirectoriesTask#DIFF_COMMAND} is useful when reviewing new mappings.
* <p>
Expand Down Expand Up @@ -80,6 +83,16 @@
* </ul>
*/
public abstract class TargetDiffPlugin implements MappingsProjectPlugin {
/**
* A wrapper for {@value DiffTargetTask#DIFF_TARGET_TASK_NAME} that conditionally depends on
* {@value DiffTargetTask#DIFF_TARGET_TASK_NAME} only if its
* {@link TargetVersionConsumingTask#getTargetVersion() targetVersion} {@link Provider#isPresent() isPresent}.
* <p>
* This is a hack to prevent unnecessarily generating sources using local mappings when
* {@link TargetVersionConsumingTask#getTargetVersion() targetVersion} isn't present.
*/
public static final String LAZILY_DIFF_TARGET_TASK_NAME = "lazilyDiffTarget";

@Override
public void apply(@NotNull Project project) {
final PluginContainer plugins = project.getPlugins();
Expand Down Expand Up @@ -232,13 +245,12 @@ public void apply(@NotNull Project project) {
.map(dest -> dest.file(JAR_MAPPINGS_PATH))
));

// TODO LATER move this to build/ once generate-diff.yml uses generateDiff
// TODO LATER move this to build/ once generate-diff.yml uses lazilyDiffTarget
task.getOutput().convention(this.getProjectDir().dir("namedTargetSrc"));
}
);

// TODO LATER use this in generate-diff.yml
tasks.register(
final var diffTarget = tasks.register(
DiffTargetTask.DIFF_TARGET_TASK_NAME,
DiffTargetTask.class,
task -> {
Expand All @@ -251,6 +263,25 @@ public void apply(@NotNull Project project) {
task.getDest().convention(this.getBuildDir().file("target.diff"));
}
);

// TODO LATER use this in generate-diff.yml
tasks.register(
LAZILY_DIFF_TARGET_TASK_NAME,
DefaultTask.class,
task -> {
task.setGroup(Groups.DIFF);

// This provider is safe to get at configuration time because it comes from a ValueSource.
// Configuring diffTarget's targetVersion to a provider mapped from a task output would break this.
final Property<String> targetVersion = diffTarget.get().getTargetVersion();
targetVersion.finalizeValue();
final boolean targetVersionPresent = targetVersion.isPresent();

task.setEnabled(targetVersionPresent);

task.dependsOn(targetVersionPresent ? diffTarget : Collections.emptyList());
}
);
}

public Provider<Directory> getTargetsBuildDir() {
Expand Down

1 comment on commit dfee3c2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With commit dfee3c2, 1 file(s) were updated with 28 line(s) added and 28 removed compared to the latest Quilt Mappings version.

View the diff here:
diff -bur namedTargetSrc/net/minecraft/entity/InteractionEntity.java namedSrc/net/minecraft/entity/InteractionEntity.java
--- namedTargetSrc/net/minecraft/entity/InteractionEntity.java	2024-12-04 06:49:40.173141072 +0000
+++ namedSrc/net/minecraft/entity/InteractionEntity.java	2024-12-04 06:48:33.521295753 +0000
@@ -38,14 +38,14 @@
    private static final Logger LOGGER = LogUtils.getLogger();
    /**
     * @mapping {@literal hashed f_rmbogufh Lnet/minecraft/unmapped/C_hvnhlgso;f_rmbogufh:Lnet/minecraft/unmapped/C_rinmcaxy;}
-    * @mapping {@literal named INTERACTION_WIDTH Lnet/minecraft/entity/InteractionEntity;INTERACTION_WIDTH:Lnet/minecraft/entity/data/TrackedData;}
+    * @mapping {@literal named WIDTH Lnet/minecraft/entity/InteractionEntity;WIDTH:Lnet/minecraft/entity/data/TrackedData;}
     */
-   private static final TrackedData<Float> INTERACTION_WIDTH = DataTracker.registerData(InteractionEntity.class, TrackedDataHandlerRegistry.FLOAT);
+   private static final TrackedData<Float> WIDTH = DataTracker.registerData(InteractionEntity.class, TrackedDataHandlerRegistry.FLOAT);
    /**
     * @mapping {@literal hashed f_luxekrhz Lnet/minecraft/unmapped/C_hvnhlgso;f_luxekrhz:Lnet/minecraft/unmapped/C_rinmcaxy;}
-    * @mapping {@literal named INTERACTION_HEIGHT Lnet/minecraft/entity/InteractionEntity;INTERACTION_HEIGHT:Lnet/minecraft/entity/data/TrackedData;}
+    * @mapping {@literal named HEIGHT Lnet/minecraft/entity/InteractionEntity;HEIGHT:Lnet/minecraft/entity/data/TrackedData;}
     */
-   private static final TrackedData<Float> INTERACTION_HEIGHT = DataTracker.registerData(InteractionEntity.class, TrackedDataHandlerRegistry.FLOAT);
+   private static final TrackedData<Float> HEIGHT = DataTracker.registerData(InteractionEntity.class, TrackedDataHandlerRegistry.FLOAT);
    /**
     * @mapping {@literal hashed f_vxdufukm Lnet/minecraft/unmapped/C_hvnhlgso;f_vxdufukm:Lnet/minecraft/unmapped/C_rinmcaxy;}
     * @mapping {@literal named RESPONSE Lnet/minecraft/entity/InteractionEntity;RESPONSE:Lnet/minecraft/entity/data/TrackedData;}
@@ -103,8 +103,8 @@
     */
    @Override
    protected void initDataTracker(DataTracker.Builder arg) {
-      arg.add(INTERACTION_WIDTH, 1.0F);
-      arg.add(INTERACTION_HEIGHT, 1.0F);
+      arg.add(WIDTH, 1.0F);
+      arg.add(HEIGHT, 1.0F);
       arg.add(RESPONSE, false);
    }
 
@@ -114,11 +114,11 @@
    @Override
    protected void readCustomDataFromNbt(NbtCompound arg) {
       if (arg.contains("width", NbtElement.NUMBER_TYPE)) {
-         this.setInteractionWidth(arg.getFloat("width"));
+         this.setWidth(arg.getFloat("width"));
       }
 
       if (arg.contains("height", NbtElement.NUMBER_TYPE)) {
-         this.setInteractionHeight(arg.getFloat("height"));
+         this.setHeight(arg.getFloat("height"));
       }
 
       if (arg.contains("attack")) {
@@ -148,8 +148,8 @@
     */
    @Override
    protected void writeCustomDataToNbt(NbtCompound arg) {
-      arg.putFloat("width", this.getInteractionWidth());
-      arg.putFloat("height", this.getInteractionHeight());
+      arg.putFloat("width", this.getWidth());
+      arg.putFloat("height", this.getHeight());
       if (this.attack != null) {
          InteractionEntity.Interaction.CODEC.encodeStart(NbtOps.INSTANCE, this.attack).ifSuccess(arg2 -> arg.put("attack", arg2));
       }
@@ -167,7 +167,7 @@
    @Override
    public void onTrackedDataSet(TrackedData<?> arg) {
       super.onTrackedDataSet(arg);
-      if (INTERACTION_HEIGHT.equals(arg) || INTERACTION_WIDTH.equals(arg)) {
+      if (HEIGHT.equals(arg) || WIDTH.equals(arg)) {
          this.calculateDimensions();
       }
    }
@@ -269,34 +269,34 @@
 
    /**
     * @mapping {@literal hashed m_uesbqavb Lnet/minecraft/unmapped/C_hvnhlgso;m_uesbqavb(F)V}
-    * @mapping {@literal named setInteractionWidth Lnet/minecraft/entity/InteractionEntity;setInteractionWidth(F)V}
+    * @mapping {@literal named setWidth Lnet/minecraft/entity/InteractionEntity;setWidth(F)V}
     */
-   private void setInteractionWidth(float width) {
-      this.dataTracker.set(INTERACTION_WIDTH, width);
+   private void setWidth(float width) {
+      this.dataTracker.set(WIDTH, width);
    }
 
    /**
     * @mapping {@literal hashed m_mcajgzfg Lnet/minecraft/unmapped/C_hvnhlgso;m_mcajgzfg()F}
-    * @mapping {@literal named getInteractionWidth Lnet/minecraft/entity/InteractionEntity;getInteractionWidth()F}
+    * @mapping {@literal named getWidth Lnet/minecraft/entity/InteractionEntity;getWidth()F}
     */
-   private float getInteractionWidth() {
-      return this.dataTracker.get(INTERACTION_WIDTH);
+   private float getWidth() {
+      return this.dataTracker.get(WIDTH);
    }
 
    /**
     * @mapping {@literal hashed m_yvnkyldm Lnet/minecraft/unmapped/C_hvnhlgso;m_yvnkyldm(F)V}
-    * @mapping {@literal named setInteractionHeight Lnet/minecraft/entity/InteractionEntity;setInteractionHeight(F)V}
+    * @mapping {@literal named setHeight Lnet/minecraft/entity/InteractionEntity;setHeight(F)V}
     */
-   private void setInteractionHeight(float height) {
-      this.dataTracker.set(INTERACTION_HEIGHT, height);
+   private void setHeight(float height) {
+      this.dataTracker.set(HEIGHT, height);
    }
 
    /**
     * @mapping {@literal hashed m_dyvbaohz Lnet/minecraft/unmapped/C_hvnhlgso;m_dyvbaohz()F}
-    * @mapping {@literal named getInteractionHeight Lnet/minecraft/entity/InteractionEntity;getInteractionHeight()F}
+    * @mapping {@literal named getHeight Lnet/minecraft/entity/InteractionEntity;getHeight()F}
     */
-   private float getInteractionHeight() {
-      return this.dataTracker.get(INTERACTION_HEIGHT);
+   private float getHeight() {
+      return this.dataTracker.get(HEIGHT);
    }
 
    /**
@@ -317,10 +317,10 @@
 
    /**
     * @mapping {@literal hashed m_acettnna Lnet/minecraft/unmapped/C_hvnhlgso;m_acettnna()Lnet/minecraft/unmapped/C_sszpscpo;}
-    * @mapping {@literal named getInteractionDimensions Lnet/minecraft/entity/InteractionEntity;getInteractionDimensions()Lnet/minecraft/entity/EntityDimensions;}
+    * @mapping {@literal named getDimensions Lnet/minecraft/entity/InteractionEntity;getDimensions()Lnet/minecraft/entity/EntityDimensions;}
     */
-   private EntityDimensions getInteractionDimensions() {
-      return EntityDimensions.changing(this.getInteractionWidth(), this.getInteractionHeight());
+   private EntityDimensions getDimensions() {
+      return EntityDimensions.changing(this.getWidth(), this.getHeight());
    }
 
    /**
@@ -328,7 +328,7 @@
     */
    @Override
    public EntityDimensions getDimensions(EntityPose pose) {
-      return this.getInteractionDimensions();
+      return this.getDimensions();
    }
 
    /**
@@ -336,7 +336,7 @@
     */
    @Override
    protected Box getDimensionsBoxAt(Vec3d pos) {
-      return this.getInteractionDimensions().getBoxAt(pos);
+      return this.getDimensions().getBoxAt(pos);
    }
 
    /**

Please sign in to comment.