Changed formatting to have bracing on a new line
This commit is contained in:
parent
e5eddd6c45
commit
e48eedb874
189 changed files with 6092 additions and 4041 deletions
|
@ -10,40 +10,50 @@ import net.minecraftforge.common.MinecraftForge;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BindableHelper {
|
||||
public class BindableHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Bind an item to a player. Handles checking if the player was an instanceof
|
||||
* {@link net.minecraftforge.common.util.FakePlayer} or other type of Fake Player.
|
||||
*
|
||||
* @param stack - The ItemStack to bind
|
||||
* @param player - The Player to bind the ItemStack to
|
||||
*
|
||||
* Bind an item to a player. Handles checking if the player was an
|
||||
* instanceof {@link net.minecraftforge.common.util.FakePlayer} or other
|
||||
* type of Fake Player.
|
||||
*
|
||||
* @param stack
|
||||
* - The ItemStack to bind
|
||||
* @param player
|
||||
* - The Player to bind the ItemStack to
|
||||
*
|
||||
* @return - Whether binding was successful
|
||||
*/
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, EntityPlayer player) {
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, EntityPlayer player)
|
||||
{
|
||||
return !PlayerHelper.isFakePlayer(player) && checkAndSetItemOwner(stack, PlayerHelper.getUUIDFromPlayer(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind an item to a username.
|
||||
*
|
||||
* Requires the Item contained in the ItemStack to be an instanceof {@link IBindable}
|
||||
*
|
||||
*
|
||||
* Requires the Item contained in the ItemStack to be an instanceof
|
||||
* {@link IBindable}
|
||||
*
|
||||
* Fires {@link ItemBindEvent}.
|
||||
*
|
||||
* @param stack - The ItemStack to bind
|
||||
* @param uuid - The username to bind the ItemStack to
|
||||
*
|
||||
*
|
||||
* @param stack
|
||||
* - The ItemStack to bind
|
||||
* @param uuid
|
||||
* - The username to bind the ItemStack to
|
||||
*
|
||||
* @return - Whether the binding was successful
|
||||
*/
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, String uuid) {
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, String uuid)
|
||||
{
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
if (!(stack.getItem() instanceof IBindable))
|
||||
return false;
|
||||
|
||||
if (Strings.isNullOrEmpty(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID))) {
|
||||
if (Strings.isNullOrEmpty(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID)))
|
||||
{
|
||||
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);
|
||||
|
@ -56,18 +66,22 @@ public class BindableHelper {
|
|||
/**
|
||||
* @see BindableHelper#checkAndSetItemOwner(ItemStack, String)
|
||||
*/
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, UUID uuid) {
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, UUID uuid)
|
||||
{
|
||||
return checkAndSetItemOwner(stack, uuid.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Owner 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
|
||||
* Sets the Owner 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 setItemOwner(ItemStack stack, String ownerName) {
|
||||
public static void setItemOwner(ItemStack stack, String ownerName)
|
||||
{
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, ownerName);
|
||||
|
@ -75,12 +89,14 @@ public class BindableHelper {
|
|||
|
||||
/**
|
||||
* Used to safely obtain the username of the ItemStack's owner
|
||||
*
|
||||
* @param stack - The ItemStack to check the owner of
|
||||
*
|
||||
*
|
||||
* @param stack
|
||||
* - The ItemStack to check the owner of
|
||||
*
|
||||
* @return - The username of the ItemStack's owner
|
||||
*/
|
||||
public static String getOwnerName(ItemStack stack) {
|
||||
public static String getOwnerName(ItemStack stack)
|
||||
{
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
return PlayerHelper.getUsernameFromStack(stack);
|
||||
|
@ -88,12 +104,14 @@ public class BindableHelper {
|
|||
|
||||
/**
|
||||
* Used to safely obtain the UUID of the ItemStack's owner
|
||||
*
|
||||
* @param stack - The ItemStack to check the owner of
|
||||
*
|
||||
*
|
||||
* @param stack
|
||||
* - The ItemStack to check the owner of
|
||||
*
|
||||
* @return - The UUID of the ItemStack's owner
|
||||
*/
|
||||
public static String getOwnerUUID(ItemStack stack) {
|
||||
public static String getOwnerUUID(ItemStack stack)
|
||||
{
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
return stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
|
||||
|
|
|
@ -4,18 +4,22 @@ import WayofTime.bloodmagic.api.Constants;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class IncenseHelper {
|
||||
public class IncenseHelper
|
||||
{
|
||||
|
||||
public static float getCurrentIncense(EntityPlayer player) {
|
||||
public static float getCurrentIncense(EntityPlayer player)
|
||||
{
|
||||
NBTTagCompound data = player.getEntityData();
|
||||
if (data.hasKey(Constants.NBT.CURRENT_INCENSE)) {
|
||||
if (data.hasKey(Constants.NBT.CURRENT_INCENSE))
|
||||
{
|
||||
return data.getFloat(Constants.NBT.CURRENT_INCENSE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void setCurrentIncense(EntityPlayer player, float amount) {
|
||||
public static void setCurrentIncense(EntityPlayer player, float amount)
|
||||
{
|
||||
NBTTagCompound data = player.getEntityData();
|
||||
data.setFloat(Constants.NBT.CURRENT_INCENSE, amount);
|
||||
}
|
||||
|
|
|
@ -4,34 +4,41 @@ import WayofTime.bloodmagic.api.BloodMagicAPI;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class LogHelper {
|
||||
public class LogHelper
|
||||
{
|
||||
|
||||
private Logger logger;
|
||||
|
||||
public LogHelper(String logger) {
|
||||
public LogHelper(String logger)
|
||||
{
|
||||
this.logger = LogManager.getLogger(logger);
|
||||
}
|
||||
|
||||
public void info(String info, Object ... format) {
|
||||
public void info(String info, Object... format)
|
||||
{
|
||||
if (BloodMagicAPI.isLoggingEnabled())
|
||||
logger.info(info, format);
|
||||
}
|
||||
|
||||
public void error(String error, Object ... format) {
|
||||
public void error(String error, Object... format)
|
||||
{
|
||||
if (BloodMagicAPI.isLoggingEnabled())
|
||||
logger.info(error, format);
|
||||
}
|
||||
|
||||
public void debug(String debug, Object ... format) {
|
||||
public void debug(String debug, Object... format)
|
||||
{
|
||||
if (BloodMagicAPI.isLoggingEnabled())
|
||||
logger.info(debug, format);
|
||||
}
|
||||
|
||||
public void fatal(String fatal, Object ... format) {
|
||||
public void fatal(String fatal, Object... format)
|
||||
{
|
||||
logger.fatal(fatal, format);
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
public Logger getLogger()
|
||||
{
|
||||
return logger;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ package WayofTime.bloodmagic.api.util.helper;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class NBTHelper {
|
||||
public class NBTHelper
|
||||
{
|
||||
|
||||
public static ItemStack checkNBT(ItemStack stack) {
|
||||
public static ItemStack checkNBT(ItemStack stack)
|
||||
{
|
||||
if (stack.getTagCompound() == null)
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
|
||||
|
|
|
@ -15,22 +15,27 @@ import net.minecraftforge.fml.common.eventhandler.Event;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NetworkHelper {
|
||||
public class NetworkHelper
|
||||
{
|
||||
|
||||
// Get
|
||||
|
||||
/**
|
||||
* Gets the SoulNetwork for the player.
|
||||
*
|
||||
* @param name - The username of the SoulNetwork owner
|
||||
* @param world - The world
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* - The username of the SoulNetwork owner
|
||||
* @param world
|
||||
* - The world
|
||||
*
|
||||
* @return - The SoulNetwork for the given name.
|
||||
*/
|
||||
public static SoulNetwork getSoulNetwork(String name, World world) {
|
||||
public static SoulNetwork getSoulNetwork(String name, World world)
|
||||
{
|
||||
SoulNetwork network = (SoulNetwork) world.getMapStorage().loadData(SoulNetwork.class, name);
|
||||
|
||||
if (network == null) {
|
||||
if (network == null)
|
||||
{
|
||||
network = new SoulNetwork(name);
|
||||
world.getMapStorage().setData(name, network);
|
||||
}
|
||||
|
@ -41,42 +46,51 @@ public class NetworkHelper {
|
|||
/**
|
||||
* @see NetworkHelper#getSoulNetwork(String, World)
|
||||
*/
|
||||
public static SoulNetwork getSoulNetwork(UUID uuid, World world) {
|
||||
public static SoulNetwork getSoulNetwork(UUID uuid, World world)
|
||||
{
|
||||
return getSoulNetwork(PlayerHelper.getUsernameFromUUID(uuid), world);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see NetworkHelper#getSoulNetwork(String, World)
|
||||
*/
|
||||
public static SoulNetwork getSoulNetwork(EntityPlayer player, World world) {
|
||||
public static SoulNetwork getSoulNetwork(EntityPlayer player, World world)
|
||||
{
|
||||
return getSoulNetwork(PlayerHelper.getUUIDFromPlayer(player), world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current orb tier of the SoulNetwork.
|
||||
*
|
||||
* @param soulNetwork - SoulNetwork to get the tier of.
|
||||
*
|
||||
*
|
||||
* @param soulNetwork
|
||||
* - SoulNetwork to get the tier of.
|
||||
*
|
||||
* @return - The Orb tier of the given SoulNetwork
|
||||
*/
|
||||
public static int getCurrentMaxOrb(SoulNetwork soulNetwork) {
|
||||
public static int getCurrentMaxOrb(SoulNetwork soulNetwork)
|
||||
{
|
||||
return soulNetwork.getOrbTier();
|
||||
}
|
||||
|
||||
// Syphon
|
||||
|
||||
/**
|
||||
* Syphons from the player and damages them if there was not enough stored LP.
|
||||
*
|
||||
* Syphons from the player and damages them if there was not enough stored
|
||||
* LP.
|
||||
*
|
||||
* Handles null-checking the player for you.
|
||||
*
|
||||
* @param soulNetwork - SoulNetwork to syphon from
|
||||
* @param toSyphon - Amount of LP to syphon
|
||||
*
|
||||
*
|
||||
* @param soulNetwork
|
||||
* - SoulNetwork to syphon from
|
||||
* @param toSyphon
|
||||
* - Amount of LP to syphon
|
||||
*
|
||||
* @return - Whether the action should be performed.
|
||||
*/
|
||||
public static boolean syphonAndDamage(SoulNetwork soulNetwork, int toSyphon) {
|
||||
if (soulNetwork.getPlayer() == null) {
|
||||
public static boolean syphonAndDamage(SoulNetwork soulNetwork, int toSyphon)
|
||||
{
|
||||
if (soulNetwork.getPlayer() == null)
|
||||
{
|
||||
soulNetwork.syphon(toSyphon);
|
||||
return true;
|
||||
}
|
||||
|
@ -86,14 +100,18 @@ public class NetworkHelper {
|
|||
|
||||
/**
|
||||
* Syphons a player from within a container.
|
||||
*
|
||||
* @param stack - ItemStack in the Container.
|
||||
* @param world - The world the Container is in
|
||||
* @param toSyphon - Amount of LP to syphon
|
||||
*
|
||||
*
|
||||
* @param stack
|
||||
* - ItemStack in the Container.
|
||||
* @param world
|
||||
* - The world the Container is in
|
||||
* @param toSyphon
|
||||
* - Amount of LP to syphon
|
||||
*
|
||||
* @return - If the syphon was successful.
|
||||
*/
|
||||
public static boolean syphonFromContainer(ItemStack stack, World world, int toSyphon) {
|
||||
public static boolean syphonFromContainer(ItemStack stack, World world, int toSyphon)
|
||||
{
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
|
||||
|
||||
|
@ -110,13 +128,16 @@ public class NetworkHelper {
|
|||
// 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
|
||||
* 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) {
|
||||
public static void setMaxOrb(SoulNetwork soulNetwork, int maxOrb)
|
||||
{
|
||||
soulNetwork.setOrbTier(Math.max(maxOrb, soulNetwork.getOrbTier()));
|
||||
soulNetwork.markDirty();
|
||||
}
|
||||
|
@ -124,23 +145,29 @@ public class NetworkHelper {
|
|||
// TODO - Remove everything below. It is deprecated and should not be used.
|
||||
|
||||
/**
|
||||
* Master method used to syphon from the player's network, and will damage them accordingly if they do not have enough LP.
|
||||
* Does not drain on the client side.
|
||||
*
|
||||
* @param stack Owned itemStack
|
||||
* @param player Player using the item
|
||||
*
|
||||
* @return True if the action should be executed and false if it should not. Always returns false if client-sided.
|
||||
* Master method used to syphon from the player's network, and will damage
|
||||
* them accordingly if they do not have enough LP. Does not drain on the
|
||||
* client side.
|
||||
*
|
||||
* @param stack
|
||||
* Owned itemStack
|
||||
* @param player
|
||||
* Player using the item
|
||||
*
|
||||
* @return True if the action should be executed and false if it should not.
|
||||
* Always returns false if client-sided.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean syphonAndDamageFromNetwork(ItemStack stack, EntityPlayer player, int syphon) {
|
||||
public static boolean syphonAndDamageFromNetwork(ItemStack stack, EntityPlayer player, int syphon)
|
||||
{
|
||||
if (player.worldObj.isRemote)
|
||||
return false;
|
||||
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
|
||||
|
||||
if (!Strings.isNullOrEmpty(ownerName)) {
|
||||
if (!Strings.isNullOrEmpty(ownerName))
|
||||
{
|
||||
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(player, ownerName, stack, syphon);
|
||||
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
|
@ -151,7 +178,8 @@ public class NetworkHelper {
|
|||
if (drainAmount == 0 || event.shouldDamage)
|
||||
hurtPlayer(player, event.syphon);
|
||||
|
||||
//The event has been told to prevent the action but allow all repercussions of using the item.
|
||||
// The event has been told to prevent the action but allow all
|
||||
// repercussions of using the item.
|
||||
return event.getResult() != Event.Result.DENY;
|
||||
}
|
||||
|
||||
|
@ -163,7 +191,8 @@ public class NetworkHelper {
|
|||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean syphonFromNetworkWhileInContainer(ItemStack stack, int syphon) {
|
||||
public static boolean syphonFromNetworkWhileInContainer(ItemStack stack, int syphon)
|
||||
{
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
|
||||
|
||||
|
@ -179,7 +208,8 @@ public class NetworkHelper {
|
|||
}
|
||||
|
||||
@Deprecated
|
||||
public static int syphonFromNetwork(ItemStack stack, int syphon) {
|
||||
public static int syphonFromNetwork(ItemStack stack, int syphon)
|
||||
{
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID);
|
||||
if (!Strings.isNullOrEmpty(ownerName))
|
||||
|
@ -189,19 +219,22 @@ public class NetworkHelper {
|
|||
}
|
||||
|
||||
@Deprecated
|
||||
public static int syphonFromNetwork(String ownerName, int syphon) {
|
||||
public static int syphonFromNetwork(String ownerName, int syphon)
|
||||
{
|
||||
if (MinecraftServer.getServer() == null)
|
||||
return 0;
|
||||
|
||||
World world = MinecraftServer.getServer().worldServers[0];
|
||||
SoulNetwork network = (SoulNetwork) world.loadItemData(SoulNetwork.class, ownerName);
|
||||
|
||||
if (network == null) {
|
||||
if (network == null)
|
||||
{
|
||||
network = new SoulNetwork(ownerName);
|
||||
world.setItemData(ownerName, network);
|
||||
}
|
||||
|
||||
if (network.getCurrentEssence() >= syphon) {
|
||||
if (network.getCurrentEssence() >= syphon)
|
||||
{
|
||||
network.setCurrentEssence(network.getCurrentEssence() - syphon);
|
||||
network.markDirty();
|
||||
return syphon;
|
||||
|
@ -214,11 +247,12 @@ public class NetworkHelper {
|
|||
|
||||
/**
|
||||
* A method to add to an owner's network up to a maximum value.
|
||||
*
|
||||
*
|
||||
* @return amount added to the network
|
||||
*/
|
||||
@Deprecated
|
||||
public static int addCurrentEssenceToMaximum(String ownerName, int addedEssence, int maximum) {
|
||||
public static int addCurrentEssenceToMaximum(String ownerName, int addedEssence, int maximum)
|
||||
{
|
||||
AddToNetworkEvent event = new AddToNetworkEvent(ownerName, addedEssence, maximum);
|
||||
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
|
@ -230,7 +264,8 @@ public class NetworkHelper {
|
|||
World world = MinecraftServer.getServer().worldServers[0];
|
||||
SoulNetwork data = (SoulNetwork) world.loadItemData(SoulNetwork.class, event.ownerNetwork);
|
||||
|
||||
if (data == null) {
|
||||
if (data == null)
|
||||
{
|
||||
data = new SoulNetwork(event.ownerNetwork);
|
||||
world.setItemData(event.ownerNetwork, data);
|
||||
}
|
||||
|
@ -250,14 +285,16 @@ public class NetworkHelper {
|
|||
// Get
|
||||
|
||||
@Deprecated
|
||||
public static int getCurrentEssence(String ownerName) {
|
||||
public static int getCurrentEssence(String ownerName)
|
||||
{
|
||||
if (MinecraftServer.getServer() == null)
|
||||
return 0;
|
||||
|
||||
World world = MinecraftServer.getServer().worldServers[0];
|
||||
SoulNetwork network = (SoulNetwork) world.loadItemData(SoulNetwork.class, ownerName);
|
||||
|
||||
if (network == null) {
|
||||
if (network == null)
|
||||
{
|
||||
network = new SoulNetwork(ownerName);
|
||||
world.setItemData(ownerName, network);
|
||||
}
|
||||
|
@ -268,20 +305,27 @@ public class NetworkHelper {
|
|||
// Do damage
|
||||
|
||||
@Deprecated
|
||||
public static void hurtPlayer(EntityPlayer user, int energySyphoned) {
|
||||
if (energySyphoned < 100 && energySyphoned > 0) {
|
||||
if (!user.capabilities.isCreativeMode) {
|
||||
public static void hurtPlayer(EntityPlayer user, int energySyphoned)
|
||||
{
|
||||
if (energySyphoned < 100 && energySyphoned > 0)
|
||||
{
|
||||
if (!user.capabilities.isCreativeMode)
|
||||
{
|
||||
user.setHealth((user.getHealth() - 1));
|
||||
|
||||
if (user.getHealth() <= 0.0005f)
|
||||
user.onDeath(BloodMagicAPI.getDamageSource());
|
||||
}
|
||||
} else if (energySyphoned >= 100) {
|
||||
if (!user.capabilities.isCreativeMode) {
|
||||
for (int i = 0; i < ((energySyphoned + 99) / 100); i++) {
|
||||
} else if (energySyphoned >= 100)
|
||||
{
|
||||
if (!user.capabilities.isCreativeMode)
|
||||
{
|
||||
for (int i = 0; i < ((energySyphoned + 99) / 100); i++)
|
||||
{
|
||||
user.setHealth((user.getHealth() - 1));
|
||||
|
||||
if (user.getHealth() <= 0.0005f) {
|
||||
if (user.getHealth() <= 0.0005f)
|
||||
{
|
||||
user.onDeath(BloodMagicAPI.getDamageSource());
|
||||
break;
|
||||
}
|
||||
|
@ -291,8 +335,10 @@ public class NetworkHelper {
|
|||
}
|
||||
|
||||
@Deprecated
|
||||
public static void hurtPlayer(EntityPlayer user, float damage) {
|
||||
if (!user.capabilities.isCreativeMode) {
|
||||
public static void hurtPlayer(EntityPlayer user, float damage)
|
||||
{
|
||||
if (!user.capabilities.isCreativeMode)
|
||||
{
|
||||
user.attackEntityFrom(BloodMagicAPI.getDamageSource(), 0F);
|
||||
user.setHealth((user.getHealth() - damage));
|
||||
}
|
||||
|
|
|
@ -13,59 +13,71 @@ import net.minecraftforge.common.util.FakePlayer;
|
|||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PlayerHelper {
|
||||
public class PlayerHelper
|
||||
{
|
||||
|
||||
private static final Pattern FAKE_PLAYER_PATTERN = Pattern.compile("^(?:\\[.*\\])|(?:ComputerCraft)$");
|
||||
|
||||
public static String getUsernameFromPlayer(EntityPlayer player) {
|
||||
public static String getUsernameFromPlayer(EntityPlayer player)
|
||||
{
|
||||
return UsernameCache.getLastKnownUsername(getUUIDFromPlayer(player));
|
||||
}
|
||||
|
||||
public static EntityPlayer getPlayerFromUsername(String username) {
|
||||
public static EntityPlayer getPlayerFromUsername(String username)
|
||||
{
|
||||
if (MinecraftServer.getServer() == null)
|
||||
return null;
|
||||
|
||||
return MinecraftServer.getServer().getConfigurationManager().getPlayerByUsername(username);
|
||||
}
|
||||
|
||||
public static EntityPlayer getPlayerFromUUID(String uuid) {
|
||||
public static EntityPlayer getPlayerFromUUID(String uuid)
|
||||
{
|
||||
return getPlayerFromUsername(getUsernameFromUUID(uuid));
|
||||
}
|
||||
|
||||
public static EntityPlayer getPlayerFromUUID(UUID uuid) {
|
||||
public static EntityPlayer getPlayerFromUUID(UUID uuid)
|
||||
{
|
||||
return getPlayerFromUsername(getUsernameFromUUID(uuid));
|
||||
}
|
||||
|
||||
public static UUID getUUIDFromPlayer(EntityPlayer player) {
|
||||
public static UUID getUUIDFromPlayer(EntityPlayer player)
|
||||
{
|
||||
return player.getGameProfile().getId();
|
||||
}
|
||||
|
||||
public static String getUsernameFromUUID(String uuid) {
|
||||
public static String getUsernameFromUUID(String uuid)
|
||||
{
|
||||
return UsernameCache.getLastKnownUsername(UUID.fromString(uuid));
|
||||
}
|
||||
|
||||
public static String getUsernameFromUUID(UUID uuid) {
|
||||
public static String getUsernameFromUUID(UUID uuid)
|
||||
{
|
||||
return UsernameCache.getLastKnownUsername(uuid);
|
||||
}
|
||||
|
||||
public static String getUsernameFromStack(ItemStack stack) {
|
||||
public static String getUsernameFromStack(ItemStack stack)
|
||||
{
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
return PlayerHelper.getUsernameFromUUID(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID));
|
||||
}
|
||||
|
||||
public static boolean isFakePlayer(EntityPlayer player) {
|
||||
public static boolean isFakePlayer(EntityPlayer player)
|
||||
{
|
||||
return player instanceof FakePlayer || FAKE_PLAYER_PATTERN.matcher(getUsernameFromPlayer(player)).matches();
|
||||
}
|
||||
|
||||
public static void causeNauseaToPlayer(ItemStack stack) {
|
||||
public static void causeNauseaToPlayer(ItemStack stack)
|
||||
{
|
||||
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) {
|
||||
public static void causeNauseaToPlayer(String ownerName)
|
||||
{
|
||||
EntityPlayer player = getPlayerFromUsername(ownerName);
|
||||
|
||||
if (player == null)
|
||||
|
|
|
@ -8,48 +8,59 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PlayerSacrificeHelper {
|
||||
public class PlayerSacrificeHelper
|
||||
{
|
||||
public static float scalingOfSacrifice = 0.001f;
|
||||
public static int soulFrayDuration = 400;
|
||||
public static Potion soulFrayId;
|
||||
|
||||
public static float getPlayerIncense(EntityPlayer player) {
|
||||
public static float getPlayerIncense(EntityPlayer player)
|
||||
{
|
||||
return IncenseHelper.getCurrentIncense(player);
|
||||
}
|
||||
|
||||
public static void setPlayerIncense(EntityPlayer player, float amount) {
|
||||
public static void setPlayerIncense(EntityPlayer player, float amount)
|
||||
{
|
||||
IncenseHelper.setCurrentIncense(player, amount);
|
||||
}
|
||||
|
||||
public static boolean incrementIncense(EntityPlayer player, float min, float max, float increment) {
|
||||
public static boolean incrementIncense(EntityPlayer player, float min, float max, float increment)
|
||||
{
|
||||
float amount = getPlayerIncense(player);
|
||||
if (amount < min || amount >= max) {
|
||||
if (amount < min || amount >= max)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
amount = amount + Math.min(increment, max - amount);
|
||||
setPlayerIncense(player, amount);
|
||||
|
||||
// System.out.println("Amount of incense: " + amount + ", Increment: " + increment);
|
||||
// System.out.println("Amount of incense: " + amount + ", Increment: " +
|
||||
// increment);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean sacrificePlayerHealth(EntityPlayer player) {
|
||||
if (player.isPotionActive(soulFrayId)) {
|
||||
public static boolean sacrificePlayerHealth(EntityPlayer player)
|
||||
{
|
||||
if (player.isPotionActive(soulFrayId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float amount = getPlayerIncense(player);
|
||||
|
||||
if (amount >= 0) {
|
||||
if (amount >= 0)
|
||||
{
|
||||
float health = player.getHealth();
|
||||
float maxHealth = player.getMaxHealth();
|
||||
|
||||
if (health > maxHealth / 10.0) {
|
||||
if (health > maxHealth / 10.0)
|
||||
{
|
||||
float sacrificedHealth = health - maxHealth / 10.0f;
|
||||
|
||||
if (findAndFillAltar(player.getEntityWorld(), player, (int) (sacrificedHealth * 100f * getModifier(amount)))) {
|
||||
if (findAndFillAltar(player.getEntityWorld(), player, (int) (sacrificedHealth * 100f * getModifier(amount))))
|
||||
{
|
||||
player.setHealth(maxHealth / 10.0f);
|
||||
setPlayerIncense(player, 0);
|
||||
player.addPotionEffect(new PotionEffect(soulFrayId.id, soulFrayDuration));
|
||||
|
@ -62,17 +73,20 @@ public class PlayerSacrificeHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static float getModifier(float amount) {
|
||||
public static float getModifier(float amount)
|
||||
{
|
||||
return 1 + amount * scalingOfSacrifice;
|
||||
}
|
||||
|
||||
public static boolean findAndFillAltar(World world, EntityPlayer player, int amount) {
|
||||
public static boolean findAndFillAltar(World world, EntityPlayer player, int amount)
|
||||
{
|
||||
int posX = (int) Math.round(player.posX - 0.5f);
|
||||
int posY = (int) player.posY;
|
||||
int posZ = (int) Math.round(player.posZ - 0.5f);
|
||||
IBloodAltar altarEntity = getAltar(world, new BlockPos(posX, posY, posZ));
|
||||
|
||||
if (altarEntity == null) {
|
||||
if (altarEntity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -82,15 +96,20 @@ public class PlayerSacrificeHelper {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static IBloodAltar getAltar(World world, BlockPos blockPos) {
|
||||
public static IBloodAltar getAltar(World world, BlockPos blockPos)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
|
||||
for (int i = -2; i <= 2; i++) {
|
||||
for (int j = -2; j <= 2; j++) {
|
||||
for (int k = -2; k <= 1; k++) {
|
||||
for (int i = -2; i <= 2; i++)
|
||||
{
|
||||
for (int j = -2; j <= 2; j++)
|
||||
{
|
||||
for (int k = -2; k <= 1; k++)
|
||||
{
|
||||
tileEntity = world.getTileEntity(new BlockPos(i + blockPos.getX(), k + blockPos.getY(), j + blockPos.getZ()));
|
||||
|
||||
if (tileEntity instanceof IBloodAltar) {
|
||||
if (tileEntity instanceof IBloodAltar)
|
||||
{
|
||||
return (IBloodAltar) tileEntity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,20 +19,24 @@ import WayofTime.bloodmagic.api.ritual.Ritual;
|
|||
import WayofTime.bloodmagic.api.ritual.RitualComponent;
|
||||
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
|
||||
|
||||
public class RitualHelper {
|
||||
public class RitualHelper
|
||||
{
|
||||
|
||||
public static boolean canCrystalActivate(Ritual ritual, int crystalLevel) {
|
||||
public static boolean canCrystalActivate(Ritual ritual, int crystalLevel)
|
||||
{
|
||||
return ritual.getCrystalLevel() <= crystalLevel && RitualRegistry.ritualEnabled(ritual);
|
||||
}
|
||||
|
||||
public static String getNextRitualKey(String currentKey) {
|
||||
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) {
|
||||
public static String getPrevRitualKey(String currentKey)
|
||||
{
|
||||
int currentIndex = RitualRegistry.getIds().indexOf(currentKey);
|
||||
int previousIndex = RitualRegistry.getIds().listIterator(currentIndex).previousIndex();
|
||||
|
||||
|
@ -40,87 +44,106 @@ public class RitualHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks the RitualRegistry to see if the configuration of the ritual stones in the world is valid
|
||||
* for the given EnumFacing.
|
||||
*
|
||||
* Checks the RitualRegistry to see if the configuration of the ritual
|
||||
* stones in the world is valid for the given EnumFacing.
|
||||
*
|
||||
* @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 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 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;
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
|
||||
for (RitualComponent component : components)
|
||||
{
|
||||
BlockPos newPos = pos.add(component.getOffset(direction));
|
||||
IBlockState worldState = world.getBlockState(newPos);
|
||||
Block block = worldState.getBlock();
|
||||
if (block instanceof IRitualStone) {
|
||||
if(!((IRitualStone)block).isRuneType(world, newPos, component.getRuneType())) {
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
return false;
|
||||
if (block instanceof IRitualStone)
|
||||
{
|
||||
if (!((IRitualStone) block).isRuneType(world, newPos, component.getRuneType()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void checkImperfectRituals(Configuration config, String packageName, String category) {
|
||||
public static void checkImperfectRituals(Configuration config, String packageName, String category)
|
||||
{
|
||||
checkRituals(config, packageName, category, ImperfectRitual.class, ImperfectRitualRegistry.enabledRituals);
|
||||
}
|
||||
|
||||
public static void checkRituals(Configuration config, String packageName, String category) {
|
||||
public static void checkRituals(Configuration config, String packageName, String category)
|
||||
{
|
||||
checkRituals(config, packageName, category, Ritual.class, RitualRegistry.enabledRituals);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds your Ritual to the {@link RitualRegistry#enabledRituals} Map.
|
||||
* This is used to determine whether your effect is enabled or not.
|
||||
*
|
||||
* The config option will be created as {@code B:ClassName=true} with a comment of
|
||||
* {@code Enables the ClassName ritual}.
|
||||
*
|
||||
* Adds your Ritual to the {@link RitualRegistry#enabledRituals} Map. This
|
||||
* is used to determine whether your effect is enabled or not.
|
||||
*
|
||||
* The config option will be created as {@code B:ClassName=true} with a
|
||||
* comment of {@code Enables the ClassName ritual}.
|
||||
*
|
||||
* Use {@link #}
|
||||
*
|
||||
*
|
||||
* Should be safe to modify at any point.
|
||||
*
|
||||
* @param config - Your mod's Forge {@link Configuration} object.
|
||||
* @param packageName - The package your Rituals are located in.
|
||||
* @param category - The config category to write to.
|
||||
*
|
||||
* @param config
|
||||
* - Your mod's Forge {@link Configuration} object.
|
||||
* @param packageName
|
||||
* - The package your Rituals are located in.
|
||||
* @param category
|
||||
* - The config category to write to.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void checkRituals(Configuration config, String packageName, String category, Class ritualClass, Map enabledMap) {
|
||||
private static void checkRituals(Configuration config, String packageName, String category, Class ritualClass, Map enabledMap)
|
||||
{
|
||||
String name = packageName;
|
||||
if (!name.startsWith("/"))
|
||||
name = "/" + name;
|
||||
|
@ -129,24 +152,31 @@ public class RitualHelper {
|
|||
URL url = BloodMagic.class.getResource(name);
|
||||
File directory = new File(url.getFile());
|
||||
|
||||
if (directory.exists()) {
|
||||
if (directory.exists())
|
||||
{
|
||||
String[] files = directory.list();
|
||||
|
||||
for (String file : files) {
|
||||
if (file.endsWith(".class")) {
|
||||
for (String file : files)
|
||||
{
|
||||
if (file.endsWith(".class"))
|
||||
{
|
||||
String className = file.substring(0, file.length() - 6);
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
Object o = Class.forName(packageName + "." + className).newInstance();
|
||||
|
||||
if (ritualClass.isInstance(o))
|
||||
enabledMap.put(ritualClass.cast(o), config.get(category, className, true).getBoolean());
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
} catch (ClassNotFoundException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
} catch (InstantiationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (IllegalAccessException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue