mirror of
https://github.com/GTNewHorizons/BloodMagic.git
synced 2026-11-27 07:13:14 +00:00
Replace a bunch of duplicated checks done for various items with methods in IBindable.
Replace a bunch of duplicated checks for toggling sigils in ISigil. Move static methods from EnergyItems to IBindable so they are more relevant for the bound tools (they don't extend EnergyItems because they need to extend the tool classes).
This commit is contained in:
1 parent
46a8c566d7
commit
b14aded91f
57 files changed
+382
-759
No files matched your search
@@ -2,6 +2,7 @@ package WayofTime.alchemicalWizardry.api.items.interfaces;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -13,21 +14,133 @@ import WayofTime.alchemicalWizardry.common.items.EnergyItems;
|
||||
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
|
||||
|
||||
public interface IBindable {
|
||||
default void addBindingInformation(ItemStack par1ItemStack, List par3List) {
|
||||
NBTTagCompound itemTag = par1ItemStack.getTagCompound();
|
||||
if (!(itemTag == null)) {
|
||||
if (itemTag.getBoolean("isActive")) {
|
||||
par3List.add(StatCollector.translateToLocal("tooltip.sigil.state.activated"));
|
||||
} else if (itemTag.hasKey("isActive")) {
|
||||
par3List.add(StatCollector.translateToLocal("tooltip.sigil.state.deactivated"));
|
||||
}
|
||||
|
||||
if (!itemTag.getString("ownerName").equals("")) {
|
||||
par3List.add(
|
||||
StatCollector.translateToLocal("tooltip.owner.currentowner") + " "
|
||||
+ itemTag.getString("ownerName"));
|
||||
// The number of ticks between passive drains
|
||||
int tickDelay = 200;
|
||||
|
||||
default boolean checkRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer,
|
||||
int rightClickCost, boolean isBoundTool) {
|
||||
if (toggle(par1ItemStack, par2World, par3EntityPlayer)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (par2World.isRemote) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isActive(par1ItemStack) || SpellHelper.isFakePlayer(par2World, par3EntityPlayer)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isBoundTool && AlchemicalWizardry.disableBoundToolsRightClick) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (par3EntityPlayer.isPotionActive(AlchemicalWizardry.customPotionInhibit)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(par3EntityPlayer.capabilities.isCreativeMode
|
||||
|| EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, rightClickCost))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
default void addBindingInformation(ItemStack par1ItemStack, List par3List) {
|
||||
NBTTagCompound itemTag = getTag(par1ItemStack);
|
||||
if (itemTag.getBoolean("isActive")) {
|
||||
par3List.add(StatCollector.translateToLocal("tooltip.sigil.state.activated"));
|
||||
} else if (itemTag.hasKey("isActive")) { // Only if present and set to false rather than not present at all
|
||||
par3List.add(StatCollector.translateToLocal("tooltip.sigil.state.deactivated"));
|
||||
}
|
||||
|
||||
if (!itemTag.getString("ownerName").equals("")) {
|
||||
par3List.add(
|
||||
StatCollector.translateToLocal("tooltip.owner.currentowner") + " "
|
||||
+ itemTag.getString("ownerName"));
|
||||
}
|
||||
}
|
||||
|
||||
static void setActive(ItemStack par1ItemStack, boolean state) {
|
||||
NBTTagCompound itemTag = getTag(par1ItemStack);
|
||||
itemTag.setBoolean("isActive", state);
|
||||
}
|
||||
|
||||
static boolean isActive(ItemStack par1ItemStack) {
|
||||
NBTTagCompound itemTag = getTag(par1ItemStack);
|
||||
return itemTag.getBoolean("isActive");
|
||||
}
|
||||
|
||||
static NBTTagCompound getTag(ItemStack par1ItemStack) {
|
||||
NBTTagCompound itemTag = par1ItemStack.getTagCompound();
|
||||
|
||||
if (itemTag == null) {
|
||||
par1ItemStack.setTagCompound(new NBTTagCompound());
|
||||
itemTag = par1ItemStack.getTagCompound();
|
||||
}
|
||||
return itemTag;
|
||||
}
|
||||
|
||||
static boolean toggle(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
|
||||
if (!checkAndSetItemOwner(par1ItemStack, par3EntityPlayer) || par3EntityPlayer.isSneaking()) {
|
||||
setActive(par1ItemStack, !isActive(par1ItemStack));
|
||||
setDrainTick(par1ItemStack, par2World, tickDelay);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void passiveDrain(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int delay,
|
||||
int cost) {
|
||||
NBTTagCompound itemTag = getTag(par1ItemStack);
|
||||
if (par2World.getTotalWorldTime() % delay == itemTag.getInteger("worldTimeDelay")
|
||||
&& itemTag.getBoolean("isActive")) {
|
||||
if (!par3EntityPlayer.capabilities.isCreativeMode) {
|
||||
if (!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, cost)) {
|
||||
setActive(par1ItemStack, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the drain tick delay based on the current world age and the given modulus
|
||||
*/
|
||||
static void setDrainTick(ItemStack par1ItemStack, World par2World, int modulus) {
|
||||
getTag(par1ItemStack).setInteger("worldTimeDelay", (int) (par2World.getTotalWorldTime() - 1) % modulus);
|
||||
}
|
||||
|
||||
// Global static methods
|
||||
static boolean checkAndSetItemOwner(ItemStack item, EntityPlayer player) {
|
||||
return !SpellHelper.isFakePlayer(player) && SoulNetworkHandler.checkAndSetItemPlayer(item, player);
|
||||
}
|
||||
|
||||
static void setItemOwner(ItemStack item, String ownerName) {
|
||||
if (item.getTagCompound() == null) {
|
||||
item.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
item.getTagCompound().setString("ownerName", ownerName);
|
||||
}
|
||||
|
||||
static void checkAndSetItemOwner(ItemStack item, String ownerName) {
|
||||
if (item.getTagCompound() == null) {
|
||||
item.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
NBTTagCompound tag = IBindable.getTag(item);
|
||||
|
||||
if (item.getTagCompound().getString("ownerName").isEmpty()) {
|
||||
item.getTagCompound().setString("ownerName", ownerName);
|
||||
}
|
||||
}
|
||||
|
||||
static String getOwnerName(ItemStack item) {
|
||||
if (item.getTagCompound() == null) {
|
||||
item.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
return item.getTagCompound().getString("ownerName");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user