Search in sources :

Example 1 with IReagentHandler

use of WayofTime.alchemicalWizardry.api.alchemy.energy.IReagentHandler in project BloodMagic by WayofTime.

the class RitualEffectOmegaTest method performEffect.

@Override
public void performEffect(IMasterRitualStone ritualStone) {
    String owner = ritualStone.getOwner();
    int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
    World world = ritualStone.getWorld();
    int x = ritualStone.getXCoord();
    int y = ritualStone.getYCoord();
    int z = ritualStone.getZCoord();
    if (world.getWorldTime() % 200 != 0) {
        return;
    }
    OmegaStructureParameters param = OmegaStructureHandler.getStructureStabilityFactor(world, x, y, z, 5, new Int3(0, 1, 0));
    int stab = param.stability;
    int enchantability = param.enchantability;
    int enchantmentLevel = param.enchantmentLevel;
    if (stab <= 0) {
        return;
    }
    // System.out.println("Stability: " + stab + ", Enchantability: " + enchantability + ", Enchantment Level: " + enchantmentLevel);
    double range = 0.5;
    List<EntityPlayer> playerList = SpellHelper.getPlayersInRange(world, x + 0.5, y + 1.5, z + 0.5, range, range);
    Reagent reagent = null;
    Map<Reagent, Integer> reagentMap = new HashMap();
    for (int i = 0; i < 4; i++) {
        Int3 jarLoc = this.getJarLocation(i);
        TileEntity tile = world.getTileEntity(x + jarLoc.xCoord, y + jarLoc.yCoord, z + jarLoc.zCoord);
        if (tile instanceof IReagentHandler) {
            IReagentHandler container = (IReagentHandler) tile;
            ReagentContainerInfo[] containerInfoArray = container.getContainerInfo(ForgeDirection.UP);
            if (containerInfoArray == null) {
                continue;
            }
            for (ReagentContainerInfo containerInfo : containerInfoArray) {
                ReagentStack containedReagent = containerInfo.reagent;
                if (containedReagent == null) {
                    continue;
                }
                Reagent rea = containedReagent.reagent;
                int amt = containedReagent.amount;
                if (reagentMap.containsKey(rea)) {
                    reagentMap.put(rea, reagentMap.get(rea) + amt);
                } else {
                    reagentMap.put(rea, amt);
                }
            }
        }
    }
    for (Entry<Reagent, Integer> entry : reagentMap.entrySet()) {
        if (entry.getValue() >= drainTotal) {
            reagent = entry.getKey();
            break;
        }
    }
    if (reagent == null) {
        return;
    }
    int tickDuration = isTesting ? 20 * 30 : 15 * 20 * 60 + (int) ((15 * 20 * 60) * Math.sqrt(stab / 700));
    int affinity = 0;
    for (EntityPlayer player : playerList) {
        OmegaParadigm waterParadigm = OmegaRegistry.getParadigmForReagent(reagent);
        if (waterParadigm != null && waterParadigm.convertPlayerArmour(player, x, y, z, stab, affinity, enchantability, enchantmentLevel)) {
            APISpellHelper.setPlayerCurrentReagentAmount(player, tickDuration);
            APISpellHelper.setPlayerMaxReagentAmount(player, tickDuration);
            APISpellHelper.setPlayerReagentType(player, reagent);
            APISpellHelper.setCurrentAdditionalMaxHP(player, waterParadigm.getMaxAdditionalHealth());
            NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getReagentBarPacket(reagent, APISpellHelper.getPlayerCurrentReagentAmount(player), APISpellHelper.getPlayerMaxReagentAmount(player)), (EntityPlayerMP) player);
            if (!isTesting) {
                int drainLeft = this.drainTotal;
                for (int i = 0; i < 4; i++) {
                    if (drainLeft <= 0) {
                        break;
                    }
                    Int3 jarLoc = this.getJarLocation(i);
                    TileEntity tile = world.getTileEntity(x + jarLoc.xCoord, y + jarLoc.yCoord, z + jarLoc.zCoord);
                    if (tile instanceof IReagentHandler) {
                        IReagentHandler container = (IReagentHandler) tile;
                        ReagentStack drained = container.drain(ForgeDirection.UP, new ReagentStack(reagent, drainLeft), true);
                        if (drained != null) {
                            drainLeft -= drained.amount;
                            world.markBlockForUpdate(x + jarLoc.xCoord, y + jarLoc.yCoord, z + jarLoc.zCoord);
                            world.addWeatherEffect(new EntityLightningBolt(world, x + jarLoc.xCoord, y + jarLoc.yCoord, z + jarLoc.zCoord));
                        }
                    }
                }
                ritualStone.setActive(false);
            }
            break;
        }
    }
}
Also used : HashMap(java.util.HashMap) ReagentContainerInfo(WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainerInfo) Int3(WayofTime.alchemicalWizardry.api.Int3) OmegaStructureParameters(WayofTime.alchemicalWizardry.common.omega.OmegaStructureParameters) ReagentStack(WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack) EntityLightningBolt(net.minecraft.entity.effect.EntityLightningBolt) World(net.minecraft.world.World) Reagent(WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent) IReagentHandler(WayofTime.alchemicalWizardry.api.alchemy.energy.IReagentHandler) TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) OmegaParadigm(WayofTime.alchemicalWizardry.common.omega.OmegaParadigm)

Example 2 with IReagentHandler

use of WayofTime.alchemicalWizardry.api.alchemy.energy.IReagentHandler in project BloodMagic by WayofTime.

the class RenderHelper method getHUDElements.

private static List<HUDElement> getHUDElements(Minecraft mc) {
    List<HUDElement> elements = new ArrayList();
    MovingObjectPosition movingobjectposition = mc.objectMouseOver;
    World world = mc.theWorld;
    if (movingobjectposition == null) {
        return elements;
    } else {
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
            int x = movingobjectposition.blockX;
            int y = movingobjectposition.blockY;
            int z = movingobjectposition.blockZ;
            TileEntity tile = world.getTileEntity(x, y, z);
            if (!(tile instanceof IReagentHandler)) {
                return elements;
            }
            IReagentHandler relay = (IReagentHandler) tile;
            ReagentContainerInfo[] infos = relay.getContainerInfo(ForgeDirection.getOrientation(movingobjectposition.sideHit));
            if (infos != null) {
                for (ReagentContainerInfo info : infos) {
                    if (info == null || info.reagent == null || info.reagent.reagent == null) {
                        continue;
                    }
                    ItemStack itemStack = ReagentRegistry.getItemForReagent(info.reagent.reagent);
                    if (itemStack != null)
                        elements.add(new HUDElement(itemStack, 16, 16, 2, info.reagent.amount));
                }
            }
        }
    }
    return elements;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ReagentContainerInfo(WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainerInfo) ArrayList(java.util.ArrayList) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) IReagentHandler(WayofTime.alchemicalWizardry.api.alchemy.energy.IReagentHandler)

Example 3 with IReagentHandler

use of WayofTime.alchemicalWizardry.api.alchemy.energy.IReagentHandler in project BloodMagic by WayofTime.

the class SigilDivination method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    EnergyItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer);
    if (!EnergyItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer) || par3EntityPlayer.worldObj.isRemote) {
        return par1ItemStack;
    }
    if (!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 0)) {
        return par1ItemStack;
    }
    NBTTagCompound itemTag = par1ItemStack.getTagCompound();
    if (itemTag == null || itemTag.getString("ownerName").equals("")) {
        return par1ItemStack;
    }
    String ownerName = itemTag.getString("ownerName");
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, false);
    if (movingobjectposition == null) {
        par3EntityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("message.divinationsigil.currentessence") + " " + SoulNetworkHandler.getCurrentEssence(ownerName) + "LP"));
        return par1ItemStack;
    } else {
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
            int x = movingobjectposition.blockX;
            int y = movingobjectposition.blockY;
            int z = movingobjectposition.blockZ;
            TileEntity tile = par2World.getTileEntity(x, y, z);
            if (!(tile instanceof IReagentHandler)) {
                par3EntityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("message.divinationsigil.currentessence") + " " + SoulNetworkHandler.getCurrentEssence(ownerName) + "LP"));
                return par1ItemStack;
            }
            IReagentHandler relay = (IReagentHandler) tile;
            ReagentContainerInfo[] infoList = relay.getContainerInfo(ForgeDirection.UNKNOWN);
            if (infoList != null) {
                for (ReagentContainerInfo info : infoList) {
                    if (info != null && info.reagent != null && info.reagent.reagent != null) {
                        par3EntityPlayer.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("message.divinationsigil.reagent") + " " + ReagentRegistry.getKeyForReagent(info.reagent.reagent) + "," + StatCollector.translateToLocal("message.divinationsigil.amount") + " " + info.reagent.amount));
                    }
                }
            }
        }
    }
    return par1ItemStack;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ReagentContainerInfo(WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainerInfo) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ChatComponentText(net.minecraft.util.ChatComponentText) IReagentHandler(WayofTime.alchemicalWizardry.api.alchemy.energy.IReagentHandler)

Aggregations

IReagentHandler (WayofTime.alchemicalWizardry.api.alchemy.energy.IReagentHandler)3 ReagentContainerInfo (WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainerInfo)3 TileEntity (net.minecraft.tileentity.TileEntity)3 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)2 World (net.minecraft.world.World)2 Int3 (WayofTime.alchemicalWizardry.api.Int3)1 Reagent (WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent)1 ReagentStack (WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack)1 OmegaParadigm (WayofTime.alchemicalWizardry.common.omega.OmegaParadigm)1 OmegaStructureParameters (WayofTime.alchemicalWizardry.common.omega.OmegaStructureParameters)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 EntityLightningBolt (net.minecraft.entity.effect.EntityLightningBolt)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ChatComponentText (net.minecraft.util.ChatComponentText)1