BloodMagic/src/main/java/WayofTime/bloodmagic/ritual/RitualFullStomach.java

118 lines
4.1 KiB
Java
Raw Normal View History

2016-01-09 18:51:55 -05:00
package WayofTime.bloodmagic.ritual;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.ritual.*;
2016-01-09 18:51:55 -05:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.FoodStats;
2017-08-15 21:30:48 -07:00
import net.minecraft.util.math.BlockPos;
2016-01-09 18:51:55 -05:00
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
2016-01-09 18:51:55 -05:00
2017-08-15 21:30:48 -07:00
public class RitualFullStomach extends Ritual {
2016-01-09 18:51:55 -05:00
public static final String FILL_RANGE = "fillRange";
public static final String CHEST_RANGE = "chest";
2016-01-09 18:51:55 -05:00
2017-08-15 21:30:48 -07:00
public RitualFullStomach() {
super("ritualFullStomach", 0, 100000, "ritual." + BloodMagic.MODID + ".fullStomachRitual");
2016-01-09 18:51:55 -05:00
addBlockRange(FILL_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-25, -25, -25), 51));
addBlockRange(CHEST_RANGE, new AreaDescriptor.Rectangle(new BlockPos(0, 1, 0), 1));
setMaximumVolumeAndDistanceOfRange(FILL_RANGE, 0, 25, 25);
setMaximumVolumeAndDistanceOfRange(CHEST_RANGE, 1, 3, 3);
2016-01-09 18:51:55 -05:00
}
@Override
2017-08-15 21:30:48 -07:00
public void performRitual(IMasterRitualStone masterRitualStone) {
2016-01-09 18:51:55 -05:00
World world = masterRitualStone.getWorldObj();
int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
2016-01-09 18:51:55 -05:00
BlockPos pos = masterRitualStone.getBlockPos();
int maxEffects = currentEssence / getRefreshCost();
int totalEffects = 0;
AreaDescriptor chestRange = getBlockRange(CHEST_RANGE);
TileEntity tile = world.getTileEntity(chestRange.getContainedPositions(pos).get(0));
2017-08-15 21:30:48 -07:00
if (!(tile instanceof IInventory)) {
2016-01-09 18:51:55 -05:00
return;
}
IInventory inventory = (IInventory) tile;
int lastSlot = 0;
AreaDescriptor fillingRange = getBlockRange(FILL_RANGE);
List<EntityPlayer> playerList = world.getEntitiesWithinAABB(EntityPlayer.class, fillingRange.getAABB(pos));
2017-08-15 21:30:48 -07:00
for (EntityPlayer player : playerList) {
2016-01-09 18:51:55 -05:00
FoodStats foodStats = player.getFoodStats();
float satLevel = foodStats.getSaturationLevel();
2017-08-15 21:30:48 -07:00
for (int i = lastSlot; i < inventory.getSizeInventory(); i++) {
2016-01-09 18:51:55 -05:00
ItemStack stack = inventory.getStackInSlot(i);
2017-08-15 21:30:48 -07:00
if (!stack.isEmpty() && stack.getItem() instanceof ItemFood) {
2016-01-09 18:51:55 -05:00
ItemFood foodItem = (ItemFood) stack.getItem();
int healAmount = foodItem.getHealAmount(stack);
float saturationAmount = foodItem.getSaturationModifier(stack) * healAmount * 2.0f;
2017-08-15 21:30:48 -07:00
if (saturationAmount + satLevel <= 20) {
2016-01-09 18:51:55 -05:00
NBTTagCompound nbt = new NBTTagCompound();
foodStats.writeNBT(nbt);
nbt.setFloat("foodSaturationLevel", saturationAmount + satLevel);
foodStats.readNBT(nbt);
inventory.decrStackSize(i, 1);
totalEffects++;
lastSlot = i;
break;
}
}
}
2017-08-15 21:30:48 -07:00
if (totalEffects >= maxEffects) {
masterRitualStone.getOwnerNetwork().causeNausea();
2016-01-09 18:51:55 -05:00
break;
}
}
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost() * totalEffects);
2016-01-09 18:51:55 -05:00
}
@Override
2017-08-15 21:30:48 -07:00
public int getRefreshTime() {
2016-01-09 18:51:55 -05:00
return 20;
}
@Override
2017-08-15 21:30:48 -07:00
public int getRefreshCost() {
2016-01-09 18:51:55 -05:00
return 100;
}
@Override
2017-08-15 21:30:48 -07:00
public ArrayList<RitualComponent> getComponents() {
2016-01-09 18:51:55 -05:00
ArrayList<RitualComponent> components = new ArrayList<RitualComponent>();
this.addParallelRunes(components, 3, 0, EnumRuneType.FIRE);
this.addCornerRunes(components, 1, 0, EnumRuneType.AIR);
this.addOffsetRunes(components, 1, 2, 0, EnumRuneType.AIR);
this.addCornerRunes(components, 4, 0, EnumRuneType.WATER);
this.addOffsetRunes(components, 4, 3, 0, EnumRuneType.EARTH);
return components;
}
@Override
2017-08-15 21:30:48 -07:00
public Ritual getNewCopy() {
2016-01-09 18:51:55 -05:00
return new RitualFullStomach();
}
}