Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.doggie.raremetalsrevised.enchantments;
- import com.doggie.raremetalsrevised.init.EnchantmentInit;
- import com.google.gson.JsonObject;
- import net.minecraft.block.AirBlock;
- import net.minecraft.block.Block;
- import net.minecraft.block.Blocks;
- import net.minecraft.enchantment.Enchantment;
- import net.minecraft.enchantment.EnchantmentHelper;
- import net.minecraft.enchantment.EnchantmentType;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.LivingEntity;
- import net.minecraft.inventory.EquipmentSlotType;
- import net.minecraft.inventory.Inventory;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.Rarity;
- import net.minecraft.item.crafting.FurnaceRecipe;
- import net.minecraft.item.crafting.IRecipeType;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.IWorld;
- import net.minecraft.world.World;
- import net.minecraft.world.storage.loot.LootContext;
- import net.minecraft.world.storage.loot.conditions.ILootCondition;
- import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
- import net.minecraftforge.common.loot.LootModifier;
- import net.minecraftforge.event.world.BlockEvent;
- import net.minecraftforge.eventbus.api.SubscribeEvent;
- import net.minecraftforge.items.ItemHandlerHelper;
- import javax.annotation.Nonnull;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- public class SmelterEnchantment extends Enchantment {
- public SmelterEnchantment(Rarity rarityIn, EnchantmentType typeIn, EquipmentSlotType... slots) {
- super(rarityIn, typeIn, slots);
- }
- }
- /**
- * The smelting enchantment causes this modifier to be invoked, via the smelting loot_modifier json
- *
- */ class SmeltingEnchantmentModifier extends LootModifier {
- public SmeltingEnchantmentModifier(ILootCondition[] conditionsIn) {
- super(conditionsIn);
- }
- @Nonnull
- @Override
- public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
- ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
- generatedLoot.forEach((stack) -> ret.add(smelt(stack, context)));
- return ret;
- }
- private static ItemStack smelt(ItemStack stack, LootContext context) {
- return context.getWorld().getRecipeManager().getRecipe(IRecipeType.SMELTING, new Inventory(stack), context.getWorld())
- .map(FurnaceRecipe::getRecipeOutput)
- .filter(itemStack -> !itemStack.isEmpty())
- .map(itemStack -> ItemHandlerHelper.copyStackWithSize(itemStack, stack.getCount() * itemStack.getCount()))
- .orElse(stack);
- }
- private static class Serializer extends GlobalLootModifierSerializer<SmeltingEnchantmentModifier> {
- @Override
- public SmeltingEnchantmentModifier read(ResourceLocation name, JsonObject json, ILootCondition[] conditionsIn) {
- return new SmeltingEnchantmentModifier(conditionsIn);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment