Skip to content

Commit

Permalink
1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertyuioplkjhgfd committed Sep 25, 2023
1 parent 2a04266 commit a813799
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Versionfiles
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'fabric-loom' version '1.3-SNAPSHOT'
id "com.modrinth.minotaur" version "2.+"
id "com.matthewprenger.cursegradle" version "1.4.0"
}
Expand All @@ -23,7 +23,7 @@ sourceCompatibility = 17
targetCompatibility = 17

ext.Versions = new Properties()
Versions.load(file("Versionfiles/mcversion-1.20.properties").newReader())
Versions.load(file("Versionfiles/mcversion-1.20.2.properties").newReader())

archivesBaseName = "advancementinfo"
ext.projectVersion = "1.3.1"
Expand Down
59 changes: 33 additions & 26 deletions src/main/java/de/guntram/mcmod/advancementinfo/AdvancementInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import de.guntram.mcmod.advancementinfo.accessors.AdvancementManagerAccess;
import de.guntram.mcmod.advancementinfo.accessors.AdvancementProgressAccessor;
import de.guntram.mcmod.advancementinfo.accessors.AdvancementScreenAccessor;
import de.guntram.mcmod.advancementinfo.accessors.AdvancementWidgetAccessor;
Expand All @@ -17,15 +18,18 @@
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementDisplay;
import net.minecraft.advancement.AdvancementProgress;
import net.minecraft.advancement.PlacedAdvancement;
import net.minecraft.advancement.criterion.CriterionConditions;
import net.minecraft.client.gui.screen.advancement.AdvancementTab;
import net.minecraft.client.gui.screen.advancement.AdvancementWidget;
import net.minecraft.client.gui.screen.advancement.AdvancementsScreen;
import net.minecraft.client.network.ClientAdvancementManager;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.predicate.entity.AdvancementEntityPredicateSerializer;
//import net.minecraft.predicate.entity.AdvancementEntityPredicateSerializer;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -82,18 +86,18 @@ private static void addStep(List<AdvancementStep> result, AdvancementProgress pr
}
}
if (translation == null) {
CriterionConditions conditions = ((AdvancementProgressAccessor)(progress)).getCriterion(s).getConditions();
if (conditions != null) {
JsonObject o = conditions.toJson(AdvancementEntityPredicateSerializer.INSTANCE);
JsonElement maybeEffects = o.get("effects");
if (maybeEffects != null && maybeEffects instanceof JsonObject) {
JsonObject effects = (JsonObject) maybeEffects;
details = new ArrayList<>(effects.entrySet().size());
for (Map.Entry<String, JsonElement> entry: effects.entrySet()) {
details.add(I18n.translate("effect."+entry.getKey().replace(':', '.')));
}
}
}
// CriterionConditions conditions = ((AdvancementProgressAccessor)(progress)).getCriterion(s).conditions();
// if (conditions != null) {
// JsonObject o = conditions.toJson();
// JsonElement maybeEffects = o.get("effects");
// if (maybeEffects != null && maybeEffects instanceof JsonObject) {
// JsonObject effects = (JsonObject) maybeEffects;
// details = new ArrayList<>(effects.entrySet().size());
// for (Map.Entry<String, JsonElement> entry: effects.entrySet()) {
// details.add(I18n.translate("effect."+entry.getKey().replace(':', '.')));
// }
// }
// }
translation = key;
}
result.add(new AdvancementStep(translation, obtained, details));
Expand All @@ -103,36 +107,39 @@ private static void addStep(List<AdvancementStep> result, AdvancementProgress pr
public static void setMatchingFrom(AdvancementsScreen screen, String text) {
List<AdvancementStep> result = new ArrayList<>();
ClientAdvancementManager advancementHandler = ((AdvancementScreenAccessor)screen).getAdvancementHandler();
Collection<Advancement> all = advancementHandler.getManager().getAdvancements();
Map<Identifier, PlacedAdvancement> all = ((AdvancementManagerAccess) advancementHandler.getManager()).getAdvancementEntries();
int lineCount = 0;

text = text.toLowerCase();
for (Advancement adv: all) {
if(adv.getId().getPath().startsWith("recipes/")) {
for (Map.Entry<Identifier, PlacedAdvancement> advancementEntry: all.entrySet()) {
PlacedAdvancement adv = advancementEntry.getValue();
Identifier id = advancementEntry.getKey();
if (id.getPath().startsWith("recipes/")) {
continue;
}
if (adv.getDisplay() == null) {
LOGGER.debug("! {} Has no display", adv.getId());
if (adv.getAdvancement().display().isEmpty()) {
LOGGER.debug("! {} Has no display", id);
continue;
}
if (adv.getDisplay().getTitle() == null) {
LOGGER.debug("! {} Has no title", adv.getId());
AdvancementDisplay display = adv.getAdvancement().display().get();
if (display.getTitle() == null) {
LOGGER.debug("! {} Has no title", id);
continue;
}
if (adv.getDisplay().getDescription() == null) {
LOGGER.debug("! {} Has no description", adv.getId());
if (display.getDescription() == null) {
LOGGER.debug("! {} Has no description", id);
continue;
}
String title = adv.getDisplay().getTitle().getString();
String desc = adv.getDisplay().getDescription().getString();
LOGGER.debug("- {} {}: {} ", adv.getId(), title, desc);
String title = display.getTitle().getString();
String desc = display.getDescription().getString();
LOGGER.debug("- {} {}: {} ", id, title, desc);
if (title.toLowerCase().contains(text)
|| desc.toLowerCase().contains(text)) {
ArrayList<String> details = new ArrayList<>();
details.add(desc);
AdvancementTab tab = ((AdvancementScreenAccessor)screen).myGetTab(adv);
if (tab == null) {
LOGGER.info("no tab found for advancement {} title {} description {}", adv.getId(), title, desc);
LOGGER.info("no tab found for advancement {} title {} description {}", id, title, desc);
continue;
}
details.add(tab.getTitle().getString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.guntram.mcmod.advancementinfo.accessors;

import net.minecraft.advancement.AdvancementManager;
import net.minecraft.advancement.PlacedAdvancement;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.Map;

@Mixin(AdvancementManager.class)
public interface AdvancementManagerAccess {
@Accessor("advancements")
public Map<Identifier, PlacedAdvancement> getAdvancementEntries();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package de.guntram.mcmod.advancementinfo.accessors;

import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.PlacedAdvancement;
import net.minecraft.client.gui.screen.advancement.AdvancementTab;
import net.minecraft.client.network.ClientAdvancementManager;

Expand All @@ -15,5 +16,5 @@
*/
public interface AdvancementScreenAccessor {
public ClientAdvancementManager getAdvancementHandler();
public AdvancementTab myGetTab(Advancement advancement);
public AdvancementTab myGetTab(PlacedAdvancement advancement);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@
import java.util.Map;
import net.minecraft.advancement.AdvancementCriterion;
import net.minecraft.advancement.AdvancementProgress;
import net.minecraft.advancement.AdvancementRequirements;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(AdvancementProgress.class)
public class AdvancementProgressMixin implements AdvancementProgressAccessor {
public abstract class AdvancementProgressMixin implements AdvancementProgressAccessor {

private Map<String, AdvancementCriterion> savedCriteria;
@Inject(method="init", at=@At("HEAD"))
public void saveCriteria(Map<String, AdvancementCriterion> criteria, String[][] requirements, CallbackInfo ci) {
savedCriteria = criteria;
}
@Override
public AdvancementCriterion getCriterion(String name) {
return savedCriteria.get(name);
}
// private Map<String, AdvancementCriterion> savedCriteria;
//
// @Inject(method="init", at=@At("HEAD"))
// public void saveCriteria(AdvancementRequirements requirements, CallbackInfo ci) {
// savedCriteria = criteria;
// }
//
// @Override
// public AdvancementCriterion getCriterion(String name) {
// return savedCriteria.get(name);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.guntram.mcmod.advancementinfo.accessors.AdvancementWidgetAccessor;
import java.util.List;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.PlacedAdvancement;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.advancement.AdvancementTab;
Expand All @@ -27,6 +28,7 @@
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -45,7 +47,7 @@ public abstract class AdvancementScreenMixin extends Screen implements Advanceme
private int currentInfoWidth = config.infoWidth.calculate(width);
private TextFieldWidget search;
@Shadow @Final private ClientAdvancementManager advancementHandler;
@Shadow protected abstract AdvancementTab getTab(Advancement advancement);
@Shadow protected abstract AdvancementTab getTab(PlacedAdvancement advancement);

@Shadow @Final private static Identifier WINDOW_TEXTURE;

Expand Down Expand Up @@ -200,17 +202,21 @@ public void rememberClickedWidget(double x, double y, int button, CallbackInfoRe
}
}

@Inject(method="onRootAdded", at=@At("HEAD"))
public void debugRootAdded(Advancement root, CallbackInfo ci) {
// @Inject(method="onRootAdded", at=@At("HEAD"))
// public void debugRootAdded(Advancement root, CallbackInfo ci) {
// System.out.println("root added to screen; display="+root.getDisplay()+", id="+root.getId().toString());
}
// }

// @Inject(method="mouseScrolled", at=@At("HEAD"), cancellable = true)
@Override
public boolean mouseScrolled(double X, double Y, double amount /*, CallbackInfoReturnable cir */) {
if (amount > 0 && scrollPos > 0) {
/**
* @author
* @reason
*/
@Overwrite
public boolean mouseScrolled(double X, double Y, double horizontalAmount, double verticalAmount /*, CallbackInfoReturnable cir */) {
if (verticalAmount > 0 && scrollPos > 0) {
scrollPos--;
} else if (amount < 0 && AdvancementInfo.cachedClickList != null
} else if (verticalAmount < 0 && AdvancementInfo.cachedClickList != null
&& scrollPos < AdvancementInfo.cachedClickListLineCount - ((height-2*config.marginY-45)/textRenderer.fontHeight - 1)) {
scrollPos++;
}
Expand Down Expand Up @@ -290,7 +296,7 @@ public ClientAdvancementManager getAdvancementHandler() {
return advancementHandler;
}

public AdvancementTab myGetTab(Advancement advancement) {
public AdvancementTab myGetTab(PlacedAdvancement advancement) {
return getTab(advancement);
}
}

0 comments on commit a813799

Please sign in to comment.