Jump to content

Fruten

Members
  • Posts

    15
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Fruten's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. package ru.fruten.ntc; import java.lang.reflect.Field; import java.util.ArrayList; import com.google.common.base.Throwables; import com.google.common.collect.Lists; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ContainerPlayer; import net.minecraft.inventory.ContainerWorkbench; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.SlotCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.ReflectionHelper; public class NewStickIRecipe implements IRecipe { private static IRecipe rec; @Override public IRecipe setRegistryName(ResourceLocation name) { return NewStickIRecipe.rec; } @Override public ResourceLocation getRegistryName() { return NewStickIRecipe.rec.getRegistryName(); } @Override public Class<IRecipe> getRegistryType() { return NewStickIRecipe.rec.getRegistryType(); } @Override public boolean matches(InventoryCrafting inv, World worldIn) { return NewStickIRecipe.rec.matches(inv, worldIn) && findPlayer(inv).experienceLevel >= 1; } @Override public ItemStack getCraftingResult(InventoryCrafting inv) { return NewStickIRecipe.rec.getCraftingResult(inv); } @Override public boolean canFit(int width, int height) { return NewStickIRecipe.rec.canFit(width, height); } @Override public ItemStack getRecipeOutput() { return NewStickIRecipe.rec.getRecipeOutput(); } private static final Field eventHandlerField = ReflectionHelper.findField(InventoryCrafting.class, "eventHandler"); private static final Field containerPlayerPlayerField = ReflectionHelper.findField(ContainerPlayer.class, "player"); private static final Field slotCraftingPlayerField = ReflectionHelper.findField(SlotCrafting.class, "player"); private static EntityPlayer findPlayer(InventoryCrafting inv) { try { Container container = (Container) eventHandlerField.get(inv); if (container instanceof ContainerPlayer) { return (EntityPlayer) containerPlayerPlayerField.get(container); } else if (container instanceof ContainerWorkbench) { return (EntityPlayer) slotCraftingPlayerField.get(container.getSlot(0)); } else { return null; } } catch (Exception e) { throw Throwables.propagate(e); } } public static IRecipe getRecipeFromItem(Item item) { ArrayList<IRecipe> recipes = Lists.newArrayList(CraftingManager.REGISTRY.iterator()); IRecipe recipeFromItemStack; for (IRecipe recipe : recipes) { if (recipe.getRecipeOutput().getItem() == item) { recipeFromItemStack = recipe; return recipeFromItemStack; } } return null; } public static void recRecipe(IRecipe recipe) { rec = recipe; } } My IRecipe. package ru.fruten.ntc.util; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; import com.google.common.collect.Lists; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistry; import net.minecraftforge.registries.IForgeRegistryEntry; import net.minecraftforge.registries.IForgeRegistryModifiable; import ru.fruten.ntc.NewStickIRecipe; public class AllVanillaRecipes { public static void addNewStickRecipe() { ForgeRegistry<IRecipe> recipeRegistry = (ForgeRegistry<IRecipe>)ForgeRegistries.RECIPES; NewStickIRecipe recipe = new NewStickIRecipe(); recipeRegistry.register(recipe); } public static void removeStickRecipe() { ForgeRegistry<IRecipe> recipeRegistry = (ForgeRegistry<IRecipe>)ForgeRegistries.RECIPES; recipeRegistry.remove(Items.STICK.getRegistryName()); } } Methods for Init. @EventHandler public static void Init(FMLInitializationEvent event) { NewStickIRecipe.recRecipe(NewStickIRecipe.getRecipeFromItem(Items.STICK)); AllVanillaRecipes.removeStickRecipe(); AllVanillaRecipes.addNewStickRecipe(); } Himself init.
  2. I registered my IRecipe instead of a stick recipe, but in the recipe book it's empty, the stick icon itself is there. As you can see in the screenshot, the recipe icon is there, but supposedly I can do it, although I have no resources. When you click on the crafting icon, there is no reaction. How to make a normal recipe in the book?
  3. I've seen it, but how do I use it in an ArrayList or List variable?
  4. Sorry, perhaps, this question already someone asked and on him someone responded, but I have very little information about this, only for old versions of. The question in the topic title. P.S. sorry for my English again.
  5. I want the player to not be able to craft the item if the condition(I don't want to say what condition) is wrong. I want other players to be able to make an item if they have a true condition.
  6. Nothing bad happened, I saw errors in the console and immediately fixed it by checking the block. if (!world.isRemote && world.getBlockState(blockPos).getBlock() == Blocks.PLANKS) { if (world.getBlockState(blockPos).getValue(BlockPlanks.VARIANT) == BlockPlanks.EnumType.OAK) { world.setBlockState(blockPos, NTCBlocks.NTC_LIGHTWOOD.getDefaultState()); } }
  7. I made this code and it works, thanks again! if (!world.isRemote && world.getBlockState(blockPos).getValue(BlockPlanks.VARIANT) == BlockPlanks.EnumType.OAK) { world.setBlockState(blockPos, NTCBlocks.NTC_LIGHTWOOD.getDefaultState()); }
  8. Look in the source code of the game?
  9. Hi, I don't speak English very well! How to check oak boards? I have this code, but it skips all kinds of planks. | I just need to check the oak planks. \ / if (!world.isRemote && world.getBlockState(blockPos).getBlock() == Blocks.PLANKS) { world.setBlockState(blockPos, NTCBlocks.NTC_LIGHTWOOD.getDefaultState()); }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.