Fully optimized the compression handler~
This commit is contained in:
parent
2f47ffa955
commit
8fbb19acc0
|
@ -74,6 +74,7 @@ import WayofTime.alchemicalWizardry.common.commands.CommandSN;
|
|||
import WayofTime.alchemicalWizardry.common.commands.CommandUnbind;
|
||||
import WayofTime.alchemicalWizardry.common.compress.AdvancedCompressionHandler;
|
||||
import WayofTime.alchemicalWizardry.common.compress.BaseCompressionHandler;
|
||||
import WayofTime.alchemicalWizardry.common.compress.StorageBlockCraftingManager;
|
||||
import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.DemonPacketMinorGrunt;
|
||||
import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.DemonPacketRegistry;
|
||||
import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.demon.EntityMinorDemonGrunt;
|
||||
|
@ -797,7 +798,6 @@ public class AlchemicalWizardry
|
|||
|
||||
this.initDemonPacketRegistiry();
|
||||
this.initiateRegistry();
|
||||
this.initCompressionHandlers();
|
||||
|
||||
this.blacklistDemons();
|
||||
|
||||
|
@ -1188,6 +1188,9 @@ public class AlchemicalWizardry
|
|||
|
||||
DemonVillageLootRegistry.init();
|
||||
|
||||
this.initCompressionHandlers();
|
||||
|
||||
|
||||
// if(parseTextFiles)
|
||||
// this.parseTextFile();
|
||||
|
||||
|
@ -1496,6 +1499,7 @@ public class AlchemicalWizardry
|
|||
|
||||
public void initCompressionHandlers()
|
||||
{
|
||||
StorageBlockCraftingManager.getInstance().addStorageBlockRecipes();
|
||||
CompressionRegistry.registerHandler(new BaseCompressionHandler(new ItemStack(Items.glowstone_dust, 4, 0), new ItemStack(Blocks.glowstone), 64));
|
||||
CompressionRegistry.registerHandler(new AdvancedCompressionHandler());
|
||||
|
||||
|
|
|
@ -23,4 +23,8 @@ public interface IBloodAltar
|
|||
public float getDislocationMultiplier();
|
||||
|
||||
public int getBufferCapacity();
|
||||
|
||||
public void sacrificialDaggerCall(int amount, boolean b);
|
||||
|
||||
public void startCycle();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
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;
|
||||
|
@ -30,7 +29,7 @@ public class AdvancedCompressionHandler extends CompressionHandler
|
|||
for(int i=2; i<=3; i++)
|
||||
{
|
||||
ItemStack stacky = getRecipe(invStack, world, i);
|
||||
if(isResultStackReversible(stacky, i, world))
|
||||
if(stacky!=null)
|
||||
{
|
||||
int threshold = CompressionRegistry.getItemThreshold(invStack);
|
||||
|
||||
|
@ -98,7 +97,7 @@ public class AdvancedCompressionHandler extends CompressionHandler
|
|||
return needed;
|
||||
}
|
||||
|
||||
public boolean isResultStackReversible(ItemStack stack, int gridSize, World world)
|
||||
public static boolean isResultStackReversible(ItemStack stack, int gridSize, World world)
|
||||
{
|
||||
if(stack == null)
|
||||
{
|
||||
|
@ -114,7 +113,7 @@ public class AdvancedCompressionHandler extends CompressionHandler
|
|||
|
||||
inventory.setInventorySlotContents(0, stack);
|
||||
|
||||
ItemStack returnStack = CraftingManager.getInstance().findMatchingRecipe(inventory, world);
|
||||
ItemStack returnStack = StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world);
|
||||
if(returnStack == null)
|
||||
{
|
||||
return false;
|
||||
|
@ -140,7 +139,7 @@ public class AdvancedCompressionHandler extends CompressionHandler
|
|||
}
|
||||
}
|
||||
|
||||
public ItemStack getRecipe(ItemStack stack, World world, int gridSize)
|
||||
public static ItemStack getRecipe(ItemStack stack, World world, int gridSize)
|
||||
{
|
||||
InventoryCrafting inventory = new InventoryCrafting(new Container()
|
||||
{
|
||||
|
@ -154,25 +153,25 @@ public class AdvancedCompressionHandler extends CompressionHandler
|
|||
inventory.setInventorySlotContents(i, stack);
|
||||
}
|
||||
|
||||
return CraftingManager.getInstance().findMatchingRecipe(inventory, world);
|
||||
return StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world);
|
||||
}
|
||||
|
||||
public boolean has22Recipe(ItemStack stack, World world)
|
||||
public static boolean has22Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return get22Recipe(stack, world) != null;
|
||||
}
|
||||
|
||||
public ItemStack get22Recipe(ItemStack stack, World world)
|
||||
public static ItemStack get22Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return getRecipe(stack, world, 2);
|
||||
}
|
||||
|
||||
public boolean has33Recipe(ItemStack stack, World world)
|
||||
public static boolean has33Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return get22Recipe(stack, world) != null;
|
||||
return get33Recipe(stack, world) != null;
|
||||
}
|
||||
|
||||
public ItemStack get33Recipe(ItemStack stack, World world)
|
||||
public static ItemStack get33Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return getRecipe(stack, world, 3);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,187 @@
|
|||
package WayofTime.alchemicalWizardry.common.compress;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
|
||||
|
||||
public class StorageBlockCraftingManager
|
||||
{
|
||||
private static final StorageBlockCraftingManager instance = new StorageBlockCraftingManager();
|
||||
private List recipes = new ArrayList();
|
||||
|
||||
public static StorageBlockCraftingManager getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void addStorageBlockRecipes()
|
||||
{
|
||||
List list = CraftingManager.getInstance().getRecipeList();
|
||||
|
||||
World world = DimensionManager.getWorld(0);
|
||||
for(Object obj : list)
|
||||
{
|
||||
if(obj instanceof IRecipe)
|
||||
{
|
||||
IRecipe recipe = (IRecipe)obj;
|
||||
ItemStack outputStack = recipe.getRecipeOutput();
|
||||
if(outputStack == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isResultStackReversible(outputStack, 2, world) || isResultStackReversible(outputStack, 3, world))
|
||||
{
|
||||
recipes.add(recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isResultStackReversible(ItemStack stack, int gridSize, World world)
|
||||
{
|
||||
if(stack == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
InventoryCrafting inventory = new InventoryCrafting(new Container()
|
||||
{
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}, 2, 2);
|
||||
|
||||
inventory.setInventorySlotContents(0, stack);
|
||||
|
||||
ItemStack returnStack = CraftingManager.getInstance().findMatchingRecipe(inventory, world);
|
||||
if(returnStack == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack compressedStack = null;
|
||||
switch(gridSize)
|
||||
{
|
||||
case 2:
|
||||
compressedStack = get22Recipe(returnStack, world);
|
||||
break;
|
||||
case 3:
|
||||
compressedStack = get33Recipe(returnStack, world);
|
||||
break;
|
||||
}
|
||||
|
||||
if(compressedStack == null)
|
||||
{
|
||||
return false;
|
||||
}else
|
||||
{
|
||||
return SpellHelper.areItemStacksEqual(stack, compressedStack);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getRecipe(ItemStack stack, World world, int gridSize)
|
||||
{
|
||||
InventoryCrafting inventory = new InventoryCrafting(new Container()
|
||||
{
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}, gridSize, gridSize);
|
||||
for(int i=0; i<inventory.getSizeInventory(); i++)
|
||||
{
|
||||
inventory.setInventorySlotContents(i, stack);
|
||||
}
|
||||
|
||||
return CraftingManager.getInstance().findMatchingRecipe(inventory, world);
|
||||
}
|
||||
|
||||
public static boolean has22Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return get22Recipe(stack, world) != null;
|
||||
}
|
||||
|
||||
public static ItemStack get22Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return getRecipe(stack, world, 2);
|
||||
}
|
||||
|
||||
public static boolean has33Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return get33Recipe(stack, world) != null;
|
||||
}
|
||||
|
||||
public static ItemStack get33Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return getRecipe(stack, world, 3);
|
||||
}
|
||||
|
||||
public ItemStack findMatchingRecipe(InventoryCrafting p_82787_1_, World p_82787_2_)
|
||||
{
|
||||
int i = 0;
|
||||
ItemStack itemstack = null;
|
||||
ItemStack itemstack1 = null;
|
||||
int j;
|
||||
|
||||
for (j = 0; j < p_82787_1_.getSizeInventory(); ++j)
|
||||
{
|
||||
ItemStack itemstack2 = p_82787_1_.getStackInSlot(j);
|
||||
|
||||
if (itemstack2 != null)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
itemstack = itemstack2;
|
||||
}
|
||||
|
||||
if (i == 1)
|
||||
{
|
||||
itemstack1 = itemstack2;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && itemstack.getItem().isRepairable())
|
||||
{
|
||||
Item item = itemstack.getItem();
|
||||
int j1 = item.getMaxDamage() - itemstack.getItemDamageForDisplay();
|
||||
int k = item.getMaxDamage() - itemstack1.getItemDamageForDisplay();
|
||||
int l = j1 + k + item.getMaxDamage() * 5 / 100;
|
||||
int i1 = item.getMaxDamage() - l;
|
||||
|
||||
if (i1 < 0)
|
||||
{
|
||||
i1 = 0;
|
||||
}
|
||||
|
||||
return new ItemStack(itemstack.getItem(), 1, i1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; j < this.recipes.size(); ++j)
|
||||
{
|
||||
IRecipe irecipe = (IRecipe)this.recipes.get(j);
|
||||
|
||||
if (irecipe.matches(p_82787_1_, p_82787_2_))
|
||||
{
|
||||
return irecipe.getCraftingResult(p_82787_1_);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,8 +14,8 @@ import net.minecraftforge.common.MinecraftForge;
|
|||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||
import WayofTime.alchemicalWizardry.api.event.SacrificeKnifeUsedEvent;
|
||||
import WayofTime.alchemicalWizardry.api.tile.IBloodAltar;
|
||||
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
|
||||
import WayofTime.alchemicalWizardry.common.tileEntity.TEAltar;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
|
@ -120,7 +120,7 @@ public class SacrificialDagger extends Item
|
|||
int posX = (int) Math.round(player.posX - 0.5f);
|
||||
int posY = (int) player.posY;
|
||||
int posZ = (int) Math.round(player.posZ - 0.5f);
|
||||
TEAltar altarEntity = getAltar(world, posX, posY, posZ);
|
||||
IBloodAltar altarEntity = getAltar(world, posX, posY, posZ);
|
||||
|
||||
if (altarEntity == null)
|
||||
{
|
||||
|
@ -131,7 +131,7 @@ public class SacrificialDagger extends Item
|
|||
altarEntity.startCycle();
|
||||
}
|
||||
|
||||
public TEAltar getAltar(World world, int x, int y, int z)
|
||||
public IBloodAltar getAltar(World world, int x, int y, int z)
|
||||
{
|
||||
TileEntity tileEntity = null;
|
||||
|
||||
|
@ -143,27 +143,27 @@ public class SacrificialDagger extends Item
|
|||
{
|
||||
tileEntity = world.getTileEntity(i + x, k + y, j + z);
|
||||
|
||||
if ((tileEntity instanceof TEAltar))
|
||||
if ((tileEntity instanceof IBloodAltar))
|
||||
{
|
||||
return (TEAltar) tileEntity;
|
||||
return (IBloodAltar) tileEntity;
|
||||
}
|
||||
}
|
||||
|
||||
if ((tileEntity instanceof TEAltar))
|
||||
if ((tileEntity instanceof IBloodAltar))
|
||||
{
|
||||
return (TEAltar) tileEntity;
|
||||
return (IBloodAltar) tileEntity;
|
||||
}
|
||||
}
|
||||
|
||||
if ((tileEntity instanceof TEAltar))
|
||||
if ((tileEntity instanceof IBloodAltar))
|
||||
{
|
||||
return (TEAltar) tileEntity;
|
||||
return (IBloodAltar) tileEntity;
|
||||
}
|
||||
}
|
||||
|
||||
if ((tileEntity instanceof TEAltar))
|
||||
if ((tileEntity instanceof IBloodAltar))
|
||||
{
|
||||
return (TEAltar) tileEntity;
|
||||
return (IBloodAltar) tileEntity;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue