# [1.9] Logic/Math Question

## 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)
{
}
}
}
}
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);
}
}
}
}

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

##### 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.

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.

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

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

• ### Posts

• As a seasoned investor, I’ve learned that the financial world can be exciting and treacherous. My experiences with investments have taught me the importance of diligence and thorough research, particularly when dealing with newer and high-risk assets like Bitcoin. Unfortunately, my journey with Bitcoin was marred by a painful lesson in the form of a scam, which I hope to share to help others avoid similar pitfalls. My introduction to Bitcoin investing seemed promising. The allure of high returns and the buzz surrounding cryptocurrency were captivating. I was drawn to several Bitcoin investment platforms that promised substantial profits. These platforms presented themselves with professional websites, attractive promotions, and genuine testimonials. I was led to believe that these sites were reliable and that I was making a sound investment. However, this trust proved to be misplaced. The platform I initially invested in showcased fake success stories and substantial profits to entice investors. They used these fabricated examples to build credibility and persuade new investors like me to commit more funds. Their tactics were sophisticated; they knew exactly how to create an illusion of success and security. I, too, was lured by their promises and gradually invested a considerable amount of money, totaling 68,000 USD.The initial investments went smoothly. My account appeared to grow with impressive returns, and I felt a sense of validation in my investment strategy. But things took a drastic turn when I decided to make a more significant investment, believing that the returns would only get better. Once I deposited a substantial sum, the platform’s behavior changed abruptly. My account was frozen without warning, and I was faced with a barrage of demands for additional payments before I could access my funds or the supposed profits. The situation was both distressing and bewildering. I was met with excuses and obstructions at every turn. It became clear that I was dealing with a fraudulent company that had no intention of honoring its commitments. The realization that I had been deceived was crushing. The emotional and financial toll of the situation was overwhelming. Determined to recover my funds, I reached out to Trust Geeks Hack Expert, a service recommended by a trusted friend who had faced a similar ordeal. My initial skepticism was tempered by desperation and hope. Trust Geeks Hack Expert took immediate action. Their team worked tirelessly to investigate the fraudulent platform and recover my lost funds. Their dedication and expertise were evident throughout the process. In just a few weeks, Trust Geeks Hack Expert managed to successfully retrieve the full amount of 68,000 USD. Their assistance was thorough and professional, and they kept me informed every step of the way. Their efforts not only resulted in the recovery of my funds but also provided me with invaluable insights into how these scams operate. This. This experience has been a harsh lesson in the importance of conducting thorough research before investing in any platform, particularly in the cryptocurrency space. The allure of high returns can be overwhelming, but it’s crucial to approach such investments with caution. Verify the legitimacy of the platform, seek out reviews from reliable sources, and ensure that any investment opportunity has a track record of transparency and reliability. To anyone who finds themselves in a similar predicament, I cannot recommend Trust Geeks Hack Expert  enough. Their professionalism and commitment to recovering my funds were exemplary:: E>mail: trustgeekshackexpert {@} fastservice{.}com -----> Tele>gram : Trustgeekshackexpert, And also  What's>App   + 1-7-1-9-4-9-2-2-6-9-3
• As a seasoned investor, I’ve learned that the financial world can be exciting and treacherous. My experiences with investments have taught me the importance of diligence and thorough research, particularly when dealing with newer and high-risk assets like Bitcoin. Unfortunately, my journey with Bitcoin was marred by a painful lesson in the form of a scam, which I hope to share to help others avoid similar pitfalls. My introduction to Bitcoin investing seemed promising. The allure of high returns and the buzz surrounding cryptocurrency were captivating. I was drawn to several Bitcoin investment platforms that promised substantial profits. These platforms presented themselves with professional websites, attractive promotions, and genuine testimonials. I was led to believe that these sites were reliable and that I was making a sound investment. However, this trust proved to be misplaced. The platform I initially invested in showcased fake success stories and substantial profits to entice investors. They used these fabricated examples to build credibility and persuade new investors like me to commit more funds. Their tactics were sophisticated; they knew exactly how to create an illusion of success and security. I, too, was lured by their promises and gradually invested a considerable amount of money, totaling 68,000 USD.The initial investments went smoothly. My account appeared to grow with impressive returns, and I felt a sense of validation in my investment strategy. But things took a drastic turn when I decided to make a more significant investment, believing that the returns would only get better. Once I deposited a substantial sum, the platform’s behavior changed abruptly. My account was frozen without warning, and I was faced with a barrage of demands for additional payments before I could access my funds or the supposed profits. The situation was both distressing and bewildering. I was met with excuses and obstructions at every turn. It became clear that I was dealing with a fraudulent company that had no intention of honoring its commitments. The realization that I had been deceived was crushing. The emotional and financial toll of the situation was overwhelming. Determined to recover my funds, I reached out to Trust Geeks Hack Expert, a service recommended by a trusted friend who had faced a similar ordeal. My initial skepticism was tempered by desperation and hope. Trust Geeks Hack Expert took immediate action. Their team worked tirelessly to investigate the fraudulent platform and recover my lost funds. Their dedication and expertise were evident throughout the process. In just a few weeks, Trust Geeks Hack Expert managed to successfully retrieve the full amount of 68,000 USD. Their assistance was thorough and professional, and they kept me informed every step of the way. Their efforts not only resulted in the recovery of my funds but also provided me with invaluable insights into how these scams operate. This. This experience has been a harsh lesson in the importance of conducting thorough research before investing in any platform, particularly in the cryptocurrency space. The allure of high returns can be overwhelming, but it’s crucial to approach such investments with caution. Verify the legitimacy of the platform, seek out reviews from reliable sources, and ensure that any investment opportunity has a track record of transparency and reliability. To anyone who finds themselves in a similar predicament, I cannot recommend Trust Geeks Hack Expert  enough. Their professionalism and commitment to recovering my funds were exemplary:: E>mail: trustgeekshackexpert{@}fastservice{.}com -----> Tele>gram : Trustgeekshackexpert, And also  What's>App   + 1-7-1-9-4-9-2-2-6-9-3
• I've been playing it for only 1 day and it doesn't want to go into the game anymore. I've tried reinstalling the game and repairing the game files (on curseforge) but it still doesn't work. Whenever i try to click on the Singleplayer icon, it just flickers into the world creation page and flickers back
• https://gist.github.com/RealMangoBot/03ce10d60ce10f126dcf2c033c3a4f46
• Sure, please notify, 1.20.1 preferred.

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...