Finishing up Compression sigil
This commit is contained in:
parent
107cc50b05
commit
174d56b8ff
.gitignore
src/main
java/WayofTime/alchemicalWizardry
resources/assets/alchemicalwizardry/textures/items
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -19,6 +19,7 @@ crash-reports/
|
|||
/resourcepacks/
|
||||
/logs/
|
||||
/mods/
|
||||
/screenshots/
|
||||
|
||||
# File Extensions
|
||||
*.psd
|
||||
|
|
|
@ -66,6 +66,7 @@ import WayofTime.alchemicalWizardry.common.alchemy.CombinedPotionRegistry;
|
|||
import WayofTime.alchemicalWizardry.common.block.ArmourForge;
|
||||
import WayofTime.alchemicalWizardry.common.bloodAltarUpgrade.UpgradedAltars;
|
||||
import WayofTime.alchemicalWizardry.common.book.BUEntries;
|
||||
import WayofTime.alchemicalWizardry.common.compress.AdvancedCompressionHandler;
|
||||
import WayofTime.alchemicalWizardry.common.compress.BaseCompressionHandler;
|
||||
import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.DemonPacketAngel;
|
||||
import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.DemonPacketRegistry;
|
||||
|
@ -1302,6 +1303,7 @@ public class AlchemicalWizardry
|
|||
|
||||
public void initCompressionHandlers()
|
||||
{
|
||||
CompressionRegistry.registerHandler(new BaseCompressionHandler(new ItemStack(Items.glowstone_dust), new ItemStack(Blocks.glowstone), 0));
|
||||
CompressionRegistry.registerHandler(new BaseCompressionHandler(new ItemStack(Items.glowstone_dust, 4, 0), new ItemStack(Blocks.glowstone), 0));
|
||||
CompressionRegistry.registerHandler(new AdvancedCompressionHandler());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ import WayofTime.alchemicalWizardry.common.items.sigil.DivinationSigil;
|
|||
import WayofTime.alchemicalWizardry.common.items.sigil.ItemBloodLightSigil;
|
||||
import WayofTime.alchemicalWizardry.common.items.sigil.ItemFluidSigil;
|
||||
import WayofTime.alchemicalWizardry.common.items.sigil.ItemHarvestSigil;
|
||||
import WayofTime.alchemicalWizardry.common.items.sigil.ItemPackRatSigil;
|
||||
import WayofTime.alchemicalWizardry.common.items.sigil.ItemSeerSigil;
|
||||
import WayofTime.alchemicalWizardry.common.items.sigil.ItemSigilOfEnderSeverance;
|
||||
import WayofTime.alchemicalWizardry.common.items.sigil.ItemSigilOfSupression;
|
||||
|
@ -195,6 +196,7 @@ public class ModItems
|
|||
|
||||
public static Item itemBloodMagicBook;
|
||||
public static Item itemHarvestSigil;
|
||||
public static Item itemCompressionSigil;
|
||||
|
||||
public static Item bucketLife;
|
||||
|
||||
|
@ -299,6 +301,7 @@ public class ModItems
|
|||
|
||||
itemBloodPack = new ItemBloodLetterPack().setUnlocalizedName("itemBloodPack");
|
||||
itemHarvestSigil = new ItemHarvestSigil().setUnlocalizedName("itemHarvestSigil");
|
||||
itemCompressionSigil = new ItemPackRatSigil().setUnlocalizedName("itemCompressionSigil");
|
||||
}
|
||||
|
||||
public static void registerItems()
|
||||
|
@ -404,6 +407,7 @@ public class ModItems
|
|||
|
||||
GameRegistry.registerItem(ModItems.itemBloodPack, "itemBloodPack");
|
||||
GameRegistry.registerItem(ModItems.itemHarvestSigil, "itemHarvestSigil");
|
||||
GameRegistry.registerItem(ModItems.itemCompressionSigil, "itemCompressionSigil");
|
||||
//GameRegistry.registerItem(ModItems.itemBloodFrame, "itemBloodFrame");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
package WayofTime.alchemicalWizardry.api.compress;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class CompressionHandler
|
||||
{
|
||||
public abstract ItemStack getResultStack();
|
||||
|
||||
public abstract ItemStack getRequiredStack();
|
||||
|
||||
{
|
||||
/**
|
||||
* Called to look at the inventory and syphons the required stack. Returns getResultStack if successful, and null if not.
|
||||
* Called to look at the inventory and syphons the required stack. Returns resultant stack if successful, and null if not.
|
||||
* @param inv The inventory iterated through
|
||||
* @return The result of the compression
|
||||
*/
|
||||
public abstract ItemStack compressInventory(ItemStack[] inv);
|
||||
public abstract ItemStack compressInventory(ItemStack[] inv, World world);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* A registry aimed to help compress items in an inventory into its compressible form.
|
||||
|
@ -18,11 +19,11 @@ public class CompressionRegistry
|
|||
compressionRegistry.add(handler);
|
||||
}
|
||||
|
||||
public static ItemStack compressInventory(ItemStack[] inv)
|
||||
public static ItemStack compressInventory(ItemStack[] inv, World world)
|
||||
{
|
||||
for(CompressionHandler handler : compressionRegistry)
|
||||
{
|
||||
ItemStack stack = handler.compressInventory(inv);
|
||||
ItemStack stack = handler.compressInventory(inv, world);
|
||||
if(stack != null)
|
||||
{
|
||||
return stack;
|
||||
|
|
|
@ -0,0 +1,175 @@
|
|||
package WayofTime.alchemicalWizardry.common.compress;
|
||||
|
||||
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;
|
||||
|
||||
public class AdvancedCompressionHandler extends CompressionHandler
|
||||
{
|
||||
public AdvancedCompressionHandler()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack compressInventory(ItemStack[] inv, World world)
|
||||
{
|
||||
return test(inv, true, world);
|
||||
}
|
||||
|
||||
public ItemStack test(ItemStack[] inv, boolean doDrain, World world)
|
||||
{
|
||||
for(ItemStack invStack : inv)
|
||||
{
|
||||
if(invStack == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
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);
|
||||
if(neededLeft <= 0)
|
||||
{
|
||||
iterateThroughInventory(invStack, 0, inv, needed, true);
|
||||
return stacky;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int iterateThroughInventory(ItemStack required, int kept, ItemStack[] inv, int needed, boolean doDrain)
|
||||
{
|
||||
int i = -1;
|
||||
|
||||
for(ItemStack invStack : inv)
|
||||
{
|
||||
i++;
|
||||
|
||||
if(invStack == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(invStack.isItemEqual(required) && (invStack.getTagCompound() == null ? required.getTagCompound() == null : invStack.getTagCompound().equals(required.getTagCompound())))
|
||||
{
|
||||
int stackSize = invStack.stackSize;
|
||||
int used = 0;
|
||||
if(kept > 0)
|
||||
{
|
||||
int remainingFromStack = Math.max(stackSize - kept, 0);
|
||||
used += stackSize - remainingFromStack;
|
||||
}
|
||||
|
||||
kept -= used;
|
||||
|
||||
if(kept <= 0 && needed > 0)
|
||||
{
|
||||
int remainingFromStack = Math.max(stackSize - used - needed, 0);
|
||||
needed -= (stackSize - used - remainingFromStack);
|
||||
if(doDrain)
|
||||
{
|
||||
invStack.stackSize = remainingFromStack;
|
||||
if(invStack.stackSize <= 0)
|
||||
{
|
||||
inv[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(needed <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return needed;
|
||||
}
|
||||
|
||||
public boolean isResultStackReversible(ItemStack stack, int gridSize, World world)
|
||||
{
|
||||
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 stack.isItemEqual(compressedStack) && (stack.getTagCompound() == null ? compressedStack.getTagCompound() == null : stack.getTagCompound().equals(compressedStack.getTagCompound()));
|
||||
}
|
||||
}
|
||||
|
||||
public 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 boolean has22Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return get22Recipe(stack, world) != null;
|
||||
}
|
||||
|
||||
public ItemStack get22Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return getRecipe(stack, world, 2);
|
||||
}
|
||||
|
||||
public boolean has33Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return get22Recipe(stack, world) != null;
|
||||
}
|
||||
|
||||
public ItemStack get33Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return getRecipe(stack, world, 3);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package WayofTime.alchemicalWizardry.common.compress;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import WayofTime.alchemicalWizardry.api.compress.CompressionHandler;
|
||||
|
||||
public class BaseCompressionHandler extends CompressionHandler
|
||||
|
@ -17,20 +18,18 @@ public class BaseCompressionHandler extends CompressionHandler
|
|||
this.leftover = leftover;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResultStack()
|
||||
{
|
||||
return this.result.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRequiredStack()
|
||||
{
|
||||
return this.required.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack compressInventory(ItemStack[] inv)
|
||||
public ItemStack compressInventory(ItemStack[] inv, World world)
|
||||
{
|
||||
int remaining = this.getRemainingNeeded(inv);
|
||||
if(remaining <= 0)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package WayofTime.alchemicalWizardry.common.compress;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class DumbyInventoryCrafting extends InventoryCrafting
|
||||
{
|
||||
public DumbyInventoryCrafting(int x, int y)
|
||||
{
|
||||
super(null, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -12,9 +12,9 @@ import net.minecraft.util.IIcon;
|
|||
import net.minecraft.world.World;
|
||||
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||
import WayofTime.alchemicalWizardry.api.compress.CompressionRegistry;
|
||||
import WayofTime.alchemicalWizardry.api.harvest.HarvestRegistry;
|
||||
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;
|
||||
|
@ -30,14 +30,14 @@ public class ItemPackRatSigil extends EnergyItems implements IHolding, ArmourUpg
|
|||
{
|
||||
super();
|
||||
this.maxStackSize = 1;
|
||||
setEnergyUsed(500);
|
||||
setEnergyUsed(200);
|
||||
setCreativeTab(AlchemicalWizardry.tabBloodMagic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
|
||||
{
|
||||
par3List.add("You sow what you reap");
|
||||
par3List.add("Hands of Diamonds");
|
||||
|
||||
if (!(par1ItemStack.stackTagCompound == null))
|
||||
{
|
||||
|
@ -57,9 +57,9 @@ public class ItemPackRatSigil extends EnergyItems implements IHolding, ArmourUpg
|
|||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IIconRegister iconRegister)
|
||||
{
|
||||
this.itemIcon = iconRegister.registerIcon("AlchemicalWizardry:HarvestGoddessSigil_deactivated");
|
||||
this.activeIcon = iconRegister.registerIcon("AlchemicalWizardry:HarvestGoddessSigil_activated");
|
||||
this.passiveIcon = iconRegister.registerIcon("AlchemicalWizardry:HarvestGoddessSigil_deactivated");
|
||||
this.itemIcon = iconRegister.registerIcon("AlchemicalWizardry:CompressionSigil_deactivated");
|
||||
this.activeIcon = iconRegister.registerIcon("AlchemicalWizardry:CompressionSigil_activated");
|
||||
this.passiveIcon = iconRegister.registerIcon("AlchemicalWizardry:CompressionSigil_deactivated");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -149,8 +149,12 @@ public class ItemPackRatSigil extends EnergyItems implements IHolding, ArmourUpg
|
|||
|
||||
if (par1ItemStack.stackTagCompound.getBoolean("isActive"))
|
||||
{
|
||||
ItemStack stack = CompressionRegistry.compressInventory(par3EntityPlayer.inventory.mainInventory);
|
||||
EntityItem entityItem = new EntityItem(par2World, par3EntityPlayer.posX, par3EntityPlayer.posY, par3EntityPlayer.posZ, stack);
|
||||
ItemStack stack = CompressionRegistry.compressInventory(par3EntityPlayer.inventory.mainInventory, par2World);
|
||||
if(stack != null)
|
||||
{
|
||||
EntityItem entityItem = new EntityItem(par2World, par3EntityPlayer.posX, par3EntityPlayer.posY, par3EntityPlayer.posZ, stack);
|
||||
par2World.spawnEntityInWorld(entityItem);
|
||||
}
|
||||
}
|
||||
if (par2World.getWorldTime() % 200 == par1ItemStack.stackTagCompound.getInteger("worldTimeDelay") && par1ItemStack.stackTagCompound.getBoolean("isActive"))
|
||||
{
|
||||
|
@ -169,23 +173,12 @@ public class ItemPackRatSigil extends EnergyItems implements IHolding, ArmourUpg
|
|||
@Override
|
||||
public void onArmourUpdate(World world, EntityPlayer player, ItemStack thisItemStack)
|
||||
{
|
||||
int range = 3;
|
||||
int verticalRange = 1;
|
||||
int posX = (int) Math.round(player.posX - 0.5f);
|
||||
int posY = (int) player.posY;
|
||||
int posZ = (int) Math.round(player.posZ - 0.5f);
|
||||
|
||||
for (int ix = posX - range; ix <= posX + range; ix++)
|
||||
{
|
||||
for (int iz = posZ - range; iz <= posZ + range; iz++)
|
||||
{
|
||||
for (int iy = posY - verticalRange; iy <= posY + verticalRange; iy++)
|
||||
{
|
||||
HarvestRegistry.harvestBlock(world, ix, iy, iz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack stack = CompressionRegistry.compressInventory(player.inventory.mainInventory, world);
|
||||
if(stack != null)
|
||||
{
|
||||
EntityItem entityItem = new EntityItem(world, player.posX, player.posY, player.posZ, stack);
|
||||
world.spawnEntityInWorld(entityItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -197,6 +190,6 @@ public class ItemPackRatSigil extends EnergyItems implements IHolding, ArmourUpg
|
|||
@Override
|
||||
public int getEnergyForTenSeconds()
|
||||
{
|
||||
return 500;
|
||||
return 200;
|
||||
}
|
||||
}
|
Binary file not shown.
After ![]() (image error) Size: 592 B |
Binary file not shown.
After ![]() (image error) Size: 616 B |
Loading…
Reference in a new issue