Jump to content

Recommended Posts

Posted

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;
    }

Posted

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.

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

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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