Jump to content

[1.9] Logic/Math Question


LogicTechCorp

Recommended Posts

I have an Infusion Altar TE that can infuse an item with souls. To do so, the Infusion Altar requires the surrounding Crucible TEs to have a certain SoulType amount. The Crucible can hold 64 souls and there are 5 SoulTypes, so the crucible can have a mixture of all SoulTypes with different amounts of each type. Currently this only works if the required SoulType amount is in one Crucible opposed to two or more. What would be the best way to change my current setup to allow this?

 

Note:

A recipe with a null SoulType will require any SoulType.

 

Recipe Class:

public class RecipeInfusion implements ISMRecipe
{
    private Object input;
    private ItemStack output;
    private SoulType soulType;
    private int requiredSoulAmount;
    private String guiButtonText;

    private static final Map<String, List<ItemStack>> oreMap = Maps.newHashMap();

    public RecipeInfusion(Object input, ItemStack output, SoulType soulType, int requiredSoulAmount, String guiButtonText)
    {
        this.input = input;
        this.output = output;
        this.soulType = soulType;
        this.requiredSoulAmount = requiredSoulAmount;
        this.guiButtonText = guiButtonText;
    }

    public boolean matches(ItemStack stack, SoulType soulType, int soulAmount)
    {
        if(stack == null || soulType == null)
        {
            return false;
        }
        else if(this.requiredSoulAmount > soulAmount || stack.stackSize * this.requiredSoulAmount > soulAmount)
        {
            return false;
        }
        else
        {
            if(this.soulType != null)
            {
                if(this.soulType == soulType)
                {
                    return this.checkMatch(stack);
                }
            }
            else
            {
                return this.checkMatch(stack);
            }
        }
        return false;
    }

    private boolean checkMatch(ItemStack stack)
    {
        if(this.input instanceof Block)
        {
            return Block.getBlockFromItem(stack.getItem()) == this.input;
        }
        else if(this.input instanceof Item)
        {
            return stack.getItem() == this.input;
        }
        else
        {
            String oreDict = (String) this.input;
            return isOreDict(stack, oreDict);
        }
    }

    private boolean isOreDict(ItemStack stack, String entry)
    {
        if(stack == null || stack.getItem() == null)
        {
            return false;
        }

        List<ItemStack> ores;

        if(oreMap.containsKey(entry))
        {
            ores = oreMap.get(entry);
        }
        else
        {
            ores = OreDictionary.getOres(entry);
            oreMap.put(entry, ores);
        }
        for(ItemStack oreStack : ores)
        {
            ItemStack newStack = oreStack.copy();
            newStack.setItemDamage(stack.getItemDamage());

            if(stack.isItemEqual(newStack))
            {
                return true;
            }
        }
        return false;
    }

    public Object getInput()
    {
        return this.input;
    }

    public ItemStack getOutput()
    {
        return this.output;
    }

    public SoulType getSoulType()
    {
        return this.soulType;
    }

    public int getRequiredSoulAmount()
    {
        return this.requiredSoulAmount;
    }

    public String getGuiButtonText()
    {
        return this.guiButtonText;
    }

 

TileEntityInfusionAltar:

public class TileEntityInfusionAltar extends TileEntityInventory
{
    public TileEntityInfusionAltar()
    {
        super(1, "soul_altar");
    }

    private List<TileEntitySoulCrucible> getCrucibles()
    {
        List<TileEntitySoulCrucible> crucibles = Lists.newArrayList();

        for(int x = pos.getX() - 3; x < pos.getX() + 4; x++)
        {
            for(int y = pos.getY() - 3; y < pos.getY() + 4; y++)
            {
                for(int z = pos.getZ() - 3; z < pos.getZ() + 4; z++)
                {
                    TileEntity tileEntity = worldObj.getTileEntity(new BlockPos(x, y, z));

                    if(tileEntity != null && tileEntity instanceof TileEntitySoulCrucible)
                    {
                        crucibles.add((TileEntitySoulCrucible) tileEntity);
                    }
                }
            }
        }
        return crucibles;
    }

    public RecipeInfusion getRecipe()
    {
        RecipeInfusion recipe = null;

        for(TileEntitySoulCrucible crucible : this.getCrucibles())
        {
            for(SoulType soulType : crucible.getContainer().SOULS.keySet())
            {
                for(ISMRecipe r : SoulMagicAPI.getRecipeRegistry().typeToRecipe.values())
                {
                    if(r instanceof RecipeInfusion)
                    {
                        RecipeInfusion newRecipe = (RecipeInfusion) r;

                        if(newRecipe.matches(this.getStackInSlot(0), soulType, crucible.getContainer().SOULS.get(soulType)))
                        {
                            recipe = newRecipe;
                        }
                    }
                }
            }
        }
        return recipe;
    }

    public void infuse()
    {
        for(TileEntitySoulCrucible crucible : this.getCrucibles())
        {
            for(SoulType soulType : crucible.getContainer().SOULS.keySet())
            {
                SoulMagicAPI.getRecipeRegistry().typeToRecipe.values().stream().filter(r -> r instanceof RecipeInfusion).forEach(r ->
                {
                    RecipeInfusion newRecipe = (RecipeInfusion) r;

                    if(newRecipe.matches(this.getStackInSlot(0), soulType, crucible.getContainer().SOULS.get(soulType)))
                    {
                        ItemStack outStack = newRecipe.getOutput();
                        outStack.stackSize = this.getStackInSlot(0).stackSize;

                        crucible.getContainer().remove(soulType, outStack.stackSize * newRecipe.getRequiredSoulAmount());
                        this.setInventorySlotContents(0, outStack);
                    }
                });
            }
        }
    }

 

Crucible Container:

public class SoulContainer
{
    private int capacity;

    public final Map<SoulType, Integer> SOULS = Maps.newHashMap();

    public SoulContainer(int capacity)
    {
        this.capacity = capacity;
    }

    public void add(SoulType soulType, int amount)
    {
        if(this.getSoulAmount() + amount < this.capacity)
        {
            if(!SOULS.keySet().contains(soulType))
            {
                SOULS.put(soulType, amount);
            }
            else
            {
                SOULS.replace(soulType, SOULS.get(soulType) + amount);
            }
        }
    }

    public void remove(SoulType soulType, int amount)
    {
        if(this.getSoulAmount() - amount >= 0)
        {
            if(SOULS.keySet().contains(soulType))
            {
                if(SOULS.get(soulType) - amount > 0)
                {
                    SOULS.replace(soulType, SOULS.get(soulType) - amount);
                }
                else
                {
                    SOULS.remove(soulType);
                }
            }
        }
    }

    public void readFromNBT(NBTTagCompound tag)
    {
        NBTTagList tagList = tag.getTagList("Souls", 10);

        for(int i = 0; i < tagList.tagCount(); i++)
        {
            NBTTagCompound soulTag = tagList.getCompoundTagAt(i);
            String soulTypeName = soulTag.getString(NBT.SOUL_TYPE);
            SoulType soulType = SoulMagicAPI.getSoulRegistry().getSoulTypeFrom(soulTypeName);
            int amount = soulTag.getInteger("SoulAmount");
            SOULS.put(soulType, amount);
        }
        this.capacity = tag.getInteger("Capacity");
    }

    public void writeToNBT(NBTTagCompound tag)
    {
        NBTTagList tagList = new NBTTagList();

        for(Map.Entry<SoulType, Integer> soul : SOULS.entrySet())
        {
            NBTTagCompound soulTag = new NBTTagCompound();
            soulTag.setString(NBT.SOUL_TYPE, soul.getKey().getName());
            soulTag.setInteger(NBT.SOUL_AMOUNT, soul.getValue());
            tagList.appendTag(soulTag);
        }
        tag.setTag("Souls", tagList);
        tag.setInteger("Capacity", this.capacity);
    }

    public boolean containsSoul(SoulType soulType)
    {
        return SOULS.containsKey(soulType);
    }

    public SoulType getRandomSoul()
    {
        Random rand = new Random();
        Object[] souls = SOULS.keySet().toArray();
        return (SoulType) souls[rand.nextInt(souls.length)];
    }

    public int getCapacity()
    {
        return this.capacity;
    }

    public int getSoulAmount()
    {
        int amount = 0;

        for(SoulType soulType : SOULS.keySet())
        {
            amount += SOULS.get(soulType);
        }
        return amount;
    }

    public int getSoulTypeAmount(SoulType soulType)
    {
        int amount = 0;

        for(SoulType sT : SOULS.keySet())
        {
            if(sT == soulType)
            {
                amount += SOULS.get(soulType);
            }
        }
        return amount;
    }

    public void setCapacity(int capacity)
    {
        this.capacity = capacity;
    }

Link to comment
Share on other sites

Step 1:

Loop through all crucibles in range, build a HashMap of the total amounts of every SoulType available in range.

Step 2:

Check the recipe against this hashmap.  If enough, recipe allowed, otherwise it isn't.

Step 3:

Create a hashmap for the SoulTypes being consumed by the recipe and loop through each crucible in range and deduct as many Soul amounts as possible (keeping track in this hashmap copy) until all souls consumed have been deducted from somewhere.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • SLOT 1000 : SLOT1000 DEPOSIT 1000 VIA DANA - SLOT 1000 VIA QRIS - SLOT DEPOSIT QRIS 1000 - SLOT DEPO 1K - SLOT 1000 BET KECIL KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • SLOT DEMO PRINCESS 1000 : DEMO SLOT STARLIGHT PRINCESS x 1000 RUPIAH GRATIS TANPA DEPOSIT KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • FREEBET SLOT : SLOT FREEBET TANPA DEPOSIT FREECHIP 20K 30K 50K TO KECIL RENDAH x2 x3 x4 x5 - SLOT GRATIS TANPA DEPOSIT KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Ratuasia77 adalah bocoran slot rekomendasi gacor dari Ratuasia77 yang bisa anda temukan di SLOT Ratuasia77. Situs SLOT Ratuasia77 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ratuasia77 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ratuasia77 merupakan SLOT Ratuasia77 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ratuasia77. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ratuasia77 hari ini yang telah disediakan SLOT Ratuasia77. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ratuasia77 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ratuasia77 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ratuasia77 di link SLOT Ratuasia77.
    • 20 SLOT DEMO GRATIS PRAGMATIC PLAY x500 RUPIAH ANTI LAG & 20 DEMO SLOT MAHJONG WAYS PG SOFT GRATIS ANTI RUNGKAD KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.