Search in sources :

Example 1 with ItemGenerationEvent

use of ivorius.reccomplex.events.ItemGenerationEvent in project RecurrentComplex by Ivorforce.

the class RCForgeEventHandler method onItemGeneration.

@SubscribeEvent
public void onItemGeneration(ItemGenerationEvent event) {
    Pair<String, Float> pair = null;
    if (event instanceof ItemGenerationEvent.Artifact)
        pair = RCConfig.customArtifactTag;
    else if (event instanceof ItemGenerationEvent.Book)
        pair = RCConfig.customBookTag;
    if (pair != null && pair.getRight() > 0.0f && event.random.nextFloat() < pair.getRight()) {
        WeightedItemCollection weightedItemCollection = WeightedItemCollectionRegistry.INSTANCE.get(pair.getLeft());
        if (weightedItemCollection != null)
            event.inventory.setInventorySlotContents(event.fromSlot, weightedItemCollection.getRandomItemStack(event.server, event.random));
        event.setCanceled(true);
    }
}
Also used : TextComponentString(net.minecraft.util.text.TextComponentString) WeightedItemCollection(ivorius.reccomplex.world.storage.loot.WeightedItemCollection) ItemGenerationEvent(ivorius.reccomplex.events.ItemGenerationEvent) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ItemGenerationEvent (ivorius.reccomplex.events.ItemGenerationEvent)1 WeightedItemCollection (ivorius.reccomplex.world.storage.loot.WeightedItemCollection)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1