Fixing compression glitches

This commit is contained in:
WayofTime 2014-11-20 10:49:21 -05:00
parent 174d56b8ff
commit 5224b808c3
7 changed files with 45 additions and 5 deletions

View file

@ -1303,7 +1303,9 @@ public class AlchemicalWizardry
public void initCompressionHandlers() 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.registerHandler(new AdvancedCompressionHandler());
CompressionRegistry.registerItemThreshold(new ItemStack(Blocks.cobblestone), 64);
} }
} }

View file

@ -1,8 +1,12 @@
package WayofTime.alchemicalWizardry.api.compress; package WayofTime.alchemicalWizardry.api.compress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; 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.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -13,12 +17,23 @@ import net.minecraft.world.World;
public class CompressionRegistry public class CompressionRegistry
{ {
public static List<CompressionHandler> compressionRegistry = new ArrayList(); public static List<CompressionHandler> compressionRegistry = new ArrayList();
public static Map<ItemStack, Integer> thresholdMap = new HashMap();
public static void registerHandler(CompressionHandler handler) public static void registerHandler(CompressionHandler handler)
{ {
compressionRegistry.add(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) public static ItemStack compressInventory(ItemStack[] inv, World world)
{ {
for(CompressionHandler handler : compressionRegistry) for(CompressionHandler handler : compressionRegistry)
@ -32,4 +47,17 @@ public class CompressionRegistry
return null; 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;
}
} }

View file

@ -7,6 +7,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.world.World; import net.minecraft.world.World;
import WayofTime.alchemicalWizardry.api.compress.CompressionHandler; 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 public class AdvancedCompressionHandler extends CompressionHandler
{ {
@ -30,13 +32,15 @@ public class AdvancedCompressionHandler extends CompressionHandler
continue; continue;
} }
int threshold = CompressionRegistry.getItemThreshold(invStack);
for(int i=2; i<=3; i++) for(int i=2; i<=3; i++)
{ {
ItemStack stacky = getRecipe(invStack, world, i); ItemStack stacky = getRecipe(invStack, world, i);
if(isResultStackReversible(stacky, i, world)) if(isResultStackReversible(stacky, i, world))
{ {
int needed = i*i; int needed = i*i;
int neededLeft = iterateThroughInventory(invStack, 0, inv, needed, false); int neededLeft = iterateThroughInventory(invStack, threshold, inv, needed, false);
if(neededLeft <= 0) if(neededLeft <= 0)
{ {
iterateThroughInventory(invStack, 0, inv, needed, true); iterateThroughInventory(invStack, 0, inv, needed, true);
@ -132,7 +136,7 @@ public class AdvancedCompressionHandler extends CompressionHandler
return false; return false;
}else }else
{ {
return stack.isItemEqual(compressedStack) && (stack.getTagCompound() == null ? compressedStack.getTagCompound() == null : stack.getTagCompound().equals(compressedStack.getTagCompound())); return SpellHelper.areItemStacksEqual(stack, compressedStack);
} }
} }

View file

@ -81,7 +81,6 @@ public class BaseCompressionHandler extends CompressionHandler
if(kept <= 0 && needed > 0) if(kept <= 0 && needed > 0)
{ {
int remainingFromStack = Math.max(stackSize - used - needed, 0); int remainingFromStack = Math.max(stackSize - used - needed, 0);
needed -= (stackSize - used - remainingFromStack);
if(doDrain) if(doDrain)
{ {
invStack.stackSize = remainingFromStack; invStack.stackSize = remainingFromStack;
@ -90,6 +89,8 @@ public class BaseCompressionHandler extends CompressionHandler
inv[i] = null; inv[i] = null;
} }
} }
needed -= (stackSize - used - remainingFromStack);
} }
if(needed <= 0) if(needed <= 0)

View file

@ -14,7 +14,6 @@ import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.api.compress.CompressionRegistry; import WayofTime.alchemicalWizardry.api.compress.CompressionRegistry;
import WayofTime.alchemicalWizardry.api.items.interfaces.ArmourUpgrade; import WayofTime.alchemicalWizardry.api.items.interfaces.ArmourUpgrade;
import WayofTime.alchemicalWizardry.api.items.interfaces.IHolding; import WayofTime.alchemicalWizardry.api.items.interfaces.IHolding;
import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler;
import WayofTime.alchemicalWizardry.common.items.EnergyItems; import WayofTime.alchemicalWizardry.common.items.EnergyItems;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;

View file

@ -562,4 +562,9 @@ public class SpellHelper
} }
return null; 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()));
}
} }

View file

@ -189,6 +189,7 @@ item.demonPlacer.name=Demon Crystal
item.creativeDagger.name=Creative Sacrificial Knife item.creativeDagger.name=Creative Sacrificial Knife
item.itemBloodPack.name=Blood Letter's Pack item.itemBloodPack.name=Blood Letter's Pack
item.itemHarvestSigil.name=Harvest Goddess Sigil item.itemHarvestSigil.name=Harvest Goddess Sigil
item.itemCompressionSigil.name=Sigil of Compression
#Creative Tab #Creative Tab
itemGroup.tabBloodMagic=Blood Magic itemGroup.tabBloodMagic=Blood Magic