#Same values

1 messages · Page 1 of 1 (latest)

ionic aspen
sinful garden
#

Wym?

ionic aspen
# sinful garden Wym?

[13:40:50] [Server thread/INFO]: ================
[13:40:50] [Server thread/INFO]: PUT - ENTRY: GOLD_ORE
[13:40:50] [Server thread/INFO]: PUT - ITEMS: [md.mirrerror.thewalkingdead.utils.Drops@33552e4e]
[13:40:50] [Server thread/INFO]: ================
[13:40:50] [Server thread/INFO]: ================
[13:40:50] [Server thread/INFO]: PUT - ENTRY: LAPIS_ORE
[13:40:50] [Server thread/INFO]: PUT - ITEMS: [md.mirrerror.thewalkingdead.utils.Drops@2d78135b]
[13:40:50] [Server thread/INFO]: ================

[13:40:50] [Server thread/INFO]: Material:GOLD_ORE; drops: [md.mirrerror.thewalkingdead.utils.Drops@2d78135b]
[13:40:50] [Server thread/INFO]: Material:LAPIS_ORE; drops: [md.mirrerror.thewalkingdead.utils.Drops@2d78135b]

sinful garden
#

That tells me nothing

#

Can you rephrase the issue here

ionic aspen
#

I put a value for the GOLD_ORE material and another one for the LAPIS_ORE material (they are not equal), but when I get the values from the map it returns me equal values

#

PUT - ENTRY is the key and PUT - ITEMS is the value that I put when I initialize this map

#

And the last two strings is the keys and values of this map

#

As u can see they has equal objects as the values

#

But on initialization they are not equal (as it has to be)

sinful garden
#

So you mean the bug is that two keys get mapped to the same value even though you mapped them to different values?

ionic aspen
#

yes

sinful garden
#

I’d advice sending more code than that clinit block of yours

ionic aspen
#

the way I get the values from this map:

    public static List<Drops> getBlockDrops(Material material) {
        return blockDrops.get(material);
    }
sinful garden
#

In fact, any class that touches the map might be relevant

#

Possibly upload the project to smtng like GitHub or gitlab

ionic aspen
#
    @EventHandler
    public void onBlockBreak(BlockBreakEvent event) {
        Block block = event.getBlock();
        if(ItemUtils.getBlockDrops(block.getType()) != null) {
            event.setCancelled(true);
            ItemUtils.getBlockDrops(block.getType()).forEach(item -> {
                int count;

                if(item.getMin() == item.getMax()) count = item.getMax();
                else count = item.getMin() + ThreadLocalRandom.current().nextInt(item.getMax() - item.getMin());

                for(int i = 0; i < count; i++) block.getWorld().dropItemNaturally(block.getLocation(), item.getDrops());
            });
            block.setType(Material.AIR);
        }
    }
ionic aspen
#

that's all

sinful garden
#

Can you send the config itself also?

ionic aspen
# sinful garden Can you send the config itself also?
AllowedEntities:
  ZOMBIE:
    SpawnOnlyOnSurface: true
    AdditionalSpawnCount:
      Min: 0
      Max: 4
ChangedBlockDrops:
  GOLD_ORE:
    1:
      Material: 'gold_nugget'
      Name: 'T1 Сера'
      Tier: 1
      Min: 1
      Max: 1
  LAPIS_ORE:
    1:
      Material: 'iron_nugget'
      Name: 'T1 Вольфрамовая руда'
      Tier: 1
      Min: 1
      Max: 1
#

if u didn't observe - it returns exactly the second value for both keys

sinful garden
#

Yes, Idk but it feels like you should just spend a minute rewriting that clinit block

#

It’s quite messy

#

Also consider to extract smaller methods

#

And the problem from what I can tell

#

Is that you reuse the same list

#

So when the second entry clears the list, the reflections are mirrored onto the first entry

#

Since their values are bound to the same list

ionic aspen
#

but why when I use the put method there is not equal keys

sinful garden
#

And?

ionic aspen
#

I mean values

#

sorry

sinful garden
#

Both the key GOLD_ORE and LAPIS_ORE are mapped to the same list instance

#

The easy solution is to use a new list for every entry

#

It also reduces mutability which is great

#

Since that was the origin of the problem anyways