Search in sources :

Example 1 with PressureChamberRecipe

use of pneumaticCraft.api.recipe.PressureChamberRecipe in project PneumaticCraft by MineMaarten.

the class EE3 method postInit.

@Override
public void postInit() {
    for (PressureChamberRecipe recipe : PressureChamberRecipe.chamberRecipes) {
        if (recipe.output.length == 1) {
            List<ItemStack> stacks = new ArrayList<ItemStack>();
            for (Object o : recipe.input) {
                stacks.add(PneumaticRecipeRegistry.getSingleStack(o));
            }
            RecipeRegistryProxy.addRecipe(recipe.output[0], stacks);
        } else {
            Log.info("Found a Pressure Chamber recipe that has more than one output. This will cause problems with DynEMC!");
        }
    }
    registerAssemblyRecipes(AssemblyRecipe.drillLaserRecipes);
    registerAssemblyRecipes(AssemblyRecipe.drillRecipes);
    registerAssemblyRecipes(AssemblyRecipe.laserRecipes);
}
Also used : ArrayList(java.util.ArrayList) PressureChamberRecipe(pneumaticCraft.api.recipe.PressureChamberRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 2 with PressureChamberRecipe

use of pneumaticCraft.api.recipe.PressureChamberRecipe in project PneumaticCraft by MineMaarten.

the class TileEntityPressureChamberValve method updateEntity.

// main update method
@Override
public void updateEntity() {
    if (readNBT) {
        // this way of doing this is needed because other TE's are
        // loaded after the reading of the NBT of this TE.
        readNBT = false;
        accessoryValves.clear();
        for (int[] valve : nbtValveList) {
            TileEntity te = worldObj.getTileEntity(valve[0], valve[1], valve[2]);
            if (te instanceof TileEntityPressureChamberValve) {
                accessoryValves.add((TileEntityPressureChamberValve) te);
            }
        }
        if (accessoryValves.isEmpty()) {
            // Hacky solution for an unexplainable bug.
            invalidateMultiBlock();
            checkIfProperlyFormed(worldObj, xCoord, yCoord, zCoord);
        }
        if (worldObj.isRemote)
            worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
    }
    if (!worldObj.isRemote) {
        // code to check if we need to leak air.
        // assume we are not leaking at any side
        boolean[] connected = new boolean[] { true, true, true, true, true, true };
        switch(// take off the sides that tubes can connect to.
        ForgeDirection.getOrientation(getBlockMetadata())) {
            case UP:
            case DOWN:
                connected[ForgeDirection.UP.ordinal()] = false;
                connected[ForgeDirection.DOWN.ordinal()] = false;
                break;
            case NORTH:
            case SOUTH:
                connected[ForgeDirection.NORTH.ordinal()] = false;
                connected[ForgeDirection.SOUTH.ordinal()] = false;
                break;
            case EAST:
            case WEST:
                connected[ForgeDirection.EAST.ordinal()] = false;
                connected[ForgeDirection.WEST.ordinal()] = false;
                break;
        }
        // we need the super method, as the overridden method adds the other valves.
        List<Pair<ForgeDirection, IAirHandler>> teList = super.getConnectedPneumatics();
        for (Pair<ForgeDirection, IAirHandler> entry : teList) {
            connected[entry.getKey().ordinal()] = true;
        }
        // retrieve the valve that is controlling the (potential) chamber.
        TileEntityPressureChamberValve baseValve = null;
        for (TileEntityPressureChamberValve valve : accessoryValves) {
            if (valve.multiBlockSize > 0) {
                baseValve = valve;
                break;
            }
        }
        // if we found one, we can scratch one side to be leaking air.
        if (baseValve != null) {
            switch(ForgeDirection.getOrientation(getBlockMetadata())) {
                case UP:
                case DOWN:
                    if (baseValve.multiBlockY == yCoord)
                        connected[ForgeDirection.UP.ordinal()] = true;
                    else
                        connected[ForgeDirection.DOWN.ordinal()] = true;
                    break;
                case NORTH:
                case SOUTH:
                    if (baseValve.multiBlockZ == zCoord)
                        connected[ForgeDirection.SOUTH.ordinal()] = true;
                    else
                        connected[ForgeDirection.NORTH.ordinal()] = true;
                    break;
                case EAST:
                case WEST:
                    if (baseValve.multiBlockX == xCoord)
                        connected[ForgeDirection.EAST.ordinal()] = true;
                    else
                        connected[ForgeDirection.WEST.ordinal()] = true;
                    break;
            }
        }
        for (int i = 0; i < 6; i++) if (!connected[i])
            airLeak(ForgeDirection.getOrientation(i));
    }
    super.updateEntity();
    if (multiBlockSize != 0 && !worldObj.isRemote) {
        ItemStack[] stacksInChamber = getStacksInChamber();
        isValidRecipeInChamber = false;
        isSufficientPressureInChamber = false;
        recipePressure = Float.MAX_VALUE;
        // simple recipes
        for (PressureChamberRecipe recipe : PressureChamberRecipe.chamberRecipes) {
            boolean isValidRecipeInChamberFlag = canBeCompressed(recipe, stacksInChamber);
            boolean isSufficientPressureInChamberFlag = recipe.pressure <= getPressure(ForgeDirection.UNKNOWN) && recipe.pressure > 0F || recipe.pressure >= getPressure(ForgeDirection.UNKNOWN) && recipe.pressure < 0F;
            if (isValidRecipeInChamberFlag) {
                isValidRecipeInChamber = true;
                if (Math.abs(recipe.pressure) < Math.abs(recipePressure)) {
                    recipePressure = recipe.pressure;
                }
            }
            if (isSufficientPressureInChamberFlag)
                isSufficientPressureInChamber = true;
            if (isValidRecipeInChamberFlag && isSufficientPressureInChamberFlag && areEntitiesDoneMoving) {
                double[] outputPosition = clearStacksInChamber(recipe.input);
                giveOutput(recipe.output, outputPosition);
            }
        }
        // special recipes
        for (IPressureChamberRecipe recipe : PressureChamberRecipe.specialRecipes) {
            ItemStack[] removedStacks = recipe.isValidRecipe(stacksInChamber);
            boolean isValidRecipeInChamberFlag = removedStacks != null;
            boolean isSufficientPressureInChamberFlag = recipe.getCraftingPressure() <= getPressure(ForgeDirection.UNKNOWN) && recipe.getCraftingPressure() > 0F || recipe.getCraftingPressure() >= getPressure(ForgeDirection.UNKNOWN) && recipe.getCraftingPressure() < 0F;
            if (isValidRecipeInChamberFlag) {
                isValidRecipeInChamber = true;
                if (Math.abs(recipe.getCraftingPressure()) < Math.abs(recipePressure)) {
                    recipePressure = recipe.getCraftingPressure();
                }
            }
            if (isSufficientPressureInChamberFlag)
                isSufficientPressureInChamber = true;
            if (isValidRecipeInChamberFlag && isSufficientPressureInChamberFlag && areEntitiesDoneMoving) {
                double[] outputPosition = clearStacksInChamber(removedStacks);
                giveOutput(recipe.craftRecipe(stacksInChamber, removedStacks), outputPosition);
            }
        }
        if (getPressure(ForgeDirection.UNKNOWN) > PneumaticValues.MAX_PRESSURE_LIVING_ENTITY) {
            AxisAlignedBB bbBox = AxisAlignedBB.getBoundingBox(multiBlockX + 1, multiBlockY + 1, multiBlockZ + 1, multiBlockX + multiBlockSize - 1, multiBlockY + multiBlockSize - 1, multiBlockZ + multiBlockSize - 1);
            List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, bbBox);
            for (EntityLivingBase entity : entities) {
                if (entity instanceof EntityVillager) {
                    EntityVillager villager = (EntityVillager) entity;
                    if (villager.getProfession() != Config.villagerMechanicID) {
                        villager.setProfession(Config.villagerMechanicID);
                        NBTTagCompound tag = new NBTTagCompound();
                        villager.writeEntityToNBT(tag);
                        if (tag.hasKey("Offers")) {
                            // reset the trade list
                            tag.removeTag("Offers");
                            villager.readEntityFromNBT(tag);
                        }
                    }
                }
                entity.attackEntityFrom(DamageSourcePneumaticCraft.pressure, (int) (getPressure(ForgeDirection.UNKNOWN) * 2D));
            }
        }
    }
    // move entities to eachother.
    AxisAlignedBB bbBox = AxisAlignedBB.getBoundingBox(multiBlockX, multiBlockY, multiBlockZ, multiBlockX + multiBlockSize, multiBlockY + multiBlockSize, multiBlockZ + multiBlockSize);
    List<EntityItem> entities = worldObj.getEntitiesWithinAABB(EntityItem.class, bbBox);
    // set to true, set to false when one of
    areEntitiesDoneMoving = true;
    // the entities is moving.
    for (int i = 0; i < entities.size() - 1; i++) {
        EntityItem lastEntity = entities.get(i);
        EntityItem entity = entities.get(i + 1);
        // XP Orb code snippet
        double d0 = 8.0D;
        double d1 = (lastEntity.posX - entity.posX) / d0;
        double d3 = (lastEntity.posZ - entity.posZ) / d0;
        double d4 = Math.sqrt(d1 * d1 + d3 * d3);
        double d5 = 1.0D - d4;
        if (d5 > 0.0D && d4 > 0.02D) {
            d5 *= d5;
            entity.motionX += d1 / d4 * d5 * 0.01D;
            entity.motionZ += d3 / d4 * d5 * 0.01D;
            lastEntity.motionX -= d1 / d4 * d5 * 0.01D;
            lastEntity.motionZ -= d3 / d4 * d5 * 0.01D;
            areEntitiesDoneMoving = false;
        }
    }
    boolean lifeUpgrade = getUpgrades(ItemMachineUpgrade.UPGRADE_ITEM_LIFE, getUpgradeSlots()) > 0;
    if (lifeUpgrade && !worldObj.isRemote) {
        for (EntityItem entity : entities) {
            entity.age--;
        }
    }
    // particles
    if (worldObj.isRemote && getPressure(ForgeDirection.UNKNOWN) > 0.2D) {
        int particles = (int) Math.pow(multiBlockSize - 2, 3);
        for (int i = 0; i < particles; i++) {
            if (rand.nextInt(Math.max(1, 8 - (int) (getPressure(ForgeDirection.UNKNOWN) * 2D))) == 0) {
                double posX = multiBlockX + 1D + rand.nextDouble() * (multiBlockSize - 2D);
                double posY = multiBlockY + 1D + rand.nextDouble() * (multiBlockSize - 2D);
                double posZ = multiBlockZ + 1D + rand.nextDouble() * (multiBlockSize - 2D);
                worldObj.spawnParticle("explode", posX, posY, posZ, 0D, 0D, 0D);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IPressureChamberRecipe(pneumaticCraft.api.recipe.IPressureChamberRecipe) PressureChamberRecipe(pneumaticCraft.api.recipe.PressureChamberRecipe) TileEntity(net.minecraft.tileentity.TileEntity) IPressureChamberRecipe(pneumaticCraft.api.recipe.IPressureChamberRecipe) IAirHandler(pneumaticCraft.api.tileentity.IAirHandler) EntityVillager(net.minecraft.entity.passive.EntityVillager) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 3 with PressureChamberRecipe

use of pneumaticCraft.api.recipe.PressureChamberRecipe in project PneumaticCraft by MineMaarten.

the class IntegratorPressureChamber method onCommandInvoke.

@Override
public void onCommandInvoke(String[] arguments, List<IReservedSpace> reservedSpaces, List<LocatedString> locatedStrings, List<LocatedStack> locatedStacks, List<IWidget> locatedTextures) throws IllegalArgumentException {
    if (arguments.length != 3)
        throw new IllegalArgumentException("Code needs 3 arguments!");
    int x;
    try {
        x = Integer.parseInt(arguments[0]);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("The first parameter (the x coordinate) contains an invalid number. Check for invalid characters!");
    }
    int y;
    try {
        y = Integer.parseInt(arguments[1]);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("The second parameter (the y coordinate) contains an invalid number. Check for invalid characters!");
    }
    locatedTextures.add(new LocatedTexture(TextureSupplier.getTexture(Textures.ICON_LOCATION + "textures/wiki/pressureChamberRecipe.png"), x, y, 1 / GuiWiki.TEXT_SCALE));
    if (arguments[2].equals("disenchanting")) {
        handleDisenchanting(x, y, locatedStacks);
    } else if (arguments[2].equals("villagers")) {
        handleVillagers(x, y, locatedTextures);
    } else {
        PressureChamberRecipe foundRecipe = null;
        for (PressureChamberRecipe recipe : PressureChamberRecipe.chamberRecipes) {
            for (ItemStack output : recipe.output) {
                if (WikiUtils.getNameFromStack(output).equals(arguments[2])) {
                    foundRecipe = recipe;
                    break;
                }
            }
        }
        if (foundRecipe == null)
            throw new IllegalArgumentException("No recipe found for the key " + arguments[2]);
        locatedStrings.add(new LocatedString(I18n.format("igwmod.pressureChamber.requiredPressure") + ":", x + 180, y + 10, 0xFF000000, false));
        locatedStrings.add(new LocatedString(foundRecipe.pressure + " bar", x + 215, y + 20, 0xFF000000, false));
        for (int i = 0; i < foundRecipe.input.length; i++) {
            LocatedStack stack = new LocatedStack(PneumaticRecipeRegistry.getSingleStack(foundRecipe.input[i]), (int) ((x + 36 + i % 3 * 34) * GuiWiki.TEXT_SCALE), (int) ((y + 102 - i / 3 * 34) * GuiWiki.TEXT_SCALE));
            locatedStacks.add(stack);
        }
        for (int i = 0; i < foundRecipe.output.length; i++) {
            LocatedStack stack = new LocatedStack(foundRecipe.output[i], (int) ((x + 180 + i % 3 * 36) * GuiWiki.TEXT_SCALE), (int) ((y + 60 + i / 3 * 36) * GuiWiki.TEXT_SCALE));
            locatedStacks.add(stack);
        }
    }
}
Also used : LocatedStack(igwmod.gui.LocatedStack) LocatedString(igwmod.gui.LocatedString) LocatedTexture(igwmod.gui.LocatedTexture) PressureChamberRecipe(pneumaticCraft.api.recipe.PressureChamberRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 4 with PressureChamberRecipe

use of pneumaticCraft.api.recipe.PressureChamberRecipe in project PneumaticCraft by MineMaarten.

the class NEIPressureChamberRecipeManager method getShape.

protected ChamberRecipe getShape(PressureChamberRecipe recipe) {
    ChamberRecipe shape = new ChamberRecipe();
    for (int i = 0; i < recipe.input.length; i++) {
        PositionedStack stack;
        int posX = 19 + i % 3 * 17;
        int posY = 93 - i / 3 * 17;
        if (recipe.input[i] instanceof Pair) {
            List<ItemStack> oreInputs = new ArrayList<ItemStack>();
            Pair<String, Integer> oreDictEntry = (Pair<String, Integer>) recipe.input[i];
            for (ItemStack s : OreDictionaryHelper.getOreDictEntries(oreDictEntry.getKey())) {
                s = s.copy();
                s.stackSize = oreDictEntry.getValue();
                oreInputs.add(s);
            }
            stack = new PositionedStack(oreInputs, posX, posY, true);
        } else {
            stack = new PositionedStack(recipe.input[i], posX, posY);
        }
        shape.addIngredient(stack);
    }
    for (int i = 0; i < recipe.output.length; i++) {
        PositionedStack stack = new PositionedStack(recipe.output[i], 101 + i % 3 * 18, 59 + i / 3 * 18);
        shape.addOutput(stack);
    }
    shape.recipePressure = recipe.pressure;
    return shape;
}
Also used : PressureChamberRecipe(pneumaticCraft.api.recipe.PressureChamberRecipe) PositionedStack(codechicken.nei.PositionedStack) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Pair(org.apache.commons.lang3.tuple.Pair)

Example 5 with PressureChamberRecipe

use of pneumaticCraft.api.recipe.PressureChamberRecipe in project PneumaticCraft by MineMaarten.

the class CraftingRegistrator method addPressureChamberStorageBlockRecipes.

/**
 * Adds recipes like 9 gold ingot --> 1 gold block, and 1 gold block --> 9 gold ingots.
 */
public static void addPressureChamberStorageBlockRecipes() {
    List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
    for (IRecipe recipe : recipes) {
        if (recipe instanceof ShapedRecipes) {
            ShapedRecipes shaped = (ShapedRecipes) recipe;
            ItemStack[] input = shaped.recipeItems;
            ItemStack ref = input[0];
            if (ref == null || input.length < 9)
                continue;
            boolean valid = true;
            for (int i = 0; i < 9; i++) {
                if (input[i] == null || !input[i].isItemEqual(ref)) {
                    valid = false;
                    break;
                }
            }
            if (valid) {
                ItemStack inputStack = ref.copy();
                inputStack.stackSize = 9;
                PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[] { inputStack }, 1.0F, new ItemStack[] { shaped.getRecipeOutput() }, false));
                ItemStack inputStack2 = shaped.getRecipeOutput().copy();
                inputStack2.stackSize = 1;
                PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[] { inputStack2 }, -0.5F, new ItemStack[] { inputStack }, false));
            }
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ItemStack(net.minecraft.item.ItemStack) PressureChamberRecipe(pneumaticCraft.api.recipe.PressureChamberRecipe)

Aggregations

ItemStack (net.minecraft.item.ItemStack)5 PressureChamberRecipe (pneumaticCraft.api.recipe.PressureChamberRecipe)5 ArrayList (java.util.ArrayList)2 Pair (org.apache.commons.lang3.tuple.Pair)2 PositionedStack (codechicken.nei.PositionedStack)1 LocatedStack (igwmod.gui.LocatedStack)1 LocatedString (igwmod.gui.LocatedString)1 LocatedTexture (igwmod.gui.LocatedTexture)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityVillager (net.minecraft.entity.passive.EntityVillager)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 ShapedRecipes (net.minecraft.item.crafting.ShapedRecipes)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 IPressureChamberRecipe (pneumaticCraft.api.recipe.IPressureChamberRecipe)1 IAirHandler (pneumaticCraft.api.tileentity.IAirHandler)1