Skip to content

Commit

Permalink
fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
mura committed Aug 23, 2019
1 parent 6a75445 commit 40dbaff
Showing 1 changed file with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
package jp.stoic.minecraft.harvestgrasses;

import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import org.apache.logging.log4j.Logger;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Mod(modid = HarvestGrassesMod.MODID, name = HarvestGrassesMod.NAME, version = HarvestGrassesMod.VERSION)
public class HarvestGrassesMod {
static final String MODID = "harvestgrassesmod";
static final String NAME = "Harvest Grasses Mod";
static final String VERSION = "0.3";

private static Logger logger;
private final static List<String> noDropItemNames = Arrays.asList(
"air", "barrier"
);

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
Expand All @@ -25,9 +35,19 @@ public void preInit(FMLPreInitializationEvent event) {

@EventHandler
public void init(FMLInitializationEvent event) {
ForgeRegistries.ITEMS.getValuesCollection().stream()
.filter(item -> !Items.AIR.equals(item))
.forEach(item -> MinecraftForge.addGrassSeed(new ItemStack(item), 10));
IForgeRegistry<Item> itemRegistry = GameRegistry.findRegistry(Item.class);
Set<Item> noDropItems = noDropItemNames.stream()
.map(ResourceLocation::new)
.filter(itemRegistry::containsKey)
.map(itemRegistry::getValue)
.collect(Collectors.toSet());
itemRegistry.getValuesCollection().stream()
.filter(item -> !noDropItems.contains(item))
.forEach(this::addGrassSeed);
logger.info("It's Harvest Time!");
}

private void addGrassSeed(Item item) {
MinecraftForge.addGrassSeed(new ItemStack(item), 10);
}
}

0 comments on commit 40dbaff

Please sign in to comment.