use of net.minecraft.item.crafting.Ingredient in project takumicraft by TNTModders.
the class EntityDestructionCreeper method takumiExplodeEvent.
@Override
public boolean takumiExplodeEvent(Detonate event) {
if (!this.world.isRemote) {
float power = this.getPowered() ? 8f : 4f;
if (event.getExplosion() instanceof TakumiExplosion) {
power = ((TakumiExplosion) event.getExplosion()).getSize();
}
if (power > 0.5) {
for (BlockPos pos : event.getAffectedBlocks()) {
if (!this.world.isRemote && this.world.getBlockState(pos).getBlock().hasTileEntity(this.world.getBlockState(pos)) && this.world.getBlockState(pos).getBlock().createTileEntity(this.world, this.world.getBlockState(pos)) instanceof IInventory && TakumiUtils.takumiGetBlockResistance(this, this.world.getBlockState(pos), pos) != -1) {
// this.world.setBlockToAir(pos);
TakumiUtils.takumiCreateExplosion(this.world, this, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, power - 0.15f, false, true);
}
}
}
Map<IBlockState, IRecipe> map = new HashMap<>();
Map<IBlockState, Integer> count = new HashMap<>();
for (BlockPos pos : event.getAffectedBlocks()) {
IBlockState state = this.world.getBlockState(pos);
if (state.getMaterial() != Material.AIR) {
ItemStack stack = state.getBlock().getPickBlock(state, null, this.world, pos, null);
boolean flg = false;
for (IRecipe recipe : Lists.newArrayList(CraftingManager.REGISTRY.iterator())) {
if (recipe.getRecipeOutput().getItem() == stack.getItem() && recipe.getRecipeOutput().getMetadata() == stack.getMetadata()) {
if (!map.containsValue(recipe)) {
map.put(state, recipe);
}
flg = true;
}
}
if (flg) {
if (count.containsKey(state)) {
count.replace(state, count.get(state) + 1);
} else {
count.put(state, 1);
}
}
}
this.world.setBlockToAir(pos);
}
if (!map.isEmpty()) {
for (Entry<IBlockState, IRecipe> entry : Lists.newArrayList(map.entrySet())) {
IRecipe recipe = entry.getValue();
int i = count.get(entry.getKey());
List<ItemStack> stackList = new ArrayList<>();
for (Ingredient ingredient : recipe.getIngredients()) {
for (ItemStack stack : ingredient.getMatchingStacks()) {
if (!stackList.contains(stack)) {
stackList.add(stack);
}
}
}
for (ItemStack stack : stackList) {
stack.setCount(i);
this.world.spawnEntity(new EntityItem(this.world, posX, posY, posZ, stack));
}
}
}
// event.getAffectedBlocks().clear();
event.getAffectedEntities().clear();
}
return true;
}
use of net.minecraft.item.crafting.Ingredient in project Random-Things by lumien231.
the class ModRecipes method addGlowingMushroomRecipes.
public static void addGlowingMushroomRecipes() {
try {
Field listField = PotionHelper.class.getDeclaredField(MCPNames.field("field_185213_a"));
ReflectionUtil.makeModifiable(listField);
Field inputField = MixPredicate.class.getDeclaredField(MCPNames.field("field_185198_a"));
ReflectionUtil.makeModifiable(inputField);
Field reagentField = MixPredicate.class.getDeclaredField(MCPNames.field("field_185199_b"));
ReflectionUtil.makeModifiable(reagentField);
Field outputField = MixPredicate.class.getDeclaredField(MCPNames.field("field_185200_c"));
ReflectionUtil.makeModifiable(outputField);
List<PotionHelper.MixPredicate<PotionType>> conversionList = (List<MixPredicate<PotionType>>) listField.get(null);
List<MixPredicate<PotionType>> toAdd = new ArrayList<MixPredicate<PotionType>>();
for (MixPredicate<PotionType> p : conversionList) {
Ingredient reagent = (Ingredient) reagentField.get(p);
if (reagent.test(new ItemStack(Items.GLOWSTONE_DUST))) {
PotionType input = (PotionType) inputField.get(p);
PotionType output = (PotionType) outputField.get(p);
toAdd.add(new MixPredicate<PotionType>(input, Ingredient.fromItem(Item.getItemFromBlock(ModBlocks.glowingMushroom)), output));
}
}
RandomThings.instance.logger.log(Level.DEBUG, "Added " + toAdd.size() + " Glowing Mushroom Recipes");
conversionList.addAll(toAdd);
} catch (Exception e) {
RandomThings.instance.logger.log(Level.ERROR, "Couldn't add glowing mushroom potion recipes, please report this as a bug");
e.printStackTrace();
}
}
use of net.minecraft.item.crafting.Ingredient in project SecurityCraft by Geforce132.
the class RegistrationHandler method registerItemWithCustomRecipe.
/**
* Registers the given item with GameData.register_implItem(), and adds the help info for the item to the SecurityCraft manual item.
* Also overrides the default recipe that would've been drawn in the manual with a new recipe.
*/
private static void registerItemWithCustomRecipe(Item item, ItemStack... customRecipe) {
GameData.register_impl(item);
NonNullList<Ingredient> recipeItems = NonNullList.<Ingredient>withSize(customRecipe.length, Ingredient.EMPTY);
for (int i = 0; i < recipeItems.size(); i++) recipeItems.set(i, Ingredient.fromStacks(customRecipe[i]));
SecurityCraft.instance.manualPages.add(new SCManualPage(item, "help." + item.getUnlocalizedName().substring(5) + ".info", recipeItems));
}
use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.
the class RecipeReplacement method process.
public void process(Collection<IRecipe> registry) {
for (IRecipe recipe : registry) {
ResourceLocation recipeName = recipe.getRegistryName();
boolean dirty = false;
if (recipe instanceof ShapedRecipes || recipe instanceof ShapelessRecipes || recipe instanceof ShapedOreRecipe || recipe instanceof ShapelessOreRecipe) {
NonNullList<Ingredient> ingredients = recipe.getIngredients();
for (int i = 0; i < ingredients.size(); i++) {
Ingredient ing = ingredients.get(i);
Ingredient ingNew = replaceIngredient(ing);
if (ingNew != null) {
ingredients.set(i, ingNew);
dirty = true;
}
}
} else if (recipe instanceof RecipeCharset) {
TCharObjectMap<Ingredient> charToIngredient = ((RecipeCharset) recipe).charToIngredient;
NonNullList<Ingredient> ingredients = recipe.getIngredients();
for (int i = 0; i < ingredients.size(); i++) {
Ingredient ing = ingredients.get(i);
Ingredient ingNew = replaceIngredient(ing);
if (ingNew != null) {
ingredients.set(i, ingNew);
TCharIterator iterator = charToIngredient.keySet().iterator();
while (iterator.hasNext()) {
char c = iterator.next();
if (charToIngredient.get(c) == ing) {
charToIngredient.put(c, ing);
}
}
dirty = true;
}
}
}
if (dirty) {
ModCharset.logger.info("Successfully edited " + recipeName + "!");
}
}
}
use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.
the class KeyOutputSupplier method getCraftingResult.
@Override
public ItemStack getCraftingResult(RecipeCharset recipe, IngredientMatcher matcher, InventoryCrafting inv) {
if (duplicate) {
for (Ingredient i : matcher.getMatchedIngredients()) {
if (i.apply(output)) {
ItemStack key = matcher.getStack(i);
ItemStack result = output.copy();
NBTTagCompound cpd = new NBTTagCompound();
cpd.setString("key", ((ItemKey) key.getItem()).getKey(key));
result.setTagCompound(cpd);
return result;
}
}
return null;
} else {
ItemStack result = output.copy();
NBTTagCompound cpd = new NBTTagCompound();
cpd.setString("key", new UUID(rand.nextLong(), rand.nextLong()).toString());
result.setTagCompound(cpd);
return result;
}
}
Aggregations