Skip to content

Commit

Permalink
Reenable advancements
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyhedral committed Dec 9, 2024
1 parent a4824ea commit f23a5c1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 32 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/sweetrpg/crafttracker/CraftTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.sweetrpg.crafttracker.common.lib.Constants;
import com.sweetrpg.crafttracker.common.registry.ModRecipeSerializers;
import com.sweetrpg.crafttracker.common.registry.ModRegistries;
import com.sweetrpg.crafttracker.data.CTAdvancementProvider;
import com.sweetrpg.crafttracker.data.CTLangProvider;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.PackOutput;
Expand Down Expand Up @@ -101,7 +102,7 @@ protected void interModProcess(final InterModProcessEvent event) {
LOGGER.debug("event {}", event);

// BackwardsComp.init();
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
// IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

AddonManager.init();
}
Expand All @@ -111,11 +112,12 @@ private void gatherData(final GatherDataEvent event) {

DataGenerator gen = event.getGenerator();
PackOutput packOutput = gen.getPackOutput();
var lookup = event.getLookupProvider();

gen.addProvider(event.includeServer(), new CTLangProvider(packOutput, Constants.LOCALE_EN_US));
gen.addProvider(event.includeServer(), new CTLangProvider(packOutput, Constants.LOCALE_EN_GB));
gen.addProvider(event.includeServer(), new CTLangProvider(packOutput, Constants.LOCALE_DE_DE));

// gen.addProvider(event.includeServer(), new CTAdvancementProvider(gen));
gen.addProvider(event.includeServer(), new CTAdvancementProvider(packOutput, lookup, event.getExistingFileHelper()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public class CraftQueueOverlay {
static int TEXT_HEIGHT = 12;
static int MAX_STRING_LENGTH = 40;

public static void init() {
MinecraftForge.EVENT_BUS.register(new CraftQueueOverlay());
// OverlayRegistry.registerOverlayAbove(HOTBAR_ELEMENT, "craft_queue", CraftQueueOverlay.CRAFT_QUEUE);
// OverlayRegistry.registerOverlayAbove(HOTBAR_ELEMENT, "shopping_list", ShoppingListOverlay.SHOPPING_LIST);
}

@SubscribeEvent
public void onRenderGuiOverlay(RenderGuiOverlayEvent event) {
CraftTracker.LOGGER.trace("CraftQueueOverlay#onRenderGuiOverlay");
Expand Down Expand Up @@ -307,10 +313,4 @@ public void onRenderGuiOverlay(RenderGuiOverlayEvent event) {
}
}

public static void init() {
MinecraftForge.EVENT_BUS.register(new CraftQueueOverlay());
// OverlayRegistry.registerOverlayAbove(HOTBAR_ELEMENT, "craft_queue", CraftQueueOverlay.CRAFT_QUEUE);
// OverlayRegistry.registerOverlayAbove(HOTBAR_ELEMENT, "shopping_list", ShoppingListOverlay.SHOPPING_LIST);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.client.event.RenderGuiOverlayEvent;
import net.minecraftforge.client.gui.overlay.ForgeGui;
import net.minecraftforge.client.gui.overlay.IGuiOverlay;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.registries.ForgeRegistries;
Expand All @@ -32,6 +31,9 @@ public class ShoppingListOverlay {
static int TEXT_HEIGHT = 12;
static int MAX_STRING_LENGTH = 40;

public static void init() {
MinecraftForge.EVENT_BUS.register(new ShoppingListOverlay());
}

@SubscribeEvent
public void onRenderGuiOverlay(RenderGuiOverlayEvent event) {
Expand Down Expand Up @@ -84,7 +86,7 @@ public void onRenderGuiOverlay(RenderGuiOverlayEvent event) {

// if products list is empty, display "empty" message
if(items.isEmpty()) {
graphics.drawCenteredString( gui.getFont(),
graphics.drawCenteredString(gui.getFont(),
Component.translatable(Constants.TRANSLATION_KEY_GUI_SHOPPING_LIST_EMPTY),
(x + olWidth - 8) / 2, (y + olHeight - 6) / 2, MESSAGE_COLOR);
return;
Expand All @@ -93,7 +95,7 @@ public void onRenderGuiOverlay(RenderGuiOverlayEvent event) {
var helpText = String.format("%s [%s]",
I18n.get(Constants.TRANSLATION_KEY_GUI_SHOPPING_LIST_HELP),
ModKeyBindings.CLEAR_SHOPPING_LIST_MAPPING.getTranslatedKeyMessage().getString());
graphics.drawCenteredString( gui.getFont(), helpText,
graphics.drawCenteredString(gui.getFont(), helpText,
(x + olWidth - 8) / 2, olHeight - TEXT_HEIGHT, HELP_COLOR);

int yPos = y + SECTION_TITLE_Y_OFFSET;
Expand Down Expand Up @@ -139,19 +141,15 @@ public void onRenderGuiOverlay(RenderGuiOverlayEvent event) {
item.getDescription().getString(MAX_STRING_LENGTH - countText.length() - 3),
countText);
CraftTracker.LOGGER.trace("text: {}", text);
graphics.drawString( gui.getFont(), text, x + ITEM_NAME_X_OFFSET, lambdaYpos + 4, TEXT_COLOR);
graphics.drawString(gui.getFont(), text, x + ITEM_NAME_X_OFFSET, lambdaYpos + 4, TEXT_COLOR);
}
else {
var text = item.getDescription().getString(MAX_STRING_LENGTH);
graphics.drawString( gui.getFont(), text, x + ITEM_NAME_X_OFFSET, yPos + 4, TEXT_COLOR);
graphics.drawString(gui.getFont(), text, x + ITEM_NAME_X_OFFSET, yPos + 4, TEXT_COLOR);
}

yPos += LINE_HEIGHT + 2;
CraftTracker.LOGGER.trace("yPos (materials item {}): {}", i, yPos);
}
}

public static void init() {
MinecraftForge.EVENT_BUS.register(new ShoppingListOverlay());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
public class AdvancementUtil {

public static void trigger(ModAdvancements.Key advancement, ServerPlayer player) {
// var ct = ModAdvancements.ENTRIES.get(advancement)
// .getCriteria().get(MAIN_CRITERION)
// .getTrigger();
// if(ModTriggers.ENTRIES.get(ct.getCriterion().getPath()) instanceof SimpleTrigger trigger) {
// trigger.trigger(player);
// }

var ct = ModAdvancements.ENTRIES.get(advancement)
.getCriteria().get(MAIN_CRITERION)
.getTrigger();
if(ModTriggers.ENTRIES.get(ct.getCriterion().getPath()) instanceof SimpleTrigger trigger) {
trigger.trigger(player);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
Expand All @@ -22,17 +23,14 @@ public class CTAdvancementProvider extends ForgeAdvancementProvider {
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().create();

public CTAdvancementProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries, ExistingFileHelper existingFileHelper) {
super(output, registries, existingFileHelper,
List.of(new DoggyAdvancementsSubProvider())
);
super(output, registries, existingFileHelper, List.of(new AdvancementsSubProvider()));
}

private static Path getPath(Path pathIn, Advancement advancementIn) {
return pathIn.resolve("data/" + advancementIn.getId().getNamespace() + "/advancements/" + advancementIn.getId().getPath() + ".json");
}

// private static Path getPath(Path pathIn, Advancement advancementIn) {
// return pathIn.resolve("data/" + advancementIn.getId().getNamespace() + "/advancements/" + advancementIn.getId().getPath() + ".json");
// }

public static class DoggyAdvancementsSubProvider implements ForgeAdvancementProvider.AdvancementGenerator {
public static class AdvancementsSubProvider implements ForgeAdvancementProvider.AdvancementGenerator {

@Override
public void generate(HolderLookup.Provider registries, Consumer<Advancement> consumer, ExistingFileHelper existingFileHelper) {
Expand Down

0 comments on commit f23a5c1

Please sign in to comment.