Swap the API packages

The new one is now built for the api jar and the old one is now internal.
It will slowly be moved around to sane places within the internal code. Most
of the features provided in the old "api" are addon specific features which
will generally rely on the main jar anyways. The new API will be specific
to compatibility features, such as blacklists, recipes, and value modification.
This commit is contained in:
Nicholas Ignoffo 2018-02-05 17:04:38 -08:00
parent 4fbcac6aa2
commit ddaadfbe52
421 changed files with 1006 additions and 999 deletions

View file

@ -0,0 +1,149 @@
package WayofTime.bloodmagic.apibutnotreally.util.helper;
import WayofTime.bloodmagic.apibutnotreally.Constants;
import WayofTime.bloodmagic.apibutnotreally.event.ItemBindEvent;
import WayofTime.bloodmagic.apibutnotreally.iface.IBindable;
import WayofTime.bloodmagic.util.handler.event.GenericHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import java.util.UUID;
public class BindableHelper {
/**
* Sets the Owner Name of the item without checking if it is already bound.
* Also bypasses {@link ItemBindEvent}.
*
* @param stack - The ItemStack to bind
* @param ownerName - The username to bind the ItemStack to
*/
public static void setItemOwnerName(ItemStack stack, String ownerName) {
stack = NBTHelper.checkNBT(stack);
stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, ownerName);
}
/**
* Sets the Owner UUID of the item without checking if it is already bound.
* Also bypasses {@link ItemBindEvent}.
*
* @param stack - The ItemStack to bind
* @param ownerUUID - The UUID to bind the ItemStack to
*/
public static void setItemOwnerUUID(ItemStack stack, String ownerUUID) {
stack = NBTHelper.checkNBT(stack);
stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, ownerUUID);
}
// Everything below is to be removed.
/**
* Deprecated.
* <p>
* Built into {@link IBindable} now.
*
* @param stack - The ItemStack to check the owner of
* @return - The username of the ItemStack's owner
*/
@Deprecated
public static String getOwnerName(ItemStack stack) {
stack = NBTHelper.checkNBT(stack);
return PlayerHelper.getUsernameFromStack(stack);
}
/**
* Deprecated.
* <p>
* Built into {@link IBindable} now.
*
* @param stack - The ItemStack to check the owner of
* @return - The UUID of the ItemStack's owner
*/
@Deprecated
public static String getOwnerUUID(ItemStack stack) {
stack = NBTHelper.checkNBT(stack);
return stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
}
/**
* Deprecated.
* <p>
* Now handled automatically with
* {@link GenericHandler#onInteract(PlayerInteractEvent.RightClickItem)}
*
* @param stack - The ItemStack to bind
* @param player - The Player to bind the ItemStack to
* @return - Whether binding was successful
*/
@Deprecated
public static boolean checkAndSetItemOwner(ItemStack stack, EntityPlayer player) {
return !PlayerHelper.isFakePlayer(player) && checkAndSetItemOwner(stack, PlayerHelper.getUUIDFromPlayer(player), player.getName());
}
/**
* Deprecated.
* <p>
* Now handled automatically with
* {@link GenericHandler#onInteract(PlayerInteractEvent.RightClickItem)}
*
* @param stack - The ItemStack to bind
* @param uuid - The username to bind the ItemStack to
* @param currentUsername - The current name of the player.
* @return - Whether the binding was successful
*/
@Deprecated
public static boolean checkAndSetItemOwner(ItemStack stack, String uuid, String currentUsername) {
stack = NBTHelper.checkNBT(stack);
if (!(stack.getItem() instanceof IBindable))
return false;
String currentOwner = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
if (currentOwner == "") //The player has not been set yet, so set everything.
{
MinecraftForge.EVENT_BUS.post(new ItemBindEvent(PlayerHelper.getPlayerFromUUID(uuid), uuid, stack));
((IBindable) stack.getItem()).onBind(PlayerHelper.getPlayerFromUUID(uuid), stack);
stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, uuid);
stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, currentUsername);
return true;
} else if (currentOwner.equals(uuid)) //The player has been set, so this will simply update the display name
{
stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, currentUsername);
}
return true;
}
/**
* Deprecated.
* <p>
* Now handled automatically with
* {@link GenericHandler#onInteract(PlayerInteractEvent.RightClickItem)}
*
* @param stack - ItemStack to check
* @param uuid - UUID of the Player
* @param currentUsername - The current name of the player.
*/
@Deprecated
public static boolean checkAndSetItemOwner(ItemStack stack, UUID uuid, String currentUsername) {
return checkAndSetItemOwner(stack, uuid.toString(), currentUsername);
}
/**
* Deprecated.
*
* @param stack - The ItemStack to bind
* @param ownerName - The username to bind the ItemStack to
* @see #setItemOwnerName(ItemStack, String)
*/
@Deprecated
public static void setItemOwner(ItemStack stack, String ownerName) {
setItemOwnerName(stack, ownerName);
}
}

View file

@ -0,0 +1,21 @@
package WayofTime.bloodmagic.apibutnotreally.util.helper;
import WayofTime.bloodmagic.apibutnotreally.Constants;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
public class IncenseHelper {
public static double getCurrentIncense(EntityPlayer player) {
NBTTagCompound data = player.getEntityData();
if (data.hasKey(Constants.NBT.CURRENT_INCENSE)) {
return data.getDouble(Constants.NBT.CURRENT_INCENSE);
}
return 0;
}
public static void setCurrentIncense(EntityPlayer player, double amount) {
NBTTagCompound data = player.getEntityData();
data.setDouble(Constants.NBT.CURRENT_INCENSE, amount);
}
}

View file

@ -0,0 +1,131 @@
package WayofTime.bloodmagic.apibutnotreally.util.helper;
import WayofTime.bloodmagic.apibutnotreally.altar.IBloodAltar;
import WayofTime.bloodmagic.apibutnotreally.iface.IItemLPContainer;
import WayofTime.bloodmagic.apibutnotreally.iface.IUpgradeTrainer;
import WayofTime.bloodmagic.apibutnotreally.livingArmour.LivingArmourHandler;
import WayofTime.bloodmagic.apibutnotreally.livingArmour.LivingArmourUpgrade;
import WayofTime.bloodmagic.item.ItemUpgradeTome;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ItemHelper {
// IItemLPContainer
public static class LPContainer {
/**
* Attempts to fill an altar with the contained LP
*
* @param altar - The altar in question
* @param itemStack - The {@link IItemLPContainer} ItemStack filling the altar
* @param world - The world
* @param altarPos - The position of the altar
* @return Whether or not the altar was filled (or at least attempted)
*/
public static boolean tryAndFillAltar(IBloodAltar altar, ItemStack itemStack, World world, BlockPos altarPos) {
if (itemStack.getItem() instanceof IItemLPContainer) {
if (!altar.isActive()) {
IItemLPContainer fillable = (IItemLPContainer) itemStack.getItem();
int amount = fillable.getStoredLP(itemStack);
if (amount > 0) {
int filledAmount = altar.fillMainTank(amount);
amount -= filledAmount;
fillable.setStoredLP(itemStack, amount);
world.notifyBlockUpdate(altarPos, world.getBlockState(altarPos), world.getBlockState(altarPos), 3);
return true;
}
}
}
return false;
}
/**
* Adds the given LP into the {@link IItemLPContainer}'s storage
*
* @param stack - The item in question
* @param toAdd - How much LP should be added to the item
* @param maxCapacity - The item's maximum holding capacity
* @return Whether or not LP was added to the item
*/
public static boolean addLPToItem(ItemStack stack, int toAdd, int maxCapacity) {
if (stack.getItem() instanceof IItemLPContainer) {
IItemLPContainer fillable = (IItemLPContainer) stack.getItem();
stack = NBTHelper.checkNBT(stack);
if (toAdd < 0)
toAdd = 0;
if (toAdd > maxCapacity)
toAdd = maxCapacity;
fillable.setStoredLP(stack, Math.min(fillable.getStoredLP(stack) + toAdd, maxCapacity));
return true;
}
return false;
}
}
public static class LivingUpgrades {
public static LivingArmourUpgrade getUpgrade(ItemStack stack) {
if (stack.getItem() instanceof ItemUpgradeTome || stack.getItem() instanceof IUpgradeTrainer) {
String key = getKey(stack);
int level = getLevel(stack);
return LivingArmourHandler.generateUpgradeFromKey(key, level);
}
return null;
}
public static void setUpgrade(ItemStack stack, LivingArmourUpgrade upgrade) {
if (stack.getItem() instanceof ItemUpgradeTome || stack.getItem() instanceof IUpgradeTrainer) {
setKey(stack, upgrade.getUniqueIdentifier());
setLevel(stack, upgrade.getUpgradeLevel());
}
}
public static void setKey(ItemStack stack, String key) {
if (stack.getItem() instanceof ItemUpgradeTome || stack.getItem() instanceof IUpgradeTrainer) {
NBTHelper.checkNBT(stack);
NBTTagCompound tag = stack.getTagCompound();
tag.setString("key", key);
}
}
public static String getKey(ItemStack stack) {
if (stack.getItem() instanceof ItemUpgradeTome || stack.getItem() instanceof IUpgradeTrainer) {
NBTHelper.checkNBT(stack);
NBTTagCompound tag = stack.getTagCompound();
return tag.getString("key");
}
return "";
}
public static void setLevel(ItemStack stack, int level) {
if (stack.getItem() instanceof ItemUpgradeTome || stack.getItem() instanceof IUpgradeTrainer) {
NBTHelper.checkNBT(stack);
NBTTagCompound tag = stack.getTagCompound();
tag.setInteger("level", level);
}
}
public static int getLevel(ItemStack stack) {
if (stack.getItem() instanceof ItemUpgradeTome || stack.getItem() instanceof IUpgradeTrainer) {
NBTHelper.checkNBT(stack);
NBTTagCompound tag = stack.getTagCompound();
return tag.getInteger("level");
}
return 0;
}
}
}

View file

@ -0,0 +1,36 @@
package WayofTime.bloodmagic.apibutnotreally.util.helper;
import WayofTime.bloodmagic.apibutnotreally.BloodMagicAPI;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class LogHelper {
private Logger logger;
public LogHelper(String logger) {
this.logger = LogManager.getLogger(logger);
}
public void info(String info, Object... format) {
if (BloodMagicAPI.loggingEnabled)
logger.info(info, format);
}
public void error(String error, Object... format) {
if (BloodMagicAPI.loggingEnabled)
logger.error(error, format);
}
public void debug(String debug, Object... format) {
if (BloodMagicAPI.loggingEnabled)
logger.debug(debug, format);
}
public void fatal(String fatal, Object... format) {
logger.error(fatal, format);
}
public Logger getLogger() {
return logger;
}
}

View file

@ -0,0 +1,13 @@
package WayofTime.bloodmagic.apibutnotreally.util.helper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class NBTHelper {
public static ItemStack checkNBT(ItemStack stack) {
if (stack.getTagCompound() == null)
stack.setTagCompound(new NBTTagCompound());
return stack;
}
}

View file

@ -0,0 +1,163 @@
package WayofTime.bloodmagic.apibutnotreally.util.helper;
import WayofTime.bloodmagic.apibutnotreally.Constants;
import WayofTime.bloodmagic.apibutnotreally.event.SoulNetworkEvent;
import WayofTime.bloodmagic.apibutnotreally.orb.BloodOrb;
import WayofTime.bloodmagic.apibutnotreally.orb.IBloodOrb;
import WayofTime.bloodmagic.apibutnotreally.registry.OrbRegistry;
import WayofTime.bloodmagic.apibutnotreally.saving.BMWorldSavedData;
import WayofTime.bloodmagic.apibutnotreally.saving.SoulNetwork;
import com.google.common.base.Strings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Event;
import java.util.UUID;
public class NetworkHelper {
// Get
/**
* Gets the SoulNetwork for the player.
*
* @param uuid - The UUID of the SoulNetwork owner - this is UUID.toString().
* @return - The SoulNetwork for the given name.
*/
public static SoulNetwork getSoulNetwork(String uuid) {
World world = DimensionManager.getWorld(0);
if (world == null || world.getMapStorage() == null) //Hack-ish way to fix the lava crystal.
return new BMWorldSavedData().getNetwork(UUID.fromString(uuid));
BMWorldSavedData saveData = (BMWorldSavedData) world.getMapStorage().getOrLoadData(BMWorldSavedData.class, BMWorldSavedData.ID);
if (saveData == null) {
saveData = new BMWorldSavedData();
world.getMapStorage().setData(BMWorldSavedData.ID, saveData);
}
return saveData.getNetwork(UUID.fromString(uuid));
}
/**
* @param uuid - The Player's Mojang UUID
* @see NetworkHelper#getSoulNetwork(String)
*/
public static SoulNetwork getSoulNetwork(UUID uuid) {
return getSoulNetwork(uuid.toString());
}
/**
* @param player - The Player
* @see NetworkHelper#getSoulNetwork(String)
*/
public static SoulNetwork getSoulNetwork(EntityPlayer player) {
return getSoulNetwork(PlayerHelper.getUUIDFromPlayer(player));
}
/**
* Gets the current orb tier of the SoulNetwork.
*
* @param soulNetwork - SoulNetwork to get the tier of.
* @return - The Orb tier of the given SoulNetwork
*/
public static int getCurrentMaxOrb(SoulNetwork soulNetwork) {
return soulNetwork.getOrbTier();
}
public static int getMaximumForTier(int tier) {
int ret = 0;
if (tier > OrbRegistry.getTierMap().size() || tier < 0)
return ret;
for (ItemStack orbStack : OrbRegistry.getOrbsForTier(tier)) {
BloodOrb orb = ((IBloodOrb) orbStack.getItem()).getOrb(orbStack);
if (orb.getCapacity() > ret)
ret = orb.getCapacity();
}
return ret;
}
// Syphon
/**
* Syphons from the player and damages them if there was not enough stored
* LP.
* <p>
* Handles null-checking the player for you.
*
* @param soulNetwork - SoulNetwork to syphon from
* @param user - User of the item.
* @param toSyphon - Amount of LP to syphon
* @return - Whether the action should be performed.
* @deprecated Use {@link #getSoulNetwork(EntityPlayer)} and {@link SoulNetwork#syphonAndDamage(EntityPlayer, int)}
*/
@Deprecated
public static boolean syphonAndDamage(SoulNetwork soulNetwork, EntityPlayer user, int toSyphon) {
// if (soulNetwork.getPlayer() == null)
// {
// soulNetwork.syphon(toSyphon);
// return true;
// }
return soulNetwork.syphonAndDamage(user, toSyphon);
}
/**
* Syphons a player from within a container.
*
* @param stack - ItemStack in the Container.
* @param toSyphon - Amount of LP to syphon
* @return - If the syphon was successful.
*/
public static boolean syphonFromContainer(ItemStack stack, int toSyphon) //TODO: Change to a String, int?
{
stack = NBTHelper.checkNBT(stack);
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
if (Strings.isNullOrEmpty(ownerName))
return false;
SoulNetwork network = getSoulNetwork(ownerName);
SoulNetworkEvent.ItemDrainInContainerEvent event = new SoulNetworkEvent.ItemDrainInContainerEvent(stack, ownerName, toSyphon);
return !(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) && network.syphon(event.syphon) >= toSyphon;
}
/**
* Checks if the ItemStack has a user to be syphoned from.
*
* @param stack - ItemStack to check
* @param toSyphon - Amount of LP to syphon
* @return - If syphoning is possible
*/
public static boolean canSyphonFromContainer(ItemStack stack, int toSyphon) {
stack = NBTHelper.checkNBT(stack);
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
if (Strings.isNullOrEmpty(ownerName))
return false;
SoulNetwork network = getSoulNetwork(ownerName);
return network.getCurrentEssence() >= toSyphon;
}
// Set
/**
* Sets the orb tier of the SoulNetwork to the given orb. Will not set if
* the given tier is lower than the current tier.
*
* @param soulNetwork - SoulNetwork to set the orb tier of
* @param maxOrb - Tier of orb to set to
*/
public static void setMaxOrb(SoulNetwork soulNetwork, int maxOrb) {
soulNetwork.setOrbTier(Math.max(maxOrb, soulNetwork.getOrbTier()));
}
}

View file

@ -0,0 +1,91 @@
package WayofTime.bloodmagic.apibutnotreally.util.helper;
import WayofTime.bloodmagic.apibutnotreally.Constants;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraftforge.common.UsernameCache;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import java.util.ArrayList;
import java.util.UUID;
public class PlayerHelper {
/**
* A list of all known fake players that do not extend FakePlayer.
* <p>
* Will be added to as needed.
*/
private static final ArrayList<String> knownFakePlayers = Lists.newArrayList();
public static String getUsernameFromPlayer(EntityPlayer player) {
return player.getEntityWorld().isRemote ? "" : UsernameCache.getLastKnownUsername(getUUIDFromPlayer(player));
}
public static EntityPlayer getPlayerFromUsername(String username) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
return null;
return FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(username);
}
public static EntityPlayer getPlayerFromUUID(String uuid) {
return getPlayerFromUsername(getUsernameFromUUID(uuid));
}
public static EntityPlayer getPlayerFromUUID(UUID uuid) {
return getPlayerFromUsername(getUsernameFromUUID(uuid));
}
public static UUID getUUIDFromPlayer(EntityPlayer player) {
return player.getGameProfile().getId();
}
public static String getUsernameFromUUID(String uuid) {
return UsernameCache.getLastKnownUsername(UUID.fromString(uuid));
}
public static String getUsernameFromUUID(UUID uuid) {
return UsernameCache.getLastKnownUsername(uuid);
}
public static String getUsernameFromStack(ItemStack stack) {
stack = NBTHelper.checkNBT(stack);
return stack.getTagCompound().getString(Constants.NBT.OWNER_NAME);
}
/**
* Checks whether or not the given player is an "actual" player
*
* @param player - The player in question
* @return If the player is fake or not
*/
public static boolean isFakePlayer(EntityPlayer player) {
return player instanceof FakePlayer || (player != null && knownFakePlayers.contains(player.getClass().getCanonicalName()));
}
public static void causeNauseaToPlayer(ItemStack stack) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
return;
stack = NBTHelper.checkNBT(stack);
if (!Strings.isNullOrEmpty(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID)))
causeNauseaToPlayer(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID));
}
public static void causeNauseaToPlayer(String ownerName) {
EntityPlayer player = getPlayerFromUsername(ownerName);
if (player == null)
return;
player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 80));
}
}

View file

@ -0,0 +1,135 @@
package WayofTime.bloodmagic.apibutnotreally.util.helper;
import WayofTime.bloodmagic.ConfigHandler;
import WayofTime.bloodmagic.apibutnotreally.altar.IBloodAltar;
import WayofTime.bloodmagic.apibutnotreally.event.SacrificeKnifeUsedEvent;
import WayofTime.bloodmagic.core.RegistrarBloodMagic;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
public class PlayerSacrificeHelper {
public static float scalingOfSacrifice = 1f;
public static int soulFrayDuration = 400;
public static Potion soulFrayId;
public static double getPlayerIncense(EntityPlayer player) {
return IncenseHelper.getCurrentIncense(player);
}
public static void setPlayerIncense(EntityPlayer player, double amount) {
IncenseHelper.setCurrentIncense(player, amount);
}
public static boolean incrementIncense(EntityPlayer player, double min, double incenseAddition, double increment) {
double amount = getPlayerIncense(player);
if (amount < min || amount >= incenseAddition) {
return false;
}
amount = amount + Math.min(increment, incenseAddition - amount);
setPlayerIncense(player, amount);
// System.out.println("Amount of incense: " + amount + ", Increment: " +
// increment);
return true;
}
/**
* Sacrifices a player's health while the player is under the influence of
* incense
*
* @param player - The player sacrificing
* @return Whether or not the health sacrificing succeeded
*/
public static boolean sacrificePlayerHealth(EntityPlayer player) {
if (player.isPotionActive(soulFrayId)) {
return false;
}
double amount = getPlayerIncense(player);
if (amount >= 0) {
float health = player.getHealth();
float maxHealth = player.getMaxHealth();
if (health > maxHealth / 10.0) {
float sacrificedHealth = health - maxHealth / 10.0f;
int lpAdded = (int) (sacrificedHealth * ConfigHandler.values.sacrificialDaggerConversion * getModifier(amount));
SacrificeKnifeUsedEvent evt = new SacrificeKnifeUsedEvent(player, true, true, (int) sacrificedHealth, lpAdded);
if (MinecraftForge.EVENT_BUS.post(evt))
return false;
if (findAndFillAltar(player.getEntityWorld(), player, evt.lpAdded, false)) {
player.setHealth(maxHealth / 10.0f);
setPlayerIncense(player, 0);
player.addPotionEffect(new PotionEffect(RegistrarBloodMagic.SOUL_FRAY, soulFrayDuration));
return true;
}
}
}
return false;
}
public static double getModifier(double amount) {
return 1 + amount * scalingOfSacrifice;
}
/**
* Finds the nearest {@link IBloodAltar} and attempts to fill it
*
* @param world - The world
* @param sacrificingEntity - The entity having the sacrifice done on (can be
* {@link EntityPlayer} for self-sacrifice)
* @param amount - The amount of which the altar should be filled
* @param isSacrifice - Whether this is a Sacrifice or a Self-Sacrifice
* @return Whether the altar is found and (attempted) filled
*/
public static boolean findAndFillAltar(World world, EntityLivingBase sacrificingEntity, int amount, boolean isSacrifice) {
IBloodAltar altarEntity = getAltar(world, sacrificingEntity.getPosition());
if (altarEntity == null)
return false;
altarEntity.sacrificialDaggerCall(amount, isSacrifice);
altarEntity.startCycle();
return true;
}
/**
* Gets the nearest {@link IBloodAltar}
*
* @param world - The world
* @param blockPos - The position of where the check should be in (in a 2 block
* radius from this)
* @return The nearest altar, if no altar is found, then this will return
* null
*/
public static IBloodAltar getAltar(World world, BlockPos blockPos) {
TileEntity tileEntity;
for (int x = -2; x <= 2; x++) {
for (int y = -2; y <= 1; y++) {
for (int z = -2; z <= 2; z++) {
tileEntity = world.getTileEntity(blockPos.add(x, y, z));
if (tileEntity instanceof IBloodAltar) {
return (IBloodAltar) tileEntity;
}
}
}
}
return null;
}
}

View file

@ -0,0 +1,33 @@
package WayofTime.bloodmagic.apibutnotreally.util.helper;
import WayofTime.bloodmagic.apibutnotreally.Constants;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.nbt.NBTTagCompound;
public class PurificationHelper {
public static double getCurrentPurity(EntityAnimal animal) {
NBTTagCompound data = animal.getEntityData();
if (data.hasKey(Constants.NBT.CURRENT_PURITY)) {
return data.getDouble(Constants.NBT.CURRENT_PURITY);
}
return 0;
}
public static void setCurrentPurity(EntityAnimal animal, double amount) {
NBTTagCompound data = animal.getEntityData();
data.setDouble(Constants.NBT.CURRENT_PURITY, amount);
}
public static double addPurity(EntityAnimal animal, double added, double max) {
double currentPurity = getCurrentPurity(animal);
double newAmount = Math.min(max, currentPurity + added);
if (newAmount < max) {
setCurrentPurity(animal, newAmount);
return newAmount - currentPurity;
}
return 0;
}
}

View file

@ -0,0 +1,143 @@
package WayofTime.bloodmagic.apibutnotreally.util.helper;
import WayofTime.bloodmagic.apibutnotreally.registry.RitualRegistry;
import WayofTime.bloodmagic.apibutnotreally.ritual.EnumRuneType;
import WayofTime.bloodmagic.apibutnotreally.ritual.IRitualStone;
import WayofTime.bloodmagic.apibutnotreally.ritual.Ritual;
import WayofTime.bloodmagic.apibutnotreally.ritual.RitualComponent;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import java.util.ArrayList;
public class RitualHelper {
@CapabilityInject(IRitualStone.Tile.class)
static Capability<IRitualStone.Tile> RUNE_CAPABILITY = null;
public static boolean canCrystalActivate(Ritual ritual, int crystalLevel) {
return ritual.getCrystalLevel() <= crystalLevel && RitualRegistry.ritualEnabled(ritual);
}
public static String getNextRitualKey(String currentKey) {
int currentIndex = RitualRegistry.getIds().indexOf(currentKey);
int nextIndex = RitualRegistry.getRituals().listIterator(currentIndex).nextIndex();
return RitualRegistry.getIds().get(nextIndex);
}
public static String getPrevRitualKey(String currentKey) {
int currentIndex = RitualRegistry.getIds().indexOf(currentKey);
int previousIndex = RitualRegistry.getIds().listIterator(currentIndex).previousIndex();
return RitualRegistry.getIds().get(previousIndex);
}
/**
* Checks the RitualRegistry to see if the configuration of the ritual
* stones in the world is valid for the given EnumFacing.
*
* @param world - The world
* @param pos - Location of the MasterRitualStone
* @return The ID of the valid ritual
*/
public static String getValidRitual(World world, BlockPos pos) {
for (String key : RitualRegistry.getIds()) {
for (EnumFacing direction : EnumFacing.HORIZONTALS) {
boolean test = checkValidRitual(world, pos, key, direction);
if (test) {
return key;
}
}
}
return "";
}
public static EnumFacing getDirectionOfRitual(World world, BlockPos pos, String key) {
for (EnumFacing direction : EnumFacing.HORIZONTALS) {
boolean test = checkValidRitual(world, pos, key, direction);
if (test) {
return direction;
}
}
return null;
}
public static boolean checkValidRitual(World world, BlockPos pos, String ritualId, EnumFacing direction) {
Ritual ritual = RitualRegistry.getRitualForId(ritualId);
if (ritual == null) {
return false;
}
ArrayList<RitualComponent> components = ritual.getComponents();
if (components == null)
return false;
for (RitualComponent component : components) {
BlockPos newPos = pos.add(component.getOffset(direction));
if (isRuneType(world, newPos, component.getRuneType())) {
continue;
} else {
return false;
}
}
return true;
}
public static boolean isRuneType(World world, BlockPos pos, EnumRuneType type) {
if (world == null)
return false;
Block block = world.getBlockState(pos).getBlock();
TileEntity tile = world.getTileEntity(pos);
if (block instanceof IRitualStone)
return ((IRitualStone) block).isRuneType(world, pos, type);
else if (tile instanceof IRitualStone.Tile)
return ((IRitualStone.Tile) tile).isRuneType(type);
else if (tile != null && tile.hasCapability(RUNE_CAPABILITY, null))
return tile.getCapability(RUNE_CAPABILITY, null).isRuneType(type);
return false;
}
public static boolean isRune(World world, BlockPos pos) {
if (world == null)
return false;
Block block = world.getBlockState(pos).getBlock();
TileEntity tile = world.getTileEntity(pos);
if (block instanceof IRitualStone)
return true;
else if (tile instanceof IRitualStone.Tile)
return true;
else if (tile != null && tile.hasCapability(RUNE_CAPABILITY, null))
return true;
return false;
}
public static void setRuneType(World world, BlockPos pos, EnumRuneType type) {
if (world == null)
return;
IBlockState state = world.getBlockState(pos);
TileEntity tile = world.getTileEntity(pos);
if (state.getBlock() instanceof IRitualStone)
((IRitualStone) state.getBlock()).setRuneType(world, pos, type);
else if (tile instanceof IRitualStone.Tile)
((IRitualStone.Tile) tile).setRuneType(type);
else if (tile != null && tile.hasCapability(RUNE_CAPABILITY, null)) {
tile.getCapability(RUNE_CAPABILITY, null).setRuneType(type);
world.notifyBlockUpdate(pos, state, state, 3);
}
}
}