#I don't know why, but my lootjs loots are not being rare, and enchanted books are not being enchant

44 messages · Page 1 of 1 (latest)

rough forum
#

Why that?
I put the randomChance() function to make some drops rare but they always drop instead of dropping rarely, and the enchantRandom() function in the enchanted book is not working, i want that the drops respect the chance that i gave them and the enchanted book drop always comes enchanted, and not blank

hybrid sandBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

rough pierBOT
#

Paste version of message.txt from @rough forum

rough forum
#

.

dusky estuary
#

You can temporarily add the mod "Advanced Loot Info" to examine the drop tables. I've personally experienced issues with this mod when using /reload, so I only use it when I'm expecting to fully restart minecraft between changes, and disable it when working with recipes.

Now, I assume that the issue is the loot where you use .randomChance();
for example, ```js
event.addEntityLootModifier("minecraft:creeper").pool(p => {
p.addLoot(
LootEntry.of("minecraft:blaze_powder")
);
p.limitCount([2,5]).applyLootingBonus([2,7]);
p.randomChance(0.15);
});


Now, looking at [the official documentation for randomChance()](<https://github.com/AlmostReliable/lootjs/wiki/1.20.1#randomchance>), we can see that the intended use is that one declares the chance, then adds the loot when the chance is successful. We're also going to look at [the way pool is meant to be used](<https://github.com/AlmostReliable/lootjs/wiki/1.20.1#pool>), where first the number of rolls on the pool is given (I assume since you gave no number, it is rolled once), then a random chance is rolled, and then it checks if the biome is a jungle OR the light level is between 0 and 7. If both these checks (the chance and the OR) succeed, diamond is added to the pool.

By comparison, what you've done here is add 1 blaze powder to the pool.  And then a random chance, but then didn't follow it up with any item to add if the chance succeeds. 

Let's rewrite that section to match the examples on the wiki,
```js
event.addEntityLootModifier("minecraft:creeper").pool(p => {
    p.randomChance(0.15).addLoot(
      LootEntry.of("minecraft:blaze_powder")
    );
    p.limitCount([2,5]).applyLootingBonus([2,7]);
  });

I'm not sure why .enchantRandomly() isn't working. The usage in the code you provided matches the wiki's example, except for the randomChance() again.

rough forum
#

or maybe i need to put it together with addLoot and random chance

dusky estuary
#

I'd definitely say give it a shot. After .addLoot(), but as part of the same line instead of getting its own p.

#

They do give it its own p. in the examples, as they do with everything in the "Functions" category, whereas same line calls are for Actions and Conditions, but my presumption is that you can apply a Function directly to a lootObject anyways.

#

Hold on, actually. I found more documentation, specifically since your using .addLoot(LootEntry.of('namespace:id')) rather than .addLoot('namespace:id'), you should actually put the .enchantRandomly() after the .of()

#

So

event.addEntityLootModifier("creeperoverhaul:desert_creeper").pool(p => {
    p.addLoot(
      LootEntry.of("minecraft:enchanted_book")
    );
    p.limitCount([1,1]);
    p.enchantRandomly();
    p.randomChance(0.30);
  });

should become

event.addEntityLootModifier("creeperoverhaul:desert_creeper").pool(p => {
    p.randomChance(0.30).addLoot(
      LootEntry.of("minecraft:enchanted_book").enchantRandomly()
    );
    p.limitCount([1,1]);
  });

OR

event.addEntityLootModifier("creeperoverhaul:desert_creeper").pool(p => {
    p.addLoot(
      LootEntry.of("minecraft:enchanted_book").enchantRandomly().when((c) => c.randomChance(0.30))
    );
    p.limitCount([1,1]);
  });

OR

event.addEntityLootModifier("creeperoverhaul:desert_creeper").pool(p => {
    p.randomChance(0.30).addLoot("minecraft:enchanted_book")
    p.enchantRandomly()
    p.limitCount([1,1]);
  });

Each of these three ways of doing it should all be equally valid.
Personally, I'd go with the first one.

rough forum
dusky estuary
#

Also, for the ones where you're doing a seperate pool for each gem,

gems.forEach(gem => {
    event.addEntityLootModifier("creeperoverhaul:snowy_creeper").pool(p => {
      p.addLoot(
        LootEntry.of(gem)
      );
      p.limitCount([1,2]).applyLootingBonus([1,4]);
      p.randomChance(0.15);
    });
  });

Is that really the way you want this to be? As is, it's a 100% chance for each gem, but obviously it's intended to be a 15% chance for each gem, and with 21 gems in the list 'gems', that's still going to average 3 gems per drop, before limitCount and applyLootingBonus apply.

I'd do this:

event.addEntityLootModifier("creeperoverhaul:snowy_creeper").randomChance(0.15).pool(p=> {
  gems.forEach(gem=>{
    p.addLoot(gem);
  });
  p.limitCount([1,2]).applyLootingBonus([1,4]);
});

If I'm correct, this should add all the gems to a singular pool, which has a 15% chance to even select an item from the pool (note how the randomChance() is before the .pool() call), but all items in the pool have an equal chance of being selected

dusky estuary
rough forum
rough forum
#

it basically had a 15% of chance of dropping all the gems

#

instead of dropping some of them

dusky estuary
#

Huh. Interesting.

#

One moment. I'm going to investigate again.

#

Ok, THIS should, 15% of the time, select one to three gems, and give 1-2 of each selected.

event.addEntityLootModifier("creeperoverhaul:snowy_creeper").randomChance(0.15).pool(p=> {
  p.rolls([1,3])
  p.addWeightedLoot([1,2],
    gems.map(gem => Item.of(gem).withChance(1) )
  )
  p.applyLootingBonus([1,4]);
});
dusky estuary
#

And if you added the "Advanced Loot Info" mod, show the JEI page for the mob that's supposed to drop the book.

rough forum
#

i killed many creepers and they dropped enchanted books without enchantments

#

but the advanced loot info shows it enchants with levels

dusky estuary
#

Interesting. It should be enchanted. Um, I'm not sure 20 is a valid value without Apotheosis installed, and even then I'm not sure... I'd test with a lower max value, like 3. But ignoring that, can you post the version of the code adding the drop that you tested with? Just because we've made a few changes and iterations, and I'd like to confirm it looks on your end how I think it looks. Otherwise, further suggestions I make might not be interpreted the same way I think they'll be interpreted.

rough forum
#

i do have

dusky estuary
#

I'm not sure if the maximum value is the number of bookshelves the enchantment is equivalent to, the number of experience levels consumed, or if it's something else.

rough pierBOT
#

Paste version of message.txt from @rough forum

dusky estuary
#

OK, so when I gave three options, you went with the 2nd option? That's probably fine, but try it with the 1st or 3rd. It might be that for some reason it interpreted it as "30% chance to be enchanted", for some bizarre reason. Though, the screenshot you posted from ALI shows that's not the case. Instead it shows a 30% chance to drop a book, which is what it SHOULD be.

Hmm. I wonder. While you test the other option(s), I'm going to have an investigation into vanilla loot tables as data packs. And see how the books in chests were handled there.

#

Alright, the research is in. The vanilla loot tables for guaranteed enchanted books look like this:


        {
          "type": "minecraft:item",
          "functions": [
            {
              "function": "minecraft:enchant_with_levels",
              "levels": 30.0,
              "treasure": true
            }
          ],
          "name": "minecraft:book"
        }

Which means that not only is 20 a valid maximum level, it's valid in vanilla. In fact, you should increase your minimum a bit.

Secondly, it means that instead of dropping "minecraft:enchanted_book", you should try it with just "minecraft:book"

#

This may be a case of "you cannot enchant what is already enchanted"

rough forum
#

i'm using enchantRandomly btw

dusky estuary
#

Alright, so the issue was the enchanted_book vs book?

rough forum
dusky estuary
#

Right. And how's the gems drop? And by extension, anything else using a list?

#

Is it to your satisfaction, or need some more adjusting?

rough forum
rough forum
#

if i need to change i change that myself

dusky estuary
#

Excellent. Yes, I trust you can balance the numbers youself, I was just concerned about the base functionality.