Search in sources :

Example 1 with ICrusherRecipe

use of com.mcmoddev.lib.registry.recipe.ICrusherRecipe in project BaseMetals by MinecraftModDevelopmentMods.

the class ItemMMDCrackHammer method onBlockDestroyed.

@Override
public boolean onBlockDestroyed(final ItemStack tool, final World world, final IBlockState target, final BlockPos coord, final EntityLivingBase player) {
    if (!world.isRemote && this.canHarvestBlock(target)) {
        IBlockState bs = world.getBlockState(coord);
        ICrusherRecipe recipe = getCrusherRecipe(bs);
        if (recipe != null) {
            ItemStack output = recipe.getOutput().copy();
            world.setBlockToAir(coord);
            if (output != null) {
                int num = output.getCount();
                output.setCount(1);
                for (int i = 0; i < num; i++) {
                    world.spawnEntity(new EntityItem(world, coord.getX() + 0.5, coord.getY() + 0.5, coord.getZ() + 0.5, output.copy()));
                }
            }
        }
    }
    return super.onBlockDestroyed(tool, world, target, coord, player);
}
Also used : ICrusherRecipe(com.mcmoddev.lib.registry.recipe.ICrusherRecipe) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with ICrusherRecipe

use of com.mcmoddev.lib.registry.recipe.ICrusherRecipe in project BaseMetals by MinecraftModDevelopmentMods.

the class ModelDataFix method crusherRecipeRegistryFix.

@SubscribeEvent
public static void crusherRecipeRegistryFix(RegistryEvent.MissingMappings<ICrusherRecipe> ev) {
    ev.getAllMappings().stream().filter(mapping -> mapping.key.getNamespace().equalsIgnoreCase(MMDLib.MODID)).forEach(mapping -> {
        ResourceLocation remap = new ResourceLocation(BaseMetals.MODID, mapping.key.getPath());
        ICrusherRecipe recipeRemap = CrusherRecipeRegistry.getInstance().getRegistry().getValue(remap);
        if (recipeRemap != null) {
            mapping.remap(recipeRemap);
        }
    });
}
Also used : Arrays(java.util.Arrays) Materials(com.mcmoddev.lib.init.Materials) MaterialNames(com.mcmoddev.lib.data.MaterialNames) Item(net.minecraft.item.Item) ICrusherRecipe(com.mcmoddev.lib.registry.recipe.ICrusherRecipe) MMDMaterial(com.mcmoddev.lib.material.MMDMaterial) MMDLib(com.mcmoddev.lib.MMDLib) Names(com.mcmoddev.lib.data.Names) List(java.util.List) Block(net.minecraft.block.Block) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) CrusherRecipeRegistry(com.mcmoddev.lib.registry.CrusherRecipeRegistry) RegistryEvent(net.minecraftforge.event.RegistryEvent) Mod(net.minecraftforge.fml.common.Mod) ICrusherRecipe(com.mcmoddev.lib.registry.recipe.ICrusherRecipe) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with ICrusherRecipe

use of com.mcmoddev.lib.registry.recipe.ICrusherRecipe in project BaseMetals by MinecraftModDevelopmentMods.

the class ItemMMDCrackHammer method onItemUse.

@Override
public EnumActionResult onItemUse(final EntityPlayer player, final World w, final BlockPos coord, final EnumHand hand, final EnumFacing facing, final float partialX, final float partialY, final float partialZ) {
    final ItemStack item = player.getHeldItemMainhand();
    if (facing != EnumFacing.UP) {
        return EnumActionResult.PASS;
    }
    /*List<EntityItem> entities = */
    AxisAlignedBB boundingBox = new AxisAlignedBB(coord.getX(), coord.getY() + 1, coord.getZ(), coord.getX() + 1, coord.getY() + 2, coord.getZ() + 1);
    List<EntityItem> entities = w.getEntitiesWithinAABB(EntityItem.class, boundingBox).stream().filter(elem -> (elem.getItem() != null)).filter(elem -> (CrusherRecipeRegistry.getRecipeForInputItem(elem.getItem()) != null)).collect(Collectors.toList());
    if (!entities.isEmpty()) {
        ItemStack targetItem = entities.get(0).getItem();
        ICrusherRecipe recipe = CrusherRecipeRegistry.getRecipeForInputItem(targetItem);
        if (hardnessCheck(targetItem)) {
            return EnumActionResult.PASS;
        }
        maybeDoCrack(recipe, targetItem, item, entities.get(0), player, w);
        w.playSound(player, coord, SoundEvents.BLOCK_GRAVEL_BREAK, SoundCategory.BLOCKS, 0.5F, 0.5F + (itemRand.nextFloat() * 0.3F));
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.PASS;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Materials(com.mcmoddev.lib.init.Materials) Item(net.minecraft.item.Item) ICrusherRecipe(com.mcmoddev.lib.registry.recipe.ICrusherRecipe) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumHand(net.minecraft.util.EnumHand) MMDMaterial(com.mcmoddev.lib.material.MMDMaterial) ITooltipFlag(net.minecraft.client.util.ITooltipFlag) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) IMMDObject(com.mcmoddev.lib.material.IMMDObject) SoundCategory(net.minecraft.util.SoundCategory) Options(com.mcmoddev.lib.util.ConfigBase.Options) EntityItem(net.minecraft.entity.item.EntityItem) Entity(net.minecraft.entity.Entity) SoundEvents(net.minecraft.init.SoundEvents) MMDToolEffects(com.mcmoddev.basemetals.items.MMDToolEffects) World(net.minecraft.world.World) Set(java.util.Set) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) Names(com.mcmoddev.lib.data.Names) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) Material(net.minecraft.block.material.Material) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) CrusherRecipeRegistry(com.mcmoddev.lib.registry.CrusherRecipeRegistry) ItemBlock(net.minecraft.item.ItemBlock) ICrusherRecipe(com.mcmoddev.lib.registry.recipe.ICrusherRecipe) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

ICrusherRecipe (com.mcmoddev.lib.registry.recipe.ICrusherRecipe)3 Names (com.mcmoddev.lib.data.Names)2 Materials (com.mcmoddev.lib.init.Materials)2 MMDMaterial (com.mcmoddev.lib.material.MMDMaterial)2 CrusherRecipeRegistry (com.mcmoddev.lib.registry.CrusherRecipeRegistry)2 List (java.util.List)2 Block (net.minecraft.block.Block)2 IBlockState (net.minecraft.block.state.IBlockState)2 EntityItem (net.minecraft.entity.item.EntityItem)2 Item (net.minecraft.item.Item)2 ItemStack (net.minecraft.item.ItemStack)2 MMDToolEffects (com.mcmoddev.basemetals.items.MMDToolEffects)1 MMDLib (com.mcmoddev.lib.MMDLib)1 MaterialNames (com.mcmoddev.lib.data.MaterialNames)1 IMMDObject (com.mcmoddev.lib.material.IMMDObject)1 Options (com.mcmoddev.lib.util.ConfigBase.Options)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1