Fixing compression glitches
This commit is contained in:
parent
174d56b8ff
commit
5224b808c3
|
@ -1303,7 +1303,9 @@ public class AlchemicalWizardry
|
|||
|
||||
public void initCompressionHandlers()
|
||||
{
|
||||
CompressionRegistry.registerHandler(new BaseCompressionHandler(new ItemStack(Items.glowstone_dust, 4, 0), new ItemStack(Blocks.glowstone), 0));
|
||||
CompressionRegistry.registerHandler(new BaseCompressionHandler(new ItemStack(Items.glowstone_dust, 4, 0), new ItemStack(Blocks.glowstone), 64));
|
||||
CompressionRegistry.registerHandler(new AdvancedCompressionHandler());
|
||||
|
||||
CompressionRegistry.registerItemThreshold(new ItemStack(Blocks.cobblestone), 64);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package WayofTime.alchemicalWizardry.api.compress;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -13,12 +17,23 @@ import net.minecraft.world.World;
|
|||
public class CompressionRegistry
|
||||
{
|
||||
public static List<CompressionHandler> compressionRegistry = new ArrayList();
|
||||
public static Map<ItemStack, Integer> thresholdMap = new HashMap();
|
||||
|
||||
public static void registerHandler(CompressionHandler handler)
|
||||
{
|
||||
compressionRegistry.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an item so that it only compresses while above this threshold
|
||||
* @param stack
|
||||
* @param threshold
|
||||
*/
|
||||
public static void registerItemThreshold(ItemStack stack, int threshold)
|
||||
{
|
||||
thresholdMap.put(stack, new Integer(threshold));
|
||||
}
|
||||
|
||||
public static ItemStack compressInventory(ItemStack[] inv, World world)
|
||||
{
|
||||
for(CompressionHandler handler : compressionRegistry)
|
||||
|
@ -32,4 +47,17 @@ public class CompressionRegistry
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getItemThreshold(ItemStack stack)
|
||||
{
|
||||
for(Entry<ItemStack, Integer> entry : thresholdMap.entrySet())
|
||||
{
|
||||
if(SpellHelper.areItemStacksEqual(entry.getKey(), stack))
|
||||
{
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.world.World;
|
||||
import WayofTime.alchemicalWizardry.api.compress.CompressionHandler;
|
||||
import WayofTime.alchemicalWizardry.api.compress.CompressionRegistry;
|
||||
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
|
||||
|
||||
public class AdvancedCompressionHandler extends CompressionHandler
|
||||
{
|
||||
|
@ -30,13 +32,15 @@ public class AdvancedCompressionHandler extends CompressionHandler
|
|||
continue;
|
||||
}
|
||||
|
||||
int threshold = CompressionRegistry.getItemThreshold(invStack);
|
||||
|
||||
for(int i=2; i<=3; i++)
|
||||
{
|
||||
ItemStack stacky = getRecipe(invStack, world, i);
|
||||
if(isResultStackReversible(stacky, i, world))
|
||||
{
|
||||
int needed = i*i;
|
||||
int neededLeft = iterateThroughInventory(invStack, 0, inv, needed, false);
|
||||
int neededLeft = iterateThroughInventory(invStack, threshold, inv, needed, false);
|
||||
if(neededLeft <= 0)
|
||||
{
|
||||
iterateThroughInventory(invStack, 0, inv, needed, true);
|
||||
|
@ -132,7 +136,7 @@ public class AdvancedCompressionHandler extends CompressionHandler
|
|||
return false;
|
||||
}else
|
||||
{
|
||||
return stack.isItemEqual(compressedStack) && (stack.getTagCompound() == null ? compressedStack.getTagCompound() == null : stack.getTagCompound().equals(compressedStack.getTagCompound()));
|
||||
return SpellHelper.areItemStacksEqual(stack, compressedStack);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,6 @@ public class BaseCompressionHandler extends CompressionHandler
|
|||
if(kept <= 0 && needed > 0)
|
||||
{
|
||||
int remainingFromStack = Math.max(stackSize - used - needed, 0);
|
||||
needed -= (stackSize - used - remainingFromStack);
|
||||
if(doDrain)
|
||||
{
|
||||
invStack.stackSize = remainingFromStack;
|
||||
|
@ -90,6 +89,8 @@ public class BaseCompressionHandler extends CompressionHandler
|
|||
inv[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
needed -= (stackSize - used - remainingFromStack);
|
||||
}
|
||||
|
||||
if(needed <= 0)
|
||||
|
|
|
@ -14,7 +14,6 @@ import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
|||
import WayofTime.alchemicalWizardry.api.compress.CompressionRegistry;
|
||||
import WayofTime.alchemicalWizardry.api.items.interfaces.ArmourUpgrade;
|
||||
import WayofTime.alchemicalWizardry.api.items.interfaces.IHolding;
|
||||
import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler;
|
||||
import WayofTime.alchemicalWizardry.common.items.EnergyItems;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
|
|
@ -562,4 +562,9 @@ public class SpellHelper
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean areItemStacksEqual(ItemStack stack, ItemStack compressedStack)
|
||||
{
|
||||
return stack.isItemEqual(compressedStack) && (stack.getTagCompound() == null ? compressedStack.getTagCompound() == null : stack.getTagCompound().equals(compressedStack.getTagCompound()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,6 +189,7 @@ item.demonPlacer.name=Demon Crystal
|
|||
item.creativeDagger.name=Creative Sacrificial Knife
|
||||
item.itemBloodPack.name=Blood Letter's Pack
|
||||
item.itemHarvestSigil.name=Harvest Goddess Sigil
|
||||
item.itemCompressionSigil.name=Sigil of Compression
|
||||
#Creative Tab
|
||||
itemGroup.tabBloodMagic=Blood Magic
|
||||
|
||||
|
|
Loading…
Reference in a new issue