A whole lot of formatting cleanup
Also changes NBTHolder to a standard Constants class with subclasses for each category
This commit is contained in:
parent
f9802900db
commit
34dee6447b
74 changed files with 861 additions and 662 deletions
|
@ -1,6 +1,6 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.api.NBTHolder;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.api.event.ItemBindEvent;
|
||||
import WayofTime.bloodmagic.api.iface.IBindable;
|
||||
import com.google.common.base.Strings;
|
||||
|
@ -16,6 +16,7 @@ public class BindableHelper {
|
|||
*
|
||||
* @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) {
|
||||
|
@ -24,25 +25,26 @@ public class BindableHelper {
|
|||
|
||||
/**
|
||||
* Bind an item to a username.
|
||||
*
|
||||
* <p/>
|
||||
* Requires the Item contained in the ItemStack to be an instanceof {@link IBindable}
|
||||
*
|
||||
* <p/>
|
||||
* Fires {@link ItemBindEvent}.
|
||||
*
|
||||
* @param stack - The ItemStack to bind
|
||||
* @param ownerName - The username to bind the ItemStack to
|
||||
*
|
||||
* @return - Whether the binding was successful
|
||||
*/
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, String ownerName) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
if (!(stack.getItem() instanceof IBindable))
|
||||
return false;
|
||||
|
||||
if (Strings.isNullOrEmpty(stack.getTagCompound().getString(NBTHolder.NBT_OWNER))) {
|
||||
if (Strings.isNullOrEmpty(stack.getTagCompound().getString(Constants.NBT.OWNER_NAME))) {
|
||||
MinecraftForge.EVENT_BUS.post(new ItemBindEvent(PlayerHelper.getPlayerFromUsername(ownerName), ownerName, stack));
|
||||
((IBindable) stack.getItem()).onBind(PlayerHelper.getPlayerFromUsername(ownerName), stack);
|
||||
stack.getTagCompound().setString(NBTHolder.NBT_OWNER, ownerName);
|
||||
stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, ownerName);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -57,20 +59,21 @@ public class BindableHelper {
|
|||
* @param ownerName - The username to bind the ItemStack to
|
||||
*/
|
||||
public static void setItemOwner(ItemStack stack, String ownerName) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
stack.getTagCompound().setString(NBTHolder.NBT_OWNER, ownerName);
|
||||
stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, ownerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to safely obtain the username of the ItemStack's owner
|
||||
*
|
||||
* @param stack - The ItemStack to check the owner of
|
||||
*
|
||||
* @return - The username of the ItemStack's owner
|
||||
*/
|
||||
public static String getOwnerName(ItemStack stack) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
return stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
|
||||
return stack.getTagCompound().getString(Constants.NBT.OWNER_NAME);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.api.NBTHolder;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class IncenseHelper {
|
||||
|
||||
public static float getCurrentIncense(EntityPlayer player) {
|
||||
NBTTagCompound data = player.getEntityData();
|
||||
if (data.hasKey(NBTHolder.NBT_CURRENT_INCENSE)) {
|
||||
return data.getFloat(NBTHolder.NBT_CURRENT_INCENSE);
|
||||
if (data.hasKey(Constants.NBT.CURRENT_INCENSE)) {
|
||||
return data.getFloat(Constants.NBT.CURRENT_INCENSE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -16,6 +17,6 @@ public class IncenseHelper {
|
|||
|
||||
public static void setCurrentIncense(EntityPlayer player, float amount) {
|
||||
NBTTagCompound data = player.getEntityData();
|
||||
data.setFloat(NBTHolder.NBT_CURRENT_INCENSE, amount);
|
||||
data.setFloat(Constants.NBT.CURRENT_INCENSE, amount);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package WayofTime.bloodmagic.api.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;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||
import WayofTime.bloodmagic.api.NBTHolder;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.api.event.AddToNetworkEvent;
|
||||
import WayofTime.bloodmagic.api.event.SoulNetworkEvent;
|
||||
import WayofTime.bloodmagic.api.network.SoulNetwork;
|
||||
|
@ -49,8 +49,8 @@ public class NetworkHelper {
|
|||
}
|
||||
|
||||
public static boolean syphonFromContainer(ItemStack stack, SoulNetwork soulNetwork, int toSyphon) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_NAME);
|
||||
|
||||
if (Strings.isNullOrEmpty(ownerName))
|
||||
return false;
|
||||
|
@ -73,9 +73,9 @@ public class NetworkHelper {
|
|||
* 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
|
||||
* @param syphon
|
||||
* @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
|
||||
|
@ -83,18 +83,18 @@ public class NetworkHelper {
|
|||
if (player.worldObj.isRemote)
|
||||
return false;
|
||||
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_NAME);
|
||||
|
||||
if (!Strings.isNullOrEmpty(ownerName)) {
|
||||
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(player, ownerName, stack, syphon);
|
||||
|
||||
if(MinecraftForge.EVENT_BUS.post(event))
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
return false;
|
||||
|
||||
int drainAmount = syphonFromNetwork(event.ownerName, event.syphon);
|
||||
|
||||
if(drainAmount == 0 || event.shouldDamage)
|
||||
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.
|
||||
|
@ -110,15 +110,15 @@ public class NetworkHelper {
|
|||
|
||||
@Deprecated
|
||||
public static boolean syphonFromNetworkWhileInContainer(ItemStack stack, int syphon) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_NAME);
|
||||
|
||||
if (Strings.isNullOrEmpty(ownerName))
|
||||
return false;
|
||||
|
||||
SoulNetworkEvent.ItemDrainInContainerEvent event = new SoulNetworkEvent.ItemDrainInContainerEvent(stack, ownerName, syphon);
|
||||
|
||||
if(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||
return false;
|
||||
|
||||
return syphonFromNetwork(event.ownerName, event.syphon) >= syphon;
|
||||
|
@ -126,8 +126,8 @@ public class NetworkHelper {
|
|||
|
||||
@Deprecated
|
||||
public static int syphonFromNetwork(ItemStack stack, int syphon) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_NAME);
|
||||
if (!Strings.isNullOrEmpty(ownerName))
|
||||
return syphonFromNetwork(ownerName, syphon);
|
||||
|
||||
|
@ -167,7 +167,7 @@ public class NetworkHelper {
|
|||
public static int addCurrentEssenceToMaximum(String ownerName, int addedEssence, int maximum) {
|
||||
AddToNetworkEvent event = new AddToNetworkEvent(ownerName, addedEssence, maximum);
|
||||
|
||||
if(MinecraftForge.EVENT_BUS.post(event))
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
return 0;
|
||||
|
||||
if (MinecraftServer.getServer() == null)
|
||||
|
@ -187,7 +187,7 @@ public class NetworkHelper {
|
|||
return 0;
|
||||
|
||||
int newEss = Math.min(event.maximum, currEss + event.addedAmount);
|
||||
if(event.getResult() != Event.Result.DENY)
|
||||
if (event.getResult() != Event.Result.DENY)
|
||||
data.setCurrentEssence(newEss);
|
||||
|
||||
return newEss - currEss;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.api.NBTHolder;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import com.google.common.base.Strings;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -36,10 +36,10 @@ public class PlayerHelper {
|
|||
}
|
||||
|
||||
public static void causeNauseaToPlayer(ItemStack stack) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
if (!Strings.isNullOrEmpty(stack.getTagCompound().getString(NBTHolder.NBT_OWNER)))
|
||||
causeNauseaToPlayer(stack.getTagCompound().getString(NBTHolder.NBT_OWNER));
|
||||
if (!Strings.isNullOrEmpty(stack.getTagCompound().getString(Constants.NBT.OWNER_NAME)))
|
||||
causeNauseaToPlayer(stack.getTagCompound().getString(Constants.NBT.OWNER_NAME));
|
||||
}
|
||||
|
||||
public static void causeNauseaToPlayer(String ownerName) {
|
||||
|
|
|
@ -42,12 +42,12 @@ public class RitualHelper {
|
|||
/**
|
||||
* Adds your Ritual to the {@link RitualRegistry#enabledRituals} Map.
|
||||
* This is used to determine whether your effect is enabled or not.
|
||||
*
|
||||
* <p/>
|
||||
* The config option will be created as {@code B:ClassName=true} with a comment of
|
||||
* {@code Enables the ClassName ritual}.
|
||||
*
|
||||
* <p/>
|
||||
* Use {@link #}
|
||||
*
|
||||
* <p/>
|
||||
* Should be safe to modify at any point.
|
||||
*
|
||||
* @param config - Your mod's Forge {@link Configuration} object.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue