package WayofTime.alchemicalWizardry.common.rituals; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipeRegistry; import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone; import WayofTime.alchemicalWizardry.api.rituals.RitualEffect; import WayofTime.alchemicalWizardry.api.soulNetwork.LifeEssenceNetwork; import WayofTime.alchemicalWizardry.common.tileEntity.TEAltar; import WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable; public class RitualEffectAutoAlchemy extends RitualEffect { @Override public void performEffect(IMasterRitualStone ritualStone) { String owner = ritualStone.getOwner(); World worldSave = MinecraftServer.getServer().worldServers[0]; LifeEssenceNetwork data = (LifeEssenceNetwork) worldSave.loadItemData(LifeEssenceNetwork.class, owner); if (data == null) { data = new LifeEssenceNetwork(owner); worldSave.setItemData(owner, data); } int currentEssence = data.currentEssence; World world = ritualStone.getWorldObj(); int x = ritualStone.getXCoord(); int y = ritualStone.getYCoord(); int z = ritualStone.getZCoord(); if (currentEssence < this.getCostPerRefresh()*6) { EntityPlayer entityOwner = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(owner); if (entityOwner == null) { return; } entityOwner.addPotionEffect(new PotionEffect(Potion.confusion.id, 80)); } else { int flag = 0; TileEntity topEntity = world.getBlockTileEntity(x, y+1, z); if(!(topEntity instanceof TEAltar)) { return; } TEAltar tileAltar = (TEAltar)topEntity; ItemStack targetStack = tileAltar.getStackInSlot(0); if(targetStack == null) { return; } ItemStack[] recipe = AlchemyRecipeRegistry.getRecipeForItemStack(targetStack); if(recipe!=null) { TEWritingTable alchemyEntity; IInventory outputInv = null; IInventory inputInv1 = null; IInventory inputInv2 = null; TileEntity northEntity = world.getBlockTileEntity(x,y,z-1); TileEntity southEntity = world.getBlockTileEntity(x,y,z+1); TileEntity eastEntity = world.getBlockTileEntity(x+1,y,z); TileEntity westEntity = world.getBlockTileEntity(x-1,y,z); if(northEntity instanceof TEWritingTable) { alchemyEntity = (TEWritingTable)northEntity; if(southEntity instanceof IInventory && !(southEntity instanceof TEWritingTable)) { outputInv = (IInventory)southEntity; } if(eastEntity instanceof IInventory && !(eastEntity instanceof TEWritingTable)) { inputInv1 = (IInventory)eastEntity; } if(westEntity instanceof IInventory && !(westEntity instanceof TEWritingTable)) { inputInv2 = (IInventory)westEntity; } }else if(southEntity instanceof TEWritingTable) { alchemyEntity = (TEWritingTable)southEntity; if(northEntity instanceof IInventory && !(northEntity instanceof TEWritingTable)) { outputInv = (IInventory)northEntity; } if(eastEntity instanceof IInventory && !(eastEntity instanceof TEWritingTable)) { inputInv1 = (IInventory)eastEntity; } if(westEntity instanceof IInventory && !(westEntity instanceof TEWritingTable)) { inputInv2 = (IInventory)westEntity; } }else if(eastEntity instanceof TEWritingTable) { alchemyEntity = (TEWritingTable)eastEntity; if(westEntity instanceof IInventory && !(westEntity instanceof TEWritingTable)) { outputInv = (IInventory)westEntity; } if(northEntity instanceof IInventory && !(northEntity instanceof TEWritingTable)) { inputInv1 = (IInventory)northEntity; } if(southEntity instanceof IInventory && !(southEntity instanceof TEWritingTable)) { inputInv2 = (IInventory)southEntity; } }else if(westEntity instanceof TEWritingTable) { alchemyEntity = (TEWritingTable)westEntity; if(eastEntity instanceof IInventory && !(eastEntity instanceof TEWritingTable)) { outputInv = (IInventory)eastEntity; } if(northEntity instanceof IInventory && !(northEntity instanceof TEWritingTable)) { inputInv1 = (IInventory)northEntity; } if(southEntity instanceof IInventory && !(southEntity instanceof TEWritingTable)) { inputInv2 = (IInventory)southEntity; } }else { return; } if(outputInv!=null) { ItemStack outputStack = alchemyEntity.getStackInSlot(6); if(outputStack!=null) { for(int i=0; i=alchStack.getMaxStackSize())) { continue; } for(int j=0;j=alchStack.getMaxStackSize())) { continue; } for(int j=0;j0) { world.markBlockForUpdate(x, y, z+1); world.markBlockForUpdate(x, y, z-1); world.markBlockForUpdate(x+1, y, z); world.markBlockForUpdate(x-1, y, z); data.currentEssence = currentEssence - this.getCostPerRefresh()*flag; data.markDirty(); } } } @Override public int getCostPerRefresh() { return 10; } }