Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Event triggered on item durability loss?


PutoPug
 Share

Recommended Posts

there are the PlayerDestroyItemEvent (which is fierd when a Player destroys a Item) and the LivingEntityUseItemEvent.Finish (which is fierd after a Item is used) unfortunately there is no Event which is directly fierd when a Item is damaged

Edit: you can combine a Start and Finish SubEvents of LivingEntityUseItemEvent check the difference (you need to store the data in a Capability)

 

Edited by Luis_ST
Link to comment
Share on other sites

I present to you, nasty hack number 703:

@SubscribeEvent
public static void playerLoggedIn(PlayerEvent.PlayerLoggedInEvent event)  {
    if (event.getPlayer() instanceof ServerPlayer player) {
        var stackRef = new MutableObject<WeakReference<ItemStack>>();
        var durabilityRef = new MutableInt(0);

        ItemDurabilityTrigger.TriggerInstance triggerInstance = new ItemDurabilityTrigger.TriggerInstance(
                EntityPredicate.Composite.ANY, ItemPredicate.ANY, MinMaxBounds.Ints.ANY, MinMaxBounds.Ints.ANY
        ) {
            @Override
            public boolean matches(ItemStack stack, int durability) {
                stackRef.setValue(new WeakReference<>(stack));
                durabilityRef.v = durability;
                return true;
            }
        };
        var advancement = player.getServer().getServerResources().getAdvancements().getAllAdvancements()
                .stream().findAny().orElseThrow();

        var listener = new CriterionTrigger.Listener<>(triggerInstance, advancement, "<dummy>") {
            @Override
            public void run(PlayerAdvancements playerAdvancements) {
                var stackWeakRef = stackRef.getValue();
                if (stackWeakRef != null) {
                    var stack = stackWeakRef.get();
                    if (stack != null) {
                        System.out.println("Durability changed for player " + player.getDisplayName().getString() + " with stack " + stack + " " + stack.getTag() + ", new durability: " + durabilityRef.v);
                    }
                }
            }
        };
        CriteriaTriggers.ITEM_DURABILITY_CHANGED.addPlayerListener(
                player.getAdvancements(), listener
        );
    }
}

 

Link to comment
Share on other sites

56 minutes ago, diesieben07 said:

I present to you, nasty hack number 703:

simple question why is there no Event for this?
an implementation for such an event is really easy
(one new Class and a new line in the patch file of ItemStack)
 

Link to comment
Share on other sites

15 hours ago, diesieben07 said:

I present to you, nasty hack number 703:

@SubscribeEvent
public static void playerLoggedIn(PlayerEvent.PlayerLoggedInEvent event)  {
    if (event.getPlayer() instanceof ServerPlayer player) {
        var stackRef = new MutableObject<WeakReference<ItemStack>>();
        var durabilityRef = new MutableInt(0);

        ItemDurabilityTrigger.TriggerInstance triggerInstance = new ItemDurabilityTrigger.TriggerInstance(
                EntityPredicate.Composite.ANY, ItemPredicate.ANY, MinMaxBounds.Ints.ANY, MinMaxBounds.Ints.ANY
        ) {
            @Override
            public boolean matches(ItemStack stack, int durability) {
                stackRef.setValue(new WeakReference<>(stack));
                durabilityRef.v = durability;
                return true;
            }
        };
        var advancement = player.getServer().getServerResources().getAdvancements().getAllAdvancements()
                .stream().findAny().orElseThrow();

        var listener = new CriterionTrigger.Listener<>(triggerInstance, advancement, "<dummy>") {
            @Override
            public void run(PlayerAdvancements playerAdvancements) {
                var stackWeakRef = stackRef.getValue();
                if (stackWeakRef != null) {
                    var stack = stackWeakRef.get();
                    if (stack != null) {
                        System.out.println("Durability changed for player " + player.getDisplayName().getString() + " with stack " + stack + " " + stack.getTag() + ", new durability: " + durabilityRef.v);
                    }
                }
            }
        };
        CriteriaTriggers.ITEM_DURABILITY_CHANGED.addPlayerListener(
                player.getAdvancements(), listener
        );
    }
}

 

Oh wow, very dirty 

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
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • When my mod attempts to build and try to download the mappings, I get this error. > Could not find net.minecraftforge:forge:1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.      Searched in the following locations:        - https://repo.maven.apache.org/maven2/net/minecraftforge/forge/1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b/forge-1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.pom        - file:/C:/Users/palad/.m2/repository/net/minecraftforge/forge/1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b/forge-1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.pom        - https://libraries.minecraft.net/net/minecraftforge/forge/1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b/forge-1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.pom        - https://maven.minecraftforge.net/net/minecraftforge/forge/1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b/forge-1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.pom        - https://dvs1.progwml6.com/files/maven/net/minecraftforge/forge/1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b/forge-1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.pom        - https://maven.tterrag.com/net/minecraftforge/forge/1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b/forge-1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.pom        - https://maven.blamejared.com/net/minecraftforge/forge/1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b/forge-1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.pom        - https://maven.minecraftforge.net/net/minecraftforge/forge/1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b/forge-1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.module        - https://maven.minecraftforge.net/net/minecraftforge/forge/1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b/forge-1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.jar        - file:/C:/Users/palad/.gradle/caches/forge_gradle/bundeled_repo/net/minecraftforge/forge/1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b/forge-1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.pom        - file:/C:/Users/palad/.gradle/caches/forge_gradle/bundeled_repo/net/minecraftforge/forge/1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b/forge-1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.jar        - https://libraries.minecraft.net/net/minecraftforge/forge/1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b/forge-1.18-38.0.15_mapped_official_1.18_at_69dcb59b344338a3e5978a88158d63d53d0bea6b.jar   How can I fix this?
    • public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, BunchOfThings.MODID); public static final RegistryObject<Block> BLACK_SLIME_BLOCK = BLOCKS.register("black_slime_block", () -> { return new ColoredSlimeBlock(BlockBehaviour.Properties.of(Material.CLAY).friction(0.8f).sound(SoundType.SLIME_BLOCK).noOcclusion()); });  
    • Forge any, nothing is done
    • I need to make a server with its own launcher and texts on the screen, such as in the lower left corner of the coins are displayed. 
    • show the Registry Entry of your ColoredSlimeBlock
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.