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;
}
}
}
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;
}
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;
}
Aggregations