Search in sources :

Example 1 with AlchemyArrayEffect

use of WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect in project BloodMagic by WayofTime.

the class BindingRecipeMaker method getRecipes.

@Nonnull
public static List<BindingRecipeJEI> getRecipes() {
    Map<List<ItemStack>, AlchemyArrayRecipeRegistry.AlchemyArrayRecipe> alchemyArrayRecipeMap = AlchemyArrayRecipeRegistry.getRecipes();
    ArrayList<BindingRecipeJEI> recipes = new ArrayList<>();
    for (Map.Entry<List<ItemStack>, AlchemyArrayRecipeRegistry.AlchemyArrayRecipe> itemStackAlchemyArrayRecipeEntry : alchemyArrayRecipeMap.entrySet()) {
        List<ItemStack> input = itemStackAlchemyArrayRecipeEntry.getValue().getInput();
        BiMap<ItemStackWrapper, AlchemyArrayEffect> catalystMap = itemStackAlchemyArrayRecipeEntry.getValue().catalystMap;
        for (Map.Entry<ItemStackWrapper, AlchemyArrayEffect> entry : catalystMap.entrySet()) {
            ItemStack catalyst = entry.getKey().toStack();
            if (AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(input, catalyst) instanceof AlchemyArrayEffectBinding) {
                ItemStack output = ((AlchemyArrayEffectBinding) itemStackAlchemyArrayRecipeEntry.getValue().getAlchemyArrayEffectForCatalyst(catalyst)).outputStack;
                BindingRecipeJEI recipe = new BindingRecipeJEI(input, catalyst, output);
                recipes.add(recipe);
            }
        }
    }
    return recipes;
}
Also used : ArrayList(java.util.ArrayList) AlchemyArrayEffectBinding(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectBinding) AlchemyArrayEffect(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect) List(java.util.List) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) ItemStackWrapper(WayofTime.bloodmagic.util.ItemStackWrapper) BiMap(com.google.common.collect.BiMap) Map(java.util.Map) Nonnull(javax.annotation.Nonnull)

Example 2 with AlchemyArrayEffect

use of WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect in project BloodMagic by WayofTime.

the class TileAlchemyArray method attemptCraft.

public boolean attemptCraft() {
    AlchemyArrayEffect effect = AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(this.getStackInSlot(0), this.getStackInSlot(1));
    if (effect != null) {
        if (arrayEffect == null) {
            arrayEffect = effect;
            key = effect.getKey();
        } else {
            String effectKey = effect.getKey();
            if (effectKey.equals(key)) {
            // Good! Moving on.
            } else {
                // Something has changed, therefore we have to move our stuffs.
                // TODO: Add an AlchemyArrayEffect.onBreak(); ?
                arrayEffect = effect;
                key = effect.getKey();
            }
        }
    } else {
        RecipeAlchemyArray recipe = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getAlchemyArray(getStackInSlot(0), getStackInSlot(1));
        if (recipe == null)
            return false;
        AlchemyArrayEffect newEffect = new AlchemyArrayEffectCraftingNew(recipe);
        if (arrayEffect == null) {
            arrayEffect = newEffect;
            key = newEffect.key;
        } else if (!newEffect.key.equals(key)) {
            arrayEffect = newEffect;
            key = newEffect.key;
        }
    }
    if (arrayEffect != null) {
        isActive = true;
        if (arrayEffect.update(this, this.activeCounter)) {
            this.decrStackSize(0, 1);
            this.decrStackSize(1, 1);
            this.getWorld().setBlockToAir(getPos());
        }
        return true;
    }
    return false;
}
Also used : AlchemyArrayEffect(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect) AlchemyArrayEffectCraftingNew(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectCraftingNew) RecipeAlchemyArray(WayofTime.bloodmagic.api.impl.recipe.RecipeAlchemyArray)

Example 3 with AlchemyArrayEffect

use of WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect in project BloodMagic by WayofTime.

the class AlchemyArrayRecipeRegistry method registerRecipe.

/**
 * General case for creating an AlchemyArrayEffect for a given input.
 *
 * @param input          - Input item(s) that is used to change the Alchemy Circle into the
 *                       circle that you are making
 * @param catalystStack  - Catalyst item that, when right-clicked onto the array, will
 *                       cause an effect
 * @param arrayEffect    - The effect that will be activated once the array is activated
 * @param circleRenderer - Circle rendered when the array is passive - can be substituted
 *                       for a special renderer
 */
public static void registerRecipe(List<ItemStack> input, @Nullable ItemStack catalystStack, AlchemyArrayEffect arrayEffect, AlchemyCircleRenderer circleRenderer) {
    effectMap.put(arrayEffect.getKey(), arrayEffect);
    for (Entry<List<ItemStack>, AlchemyArrayRecipe> entry : recipes.entrySet()) {
        AlchemyArrayRecipe arrayRecipe = entry.getValue();
        if (arrayRecipe.doesInputMatchRecipe(input)) {
            AlchemyArrayEffect eff = arrayRecipe.getAlchemyArrayEffectForCatalyst(catalystStack);
            if (eff != null) {
                // Recipe already exists!
                return;
            } else {
                arrayRecipe.catalystMap.put(ItemStackWrapper.getHolder(catalystStack), arrayEffect);
                if (circleRenderer != null) {
                    if (arrayRecipe.defaultCircleRenderer == null) {
                        arrayRecipe.defaultCircleRenderer = circleRenderer;
                    } else {
                        arrayRecipe.circleMap.put(ItemStackWrapper.getHolder(catalystStack), circleRenderer);
                    }
                }
                return;
            }
        }
    }
    recipes.put(input, new AlchemyArrayRecipe(input, catalystStack, arrayEffect, circleRenderer == null ? DEFAULT_RENDERER : circleRenderer));
}
Also used : AlchemyArrayEffect(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect) List(java.util.List)

Example 4 with AlchemyArrayEffect

use of WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect in project BloodMagic by WayofTime.

the class TurretAlchemyCircleRenderer method renderAt.

@Override
public void renderAt(TileEntity tile, double x, double y, double z, float craftTime) {
    if (!(tile instanceof TileAlchemyArray)) {
        return;
    }
    // Not working
    float f = 0;
    TileAlchemyArray tileArray = (TileAlchemyArray) tile;
    AlchemyArrayEffect effect = tileArray.arrayEffect;
    double pitch = 0;
    double yaw = 0;
    int arrowTimer = -1;
    if (effect instanceof AlchemyArrayEffectArrowTurret) {
        AlchemyArrayEffectArrowTurret turretEffect = (AlchemyArrayEffectArrowTurret) effect;
        pitch = (turretEffect.getPitch() - turretEffect.getLastPitch()) * f + turretEffect.getLastPitch();
        yaw = (turretEffect.getYaw() - turretEffect.getLastYaw()) * f + turretEffect.getLastYaw();
        arrowTimer = turretEffect.arrowTimer;
    }
    double arrowAnimation = arrowTimer + f;
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder wr = tessellator.getBuffer();
    GlStateManager.pushMatrix();
    float rot = getRotation(craftTime);
    float size = 1.0F * getSizeModifier(craftTime);
    // Bind the texture to the circle
    Minecraft.getMinecraft().renderEngine.bindTexture(arrayResource);
    GlStateManager.disableCull();
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(770, 1);
    GlStateManager.translate(x, y, z);
    // Specify which face this "circle" is located on
    EnumFacing sideHit = EnumFacing.UP;
    EnumFacing rotation = tileArray.getRotation();
    GlStateManager.translate(sideHit.getFrontOffsetX() * offsetFromFace, sideHit.getFrontOffsetY() * offsetFromFace, sideHit.getFrontOffsetZ() * offsetFromFace);
    switch(sideHit) {
        case DOWN:
            GlStateManager.translate(0, 0, 1);
            GlStateManager.rotate(-90.0f, 1, 0, 0);
            break;
        case EAST:
            GlStateManager.rotate(-90.0f, 0, 1, 0);
            GlStateManager.translate(0, 0, -1);
            break;
        case NORTH:
            break;
        case SOUTH:
            GlStateManager.rotate(180.0f, 0, 1, 0);
            GlStateManager.translate(-1, 0, -1);
            break;
        case UP:
            GlStateManager.translate(0, 1, 0);
            GlStateManager.rotate(90.0f, 1, 0, 0);
            break;
        case WEST:
            GlStateManager.translate(0, 0, 1);
            GlStateManager.rotate(90.0f, 0, 1, 0);
            break;
    }
    GlStateManager.pushMatrix();
    GlStateManager.translate(0.5f, 0.5f, getVerticalOffset(craftTime));
    // GlStateManager.rotate(rotation.getHorizontalAngle() + 180, 0, 0, 1);
    GlStateManager.pushMatrix();
    double topHeightOffset = getTopHeightOffset(craftTime, arrowAnimation);
    double middleHeightOffset = getMiddleHeightOffset(craftTime, arrowAnimation);
    double bottomHeightOffset = getBottomHeightOffset(craftTime, arrowAnimation);
    BlockPos pos = tileArray.getPos();
    World world = tileArray.getWorld();
    GlStateManager.rotate((float) (yaw + 360 * getStartupPitchYawRatio(craftTime)), 0, 0, 1);
    GlStateManager.rotate((float) ((pitch + 90) * getStartupPitchYawRatio(craftTime)), 1, 0, 0);
    GlStateManager.pushMatrix();
    Minecraft.getMinecraft().renderEngine.bindTexture(bottomArrayResource);
    GlStateManager.rotate(-rot, 0, 0, 1);
    GlStateManager.translate(0, 0, -bottomHeightOffset);
    renderStandardCircle(tessellator, wr, size / 2);
    GlStateManager.popMatrix();
    GlStateManager.pushMatrix();
    Minecraft.getMinecraft().renderEngine.bindTexture(middleArrayResource);
    GlStateManager.rotate(0, 0, 0, 1);
    GlStateManager.translate(0, 0, -middleHeightOffset);
    renderStandardCircle(tessellator, wr, size);
    GlStateManager.popMatrix();
    GlStateManager.pushMatrix();
    Minecraft.getMinecraft().renderEngine.bindTexture(arrayResource);
    GlStateManager.rotate(rot, 0, 0, 1);
    GlStateManager.translate(0, 0, -topHeightOffset);
    renderStandardCircle(tessellator, wr, size);
    GlStateManager.popMatrix();
    GlStateManager.popMatrix();
    // GlStateManager.depthMask(true);
    GlStateManager.disableBlend();
    GlStateManager.enableCull();
    // GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GlStateManager.popMatrix();
    GlStateManager.popMatrix();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) EnumFacing(net.minecraft.util.EnumFacing) AlchemyArrayEffect(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect) BlockPos(net.minecraft.util.math.BlockPos) TileAlchemyArray(WayofTime.bloodmagic.tile.TileAlchemyArray) World(net.minecraft.world.World) AlchemyArrayEffectArrowTurret(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectArrowTurret)

Example 5 with AlchemyArrayEffect

use of WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect in project BloodMagic by WayofTime.

the class AlchemyArrayRecipeRegistry method getRecipeForOutputStack.

/**
 * @param stack of the recipe
 * @return an array of two ItemStacks - first index is the input stack,
 * second is the catalyst stack. Returns {null, null} if no recipe
 * is valid.
 */
public static ItemStack[] getRecipeForOutputStack(ItemStack stack) {
    for (Entry<List<ItemStack>, AlchemyArrayRecipe> entry : recipes.entrySet()) {
        AlchemyArrayRecipe recipe = entry.getValue();
        if (recipe != null && entry.getKey().size() > 0) {
            for (Entry<ItemStackWrapper, AlchemyArrayEffect> effectEntry : recipe.catalystMap.entrySet()) {
                if (effectEntry.getValue() instanceof AlchemyArrayEffectCrafting) {
                    AlchemyArrayEffectCrafting craftingEffect = (AlchemyArrayEffectCrafting) effectEntry.getValue();
                    ItemStack resultStack = craftingEffect.outputStack;
                    if (!resultStack.isEmpty()) {
                        if (resultStack.getItem() == stack.getItem() && resultStack.getItemDamage() == stack.getItemDamage()) {
                            return new ItemStack[] { entry.getKey().get(0), effectEntry.getKey().toStack() };
                        }
                    }
                }
            }
        }
    }
    return new ItemStack[] { null, null };
}
Also used : AlchemyArrayEffectCrafting(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectCrafting) AlchemyArrayEffect(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect) List(java.util.List) ItemStackWrapper(WayofTime.bloodmagic.util.ItemStackWrapper) ItemStack(net.minecraft.item.ItemStack)

Aggregations

AlchemyArrayEffect (WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect)5 List (java.util.List)3 ItemStackWrapper (WayofTime.bloodmagic.util.ItemStackWrapper)2 ItemStack (net.minecraft.item.ItemStack)2 AlchemyArrayEffectArrowTurret (WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectArrowTurret)1 AlchemyArrayEffectBinding (WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectBinding)1 AlchemyArrayEffectCrafting (WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectCrafting)1 AlchemyArrayEffectCraftingNew (WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectCraftingNew)1 RecipeAlchemyArray (WayofTime.bloodmagic.api.impl.recipe.RecipeAlchemyArray)1 TileAlchemyArray (WayofTime.bloodmagic.tile.TileAlchemyArray)1 BiMap (com.google.common.collect.BiMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Nonnull (javax.annotation.Nonnull)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1