use of net.minecraft.item.crafting.Ingredient in project Tropicraft by Tropicraft.
the class Encyclopedia method getFormattedRecipe.
public RecipeEntry getFormattedRecipe(IRecipe recipe) {
// TODO support other kinds of recipes
if (recipe instanceof ShapedRecipes) {
ShapedRecipes shaped = (ShapedRecipes) recipe;
int width = shaped.recipeWidth;
int height = shaped.recipeHeight;
NonNullList<Ingredient> items = shaped.recipeItems;
ItemStack output = recipe.getRecipeOutput();
return new RecipeEntry(width, height, items, output);
} else if (recipe instanceof ShapelessRecipes) {
return new RecipeEntry(3, 3, recipe.getIngredients(), recipe.getRecipeOutput());
}
return null;
}
use of net.minecraft.item.crafting.Ingredient in project BloodMagic by WayofTime.
the class BloodMagicRecipeRegistrar method addTartaricForge.
@Override
public void addTartaricForge(@Nonnull ItemStack output, @Nonnegative double minimumSouls, @Nonnegative double soulDrain, @Nonnull Ingredient... input) {
Preconditions.checkNotNull(output, "output cannot be null.");
Preconditions.checkArgument(minimumSouls >= 0, "minimumSouls cannot be negative.");
Preconditions.checkArgument(soulDrain >= 0, "soulDrain cannot be negative.");
Preconditions.checkNotNull(input, "input cannot be null.");
NonNullList<Ingredient> inputs = NonNullList.from(Ingredient.EMPTY, input);
tartaricForgeRecipes.add(new RecipeTartaricForge(inputs, output, minimumSouls, soulDrain));
}
use of net.minecraft.item.crafting.Ingredient in project MC-Prefab by Brian-Wuest.
the class ShapedRecipeForFile method createFromShapedRecipe.
public static ShapedRecipeForFile createFromShapedRecipe(ShapedRecipes recipe) {
ShapedRecipeForFile convertedRecipe = new ShapedRecipeForFile();
convertedRecipe.group = recipe.getGroup();
ItemStack resultStack = recipe.getRecipeOutput();
convertedRecipe.result.count = resultStack.getCount();
convertedRecipe.result.item.item = resultStack.getItem().getRegistryName().toString();
if (resultStack.getItemDamage() != -1) {
convertedRecipe.result.item.data = resultStack.getItemDamage();
}
convertedRecipe.registryName = recipe.getRegistryName().getResourcePath();
NonNullList<Ingredient> ingredients = recipe.getIngredients();
String patternLine = "";
HashMap<String, ItemName> mappedItems = new HashMap();
mappedItems.put("a", null);
mappedItems.put("b", null);
mappedItems.put("c", null);
mappedItems.put("d", null);
mappedItems.put("e", null);
mappedItems.put("f", null);
mappedItems.put("g", null);
mappedItems.put("h", null);
mappedItems.put("i", null);
for (int i = 0; i < 9; i++) {
if (i == 3 || i == 6) {
convertedRecipe.pattern.add(patternLine);
patternLine = "";
}
Ingredient ingredient = ingredients.get(i);
ItemStack[] stacks = ingredient.getMatchingStacks();
if (stacks.length > 0) {
ItemStack stack = stacks[0];
if (stack != ItemStack.EMPTY) {
ItemName itemName = new ItemName();
itemName.item = stack.getItem().getRegistryName().toString();
if (stack.getItemDamage() != -1) {
itemName.data = stack.getItemDamage();
}
String key = "";
for (Entry<String, ItemName> entry : mappedItems.entrySet()) {
if (entry.getValue() != null && entry.getValue().item.equals(stack.getItem().getRegistryName().toString())) {
key = "existingItem";
patternLine = patternLine + entry.getKey();
break;
} else if (entry.getValue() == null) {
// This entry is blank, set it.
key = entry.getKey();
break;
}
}
if (!key.equals("")) {
if (!key.equals("existingItem")) {
mappedItems.put(key, itemName);
patternLine = patternLine + key;
switch(key) {
case "a":
{
convertedRecipe.key.a = itemName;
break;
}
case "b":
{
convertedRecipe.key.b = itemName;
break;
}
case "c":
{
convertedRecipe.key.c = itemName;
break;
}
case "d":
{
convertedRecipe.key.d = itemName;
break;
}
case "e":
{
convertedRecipe.key.e = itemName;
break;
}
case "f":
{
convertedRecipe.key.f = itemName;
break;
}
case "g":
{
convertedRecipe.key.g = itemName;
break;
}
case "h":
{
convertedRecipe.key.h = itemName;
break;
}
case "i":
{
convertedRecipe.key.i = itemName;
break;
}
}
}
} else {
patternLine = patternLine + " ";
}
} else {
patternLine = patternLine + " ";
}
} else {
patternLine = patternLine + " ";
}
}
convertedRecipe.pattern.add(patternLine);
return convertedRecipe;
}
use of net.minecraft.item.crafting.Ingredient in project Wizardry by TeamWizardry.
the class IStructure method craftItemFromInventory.
static ItemStack craftItemFromInventory(EntityPlayer player, ItemStack output) {
HashSet<IRecipe> recipes = getRecipesForItem(output);
if (recipes.isEmpty())
return ItemStack.EMPTY;
HashMap<ItemStack, Integer> finalInv = new HashMap<>();
IRecipe finalRecipe = null;
mainLoop: for (IRecipe recipe : recipes) {
if (recipe == null)
continue;
finalInv.clear();
finalRecipe = recipe;
ingLoop: for (Ingredient ingredient : recipe.getIngredients()) {
if (ingredient.getMatchingStacks().length <= 0)
continue;
// Check if has items
{
HashMap<Item, Integer> countStacks = new HashMap<>();
HashMap<Item, Integer> countAgainstStacks = new HashMap<>();
for (ItemStack stack : player.inventory.mainInventory) {
if (stack.isEmpty())
continue;
countStacks.put(stack.getItem(), countStacks.getOrDefault(stack.getItem(), 0) + stack.getCount());
}
for (ItemStack stack : finalInv.keySet()) {
countAgainstStacks.put(stack.getItem(), countAgainstStacks.getOrDefault(stack.getItem(), 0) + finalInv.get(stack));
}
for (Item countStack : countStacks.keySet()) {
if (countStacks.get(countStack) < countAgainstStacks.getOrDefault(countStack, 0)) {
finalInv.clear();
finalRecipe = null;
continue mainLoop;
}
}
}
for (ItemStack variant : ingredient.getMatchingStacks()) {
ItemStack stack;
if (player.inventory.hasItemStack(variant)) {
stack = player.inventory.getStackInSlot(player.inventory.getSlotFor(variant));
} else {
stack = craftItemFromInventory(player, variant);
if (!stack.isEmpty()) {
player.inventory.addItemStackToInventory(stack);
player.inventory.markDirty();
}
}
if (stack.isEmpty())
continue ingLoop;
finalInv.put(stack, (finalInv.getOrDefault(stack, 0)) + variant.getCount());
continue ingLoop;
}
continue mainLoop;
}
break;
}
if (finalRecipe == null)
return ItemStack.EMPTY;
if (finalInv.isEmpty())
return ItemStack.EMPTY;
else {
for (ItemStack stack : finalInv.keySet()) {
stack.shrink(finalInv.get(stack));
}
return finalRecipe.getRecipeOutput().copy();
}
}
use of net.minecraft.item.crafting.Ingredient in project Wizardry by TeamWizardry.
the class BlockFluidMana method onEntityUpdate.
@SubscribeEvent
public static void onEntityUpdate(EntityUpdateEvent event) {
Entity entityIn = event.getEntity();
BlockPos pos = entityIn.getPosition();
World world = entityIn.world;
IBlockState state = world.getBlockState(pos);
if (state.getBlock() == ModFluids.MANA.getActualBlock()) {
// Fizz all entities in the pool
if (world.isRemote)
run(world, pos, state.getBlock(), entityIn, entity -> true, entity -> LibParticles.FIZZING_AMBIENT(world, entityIn.getPositionVector()));
// Nullify gravity of player
if (!world.isRemote)
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityLivingBase, entity -> {
((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(ModPotions.NULLIFY_GRAVITY, 100, 0, true, false));
if (RandUtil.nextInt(50) == 0)
entity.attackEntityFrom(DamageSourceMana.INSTANCE, 0.1f);
});
// Subtract player food
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityPlayer, entity -> {
if (!world.isRemote) {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
Advancement advancement = server.getAdvancementManager().getAdvancement(new ResourceLocation(Wizardry.MODID, "advancements/advancement_crunch.json"));
if (advancement == null)
return;
AdvancementProgress progress = ((EntityPlayerMP) entity).getAdvancements().getProgress(advancement);
for (String s : progress.getRemaningCriteria()) {
((EntityPlayerMP) entity).getAdvancements().grantCriterion(advancement, s);
}
}
if (!((EntityPlayer) entity).capabilities.isCreativeMode && RandUtil.nextInt(50) == 0)
((EntityPlayer) entity).getFoodStats().addExhaustion(1f);
});
// Explode explodable items
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityItem && ((EntityItem) entity).getItem().getItem() instanceof IExplodable, entity -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), new ManaRecipes.ExplodableCrafter()));
}
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityItem && ManaRecipes.RECIPES.keySet().stream().anyMatch(item -> item.apply(((EntityItem) entity).getItem())), entity -> {
List<Map.Entry<Ingredient, FluidRecipeLoader.FluidCrafter>> allEntries = ManaRecipes.RECIPES.entries().stream().filter(entry -> entry.getValue().getFluid().getBlock() == state.getBlock() && entry.getKey().apply(((EntityItem) entity).getItem())).collect(Collectors.toList());
allEntries.forEach(crafter -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), crafter.getValue().build()));
});
}
Aggregations