Merge apibutnotreally with the main packages
Do not consider anything outside of the true API safe to use. And even then, I'm changing things. Just wait. Please I beg you.
This commit is contained in:
parent
616c08094b
commit
2fecb427fd
399 changed files with 958 additions and 977 deletions
68
src/main/java/WayofTime/bloodmagic/util/BlockStack.java
Normal file
68
src/main/java/WayofTime/bloodmagic/util/BlockStack.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
package WayofTime.bloodmagic.util;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@Deprecated
|
||||
public class BlockStack {
|
||||
private final Block block;
|
||||
private final int meta;
|
||||
private final IBlockState state;
|
||||
|
||||
public BlockStack(Block block, int meta) {
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
this.state = block.getStateFromMeta(meta);
|
||||
}
|
||||
|
||||
public BlockStack(Block block) {
|
||||
this(block, 0);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return new ItemStack(block, 1, meta);
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public int getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public IBlockState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof BlockStack)) return false;
|
||||
|
||||
BlockStack that = (BlockStack) o;
|
||||
|
||||
if (meta != that.meta) return false;
|
||||
return block != null ? block.equals(that.block) : that.block == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = block != null ? block.hashCode() : 0;
|
||||
result = 31 * result + meta;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getBlock().getRegistryName() + ":" + getMeta();
|
||||
}
|
||||
|
||||
public static BlockStack getStackFromPos(World world, BlockPos pos) {
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
return new BlockStack(state.getBlock(), state.getBlock().getMetaFromState(state));
|
||||
}
|
||||
}
|
166
src/main/java/WayofTime/bloodmagic/util/Constants.java
Normal file
166
src/main/java/WayofTime/bloodmagic/util/Constants.java
Normal file
|
@ -0,0 +1,166 @@
|
|||
package WayofTime.bloodmagic.util;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class Constants {
|
||||
public static class NBT {
|
||||
public static final String OWNER_UUID = "ownerUUID";
|
||||
public static final String OWNER_NAME = "ownerNAME";
|
||||
public static final String USES = "uses";
|
||||
public static final String ACTIVATED = "activated";
|
||||
public static final String UNUSABLE = "unusable";
|
||||
public static final String SACRIFICE = "sacrifice";
|
||||
public static final String DIMENSION_ID = "dimensionId";
|
||||
public static final String X_COORD = "xCoord";
|
||||
public static final String Y_COORD = "yCoord";
|
||||
public static final String Z_COORD = "zCoord";
|
||||
public static final String PORTAL_LOCATION = "portalLocation";
|
||||
public static final String ORB_TIER = "orbTier";
|
||||
public static final String CURRENT_ESSENCE = "currentEssence";
|
||||
public static final String CURRENT_RITUAL = "currentRitual";
|
||||
public static final String CURRENT_RITUAL_TAG = "currentRitualTag";
|
||||
public static final String IS_RUNNING = "isRunning";
|
||||
public static final String IS_REDSTONED = "isStoned";
|
||||
public static final String RUNTIME = "runtime";
|
||||
public static final String DIRECTION = "direction";
|
||||
public static final String REAGENT_TANKS = "reagentTanks";
|
||||
public static final String CURRENT_INCENSE = "BM:CurrentIncense";
|
||||
public static final String CURRENT_PURITY = "BM:CurrentPurity";
|
||||
public static final String EMPTY = "Empty";
|
||||
public static final String OUTPUT_AMOUNT = "outputAmount";
|
||||
public static final String INPUT_AMOUNT = "inputAmount";
|
||||
public static final String STORED_LP = "storedLP";
|
||||
public static final String RITUAL_READER = "ritualReaderState";
|
||||
public static final String ITEMS = "Items";
|
||||
public static final String SLOT = "Slot";
|
||||
|
||||
public static final String ALTAR = "bloodAltar";
|
||||
public static final String ALTAR_TIER = "upgradeLevel";
|
||||
public static final String ALTAR_ACTIVE = "isActive";
|
||||
public static final String ALTAR_LIQUID_REQ = "liquidRequired";
|
||||
public static final String ALTAR_FILLABLE = "fillable";
|
||||
public static final String ALTAR_UPGRADED = "isUpgraded";
|
||||
public static final String ALTAR_CONSUMPTION_RATE = "consumptionRate";
|
||||
public static final String ALTAR_DRAIN_RATE = "drainRate";
|
||||
public static final String ALTAR_CONSUMPTION_MULTIPLIER = "consumptionMultiplier";
|
||||
public static final String ALTAR_EFFICIENCY_MULTIPLIER = "efficiencyMultiplier";
|
||||
public static final String ALTAR_SELF_SACRIFICE_MULTIPLIER = "selfSacrificeMultiplier";
|
||||
public static final String ALTAR_SACRIFICE_MULTIPLIER = "sacrificeMultiplier";
|
||||
public static final String ALTAR_CAPACITY_MULTIPLIER = "capacityMultiplier";
|
||||
public static final String ALTAR_ORB_CAPACITY_MULTIPLIER = "orbCapacityMultiplier";
|
||||
public static final String ALTAR_DISLOCATION_MULTIPLIER = "dislocationMultiplier";
|
||||
public static final String ALTAR_CAPACITY = "capacity";
|
||||
public static final String ALTAR_BUFFER_CAPACITY = "bufferCapacity";
|
||||
public static final String ALTAR_PROGRESS = "progress";
|
||||
public static final String ALTAR_IS_RESULT_BLOCK = "isResultBlock";
|
||||
public static final String ALTAR_LOCKDOWN_DURATION = "lockdownDuration";
|
||||
public static final String ALTAR_ACCELERATION_UPGRADES = "accelerationUpgrades";
|
||||
public static final String ALTAR_DEMON_BLOOD_DURATION = "demonBloodDuration";
|
||||
public static final String ALTAR_COOLDOWN_AFTER_CRAFTING = "cooldownAfterCrafting";
|
||||
public static final String ALTAR_TOTAL_CHARGE = "totalCharge";
|
||||
public static final String ALTAR_MAX_CHARGE = "maxCharge";
|
||||
public static final String ALTAR_CHARGE_RATE = "chargeRate";
|
||||
public static final String ALTAR_CHARGE_FREQUENCY = "chargeFrequency";
|
||||
public static final String ALTAR_CURRENT_TIER_DISPLAYED = "currentTierDisplayed";
|
||||
|
||||
public static final String ALTARMAKER_CURRENT_TIER = "currentTier";
|
||||
|
||||
public static final String PROJECTILE_TICKS_IN_AIR = "projectileTicksInAir";
|
||||
public static final String PROJECTILE_MAX_TICKS_IN_AIR = "projectileMaxTicksInAir";
|
||||
|
||||
public static final String TICKS_REMAINING = "ticksRemaining";
|
||||
public static final String CONTAINED_BLOCK_NAME = "containedBlockName";
|
||||
public static final String CONTAINED_BLOCK_META = "containedBlockMeta";
|
||||
public static final String CONTAINED_TILE_ENTITY = "containedTileEntity";
|
||||
|
||||
public static final String PREVIOUS_INPUT = "previousInput";
|
||||
|
||||
public static final String LIVING_ARMOUR = "livingArmour";
|
||||
|
||||
public static final String CHARGE_TIME = "chargeTime";
|
||||
public static final String HELD_DOWN = "heldDown";
|
||||
|
||||
public static final String UPGRADE_POISON_TIMER = "poisonTimer";
|
||||
public static final String UPGRADE_FIRE_TIMER = "fireTimer";
|
||||
|
||||
public static final String SOULS = "souls";
|
||||
public static final String SOUL_SWORD_DAMAGE = "soulSwordDamage";
|
||||
public static final String SOUL_SWORD_ACTIVE_DRAIN = "soulSwordActiveDrain";
|
||||
public static final String SOUL_SWORD_DROP = "soulSwordDrop";
|
||||
public static final String SOUL_SWORD_STATIC_DROP = "soulSwordStaticDrop";
|
||||
public static final String SOUL_SWORD_HEALTH = "soulSwordHealth";
|
||||
public static final String SOUL_SWORD_ATTACK_SPEED = "soulSwordAttackSpeed";
|
||||
public static final String SOUL_SWORD_SPEED = "soulSwordSpeed";
|
||||
public static final String SOUL_SWORD_DIG_SPEED = "soulSwordDigSpeed";
|
||||
public static final String WILL_TYPE = "demonWillType";
|
||||
|
||||
public static final String SOUL_FORGE_BURN = "burnTime";
|
||||
public static final String SOUL_FORGE_CONSUMED = "consumedSouls";
|
||||
|
||||
public static final String ROUTING_MASTER = "master";
|
||||
public static final String ROUTING_CONNECTION = "connections";
|
||||
public static final String ROUTING_PRIORITY = "prioritiesPeople";
|
||||
public static final String ROUTING_MASTER_GENERAL = "generalList";
|
||||
public static final String ROUTING_MASTER_INPUT = "inputList";
|
||||
public static final String ROUTING_MASTER_OUTPUT = "outputList";
|
||||
|
||||
public static final String GHOST_STACK_SIZE = "stackSize";
|
||||
|
||||
public static final String ITEM_INVENTORY = "itemInventory";
|
||||
|
||||
public static final String BLOCKPOS_CONNECTION = "connections";
|
||||
|
||||
public static final String CURRENT_SIGIL = "currentSigil";
|
||||
public static final String MOST_SIG = "mostSig";
|
||||
public static final String LEAST_SIG = "leastSig";
|
||||
public static final String COLOR = "color";
|
||||
|
||||
public static final String POTION_AUGMENT_LENGHT = "length:";
|
||||
public static final String POTION_AUGMENT_STRENGTH = "strength:";
|
||||
public static final String POTION_IMPURITY = "impurity";
|
||||
|
||||
public static final String TANK = "tank";
|
||||
}
|
||||
|
||||
public static class Mod {
|
||||
public static final String DOMAIN = BloodMagic.MODID.toLowerCase(Locale.ENGLISH) + ":";
|
||||
}
|
||||
|
||||
public static final class Gui {
|
||||
public static final int TELEPOSER_GUI = 0;
|
||||
public static final int SOUL_FORGE_GUI = 1;
|
||||
public static final int ROUTING_NODE_GUI = 2;
|
||||
public static final int MASTER_ROUTING_NODE_GUI = 3;
|
||||
public static final int ALCHEMY_TABLE_GUI = 4;
|
||||
public static final int SIGIL_HOLDING_GUI = 5;
|
||||
}
|
||||
|
||||
public static class Compat {
|
||||
public static final String JEI_CATEGORY_ALTAR = BloodMagic.MODID + ":altar";
|
||||
public static final String JEI_CATEGORY_BINDING = BloodMagic.MODID + ":binding";
|
||||
public static final String JEI_CATEGORY_ALCHEMYARRAY = BloodMagic.MODID + ":alchemyArray";
|
||||
public static final String JEI_CATEGORY_SOULFORGE = BloodMagic.MODID + ":soulForge";
|
||||
public static final String JEI_CATEGORY_ALCHEMYTABLE = BloodMagic.MODID + ":salchemyTable";
|
||||
public static final String JEI_CATEGORY_ARMOURDOWNGRADE = BloodMagic.MODID + ":armourDowngrade";
|
||||
|
||||
public static final String WAILA_CONFIG_ALTAR = BloodMagic.MODID + ".bloodAltar";
|
||||
public static final String WAILA_CONFIG_TELEPOSER = BloodMagic.MODID + ".teleposer";
|
||||
public static final String WAILA_CONFIG_RITUAL = BloodMagic.MODID + ".ritualController";
|
||||
public static final String WAILA_CONFIG_ARRAY = BloodMagic.MODID + ".array";
|
||||
public static final String WAILA_CONFIG_BLOOD_TANK = BloodMagic.MODID + ".bloodTank";
|
||||
|
||||
public static final Item THAUMCRAFT_GOGGLES = ForgeRegistries.ITEMS.getValue(new ResourceLocation("Thaumcraft", "goggles"));
|
||||
}
|
||||
|
||||
public static class Misc {
|
||||
public static final int POTION_ARRAY_SIZE = 256;
|
||||
public static final float ALTERED_STEP_HEIGHT = 1.00314159f;
|
||||
public static final int NIGHT_VISION_CONSTANT_BEGIN = 30002;
|
||||
public static final int NIGHT_VISION_CONSTANT_END = 30000;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package WayofTime.bloodmagic.util;
|
||||
|
||||
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
public class DamageSourceBloodMagic extends DamageSource {
|
||||
public DamageSourceBloodMagic() {
|
||||
super("bloodMagic");
|
||||
|
||||
setDamageBypassesArmor();
|
||||
setDamageIsAbsolute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDeathMessage(EntityLivingBase livingBase) {
|
||||
return new TextComponentString(TextHelper.localizeEffect("chat.bloodmagic.damageSource", livingBase.getName()));
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package WayofTime.bloodmagic.util;
|
||||
|
||||
import WayofTime.bloodmagic.apibutnotreally.Constants;
|
||||
import WayofTime.bloodmagic.apibutnotreally.util.helper.NBTHelper;
|
||||
import WayofTime.bloodmagic.util.helper.NBTHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
|
|
113
src/main/java/WayofTime/bloodmagic/util/ItemStackWrapper.java
Normal file
113
src/main/java/WayofTime/bloodmagic/util/ItemStackWrapper.java
Normal file
|
@ -0,0 +1,113 @@
|
|||
package WayofTime.bloodmagic.util;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated
|
||||
public class ItemStackWrapper {
|
||||
public final Item item;
|
||||
public final int stackSize;
|
||||
public final int meta;
|
||||
public NBTTagCompound nbtTag;
|
||||
|
||||
public ItemStackWrapper(Item item, int stackSize, int meta) {
|
||||
this.item = item;
|
||||
this.stackSize = stackSize;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public ItemStackWrapper(Item item, int stackSize) {
|
||||
this(item, stackSize, 0);
|
||||
}
|
||||
|
||||
public ItemStackWrapper(Item item) {
|
||||
this(item, 1, 0);
|
||||
}
|
||||
|
||||
public ItemStackWrapper(Block block, int stackSize, int meta) {
|
||||
this(Item.getItemFromBlock(block), stackSize, meta);
|
||||
}
|
||||
|
||||
public ItemStackWrapper(Block block, int stackSize) {
|
||||
this(block, stackSize, 0);
|
||||
}
|
||||
|
||||
public ItemStackWrapper(Block block) {
|
||||
this(block, 1, 0);
|
||||
}
|
||||
|
||||
public ItemStackWrapper(BlockStack blockStack) {
|
||||
this(blockStack.getBlock(), 1, blockStack.getMeta());
|
||||
}
|
||||
|
||||
public ItemStack toStack() {
|
||||
return new ItemStack(item, stackSize, meta);
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return toStack().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return stackSize + "x" + item.getUnlocalizedName() + "@" + this.meta;
|
||||
}
|
||||
|
||||
public ItemStack toStack(int count) {
|
||||
ItemStack result = new ItemStack(item, count, meta);
|
||||
result.setTagCompound(nbtTag);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public int getStackSize() {
|
||||
return stackSize;
|
||||
}
|
||||
|
||||
public int getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public NBTTagCompound getNbtTag() {
|
||||
return nbtTag;
|
||||
}
|
||||
|
||||
public void setNbtTag(NBTTagCompound nbtTag) {
|
||||
this.nbtTag = nbtTag;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ItemStackWrapper getHolder(ItemStack stack) {
|
||||
if (stack.isEmpty())
|
||||
return null;
|
||||
|
||||
ItemStackWrapper wrapper = new ItemStackWrapper(stack.getItem(), stack.getCount(), stack.getItemDamage());
|
||||
wrapper.setNbtTag(stack.getTagCompound());
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public static List<ItemStackWrapper> toWrapperList(List<ItemStack> itemStackList) {
|
||||
List<ItemStackWrapper> wrapperList = new ArrayList<ItemStackWrapper>();
|
||||
for (ItemStack stack : itemStackList)
|
||||
wrapperList.add(ItemStackWrapper.getHolder(stack));
|
||||
|
||||
return wrapperList;
|
||||
}
|
||||
|
||||
public static List<ItemStack> toStackList(List<ItemStackWrapper> wrapperList) {
|
||||
List<ItemStack> stackList = new ArrayList<ItemStack>();
|
||||
for (ItemStackWrapper wrapper : wrapperList)
|
||||
stackList.add(wrapper.toStack());
|
||||
|
||||
return stackList;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package WayofTime.bloodmagic.util;
|
||||
|
||||
import WayofTime.bloodmagic.util.helper.LogHelper;
|
||||
import net.minecraft.util.DamageSource;
|
||||
|
||||
/**
|
||||
* The primary API class. Includes helper methods and blacklists.
|
||||
* <p>
|
||||
* Some API methods can be used via IMC instead. The supported methods are:
|
||||
*/
|
||||
// TODO - Nuke this class
|
||||
@Deprecated
|
||||
public class PleaseStopUsingMe {
|
||||
public static boolean loggingEnabled;
|
||||
|
||||
public static LogHelper logger = new LogHelper("BloodMagic|API");
|
||||
|
||||
public static DamageSource damageSource = new DamageSourceBloodMagic();
|
||||
}
|
|
@ -1,10 +1,8 @@
|
|||
package WayofTime.bloodmagic.util;
|
||||
|
||||
import WayofTime.bloodmagic.apibutnotreally.BlockStack;
|
||||
import WayofTime.bloodmagic.apibutnotreally.Constants;
|
||||
import WayofTime.bloodmagic.apibutnotreally.altar.EnumAltarComponent;
|
||||
import WayofTime.bloodmagic.apibutnotreally.iface.IDemonWillViewer;
|
||||
import WayofTime.bloodmagic.apibutnotreally.util.helper.NBTHelper;
|
||||
import WayofTime.bloodmagic.altar.EnumAltarComponent;
|
||||
import WayofTime.bloodmagic.iface.IDemonWillViewer;
|
||||
import WayofTime.bloodmagic.util.helper.NBTHelper;
|
||||
import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks;
|
||||
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
|
||||
import WayofTime.bloodmagic.network.PlayerVelocityPacketProcessor;
|
||||
|
|
|
@ -2,10 +2,10 @@ package WayofTime.bloodmagic.util.handler.event;
|
|||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.ConfigHandler;
|
||||
import WayofTime.bloodmagic.apibutnotreally.Constants;
|
||||
import WayofTime.bloodmagic.apibutnotreally.registry.RitualRegistry;
|
||||
import WayofTime.bloodmagic.apibutnotreally.ritual.Ritual;
|
||||
import WayofTime.bloodmagic.apibutnotreally.ritual.RitualComponent;
|
||||
import WayofTime.bloodmagic.util.Constants;
|
||||
import WayofTime.bloodmagic.core.registry.RitualRegistry;
|
||||
import WayofTime.bloodmagic.ritual.data.Ritual;
|
||||
import WayofTime.bloodmagic.ritual.data.RitualComponent;
|
||||
import WayofTime.bloodmagic.client.hud.HUDElement;
|
||||
import WayofTime.bloodmagic.client.key.KeyBindings;
|
||||
import WayofTime.bloodmagic.client.render.block.RenderFakeBlocks;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package WayofTime.bloodmagic.util.handler.event;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.apibutnotreally.Constants;
|
||||
import WayofTime.bloodmagic.apibutnotreally.event.AltarCraftedEvent;
|
||||
import WayofTime.bloodmagic.apibutnotreally.iface.IUpgradeTrainer;
|
||||
import WayofTime.bloodmagic.apibutnotreally.livingArmour.LivingArmourUpgrade;
|
||||
import WayofTime.bloodmagic.apibutnotreally.util.helper.ItemHelper;
|
||||
import WayofTime.bloodmagic.apibutnotreally.util.helper.NBTHelper;
|
||||
import WayofTime.bloodmagic.util.Constants;
|
||||
import WayofTime.bloodmagic.event.AltarCraftedEvent;
|
||||
import WayofTime.bloodmagic.iface.IUpgradeTrainer;
|
||||
import WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade;
|
||||
import WayofTime.bloodmagic.util.helper.ItemHelper;
|
||||
import WayofTime.bloodmagic.util.helper.NBTHelper;
|
||||
import WayofTime.bloodmagic.block.BlockLifeEssence;
|
||||
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
||||
import WayofTime.bloodmagic.item.ItemInscriptionTool;
|
||||
|
|
|
@ -3,18 +3,17 @@ package WayofTime.bloodmagic.util.handler.event;
|
|||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.ConfigHandler;
|
||||
import WayofTime.bloodmagic.api.impl.BloodMagicAPI;
|
||||
import WayofTime.bloodmagic.apibutnotreally.Constants;
|
||||
import WayofTime.bloodmagic.apibutnotreally.event.ItemBindEvent;
|
||||
import WayofTime.bloodmagic.apibutnotreally.event.SacrificeKnifeUsedEvent;
|
||||
import WayofTime.bloodmagic.apibutnotreally.event.TeleposeEvent;
|
||||
import WayofTime.bloodmagic.apibutnotreally.iface.IBindable;
|
||||
import WayofTime.bloodmagic.apibutnotreally.iface.ISentientTool;
|
||||
import WayofTime.bloodmagic.apibutnotreally.livingArmour.LivingArmourUpgrade;
|
||||
import WayofTime.bloodmagic.apibutnotreally.orb.BloodOrb;
|
||||
import WayofTime.bloodmagic.apibutnotreally.orb.IBloodOrb;
|
||||
import WayofTime.bloodmagic.apibutnotreally.saving.SoulNetwork;
|
||||
import WayofTime.bloodmagic.apibutnotreally.soul.DemonWillHolder;
|
||||
import WayofTime.bloodmagic.apibutnotreally.util.helper.*;
|
||||
import WayofTime.bloodmagic.util.Constants;
|
||||
import WayofTime.bloodmagic.event.ItemBindEvent;
|
||||
import WayofTime.bloodmagic.event.SacrificeKnifeUsedEvent;
|
||||
import WayofTime.bloodmagic.event.TeleposeEvent;
|
||||
import WayofTime.bloodmagic.iface.IBindable;
|
||||
import WayofTime.bloodmagic.iface.ISentientTool;
|
||||
import WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade;
|
||||
import WayofTime.bloodmagic.orb.BloodOrb;
|
||||
import WayofTime.bloodmagic.orb.IBloodOrb;
|
||||
import WayofTime.bloodmagic.core.data.SoulNetwork;
|
||||
import WayofTime.bloodmagic.soul.DemonWillHolder;
|
||||
import WayofTime.bloodmagic.block.BlockAltar;
|
||||
import WayofTime.bloodmagic.core.RegistrarBloodMagic;
|
||||
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
||||
|
@ -33,7 +32,7 @@ import WayofTime.bloodmagic.network.DemonAuraPacketProcessor;
|
|||
import WayofTime.bloodmagic.potion.BMPotionUtils;
|
||||
import WayofTime.bloodmagic.util.ChatUtil;
|
||||
import WayofTime.bloodmagic.util.Utils;
|
||||
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||
import WayofTime.bloodmagic.util.helper.*;
|
||||
import com.google.common.base.Strings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package WayofTime.bloodmagic.util.handler.event;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.apibutnotreally.Constants;
|
||||
import WayofTime.bloodmagic.apibutnotreally.livingArmour.LivingArmourUpgrade;
|
||||
import WayofTime.bloodmagic.util.Constants;
|
||||
import WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade;
|
||||
import WayofTime.bloodmagic.core.RegistrarBloodMagic;
|
||||
import WayofTime.bloodmagic.item.armour.ItemLivingArmour;
|
||||
import WayofTime.bloodmagic.livingArmour.LivingArmour;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package WayofTime.bloodmagic.util.handler.event;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.apibutnotreally.livingArmour.LivingArmourUpgrade;
|
||||
import WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade;
|
||||
import WayofTime.bloodmagic.item.armour.ItemLivingArmour;
|
||||
import WayofTime.bloodmagic.item.armour.ItemSentientArmour;
|
||||
import WayofTime.bloodmagic.livingArmour.LivingArmour;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package WayofTime.bloodmagic.util.handler.event;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.apibutnotreally.soul.*;
|
||||
import WayofTime.bloodmagic.soul.*;
|
||||
import WayofTime.bloodmagic.core.RegistrarBloodMagic;
|
||||
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
||||
import WayofTime.bloodmagic.demonAura.PosXY;
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
package WayofTime.bloodmagic.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.util.Constants;
|
||||
import WayofTime.bloodmagic.event.ItemBindEvent;
|
||||
import WayofTime.bloodmagic.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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package WayofTime.bloodmagic.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.util.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);
|
||||
}
|
||||
}
|
131
src/main/java/WayofTime/bloodmagic/util/helper/ItemHelper.java
Normal file
131
src/main/java/WayofTime/bloodmagic/util/helper/ItemHelper.java
Normal file
|
@ -0,0 +1,131 @@
|
|||
package WayofTime.bloodmagic.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.altar.IBloodAltar;
|
||||
import WayofTime.bloodmagic.iface.IItemLPContainer;
|
||||
import WayofTime.bloodmagic.iface.IUpgradeTrainer;
|
||||
import WayofTime.bloodmagic.livingArmour.LivingArmourHandler;
|
||||
import WayofTime.bloodmagic.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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package WayofTime.bloodmagic.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.util.PleaseStopUsingMe;
|
||||
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 (PleaseStopUsingMe.loggingEnabled)
|
||||
logger.info(info, format);
|
||||
}
|
||||
|
||||
public void error(String error, Object... format) {
|
||||
if (PleaseStopUsingMe.loggingEnabled)
|
||||
logger.error(error, format);
|
||||
}
|
||||
|
||||
public void debug(String debug, Object... format) {
|
||||
if (PleaseStopUsingMe.loggingEnabled)
|
||||
logger.debug(debug, format);
|
||||
}
|
||||
|
||||
public void fatal(String fatal, Object... format) {
|
||||
logger.error(fatal, format);
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package WayofTime.bloodmagic.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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
package WayofTime.bloodmagic.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.util.Constants;
|
||||
import WayofTime.bloodmagic.event.SoulNetworkEvent;
|
||||
import WayofTime.bloodmagic.orb.BloodOrb;
|
||||
import WayofTime.bloodmagic.orb.IBloodOrb;
|
||||
import WayofTime.bloodmagic.core.registry.OrbRegistry;
|
||||
import WayofTime.bloodmagic.core.data.BMWorldSavedData;
|
||||
import WayofTime.bloodmagic.core.data.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()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package WayofTime.bloodmagic.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.util.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));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package WayofTime.bloodmagic.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.ConfigHandler;
|
||||
import WayofTime.bloodmagic.altar.IBloodAltar;
|
||||
import WayofTime.bloodmagic.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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package WayofTime.bloodmagic.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.util.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;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package WayofTime.bloodmagic.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.apibutnotreally.recipe.TartaricForgeRecipe;
|
||||
import WayofTime.bloodmagic.apibutnotreally.registry.AltarRecipeRegistry;
|
||||
import WayofTime.bloodmagic.apibutnotreally.registry.TartaricForgeRecipeRegistry;
|
||||
import WayofTime.bloodmagic.recipe.TartaricForgeRecipe;
|
||||
import WayofTime.bloodmagic.core.registry.AltarRecipeRegistry;
|
||||
import WayofTime.bloodmagic.core.registry.TartaricForgeRecipeRegistry;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
|
|
143
src/main/java/WayofTime/bloodmagic/util/helper/RitualHelper.java
Normal file
143
src/main/java/WayofTime/bloodmagic/util/helper/RitualHelper.java
Normal file
|
@ -0,0 +1,143 @@
|
|||
package WayofTime.bloodmagic.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.core.registry.RitualRegistry;
|
||||
import WayofTime.bloodmagic.ritual.data.EnumRuneType;
|
||||
import WayofTime.bloodmagic.ritual.data.IRitualStone;
|
||||
import WayofTime.bloodmagic.ritual.data.Ritual;
|
||||
import WayofTime.bloodmagic.ritual.data.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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue