Skip to content

Commit

Permalink
unlock the recipe by collecting string
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Jul 23, 2017
1 parent f64e023 commit c49ebc3
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/main/java/mod/upcraftlp/cobwebs/Main.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package mod.upcraftlp.cobwebs;

import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.BlockWeb;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
Expand All @@ -24,6 +30,7 @@
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;

import java.util.Random;

Expand All @@ -38,6 +45,8 @@ public void init(FMLInitializationEvent event) {
Blocks.FIRE.setFireInfo(Blocks.WEB, 15, 70);
Blocks.FIRE.setFireInfo(ModThings.DECO_WEB, 15, 70);
}
WebHandler.stringID = OreDictionary.getOreID("string");
WebHandler.deco_web_recipe = CraftingManager.getRecipe(new ResourceLocation(MOD_ID, "deco_web"));
}

@GameRegistry.ObjectHolder(MOD_ID)
Expand All @@ -50,7 +59,24 @@ public static class ModThings {
@Mod.EventBusSubscriber
public static class WebHandler {

public static final Random random = new Random();
private static final Random random = new Random();
private static IRecipe deco_web_recipe;
private static int stringID;


@SubscribeEvent
public static void onPickupString(EntityItemPickupEvent event) {
if(event.getEntityPlayer() instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) event.getEntityPlayer();
if(player.getRecipeBook().containsRecipe(deco_web_recipe)) return;
for(int id : OreDictionary.getOreIDs(event.getItem().getItem())) {
if(id == stringID) {
player.unlockRecipes(Lists.newArrayList(deco_web_recipe));
break;
}
}
}
}

@SubscribeEvent
public static void onRegisterBlocks(RegistryEvent.Register<Block> event) {
Expand Down

0 comments on commit c49ebc3

Please sign in to comment.