Jump to content

[1.8.9][Loot] Changing default values of Minecraft entities, blocks or items


Major Squirrel

Recommended Posts

Good evening,

 

This question has surely be asked but I couldn't find an available answer for 1.8.9 with the search engine.

 

Is it possible to change the loot values/probabilities of Minecraft basic entities, and blocks such as BlockBushes ? Also, can I easily change the saturation of existing food ?

 

I suppose this is possible for BlockCrop/BlockBush and ItemFood, using substitution aliases, but I can't see any way for existing entities in Minecraft.

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

You should be able to register substitution aliases for blocks and items (in fact those are the only things you can register substitution aliases for), but I haven't managed to get it working myself (see this thread).

 

You should always try to use events or hooks before you resort to drastic measures like replacing vanilla classes or modifying them with ASM. If there's no hook or event for your use case, consider suggesting one in the Suggestions section or on GitHub.

 

HarvestDropsEvent

lets you change drops from blocks.

LivingDropsEvent

lets you change drops from living entities (including players).

 

There's no direct way to modify the saturation value of existing food without resorting to some hacky reflection that makes the fields in

ItemFood

non-final, but you can subscribe to

PlayerUseItemEvent.Finish

and modify the player's food values through their

FoodStats

object if they used a particular food item.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

You should be able to register substitution aliases for blocks and items (in fact those are the only things you can register substitution aliases for), but I haven't managed to get it working myself (see this thread).

 

You should always try to use events or hooks before you resort to drastic measures like replacing vanilla classes or modifying them with ASM. If there's no hook or event for your use case, consider suggesting one in the Suggestions section or on GitHub.

 

HarvestDropsEvent

lets you change drops from blocks.

LivingDropsEvent

lets you change drops from living entities (including players).

 

There's no direct way to modify the saturation value of existing food without resorting to some hacky reflection that makes the fields in

ItemFood

non-final, but you can subscribe to

PlayerUseItemEvent.Finish

and modify the player's food values through their

FoodStats

object if they used a particular food item.

 

Yeah I paid attention to your thread few days ago, in fact I was wondering if this was fixed in next builds or not. However, the thing that bothers me with events or hooks is that I have to use them as I implement new types of blocks or items, instead of coding them in their own class and be quiet.

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

At the moment I'm facing a problem : I would like to add a slow effect (not the enchant) to the player when wearing basic Minecraft armors. There is a specific value for each piece of armor, made of each ItemArmor.ArmorMaterial.

 

I suppose I have two possibilities : the first one would be to re-create the existing armors, adding my own onArmorTick event and registering the Items as a substitution, but it seems that it doesn't work very well (cf. Choonster post above). The second one would be to catch a specific TickEvent for my uses and checking each piece of armor the player is wearing, but it is called every tick for players and not every tick for pieces being worn.

 

I would implement this for a private server, and I can't really imagine how fast/slow it would be.

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

Using PlayerTickEvent for this should be fine.

 

Thank you diesieben07, I was wondering if I had to check the side of the event (Side.CLIENT or Side.SERVER) since it is a calculation assigned to the player ? I don't understand in which way I should handle sides in events...

Squirrel ! Squirrel ! Squirrel !

Link to comment
Share on other sites

Neither.  Use

World#isRemote

, specifically,

!isRemote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Is accessing to the player worldObj okay ?

 

    @SubscribeEvent
    public void                 onArmorWorn(TickEvent.PlayerTickEvent event) {
        Double                  result = 0.0D;
        Item                    itemArmor;
        AttributeModifier       armorSlowModifier;
        IAttributeInstance      attributeInstance;

        if (!event.player.worldObj.isRemote && event.phase == TickEvent.Phase.START) {
            for (int index = 0; index < 4; ++index) {
                if (event.player.getCurrentArmor(index) != null) {
                    itemArmor = event.player.getCurrentArmor(index).getItem();
                    result += ItemArmorHelper.getSlowValue(itemArmor);
                }
            }
            result = (1.0D / (1.0D + (result / 1.5D) / 2.0D));
            armorSlowModifier = new AttributeModifier(heavinessModifierMalus, "Armor heaviness malus", result - 1, 2).setSaved(false);
            attributeInstance = event.player.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
            if (attributeInstance.getModifier(heavinessModifierMalus) != null)
                attributeInstance.removeModifier(armorSlowModifier);
            attributeInstance.applyModifier(armorSlowModifier);
        }
    }

Squirrel ! Squirrel ! Squirrel !

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.



×
×
  • Create New...

Important Information

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