Jump to content

[1.16.1] Advancement quantity criterion


PlayPrey

Recommended Posts

Greetings,

 

I am attempting to update an old mod of mine, which added a lot of achievements.

I thought I would start with the simple stuff, namely adding the milestone styled advancements first.

However it turns out triggering an advancement after for example killing 5 zombies is more difficult than expected. 

It appears easy if all the entities for the advancement are different, but I tried the option that obviously wouldn't work- adding 5x of the zombie kill trigger criterion. 

As expected the advancement is still triggered after killing just one. 

 

As far as I know it is not possible to read from the stats easily from the JSON files.

 

I'll admit, i'm a few years behind with this new system of doing things- but I have managed the simple normal things in advancements. 

 

I have been googling about, and it is possible to use custom triggers,- but the tutorial I found said "copy and paste this code"- which didn't work,- and had no documentation to explain things. 

 

Does anyone here have experience with triggering advancements with a quantity requirement? It would be a nice detail if I could use the counter that's visible on some advancements (like discover all biomes). 

Edited by PlayPrey

Intel(R) Core(TM) i7-8700K

32GB DDR4 2400MHz 

NVIDIA GeForce RTX 2080 8GB

Link to comment
Share on other sites

Thank you, what you're saying does make sense- however it's been 5 years since I worked with stat tracking and things have changed.

In addition to that it's been a while since I worked with Java + Forge ( I normally code C# applications ). 

 

You don't have to of course, but would you be willing to aid me with some slight tea-spoon styled assistance? 

 

Just to test I added 

LOGGER.info("Common setup");

into the 

private void setup(final FMLCommonSetupEvent event)

 

In my head this would trigger after the mod has loaded, or during?  However it never logged my text into the console. 

 

It's kinda embarrassing to be in this early beginner stages again, hehe. 

Intel(R) Core(TM) i7-8700K

32GB DDR4 2400MHz 

NVIDIA GeForce RTX 2080 8GB

Link to comment
Share on other sites

12 hours ago, PlayPrey said:

However it never logged my text into the console.

Show the class your event is in, I suspect you didn't call IEventBus#addListener(Consumer<T extends Event>) or annotate it with @SubscribeEvent.

Edited by Novârch

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

This is not going to be pretty, brace yourself. 

 

I saw that I am adding the listener (From the forge example), but that didn't work- so I tried adding subscribe event,- which didn't work because it was a private method.

This is the latest attempt at a... log message.... 

 

package no.pcservicetbg.advancementextreme;

import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.stream.Collectors;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("advancementextreme")
public class AdvancementExtreme
{


    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();

    public AdvancementExtreme() {
        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }

    @SubscribeEvent
    public void setup(final FMLCommonSetupEvent event)
    {
        LOGGER.info("Common SETUP");
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
    }

    private void enqueueIMC(final InterModEnqueueEvent event)
    {
    }

    private void processIMC(final InterModProcessEvent event)
    {
        // some example code to receive and process InterModComms from other mods
    }




    // You can use SubscribeEvent and let the Event Bus discover methods to call
    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        // do something when the server starts
    }


    // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
    // Event bus for receiving Registry Events)
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
            // register a new block here
            LOGGER.info("HELLO from Register Block");
        }
    }
}

 

Intel(R) Core(TM) i7-8700K

32GB DDR4 2400MHz 

NVIDIA GeForce RTX 2080 8GB

Link to comment
Share on other sites

1 minute ago, PlayPrey said:

This is not going to be pretty, brace yourself. 

 

I saw that I am adding the listener (From the forge example), but that didn't work- so I tried adding subscribe event,- which didn't work because it was a private method.

This is the latest attempt at a... log message.... 

 

That should work, is it possible you just missed the message? Pro tip if you're logging in a spammy log, do something like this to ensure you can see you're message,

for (int i = 0; i < 1000; i++)
  LogManager.getLogger().debug("Common setup fired!");

Please remove it before publishing your mod though.

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

So I added the loop, and it still didn't show up at all in the log. 

This is odd, the example mod did come with logging in the other methods (which I removed) and they worked fine. 

 

@SubscribeEvent
    public void setup(final FMLCommonSetupEvent event)
    {
        for(int i = 0; i < 1000; i++)
        {
            LOGGER.info("Common SETUP");
        }
    }

 

Intel(R) Core(TM) i7-8700K

32GB DDR4 2400MHz 

NVIDIA GeForce RTX 2080 8GB

Link to comment
Share on other sites

6 hours ago, PlayPrey said:

So I added the loop, and it still didn't show up at all in the log. 

This is odd, the example mod did come with logging in the other methods (which I removed) and they worked fine. 

 


@SubscribeEvent
    public void setup(final FMLCommonSetupEvent event)
    {
        for(int i = 0; i < 1000; i++)
        {
            LOGGER.info("Common SETUP");
        }
    }

 

You certainly don't need the @SubscribeEvent annotation there. This method doesn't have it in the example mod either.

 

Also, can you stop telling everytime to everyone here and there that you've had experience with Java eternity ago? You've been saying that for four years already and it doesn't seem like you improved during recent activity or had any experience before that at all. Maybe you was as bad as you are now and that's all. Really doesn't worth mentioning. Pls stop.

Edited by Rinkashikachi
Link to comment
Share on other sites

20 hours ago, Rinkashikachi said:

You certainly don't need the @SubscribeEvent annotation there. This method doesn't have it in the example mod either.

For some reason it doesn't work with or without the @SubscribeEvent 

Quote

Also, can you stop telling everytime to everyone here and there that you've had experience with Java eternity ago? You've been saying that for four years already and it doesn't seem like you improved during recent activity or had any experience before that at all. Maybe you was as bad as you are now and that's all. Really doesn't worth mentioning. Pls stop.

Also, I apologize- I don't know why I felt the need to assure people "knew" about my past "experience". I guess I thought it would help people when they knew more about who they were dealing with.

Intel(R) Core(TM) i7-8700K

32GB DDR4 2400MHz 

NVIDIA GeForce RTX 2080 8GB

Link to comment
Share on other sites

So good news, the events always worked- it's just the logging part that didn't. 

Tested with something else, like teleporting/hurting/etc the player and it all triggered fine. 

 

Now, I do wish there was a simple way of granting an advancement from a string value (as ID). 

For example: player.getAdvancement("mod:folder/jsonfile") but sadly that method doesn't exist. 

 

Does anyone know of a way like that? Or is the best way to actually create a new Criterion and reference to that from the json files? 

 

I looked into the built in triggers in the game and got a little stuck, because a lot of the functions in them have names like "p_230241_2" all over them. 

That just makes me confused. But if that's the way I am willing to at least give it a shot. 

Just don't want to go about it the completely wrong way from the get go. 

 

Thanks so far. 

Intel(R) Core(TM) i7-8700K

32GB DDR4 2400MHz 

NVIDIA GeForce RTX 2080 8GB

Link to comment
Share on other sites

Take a look at

AdvancementCommand

, it seems helpful.

Edited by Novârch

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

2 hours ago, Novârch said:

Take a look at


AdvancementCommand

, it seems helpful.

It certainly does, however I am missing out on something simple again.

The AdvancementCommand way requires the ServerPlayerEntity,- and I have to admit I struggle getting the current player as an ServerPlayerEntity.

 

Just to test I did something like

sp = mc.player;
ServerPlayerEntity mp = sp.getServer().getPlayerList().getPlayerByUsername("Dev");

Considering the debug player name is Dev I thought it might work. I know one shouldn't do getPlayerByUsername but end goal here was just to see a working result, before optimizing it. 

However this code just returns null + throws a NullPointerException. 

 

So in short, how do I get the _current_ player as an ServerPlayerEntity? :) This mod has no intention of having any multiplayer functions,- so the mod itself doesn't require knowing anything about other players. However Minecraft is basically a server run game now so it's probably unavoidable. 

Intel(R) Core(TM) i7-8700K

32GB DDR4 2400MHz 

NVIDIA GeForce RTX 2080 8GB

Link to comment
Share on other sites

4 minutes ago, PlayPrey said:

mc.player

Minecraft#player is a ClientPlayerEntity, your NP comes from you trying to get it's server. 

 

5 minutes ago, PlayPrey said:

This mod has no intention of having any multiplayer functions

That is not a good thing to do, unless your mod is client-side, you should always support multiplayer. If your mod is client-side, I'm pretty sure you can't do this, the server doesn't trust the client.

Where are you running this code? Context is important.

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

2 minutes ago, Novârch said:

Where are you running this code? Context is important.

I'd like to point out, it's purely for testing purposes but I am running the code on every EntityDeath from a;

@SubscribeEvent
    public void onDeath(LivingDeathEvent event)
    {
        if(sp == null) sp = mc.player;

        mp = sp.getServer().getPlayerList().getPlayerByUsername("Dev");
    }

This has no intention of staying in a final product. 

The mc variable gets assigned to from the mods initializer as

mc = Minecraft.getInstance();

The variables are stored in the class itself. 

Intel(R) Core(TM) i7-8700K

32GB DDR4 2400MHz 

NVIDIA GeForce RTX 2080 8GB

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

Then you must stay purely client side (visuals, etc.).

Single player is running a server. You cannot ignore multiplayer.

There is no "current player". You have to decide which player you want. Formulate it in English, then we can help you translate it into code. But there is no "current" player.

By current I simply mean yourself. In the same way as "Minecraft.player" returns yourself, but I want to get the ServerPlayerEntity version. If I am playing on a server with 100 players, I still only want myself to be affected. I hope that made it more clear? The reason I need the server version of myself is because Advancements seems to be completely server-side driven. 

Intel(R) Core(TM) i7-8700K

32GB DDR4 2400MHz 

NVIDIA GeForce RTX 2080 8GB

Link to comment
Share on other sites

Just now, diesieben07 said:

The server has no concept of "yourself". The server only has a list of players.

I am aware of this, but I still want a way to find _me_ out of these players. 

I remember you or someone else mentioning finding players using Uuid,- can I somehow get my own Uuid- then check that upon the list of players to find me?

Intel(R) Core(TM) i7-8700K

32GB DDR4 2400MHz 

NVIDIA GeForce RTX 2080 8GB

Link to comment
Share on other sites

6 minutes ago, PlayPrey said:

can I somehow get my own Uuid- then check that upon the list of players to find me?

Maybe, but it is still recommended you mod normally and in a way your mod can work with multiple players.

 

14 minutes ago, PlayPrey said:

If I am playing on a server with 100 players

Nope, advancements are server-side, you cannot modify them from the client. Why? Because the client is a liar.

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

1 minute ago, Novârch said:

Maybe, but it is still recommended you mod normally and in a way your mod can work with multiple players.

 

1 minute ago, diesieben07 said:

You keep saying "me". The server has no concept of this.

OK, so what I might be realizing here, is that instead of keeping track of myself,- it should keep track of every player. (I feel like this means the host must have the mod installed and the mod won't work on servers, like the old achievement system did- but that's fine for now.)

 

So.. What I have learned, is that my thought process was wrong. Advancements are server-side and shouldn't be messed with client-side. 

 

I have currently successfully retrieved the ServerPlayerEntity of who's killing by simply using 

ServerPlayerEntity spe = (ServerPlayerEntity)event.getSource().getTrueSource();

 

And it works fine. I guess I could store the players in a list to keep track of things in. 

We're making progress :)

 

Next task is to try and find a advancement I have made in a json file,- I don't have time right now to try out different things- but I'll throw out a question real quick:

Do you recommend reading every single advancement in the game and matching names or something, or do you know a way to straight up get a advancement like:

Advancement advancement = Advancement.getFromID("modid:folder1/jsonfilename"); 

I know this code doesn't exist, but if you know of a similar method? I feel like I am close to my goal, that is if the AdvancementCommand way works as it should. :)

Intel(R) Core(TM) i7-8700K

32GB DDR4 2400MHz 

NVIDIA GeForce RTX 2080 8GB

Link to comment
Share on other sites

11 minutes ago, PlayPrey said:

I have currently successfully retrieved the ServerPlayerEntity of who's killing by simply using 


ServerPlayerEntity spe = (ServerPlayerEntity)event.getSource().getTrueSource();

Have you checked instanceof, whether you're on the server with World#isRemote? These are potential issues.

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

Hey, guess what? Got it working- it was surprisingly simple. I saw in the PlayerPredicate class how one finds an advancement via a ResourceLocation and I stole the grant advancement code from AdvancementCommand- and it worked just fine. Advancements get granted via code as well now. Thank you. 

 

However, before I dig myself a hole that I can't get out of, 

3 hours ago, Novârch said:

Have you checked instanceof, whether you're on the server with World#isRemote? These are potential issues.

I don't think so, currently this is my code. It isn't clean yet but thats OK for now.

@SubscribeEvent
    public void onDeath(LivingDeathEvent event)
    {
        ResourceLocation rl = new ResourceLocation("advancementextreme", "slayer/zombie/5zombie");

        if(event.getSource().getTrueSource() instanceof ServerPlayerEntity)
        {
            ServerPlayerEntity spe = (ServerPlayerEntity)event.getSource().getTrueSource();

            PlayerAdvancements pa = spe.getAdvancements();
            AdvancementManager am = spe.getServer().getAdvancementManager();

            Advancement test = am.getAdvancement(rl);

            applyToAdvancement(spe, test);
        }
    }

	protected boolean applyToAdvancement(ServerPlayerEntity player, Advancement advancementIn) {
        AdvancementProgress advancementprogress = player.getAdvancements().getProgress(advancementIn);
        if (advancementprogress.isDone()) {
            return false;
        } else {
            for(String s : advancementprogress.getRemaningCriteria()) {
                player.getAdvancements().grantCriterion(advancementIn, s);
            }

            return true;
        }
    }

I am doing an instanceof check but no World#isRemote check,- I'll have to look into that. 

 

Thank you both a ton so far :)

Intel(R) Core(TM) i7-8700K

32GB DDR4 2400MHz 

NVIDIA GeForce RTX 2080 8GB

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm creating a custom staff, that can be used like a bow, meaning i can use it and it should "load" the staff.   As far as i can see the interaction is pretty simple: activate the "draw" stage via overriding use and then when the mouse is released the "releaseUsing" and "useOnRelease" methods are called.    What i want to achieve is between the activation and the release: I want to do stuff while it is drawn. For example i want to create particles and i want to stop the "drawn" stage in certain conditions. Is something like this possible and if so, where can i look? I'm also happy with examples from other mods. (For example i think that mana and artifice has something like that with the beam spells, but that mod is not open source).
    • Minecraft Version: 1.8-1.20.X Forge Version: All (Tested on 49.0.27, 11.14.4.1577 and some others) Steps to Reproduce: Setup a server with IPV6 only Setup a docker container with forge Try to connect to the Forge Server Description of issue: Hello, I am reaching out to seek your expertise within this forum to clarify a technical situation I am encountering, suspecting a potential issue related to Forge in a Docker environment, specifically in an IPv6 context. Initial Configuration: Debian 12 server, configured exclusively for IPv6, with Docker installed. Using the Docker image ghcr.io/pterodactyl/yolks:java_17, launching a Minecraft Vanilla server version 1.20.4 proceeds without any issues. Problem: The issue arises when deploying a Minecraft Forge server version 1.20.4 with the same Docker image (ghcr.io/pterodactyl/yolks:java_17), where connecting to the server becomes impossible. Notably, this issue does not occur when launching outside of Docker, where the server functions as expected. Hypothesis: This situation leads me to question the interaction between Forge and Docker, particularly in an IPv6-only configuration, despite several resolution attempts (testing with different versions of Forge, adjusting container network configurations (0.0.0.0, ::/0, and the server's ipv6), trials with various network settings, and modifications of Java options). Further testing was conducted with and without the use of the Pterodactyl game panel, unsuccessfully. The parameter -Djava.net.preferIPv4Stack=false also did not provide a solution. I tried to do the same things on multiple Minecraft server (include vanilla,spigot,fabric,sponge) and this work fine. The problem only happend with Forge. This issue seem to happend on all forge versions.   I appreciate your time and assistance in advance.
    • The game crashed whilst exception ticking world Error: java.lang.NullPointerException: Cannot invoke "net.minecraft.resources.ResourceLocation.equals(Object)" because "this.lootTableId" is null Error given is above. I was already playing for around 15 minutes and wasn't doing anything specific or even breaking anything when the crashed happened. This is update 1.19.2 forge: 43.2.23 Mod list: ESSENTIAL Mod (by SparkUniverse_) Traveler's Titles (Forge) (by YUNGNICKYOUNG) Resourceful Config (by ThatGravyBoat) Dynamic Lights (by atomicstrykergrumpy) TenzinLib (by CommodoreThrawn) Nature's Compass (by Chaosyr) Library Ferret - Forge (by jtl_elisa) Cold Sweat (by Mikul) Simple Voice Chat (by henkelmax) Waystones (by BlayTheNinth) Carry On (by Tschipp) [Let's Do] Meadow (by satisfy) Creeper Overhaul (by joosh_7889) AutoRegLib (by Vazkii) Moonlight Lib (by MehVahdJukaar) AppleSkin (by squeek502) Xaero's World Map (by xaero96) Rotten Creatures (by fusionstudiomc) YUNG's API (Forge) (by YUNGNICKYOUNG) Village Artifacts (by Lothrazar) Right Click, Get Crops (by TeamCoFH) Supplementaries (by MehVahdJukaar) Automatic Tool Swap (by MelanX) Better Third Person (by Socolio) Supplementaries Squared (by plantspookable) Traveler's Backpack (by Tiviacz1337) Caelus API (Forge/NeoForge) (by TheIllusiveC4) Creatures and Beasts (by joosh_7889) Architectury API (Fabric/Forge/NeoForge) (by shedaniel) Quark Oddities (by Vazkii) Origins (Forge) (by EdwinMindcraft) Villager Names (by Serilum) GeckoLib (by Gecko) Realistic Bees (by Serilum) Illuminations Forge 🔥 (by dimadencep) Serene Seasons (by TheAdubbz) Critters and Companions (by joosh_7889) [Let's Do] Bakery (by satisfy) Falling Leaves (Forge) (by Cheaterpaul) Jade 🔍 (by Snownee) Collective (by Serilum) TerraBlender (Forge) (by TheAdubbz) [Let's Do] API (by Cristelknight) Towns and Towers (by Biban_Auriu) More Villagers (by SameDifferent) Biomes O' Plenty (by Forstride) Goblin Traders (by MrCrayfish) Corpse (by henkelmax) Tree Harvester (by Serilum) Balm (Forge Edition) (by BlayTheNinth) Mouse Tweaks (by YaLTeR) Sound Physics Remastered (by henkelmax) Xaero's Minimap (by xaero96) Just Enough Items (JEI) (by mezz) Terralith (by Starmute) Quark (by Vazkii) [Let's Do] Vinery (by satisfy) [Let's Do] Candlelight (by satisfy) Repurposed Structures (Neoforge/Forge) (by telepathicgrunt) Dusty Decorations (by flint_mischiff) Immersive Armors [Fabric/Forge] (by Conczin) Serene Seasons Fix (by Or_OS) Shutup Experimental Settings! (by Corgi_Taco) Skin Layers 3D (Fabric/Forge) (by tr7zw)
    • Make sure Java is running via Nvidia GPU https://windowsreport.com/minecraft-not-using-gpu/  
    • Also make a test with other Custom Launchers like AT Launcher, MultiMC or Technic Launcher
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.