Refactor everything to WayofTime.bloodmagic.*

This commit is contained in:
Nick 2015-11-02 12:39:44 -08:00
parent 46742a73d1
commit 096ba02450
771 changed files with 566 additions and 573 deletions

View file

@ -0,0 +1,80 @@
package WayofTime.bloodmagic;
import WayofTime.bloodmagic.api.util.helper.LogHelper;
import WayofTime.bloodmagic.network.AlchemicalWizardryPacketHandler;
import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.registry.ModEntities;
import WayofTime.bloodmagic.registry.ModItems;
import WayofTime.bloodmagic.registry.ModPotions;
import WayofTime.bloodmagic.proxy.CommonProxy;
import WayofTime.bloodmagic.util.handler.EventHandler;
import WayofTime.bloodmagic.util.helper.InventoryRenderHelper;
import lombok.Getter;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import java.io.File;
import java.util.Locale;
@Mod(modid = BloodMagic.MODID, name = BloodMagic.NAME, version = BloodMagic.VERSION, dependencies = BloodMagic.DEPEND, guiFactory = "WayofTime.bloodmagic.client.gui.ConfigGuiFactory")
@Getter
public class BloodMagic {
public static final String MODID = "BloodMagic";
public static final String NAME = "Blood Magic: Alchemical Wizardry";
public static final String VERSION = "@VERSION@";
public static final String DEPEND = "";
public static final String DOMAIN = MODID.toLowerCase(Locale.ENGLISH) + ":";
@SidedProxy(serverSide = "WayofTime.bloodmagic.proxy.CommonProxy", clientSide = "WayofTime.bloodmagic.proxy.ClientProxy")
public static CommonProxy proxy;
@Mod.Instance(MODID)
public static BloodMagic instance;
public static CreativeTabs tabBloodMagic = new CreativeTabs(MODID + ".creativeTab") {
@Override
public Item getTabIconItem() {
return ModItems.bloodOrb;
}
};
private InventoryRenderHelper renderHelper = new InventoryRenderHelper(DOMAIN);
private LogHelper logger = new LogHelper(MODID);
private File configDir;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
configDir = new File(event.getModConfigurationDirectory(), "BloodMagic");
ConfigHandler.init(new File(getConfigDir(), "BloodMagic.cfg"));
EventHandler eventHandler = new EventHandler();
FMLCommonHandler.instance().bus().register(eventHandler);
MinecraftForge.EVENT_BUS.register(eventHandler);
ModBlocks.init();
ModItems.init();
ModPotions.init();
ModEntities.init();
proxy.preInit();
}
@Mod.EventHandler
public void init(FMLPreInitializationEvent event) {
AlchemicalWizardryPacketHandler.init();
proxy.init();
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
proxy.postInit();
}
}

View file

@ -0,0 +1,195 @@
package WayofTime.bloodmagic;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.BlockStack;
import WayofTime.bloodmagic.registry.ModPotions;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.block.Block;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.OreDictionary;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ConfigHandler {
public static Configuration config;
// Teleposer
public static String[] teleposerBlacklisting;
public static ArrayList<BlockStack> teleposerBlacklist = new ArrayList<BlockStack>();
// Item/Block Disabling
public static List itemBlacklist;
public static List blockBlacklist;
// Potion ID's
public static int customPotionDrowningID;
public static int customPotionBoostID;
public static int customPotionProjProtID;
public static int customPotionInhibitID;
public static int customPotionFlightID;
public static int customPotionReciprocationID;
public static int customPotionFlameCloakID;
public static int customPotionIceCloakID;
public static int customPotionHeavyHeartID;
public static int customPotionFireFuseID;
public static int customPotionPlanarBindingID;
public static int customPotionSoulFrayID;
public static int customPotionSoulHardenID;
public static int customPotionDeafID;
public static int customPotionFeatherFallID;
public static int customPotionDemonCloakID;
public static int customPotionAmphibianID;
// Potion toggles
public static boolean customPotionDrowningEnabled;
public static boolean customPotionBoostEnabled;
public static boolean customPotionProjProtEnabled;
public static boolean customPotionInhibitEnabled;
public static boolean customPotionFlightEnabled;
public static boolean customPotionReciprocationEnabled;
public static boolean customPotionFlameCloakEnabled;
public static boolean customPotionIceCloakEnabled;
public static boolean customPotionHeavyHeartEnabled;
public static boolean customPotionFireFuseEnabled;
public static boolean customPotionPlanarBindingEnabled;
public static boolean customPotionSoulFrayEnabled;
public static boolean customPotionSoulHardenEnabled;
public static boolean customPotionDeafEnabled;
public static boolean customPotionFeatherFallEnabled;
public static boolean customPotionDemonCloakEnabled;
public static boolean customPotionAmphibianEnabled;
public static boolean vanillaPotionRegenerationEnabled;
public static boolean vanillaPotionNightVisionEnabled;
public static boolean vanillaPotionFireResistEnabled;
public static boolean vanillaPotionWaterBreathingEnabled;
public static boolean vanillaPotionSpeedEnabled;
public static boolean vanillaPotionHealthEnabled;
public static boolean vanillaPotionPoisonEnabled;
public static boolean vanillaPotionBlindnessEnabled;
public static boolean vanillaPotionWeaknessEnabled;
public static boolean vanillaPotionStrengthEnabled;
public static boolean vanillaPotionJumpBoostEnabled;
public static boolean vanillaPotionSlownessEnabled;
public static boolean vanillaPotionMiningEnabled;
public static boolean vanillaPotionInvisibilityEnabled;
public static boolean vanillaPotionResistanceEnabled;
public static boolean vanillaPotionSaturationEnabled;
public static boolean vanillaPotionHealthBoostEnabled;
public static boolean vanillaPotionAbsorptionEnabled;
public static void init(File file) {
config = new Configuration(file);
syncConfig();
}
public static void syncConfig() {
String category;
category = "Item/Block Blacklisting";
config.addCustomCategoryComment(category, "Allows disabling of specific Blocks/Items.\nNote that using this may result in crashes. Use is not supported.");
config.setCategoryRequiresMcRestart(category, true);
itemBlacklist = Arrays.asList(config.getStringList("itemBlacklist", category, new String[]{}, "Items to not be registered. This requires their mapping name. Usually the same as the class name. Can be found in F3+H mode."));
blockBlacklist = Arrays.asList(config.getStringList("blockBlacklist", category, new String[]{}, "Blocks to not be registered. This requires their mapping name. Usually the same as the class name. Can be found in F3+H mode."));
category = "Teleposer Blacklist";
config.addCustomCategoryComment(category, "Block blacklisting");
teleposerBlacklisting = config.getStringList("teleposerBlacklist", category, new String[] {"minecraft:bedrock"}, "Stops specified blocks from being teleposed. Put entries on new lines. Valid syntax is:\nmodid:blockname:meta");
buildTeleposerBlacklist();
category = "Potions";
config.addCustomCategoryComment(category, "Potion settings");
config.addCustomCategoryComment(category + ".id", "Potion ID settings");
customPotionDrowningID = config.getInt("customPotionDrowningID", category + ".id", 100, 20, ModPotions.getArraySize(), "ID of the Drowning potion");
customPotionBoostID = config.getInt("customPotionBoostID", category + ".id", 101, 20, ModPotions.getArraySize(), "ID of the Boost potion");
customPotionProjProtID = config.getInt("customPotionProjProtID", category + ".id", 102, 20, ModPotions.getArraySize(), "ID of the Projectile Protection potion");
customPotionInhibitID = config.getInt("customPotionInhibitID", category + ".id", 103, 20, ModPotions.getArraySize(), "ID of the Inhibit potion");
customPotionFlightID = config.getInt("customPotionFlightID", category + ".id", 104, 20, ModPotions.getArraySize(), "ID of the Flight potion");
customPotionReciprocationID = config.getInt("customPotionReciprocationID", category + ".id", 105, 20, ModPotions.getArraySize(), "ID of the Reciprocation potion");
customPotionFlameCloakID = config.getInt("customPotionFlameCloakID", category + ".id", 106, 20, ModPotions.getArraySize(), "ID of the Flame Cloak potion");
customPotionIceCloakID = config.getInt("customPotionIceCloakID", category + ".id", 107, 20, ModPotions.getArraySize(), "ID of the Ice Cloak potion");
customPotionHeavyHeartID = config.getInt("customPotionHeavyHeartID", category + ".id", 108, 20, ModPotions.getArraySize(), "ID of the Heavy Heart potion");
customPotionFireFuseID = config.getInt("customPotionFireFuseID", category + ".id", 109, 20, ModPotions.getArraySize(), "ID of the Fire Fuse potion");
customPotionPlanarBindingID = config.getInt("customPotionPlanarBindingID", category + ".id", 110, 20, ModPotions.getArraySize(), "ID of the Planar Binding potion");
customPotionSoulFrayID = config.getInt("customPotionSoulFrayID", category + ".id", 111, 20, ModPotions.getArraySize(), "ID of the Soul Fray potion");
customPotionSoulHardenID = config.getInt("customPotionSoulHardenID", category + ".id", 112, 20, ModPotions.getArraySize(), "ID of the Soul Harden potion");
customPotionDeafID = config.getInt("customPotionDeafID", category + ".id", 113, 20, ModPotions.getArraySize(), "ID of the Deaf potion");
customPotionFeatherFallID = config.getInt("customPotionFeatherFallID", category + ".id", 114, 20, ModPotions.getArraySize(), "ID of the Feather Fall potion");
customPotionDemonCloakID = config.getInt("customPotionDemonCloakID", category + ".id", 115, 20, ModPotions.getArraySize(), "ID of the Demon Cloak potion");
customPotionAmphibianID = config.getInt("customPotionAmphibianID", category + ".id", 116, 20, ModPotions.getArraySize(), "ID of the Amphibian potion");
config.addCustomCategoryComment(category + ".toggle", "Toggle potions available in Alchemy");
customPotionDrowningEnabled = config.getBoolean("customPotionDrowningEnabled", category + ".toggle", true, "Enables the Drowning potion in Alchemy");
customPotionBoostEnabled = config.getBoolean("customPotionBoostEnabled", category + ".toggle", true, "Enables the Boost potion in Alchemy");
customPotionProjProtEnabled = config.getBoolean("customPotionProjProtEnabled", category + ".toggle", true, "Enables the Projectile Protection potion in Alchemy");
customPotionInhibitEnabled = config.getBoolean("customPotionInhibitEnabled", category + ".toggle", true, "Enables the Inhibit potion in Alchemy");
customPotionFlightEnabled = config.getBoolean("customPotionFlightEnabled", category + ".toggle", true, "Enables the Flight potion in Alchemy");
customPotionReciprocationEnabled = config.getBoolean("customPotionReciprocationEnabled", category + ".toggle", true, "Enables the Reciprocation potion in Alchemy");
customPotionFlameCloakEnabled = config.getBoolean("customPotionFlameCloakEnabled", category + ".toggle", true, "Enables the Flame Cloak potion in Alchemy");
customPotionIceCloakEnabled = config.getBoolean("customPotionIceCloakEnabled", category + ".toggle", true, "Enables the Ice Cloak potion in Alchemy");
customPotionHeavyHeartEnabled = config.getBoolean("customPotionHeavyHeartEnabled", category + ".toggle", true, "Enables the Heavy Heart potion in Alchemy");
customPotionFireFuseEnabled = config.getBoolean("customPotionFireFuseEnabled", category + ".toggle", true, "Enables the Fire Fuse potion in Alchemy");
customPotionPlanarBindingEnabled = config.getBoolean("customPotionPlanarBindingEnabled", category + ".toggle", true, "Enables the Planar Binding potion in Alchemy");
customPotionSoulFrayEnabled = config.getBoolean("customPotionSoulFrayEnabled", category + ".toggle", true, "Enables the Soul Fray potion in Alchemy");
customPotionSoulHardenEnabled = config.getBoolean("customPotionSoulHardenEnabled", category + ".toggle", true, "Enables the Soul Harden potion in Alchemy");
customPotionDeafEnabled = config.getBoolean("customPotionDeafEnabled", category + ".toggle", true, "Enables the Deaf potion in Alchemy");
customPotionFeatherFallEnabled = config.getBoolean("customPotionFeatherFallEnabled", category + ".toggle", true, "Enables the Feather Fall potion in Alchemy");
customPotionDemonCloakEnabled = config.getBoolean("customPotionDemonCloakEnabled", category + ".toggle", true, "Enables the Demon Cloak potion in Alchemy");
customPotionAmphibianEnabled = config.getBoolean("customPotionAmphibianEnabled", category + ".toggle", true, "Enables the Amphibian potion in Alchemy");
vanillaPotionAbsorptionEnabled = config.getBoolean("vanillaPotionAbsorptionEnabled", category + ".toggle", true, "Enables the Absorption potion in Alchemy");
vanillaPotionBlindnessEnabled = config.getBoolean("vanillaPotionBlindnessEnabled", category + ".toggle", true, "Enables the Blindness potion in Alchemy");
vanillaPotionFireResistEnabled = config.getBoolean("vanillaPotionFireResistEnabled", category + ".toggle", true, "Enables the Fire Resistance potion in Alchemy");
vanillaPotionHealthBoostEnabled = config.getBoolean("vanillaPotionHealthBoostEnabled", category + ".toggle", true, "Enables the Health Boost potion in Alchemy");
vanillaPotionHealthEnabled = config.getBoolean("vanillaPotionHealthEnabled", category + ".toggle", true, "Enables the Instant Health potion in Alchemy");
vanillaPotionInvisibilityEnabled = config.getBoolean("vanillaPotionInvisibilityEnabled", category + ".toggle", true, "Enables the Invisibility potion in Alchemy");
vanillaPotionJumpBoostEnabled = config.getBoolean("vanillaPotionJumpBoostEnabled", category + ".toggle", true, "Enables the Jump Boost potion in Alchemy");
vanillaPotionMiningEnabled = config.getBoolean("vanillaPotionMiningEnabled", category + ".toggle", true, "Enables the Mining potion in Alchemy");
vanillaPotionPoisonEnabled = config.getBoolean("vanillaPotionPoisonEnabled", category + ".toggle", true, "Enables the Poison potion in Alchemy");
vanillaPotionRegenerationEnabled = config.getBoolean("vanillaPotionRegenerationEnabled", category + ".toggle", true, "Enables the Regeneration potion in Alchemy");
vanillaPotionNightVisionEnabled = config.getBoolean("vanillaPotionNightVisionEnabled", category + ".toggle", true, "Enables the Night Vision potion in Alchemy");
vanillaPotionResistanceEnabled = config.getBoolean("vanillaPotionResistanceEnabled", category + ".toggle", true, "Enables the Resistance potion in Alchemy");
vanillaPotionSaturationEnabled = config.getBoolean("vanillaPotionSaturationEnabled", category + ".toggle", true, "Enables the Saturation potion in Alchemy");
vanillaPotionSlownessEnabled = config.getBoolean("vanillaPotionSlownessEnabled", category + ".toggle", true, "Enables the Slowness potion in Alchemy");
vanillaPotionSpeedEnabled = config.getBoolean("vanillaPotionSpeedEnabled", category + ".toggle", true, "Enables the Speed potion in Alchemy");
vanillaPotionStrengthEnabled = config.getBoolean("vanillaPotionStrengthEnabled", category + ".toggle", true, "Enables the Strength potion in Alchemy");
vanillaPotionWaterBreathingEnabled = config.getBoolean("vanillaPotionWaterBreathingEnabled", category + ".toggle", true, "Enables the Water Breathing potion in Alchemy");
vanillaPotionWeaknessEnabled = config.getBoolean("vanillaPotionWeaknessEnabled", category + ".toggle", true, "Enables the Weakness potion in Alchemy");
category = "General";
config.addCustomCategoryComment(category, "General settings");
BloodMagicAPI.setLoggingEnabled(config.getBoolean("enableLogging", category, true, "Allows logging information to the console. Fatal errors will bypass this"));
config.save();
}
private static void buildTeleposerBlacklist() {
// Make sure it's empty before setting the blacklist.
// Otherwise, reloading the config while in-game will duplicate the list.
teleposerBlacklist.clear();
for (String blockSet : teleposerBlacklisting) {
String[] blockData = blockSet.split(":");
Block block = GameRegistry.findBlock(blockData[0], blockData[1]);
int meta = 0;
// If the block follows full syntax: modid:blockname:meta
if (blockData.length == 3) {
// Check if it's an int, if so, parse it. If not, set meta to 0 to avoid crashing.
if (Utils.isInteger(blockData[2]))
meta = Integer.parseInt(blockData[2]);
else if (blockData[2].equals("*"))
meta = OreDictionary.WILDCARD_VALUE;
else
meta = 0;
}
teleposerBlacklist.add(new BlockStack(block, meta));
}
}
}

View file

@ -0,0 +1,131 @@
package WayofTime.bloodmagic.altar;
import WayofTime.bloodmagic.api.BlockStack;
import WayofTime.bloodmagic.api.altar.AltarComponent;
import WayofTime.bloodmagic.api.altar.IAltarComponent;
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
import WayofTime.bloodmagic.api.altar.EnumAltarTier;
import net.minecraft.block.BlockBeacon;
import net.minecraft.block.BlockGlowstone;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
public class BloodAltar {
public static EnumAltarTier getAltarTier(World world, BlockPos pos) {
for (int i = EnumAltarTier.MAXTIERS; i >= 2; i--)
if (checkAltarIsValid(world, pos, i))
return EnumAltarTier.values()[i];
return EnumAltarTier.ONE;
}
public static boolean checkAltarIsValid(World world, BlockPos worldPos, int altarTier) {
for (AltarComponent altarComponent : EnumAltarTier.values()[altarTier].getAltarComponents()) {
BlockPos componentPos = worldPos.add(altarComponent.getOffset());
BlockStack worldBlock = new BlockStack(world.getBlockState(componentPos).getBlock(), world.getBlockState(componentPos).getBlock().getMetaFromState(world.getBlockState(componentPos)));
if (altarComponent.isBloodRune()) {
if (!checkRune(altarComponent, worldBlock))
return false;
} else {
if (((altarComponent.getBlockStack().getBlock() != worldBlock.getBlock()) || (altarComponent.getBlockStack().getMeta() != worldBlock.getMeta())) && (altarComponent.getBlockStack().getBlock() == Blocks.air && !world.isAirBlock(componentPos)))
if (!checkSpecials(altarComponent, worldBlock))
return false;
}
}
return true;
}
// public static AltarUpgrade getUpgrades(World world, BlockPos pos, int altarTier) {
// if(world.isRemote)
// return null;
//
// AltarUpgrade upgrades = new AltarUpgrade();
// List<AltarComponent> list = EnumAltarTier.values()[altarTier].getAltarComponents();
//
// for (AltarComponent altarComponent : list) {
// BlockPos componentPos = pos.add(altarComponent.getOffset());
//
// if (altarComponent.isUpgradeSlot()) {
// BlockStack worldBlock = new BlockStack(world.getBlockState(componentPos).getBlock(), world.getBlockState(componentPos).getBlock().getMetaFromState(world.getBlockState(componentPos)));
//
// if (worldBlock.getBlock() instanceof BlockBloodRune) {
// if (worldBlock.getBlock() instanceof IFadedRune && altarTier > ((IFadedRune)worldBlock.getBlock()).getAltarTierLimit(worldBlock.getMeta()))
// return getUpgrades(world, pos, ((IFadedRune) worldBlock.getBlock()).getAltarTierLimit(worldBlock.getMeta()));
//
// switch (((BlockBloodRune) worldBlock.getBlock()).getRuneEffect(worldBlock.getMeta())) {
// case 1:
// upgrades.addSpeed();
// break;
//
// case 2:
// upgrades.addEfficiencyUpgrade();
// break;
//
// case 3:
// upgrades.addSacrificeUpgrade();
// break;
//
// case 4:
// upgrades.addSelfSacrificeUpgrade();
// break;
//
// case 5:
// upgrades.addaltarCapacitiveUpgrade();
// break;
//
// case 6:
// upgrades.addDisplacementUpgrade();
// break;
//
// case 7:
// upgrades.addorbCapacitiveUpgrade();
// break;
//
// case 8:
// upgrades.addBetterCapacitiveUpgrade();
// break;
//
// case 9:
// upgrades.addAccelerationUpgrade();
// break;
// }
// }
// }
// }
//
// return upgrades;
// }
private static boolean checkRune(AltarComponent altarComponent, BlockStack blockStack) {
// if (altarComponent.getBlockStack().getBlock() == ModBlocks.rune)
// if (blockStack.getBlock() instanceof BlockBloodRune || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.BLOODRUNE)))
// return true;
return false;
}
private static boolean checkSpecials(AltarComponent altarComponent, BlockStack blockStack) {
// if (altarComponent.getBlockStack().getBlock() == ModBlocks.bloodStone)
// if (blockStack.getBlock() instanceof BlockBloodStone || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.BLOODSTONE)))
// return true;
// if (altarComponent.getBlockStack().getBlock() == ModBlocks.crystal)
// if (blockStack.getBlock() instanceof BlockCrystal || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.CRYSTAL)))
// return true;
if (altarComponent.getBlockStack().getBlock() == Blocks.glowstone)
if (blockStack.getBlock() instanceof BlockGlowstone || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.GLOWSTONE)))
return true;
if (altarComponent.getBlockStack().getBlock() == Blocks.beacon)
if (blockStack.getBlock() instanceof BlockBeacon || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.BEACON)))
return true;
return false;
}
}

View file

@ -0,0 +1,28 @@
package WayofTime.bloodmagic.api;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import net.minecraft.block.Block;
import net.minecraftforge.fml.common.registry.GameData;
@Getter
@EqualsAndHashCode
public class BlockStack {
private final Block block;
private final int meta;
public BlockStack(Block block, int meta) {
this.block = block;
this.meta = meta;
}
public BlockStack(Block block) {
this(block, 0);
}
@Override
public String toString() {
return GameData.getBlockRegistry().getNameForObject(block) + ":" + meta;
}
}

View file

@ -0,0 +1,26 @@
package WayofTime.bloodmagic.api;
import WayofTime.bloodmagic.api.util.helper.LogHelper;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.item.Item;
import net.minecraft.util.DamageSource;
import net.minecraftforge.fluids.Fluid;
public class BloodMagicAPI {
@Getter @Setter
private static boolean loggingEnabled;
@Getter
private static LogHelper logger = new LogHelper("BloodMagic|API");
@Getter
private static DamageSource damageSource = new DamageSourceBloodMagic();
@Getter @Setter
private static Item orbItem;
@Getter @Setter
private static Fluid lifeEssence;
}

View file

@ -0,0 +1,12 @@
package WayofTime.bloodmagic.api;
import net.minecraft.util.DamageSource;
public class DamageSourceBloodMagic extends DamageSource {
public DamageSourceBloodMagic() {
super("bloodMagic");
setDamageBypassesArmor();
}
}

View file

@ -0,0 +1,29 @@
package WayofTime.bloodmagic.api;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class NBTHolder {
public static final String NBT_OWNER = "ownerName";
public static final String NBT_USES = "uses";
public static final String NBT_UNUSABLE = "unusable";
public static final String NBT_SACRIFICE = "sacrifice";
public static final String NBT_DIMID = "dimensionId";
public static final String NBT_COORDX = "xCoord";
public static final String NBT_COORDY = "yCoord";
public static final String NBT_COORDZ = "zCoord";
public static final String NBT_MAXORB = "maxOrb";
public static final String NBT_CURRENTESSENCE = "currentEssence";
public static final String NBT_CURRENTRITUAL = "currentRitual";
public static final String NBT_RUNNING = "isRunning";
public static final String NBT_RUNTIME = "runtime";
public static final String NBT_REAGENTTANK = "reagentTanks";
public static ItemStack checkNBT(ItemStack stack) {
if (stack.getTagCompound() == null)
stack.setTagCompound(new NBTTagCompound());
return stack;
}
}

View file

@ -0,0 +1,64 @@
package WayofTime.bloodmagic.api.altar;
import WayofTime.bloodmagic.api.BlockStack;
import lombok.Getter;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
/**
* Used for building the altar structure.
*/
@Getter
public class AltarComponent {
private BlockPos offset;
private BlockStack blockStack;
private boolean bloodRune;
private boolean upgradeSlot;
/**
* @param offset - The position in the world relative to the MasterRitualStone
* @param blockStack - The block and meta combination expected
*/
public AltarComponent(BlockPos offset, BlockStack blockStack) {
this.offset = offset;
this.blockStack = blockStack;
}
/**
* Non-meta based variant for ease of use.
*/
public AltarComponent(BlockPos offset, Block block) {
this(offset, new BlockStack(block));
}
/**
* Use for setting a location at which there must be a block, but the type
* of block does not matter.
*/
public AltarComponent(BlockPos offset) {
this(offset, new BlockStack(Blocks.air));
}
/**
* Sets the location to a Blood Rune. This does not mean that the location
* can be used as an upgrade.
*
* @return the current instance for further use.
*/
public AltarComponent setBloodRune() {
this.bloodRune = true;
return this;
}
/**
* Sets the location to an upgrade slot.
*
* @return the current instance for further use.
*/
public AltarComponent setUpgradeSlot() {
this.upgradeSlot = true;
return this;
}
}

View file

@ -0,0 +1,44 @@
package WayofTime.bloodmagic.api.altar;
import lombok.Getter;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
@Getter
public class AltarRecipe {
public final int minTier, syphon, consumeRate, drainRate;
public final boolean useTag;
public final ItemStack input, output;
/**
* Allows creation of a recipe for the {@link WayofTime.bloodmagic.block.BlockAltar} / {@link WayofTime.bloodmagic.tile.TileAltar}.
* The output ItemStack is allowed to be null as some recipes do not contain an output. (Blood Orbs)
*
* @param input - The input ItemStack
* @param output - The ItemStack obtained from the recipe
* @param minTier - The minimum tier of Altar required
* @param syphon - The amount of LP to syphon from the Altar
* @param consumeRate - The rate at which LP is consumed during crafting
* @param drainRate - The rate at which LP is drained during crafting
* @param useTag -
*/
public AltarRecipe(ItemStack input, @Nullable ItemStack output, int minTier, int syphon, int consumeRate, int drainRate, boolean useTag) {
this.input = input;
this.output = output;
this.minTier = minTier;
this.syphon = syphon;
this.consumeRate = consumeRate;
this.drainRate = drainRate;
this.useTag = useTag;
}
public AltarRecipe(ItemStack input, ItemStack output, int minTier, int syphon, int consumeRate, int drainRate) {
this(input, output, minTier, syphon, consumeRate, drainRate, false);
}
public AltarRecipe (ItemStack input, int minTier, int consumeRate, int drainRate) {
this(input, null, minTier, 0, consumeRate, drainRate);
}
}

View file

@ -0,0 +1,20 @@
package WayofTime.bloodmagic.api.altar;
import lombok.Getter;
@Getter
public class AltarUpgrade {
private int speedCount;
public AltarUpgrade() {
}
// Adders
public AltarUpgrade addSpeed() {
speedCount++;
return this;
}
}

View file

@ -0,0 +1,10 @@
package WayofTime.bloodmagic.api.altar;
public enum EnumAltarComponent {
GLOWSTONE,
BLOODSTONE,
BEACON,
BLOODRUNE,
CRYSTAL
}

View file

@ -0,0 +1,135 @@
package WayofTime.bloodmagic.api.altar;
import WayofTime.bloodmagic.api.BlockStack;
import WayofTime.bloodmagic.registry.ModBlocks;
import lombok.Getter;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import java.util.ArrayList;
@Getter
public enum EnumAltarTier {
ONE(),
TWO() {
@Override
public void buildComponents() {
altarComponents.add(new AltarComponent(new BlockPos(-1, -1, -1), ModBlocks.rune).setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(0, -1, -1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(1, -1, -1), ModBlocks.rune).setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(-1, -1, 0), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(1, -1, 0), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(-1, -1, 1), ModBlocks.rune).setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(0, -1, 1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(1, -1, 1), ModBlocks.rune).setBloodRune());
}
},
THREE() {
@Override
public void buildComponents() {
altarComponents.addAll(TWO.getAltarComponents());
altarComponents.add(new AltarComponent(new BlockPos(-1, -1, -1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(0, -1, -1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(1, -1, -1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(-1, -1, 0), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(1, -1, 0), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(-1, -1, 1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(0, -1, 1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(1, -1, 1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(-3, -1, -3)));
altarComponents.add(new AltarComponent(new BlockPos(-3, 0, -3)));
altarComponents.add(new AltarComponent(new BlockPos(3, -1, -3)));
altarComponents.add(new AltarComponent(new BlockPos(3, 0, -3)));
altarComponents.add(new AltarComponent(new BlockPos(-3, -1, 3)));
altarComponents.add(new AltarComponent(new BlockPos(-3, 0, 3)));
altarComponents.add(new AltarComponent(new BlockPos(3, -1, 3)));
altarComponents.add(new AltarComponent(new BlockPos(3, 0, 3)));
altarComponents.add(new AltarComponent(new BlockPos(-3, 1, -3), Blocks.glowstone));
altarComponents.add(new AltarComponent(new BlockPos(3, 1, -3), Blocks.glowstone));
altarComponents.add(new AltarComponent(new BlockPos(-3, 1, 3), Blocks.glowstone));
altarComponents.add(new AltarComponent(new BlockPos(3, 1, 3), Blocks.glowstone));
for (int i = -2; i <= 2; i++) {
altarComponents.add(new AltarComponent(new BlockPos(3, -2, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(-3, -2, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(i, -2, 3), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(i, -2, -3), ModBlocks.rune).setUpgradeSlot().setBloodRune());
}
}
},
FOUR() {
@Override
public void buildComponents() {
altarComponents.addAll(THREE.getAltarComponents());
for (int i = -3; i <= 3; i++) {
altarComponents.add(new AltarComponent(new BlockPos(5, -3, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(-5, -3, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(i, -3, 5), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(i, -3, -5), ModBlocks.rune).setUpgradeSlot().setBloodRune());
}
for (int i = -2; i <= 1; i++) {
altarComponents.add(new AltarComponent(new BlockPos(5, i, 5)));
altarComponents.add(new AltarComponent(new BlockPos(5, i, -5)));
altarComponents.add(new AltarComponent(new BlockPos(-5, i, -5)));
altarComponents.add(new AltarComponent(new BlockPos(-5, i, 5)));
}
altarComponents.add(new AltarComponent(new BlockPos(5, 2, 5), new BlockStack(ModBlocks.bloodStone, 1)));
altarComponents.add(new AltarComponent(new BlockPos(5, 2, -5), new BlockStack(ModBlocks.bloodStone, 1)));
altarComponents.add(new AltarComponent(new BlockPos(-5, 2, -5), new BlockStack(ModBlocks.bloodStone, 1)));
altarComponents.add(new AltarComponent(new BlockPos(-5, 2, 5), new BlockStack(ModBlocks.bloodStone, 1)));
}
},
FIVE() {
@Override
public void buildComponents() {
altarComponents.addAll(FOUR.getAltarComponents());
altarComponents.add(new AltarComponent(new BlockPos(-8, -3, 8), Blocks.beacon));
altarComponents.add(new AltarComponent(new BlockPos(-8, -3, -8), Blocks.beacon));
altarComponents.add(new AltarComponent(new BlockPos(8, -3, -8), Blocks.beacon));
altarComponents.add(new AltarComponent(new BlockPos(8, -3, 8), Blocks.beacon));
for (int i = -6; i <= 6; i++) {
altarComponents.add(new AltarComponent(new BlockPos(8, -4, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(-8, -4, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(i, -4, 8), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(i, -4, -8), ModBlocks.rune).setUpgradeSlot().setBloodRune());
}
}
},
SIX() {
@Override
public void buildComponents() {
altarComponents.addAll(FIVE.getAltarComponents());
for(int i = -4; i <= 2; i++) {
altarComponents.add(new AltarComponent(new BlockPos(11, i, 11)));
altarComponents.add(new AltarComponent(new BlockPos(-11, i, -11)));
altarComponents.add(new AltarComponent(new BlockPos(11, i, -11)));
altarComponents.add(new AltarComponent(new BlockPos(-11, i, 11)));
}
altarComponents.add(new AltarComponent(new BlockPos(11, 3, 11), ModBlocks.crystal));
altarComponents.add(new AltarComponent(new BlockPos(-11, 3, -11), ModBlocks.crystal));
altarComponents.add(new AltarComponent(new BlockPos(11, 3, -11), ModBlocks.crystal));
altarComponents.add(new AltarComponent(new BlockPos(-11, 3, 11), ModBlocks.crystal));
for (int i = -9; i <= 9; i++) {
altarComponents.add(new AltarComponent(new BlockPos(11, -5, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(-11, -5, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(i, -5, 11), ModBlocks.rune).setUpgradeSlot().setBloodRune());
altarComponents.add(new AltarComponent(new BlockPos(i, -5, -11), ModBlocks.rune).setUpgradeSlot().setBloodRune());
}
}
};
public static final int MAXTIERS = values().length;
ArrayList<AltarComponent> altarComponents = new ArrayList<AltarComponent>();
public void buildComponents() {
}
}

View file

@ -0,0 +1,6 @@
package WayofTime.bloodmagic.api.altar;
public interface IAltarComponent {
EnumAltarComponent getType(int meta);
}

View file

@ -0,0 +1,40 @@
package WayofTime.bloodmagic.api.altar;
public interface IBloodAltar {
int getCapacity();
int getCurrentBlood();
int getTier();
int getProgress();
float getSacrificeMultiplier();
float getSelfSacrificeMultiplier();
float getOrbMultiplier();
float getDislocationMultiplier();
int getBufferCapacity();
void sacrificialDaggerCall(int amount, boolean b);
void startCycle();
/**
* Will set the altar to initiate a cooldown cycle after it crafts before starting to craft again, giving the user time to interact with the altar.
* This can only be set while the altar is not active.
*
* @param cooldown - How long the cooldown should last
*/
void requestPauseAfterCrafting(int cooldown);
void addToDemonBloodDuration(int dur);
boolean hasDemonBlood();
void decrementDemonBlood();
}

View file

@ -0,0 +1,24 @@
package WayofTime.bloodmagic.api.event;
import net.minecraftforge.fml.common.eventhandler.Event;
public class AddToNetworkEvent extends Event {
public String ownerNetwork;
public int addedAmount;
public int maximum;
/**
* This event is called whenever the network is added to. If cancelled, no LP will be drained from the source. If result is set to Result.DENY,
* the LP will still be drained but the soul network will not be added to.
*
* @param ownerNetwork Key used for the soul network
* @param addedAmount Amount added
* @param maximum Ceiling that the network can add to
*/
public AddToNetworkEvent(String ownerNetwork, int addedAmount, int maximum) {
this.ownerNetwork = ownerNetwork;
this.addedAmount = addedAmount;
this.maximum = maximum;
}
}

View file

@ -0,0 +1,21 @@
package WayofTime.bloodmagic.api.event;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
@Cancelable
public class ItemBindEvent extends Event {
public final EntityPlayer player;
public String key;
public ItemStack itemStack;
public ItemBindEvent(EntityPlayer player, String key, ItemStack itemStack) {
super();
this.player = player;
this.key = key;
this.itemStack = itemStack;
}
}

View file

@ -0,0 +1,86 @@
package WayofTime.bloodmagic.api.event;
import WayofTime.bloodmagic.api.ritual.IMasterRitualStone;
import WayofTime.bloodmagic.api.ritual.Ritual;
import WayofTime.bloodmagic.api.ritual.imperfect.IImperfectRitualStone;
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
public class RitualEvent extends Event {
public final IMasterRitualStone mrs;
public final String ownerName;
public final Ritual ritual;
private RitualEvent(IMasterRitualStone mrs, String ownerName, Ritual ritual) {
this.mrs = mrs;
this.ownerName = ownerName;
this.ritual = ritual;
}
/**
* This event is called when a ritual is activated. If cancelled, it will not activate.
*
* {@link WayofTime.bloodmagic.api.util.helper.RitualHelper#activate(IMasterRitualStone, Ritual, EntityPlayer)}
*/
@Cancelable
public static class RitualActivatedEvent extends RitualEvent {
public final EntityPlayer player;
public final ItemStack crystalStack;
public int crystalTier;
public RitualActivatedEvent(IMasterRitualStone mrs, String owner, Ritual ritual, EntityPlayer player, ItemStack activationCrystal, int crystalTier) {
super(mrs, owner, ritual);
this.player = player;
this.crystalStack = activationCrystal;
this.crystalTier = crystalTier;
}
}
/**
* This event is called when a Ritual effect is performed. If cancelled, the effect will not happen.
*
* {@link WayofTime.bloodmagic.api.util.helper.RitualHelper#perform(IMasterRitualStone, Ritual)}
*/
@Cancelable
public static class RitualRunEvent extends RitualEvent {
public RitualRunEvent(IMasterRitualStone mrs, String owner, Ritual ritual) {
super(mrs, owner, ritual);
}
}
/**
* This event is called when a Ritual is stopped by a {@link Ritual.BreakType}.
*
* {@link WayofTime.bloodmagic.api.util.helper.RitualHelper#stop(IMasterRitualStone, Ritual, Ritual.BreakType)}
*/
public static class RitualStopEvent extends RitualEvent {
public final Ritual.BreakType method;
public RitualStopEvent(IMasterRitualStone mrs, String owner, Ritual ritual, Ritual.BreakType method) {
super(mrs, owner, ritual);
this.method = method;
}
}
@Cancelable
public static class ImperfectRitualActivatedEvent extends Event {
public final IImperfectRitualStone ims;
public final String ownerName;
public final ImperfectRitual imperfectRitual;
public ImperfectRitualActivatedEvent(IImperfectRitualStone ims, String ownerName, ImperfectRitual imperfectRitual) {
this.ims = ims;
this.ownerName = ownerName;
this.imperfectRitual = imperfectRitual;
}
}
}

View file

@ -0,0 +1,62 @@
package WayofTime.bloodmagic.api.event;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
public class SoulNetworkEvent extends Event {
public String ownerName;
public int syphon;
public SoulNetworkEvent(String ownerName, int syphon) {
this.ownerName = ownerName;
this.syphon = syphon;
}
@Cancelable
public static class ItemDrainInContainerEvent extends SoulNetworkEvent {
public ItemStack stack;
public ItemDrainInContainerEvent(ItemStack stack, String ownerName, int syphon) {
super(ownerName, syphon);
this.stack = stack;
}
}
@Cancelable
public static class PlayerDrainNetworkEvent extends SoulNetworkEvent {
public final EntityPlayer player;
public boolean shouldDamage; //If true, will damage regardless of if the network had enough inside it
public PlayerDrainNetworkEvent(EntityPlayer player, String ownerNetwork, int drainAmount) {
super(ownerNetwork, drainAmount);
this.shouldDamage = false;
this.player = player;
}
}
@Cancelable
public static class ItemDrainNetworkEvent extends PlayerDrainNetworkEvent {
public final ItemStack itemStack;
public float damageAmount; //Amount of damage that would incur if the network could not drain properly
/**
* Set result to deny the action i.e. damage/drain anyways. Cancelling event prevents action without penalties
*
* @param player Player using the item
* @param ownerNetwork Network that the item is tied to
* @param itemStack Item used
* @param drainAmount Original drain amount - change to alter cost
*/
public ItemDrainNetworkEvent(EntityPlayer player, String ownerNetwork, ItemStack itemStack, int drainAmount) {
super(player, ownerNetwork, drainAmount);
this.itemStack = itemStack;
this.damageAmount = (float)(drainAmount) / 100.0f;
}
}
}

View file

@ -0,0 +1,17 @@
package WayofTime.bloodmagic.api.iface;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
/**
* Implement this interface on any Item that can be bound to a player.
*/
public interface IBindable {
/**
* Called when the player attempts to bind the item.
*
* If false, binding fails.
*/
boolean onBind(EntityPlayer player, ItemStack stack);
}

View file

@ -0,0 +1,4 @@
package WayofTime.bloodmagic.api.iface;
public interface ISigil {
}

View file

@ -0,0 +1,88 @@
package WayofTime.bloodmagic.api.network;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.NBTHolder;
import WayofTime.bloodmagic.api.event.SoulNetworkEvent;
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.WorldSavedData;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Event;
@Getter
@Setter
public class SoulNetwork extends WorldSavedData {
private int currentEssence;
private int maxOrb;
private final EntityPlayer player;
public SoulNetwork(String name) {
super(name);
currentEssence = 0;
maxOrb = 0;
player = PlayerHelper.getPlayerFromUsername(name);
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
currentEssence = nbttagcompound.getInteger(NBTHolder.NBT_CURRENTESSENCE);
maxOrb = nbttagcompound.getInteger(NBTHolder.NBT_MAXORB);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger(NBTHolder.NBT_CURRENTESSENCE, currentEssence);
nbttagcompound.setInteger(NBTHolder.NBT_MAXORB, maxOrb);
}
public int syphon(int syphon) {
if (getCurrentEssence() >= syphon) {
setCurrentEssence(getCurrentEssence() - syphon);
markDirty();
return syphon;
}
return 0;
}
public boolean syphonAndDamage(int syphon) {
SoulNetworkEvent.PlayerDrainNetworkEvent event = new SoulNetworkEvent.PlayerDrainNetworkEvent(getPlayer(), mapName, syphon);
if (MinecraftForge.EVENT_BUS.post(event))
return false;
int drain = syphon(event.syphon);
if (drain == 0 || event.shouldDamage)
hurtPlayer(event.syphon);
return event.getResult() != Event.Result.DENY;
}
public void hurtPlayer(int syphon) {
if (syphon < 100 && syphon > 0) {
if (!player.capabilities.isCreativeMode) {
player.setHealth((player.getHealth() - 1));
if (player.getHealth() <= 0.0005f)
player.onDeath(BloodMagicAPI.getDamageSource());
}
} else if (syphon >= 100) {
if (!player.capabilities.isCreativeMode) {
for (int i = 0; i < ((syphon + 99) / 100); i++) {
player.setHealth((player.getHealth() - 1));
if (player.getHealth() <= 0.0005f) {
player.onDeath(BloodMagicAPI.getDamageSource());
break;
}
}
}
}
}
}

View file

@ -0,0 +1,69 @@
package WayofTime.bloodmagic.api.orb;
import WayofTime.bloodmagic.api.registry.OrbRegistry;
/**
* Base object for all Blood Orbs. Makes Orb creation quite a bit easier.
*
* Just create a new BloodOrb instance then register it with {@link OrbRegistry#registerOrb(BloodOrb)}
* This will allow the use of just one item ID for all orbs. If an addon dev needs more control over the intricacies
* of their orb (custom right clicking, renderers, etc), they can just create their own item as normal.
*
*/
public class BloodOrb {
private String name;
private int tier;
private int capacity;
private String owner = "BloodMagic";
/**
* A base object for BloodOrbs. A bit cleaner than the
* old way through EnergyItems.
*
* @param name - A name for the Orb. Gets put into an unlocalized name.
* @param tier - The tier of the Orb.
* @param capacity - The max amount of LP the Orb can store.
*/
public BloodOrb(String name, int tier, int capacity) {
this.name = name;
this.tier = tier;
this.capacity = capacity;
}
public String getName() {
return name;
}
public int getTier() {
return tier;
}
public int getCapacity() {
return capacity;
}
public String getOwner() {
return owner;
}
/**
* For setting the MODID of the mod that creates the Orb. Not required, but preferred.
*
* @return - The BloodOrb object for further use.
*/
public BloodOrb setOwner(String owner) {
this.owner = owner;
return this;
}
@Override
public String toString() {
return "BloodOrb{" +
"name='" + name + '\'' +
", tier=" + tier +
", capacity=" + capacity +
", owner=" + owner +
'}';
}
}

View file

@ -0,0 +1,10 @@
package WayofTime.bloodmagic.api.orb;
public interface IBloodOrb {
BloodOrb getOrb(int meta);
int getMaxEssence(int meta);
int getOrbLevel(int meta);
}

View file

@ -0,0 +1,4 @@
@API(owner = "BloodMagic", provides = "BloodMagic|API", apiVersion = "@VERSION@")
package WayofTime.bloodmagic.api;
import net.minecraftforge.fml.common.API;

View file

@ -0,0 +1,25 @@
package WayofTime.bloodmagic.api.registry;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.altar.AltarRecipe;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import lombok.Getter;
import net.minecraft.item.ItemStack;
public class AltarRecipeRegistry {
@Getter
private static BiMap<ItemStack, AltarRecipe> recipes = HashBiMap.create();
public static void registerRecipe(AltarRecipe recipe) {
if (!recipes.containsValue(recipe))
recipes.put(recipe.input, recipe);
else
BloodMagicAPI.getLogger().error("Error adding recipe for " + recipe.input.getDisplayName() + (recipe.output == null ? "" : " -> " + recipe.output.getDisplayName()) + ". Recipe already exists.");
}
public static AltarRecipe getRecipeForInput(ItemStack input) {
return recipes.get(input);
}
}

View file

@ -0,0 +1,61 @@
package WayofTime.bloodmagic.api.registry;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import java.util.ArrayList;
public class ImperfectRitualRegistry {
public static final BiMap<ImperfectRitual, Boolean> enabledRituals = HashBiMap.create();
private static final BiMap<String, ImperfectRitual> registry = HashBiMap.create();
/**
* The safe way to register a new Ritual.
*
* @param imperfectRitual - The imperfect ritual to register.
* @param id - The ID for the imperfect ritual. Cannot be duplicated.
*/
public static void registerRitual(ImperfectRitual imperfectRitual, String id) {
if (imperfectRitual != null) {
if (registry.containsKey(id))
BloodMagicAPI.getLogger().error("Duplicate imperfect ritual id: " + id);
else
registry.put(id, imperfectRitual);
}
}
public static ImperfectRitual getRitualForId(String id) {
return registry.get(id);
}
public static String getIdForRitual(ImperfectRitual imperfectRitual) {
return registry.inverse().get(imperfectRitual);
}
public static boolean isMapEmpty() {
return registry.isEmpty();
}
public static int getMapSize() {
return registry.size();
}
public static boolean ritualEnabled(ImperfectRitual imperfectRitual) {
return enabledRituals.get(imperfectRitual);
}
public static BiMap<String, ImperfectRitual> getRegistry() {
return HashBiMap.create(registry);
}
public static ArrayList<String> getIds() {
return new ArrayList<String>(registry.keySet());
}
public static ArrayList<ImperfectRitual> getRituals() {
return new ArrayList<ImperfectRitual>(registry.values());
}
}

View file

@ -0,0 +1,59 @@
package WayofTime.bloodmagic.api.registry;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.orb.BloodOrb;
import lombok.Getter;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.List;
/**
* This is only for those who wish to add a basic {@link BloodOrb}. If you need custom handling,
* you will need your own item class.
*/
public class OrbRegistry {
@Getter
private static List<BloodOrb> orbs = new ArrayList<BloodOrb>();
public static void registerOrb(BloodOrb orb) {
if (!orbs.contains(orb))
orbs.add(orb);
else
BloodMagicAPI.getLogger().error("Error adding orb: " + orb.toString() + ". Orb already exists!");
}
@SideOnly(Side.CLIENT)
public static void registerOrbTexture(BloodOrb orb, String resourceLocation) {
int meta = getIndexOf(orb);
ModelBakery.addVariantName(BloodMagicAPI.getOrbItem(), resourceLocation);
ModelLoader.setCustomModelResourceLocation(BloodMagicAPI.getOrbItem(), meta, new ModelResourceLocation(resourceLocation, "inventory"));
}
public static BloodOrb getOrb(int index) {
return orbs.get(index);
}
public static int getIndexOf(BloodOrb orb) {
return orbs.indexOf(orb);
}
public static boolean isEmpty() {
return orbs.isEmpty();
}
public static int getSize() {
return orbs.size();
}
public static ItemStack getOrbStack(BloodOrb orb) {
return new ItemStack(BloodMagicAPI.getOrbItem(), 1, getIndexOf(orb));
}
}

View file

@ -0,0 +1,60 @@
package WayofTime.bloodmagic.api.registry;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.ritual.Ritual;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import java.util.ArrayList;
public class RitualRegistry {
public static final BiMap<Ritual, Boolean> enabledRituals = HashBiMap.create();
private static final BiMap<String, Ritual> registry = HashBiMap.create();
/**
* The safe way to register a new Ritual.
*
* @param ritual - The ritual to register.
* @param id - The ID for the ritual. Cannot be duplicated.
*/
public static void registerRitual(Ritual ritual, String id) {
if (ritual != null) {
if (registry.containsKey(id))
BloodMagicAPI.getLogger().error("Duplicate ritual id: " + id);
else
registry.put(id, ritual);
}
}
public static Ritual getRitualForId(String id) {
return registry.get(id);
}
public static String getIdForRitual(Ritual ritual) {
return registry.inverse().get(ritual);
}
public static boolean isMapEmpty() {
return registry.isEmpty();
}
public static int getMapSize() {
return registry.size();
}
public static boolean ritualEnabled(Ritual ritual) {
return enabledRituals.get(ritual);
}
public static BiMap<String, Ritual> getRegistry() {
return HashBiMap.create(registry);
}
public static ArrayList<String> getIds() {
return new ArrayList<String>(registry.keySet());
}
public static ArrayList<Ritual> getRituals() {
return new ArrayList<Ritual>(registry.values());
}
}

View file

@ -0,0 +1,33 @@
package WayofTime.bloodmagic.api.ritual;
import net.minecraft.util.IStringSerializable;
import java.util.Locale;
public enum EnumRuneType implements IStringSerializable {
BLANK,
WATER,
FIRE,
EARTH,
AIR,
DUSK,
DAWN;
@Override
public String toString() {
return name().toLowerCase(Locale.ENGLISH);
}
@Override
public String getName() {
return this.toString();
}
public static EnumRuneType byMetadata(int meta) {
if (meta < 0 || meta >= values().length)
meta = 0;
return values()[meta];
}
}

View file

@ -0,0 +1,32 @@
package WayofTime.bloodmagic.api.ritual;
import WayofTime.bloodmagic.api.ritual.imperfect.IImperfectRitualStone;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
public interface IMasterRitualStone extends IImperfectRitualStone {
void performRitual(World world, BlockPos pos, Ritual ritual);
void setCooldown(int cooldown);
int getCooldown();
void setActive(boolean active);
EnumFacing getDirection();
NBTTagCompound getCustomRitualTag();
void setCustomRitualTag(NBTTagCompound tag);
boolean areTanksEmpty();
int getRunningTime();
LocalRitualStorage getLocalStorage();
void setLocalStorage(LocalRitualStorage storage);
}

View file

@ -0,0 +1,13 @@
package WayofTime.bloodmagic.api.ritual;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
public interface IRitualStone {
boolean isRuneType(World world, BlockPos pos, int meta, EnumRuneType runeType);
interface Tile {
boolean isRuneType(EnumRuneType runeType);
}
}

View file

@ -0,0 +1,28 @@
package WayofTime.bloodmagic.api.ritual;
import WayofTime.bloodmagic.api.NBTHolder;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockPos;
/**
* This class is used to pass ritual-specific data into the RitualEffect from the containing Master Ritual Stone. This is basically used as auxiliary storage,
* for when simply storing to NBT becomes... difficult.
*/
@Getter
@Setter
public class LocalRitualStorage {
private BlockPos pos;
public void writeToNBT(NBTTagCompound tagCompound) {
tagCompound.setInteger(NBTHolder.NBT_COORDX, pos.getX());
tagCompound.setInteger(NBTHolder.NBT_COORDY, pos.getY());
tagCompound.setInteger(NBTHolder.NBT_COORDZ, pos.getZ());
}
public void readFromNBT(NBTTagCompound tagCompound) {
this.pos = new BlockPos(tagCompound.getInteger(NBTHolder.NBT_COORDX), tagCompound.getInteger(NBTHolder.NBT_COORDY), tagCompound.getInteger(NBTHolder.NBT_COORDZ));
}
}

View file

@ -0,0 +1,72 @@
package WayofTime.bloodmagic.api.ritual;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.BlockPos;
import java.util.ArrayList;
@Getter
@RequiredArgsConstructor
public abstract class Ritual {
private final String name;
private final int crystalLevel;
private final int activationCost;
private final RitualRenderer renderer;
public final ArrayList<RitualComponent> ritualComponents = new ArrayList<RitualComponent>();
public Ritual(String name, int crystalLevel, int activationCost) {
this(name, crystalLevel, activationCost, null);
}
public abstract boolean startRitual(IMasterRitualStone masterRitualStone, EntityPlayer player);
public abstract void performEffect(IMasterRitualStone masterRitualStone);
public abstract void onRitualBroken(IMasterRitualStone masterRitualStone, Ritual.BreakType breakType);
public abstract int getRefreshCost();
public abstract ArrayList<RitualComponent> getComponents();
public LocalRitualStorage getNewLocalStorage() {
return new LocalRitualStorage();
}
public void addOffsetRunes(ArrayList<RitualComponent> components, int offset1, int offset2, int y, EnumRuneType rune) {
components.add(new RitualComponent(new BlockPos(offset1, y, offset2), rune));
components.add(new RitualComponent(new BlockPos(offset2, y, offset1), rune));
components.add(new RitualComponent(new BlockPos(offset1, y, -offset2), rune));
components.add(new RitualComponent(new BlockPos(-offset2, y, offset1), rune));
components.add(new RitualComponent(new BlockPos(-offset1, y, offset2), rune));
components.add(new RitualComponent(new BlockPos(offset2, y, -offset1), rune));
components.add(new RitualComponent(new BlockPos(-offset1, y, -offset2), rune));
components.add(new RitualComponent(new BlockPos(-offset2, y, -offset1), rune));
}
public void addCornerRunes(ArrayList<RitualComponent> components, int offset, int y, EnumRuneType rune) {
components.add(new RitualComponent(new BlockPos(offset, y, offset), rune));
components.add(new RitualComponent(new BlockPos(offset, y, -offset), rune));
components.add(new RitualComponent(new BlockPos(-offset, y, -offset), rune));
components.add(new RitualComponent(new BlockPos(-offset, y, offset), rune));
}
public void addParallelRunes(ArrayList<RitualComponent> components, int offset, int y, EnumRuneType rune) {
components.add(new RitualComponent(new BlockPos(offset, y, 0), rune));
components.add(new RitualComponent(new BlockPos(-offset, y, 0), rune));
components.add(new RitualComponent(new BlockPos(0, y, -offset), rune));
components.add(new RitualComponent(new BlockPos(0, y, offset), rune));
}
public enum BreakType {
REDSTONE,
BREAK_MRS,
BREAK_STONE,
ACTIVATE,
DEACTIVATE,
EXPLOSION,
}
}

View file

@ -0,0 +1,40 @@
package WayofTime.bloodmagic.api.ritual;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
@Getter
@RequiredArgsConstructor
public class RitualComponent {
private final BlockPos offset;
private final EnumRuneType runeType;
public int getX(EnumFacing direction) {
switch (direction) {
case EAST:
return -this.getOffset().getZ();
case SOUTH:
return -this.getOffset().getX();
case WEST:
return this.getOffset().getZ();
default:
return this.getOffset().getX();
}
}
public int getZ(EnumFacing direction) {
switch (direction) {
case EAST:
return this.getOffset().getX();
case SOUTH:
return -this.getOffset().getZ();
case WEST:
return -this.getOffset().getX();
default:
return this.getOffset().getZ();
}
}
}

View file

@ -0,0 +1,13 @@
package WayofTime.bloodmagic.api.ritual;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
public abstract class RitualRenderer {
public abstract void renderAt(IMasterRitualStone masterRitualStone, double x, double y, double z);
protected void bindTexture(ResourceLocation resourceLocation) {
Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation);
}
}

View file

@ -0,0 +1,13 @@
package WayofTime.bloodmagic.api.ritual.imperfect;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
public interface IImperfectRitualStone {
String getOwner();
World getWorld();
BlockPos getPos();
}

View file

@ -0,0 +1,19 @@
package WayofTime.bloodmagic.api.ritual.imperfect;
import WayofTime.bloodmagic.api.BlockStack;
import lombok.RequiredArgsConstructor;
import net.minecraft.entity.player.EntityPlayer;
@RequiredArgsConstructor
public abstract class ImperfectRitual {
private final BlockStack requiredBlock;
private final int activationCost;
private final boolean lightshow;
public ImperfectRitual(BlockStack requiredBlock, int activationCost) {
this(requiredBlock, activationCost, false);
}
public abstract boolean onActivate(IImperfectRitualStone imperfectRitualStone, EntityPlayer player);
}

View file

@ -0,0 +1,76 @@
package WayofTime.bloodmagic.api.util.helper;
import WayofTime.bloodmagic.api.NBTHolder;
import WayofTime.bloodmagic.api.event.ItemBindEvent;
import WayofTime.bloodmagic.api.iface.IBindable;
import com.google.common.base.Strings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
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
* @return - Whether binding was successful
*/
public static boolean checkAndSetItemOwner(ItemStack stack, EntityPlayer player) {
return !PlayerHelper.isFakePlayer(player) && checkAndSetItemOwner(stack, player.getGameProfile().getName());
}
/**
* Bind an item to a username.
*
* Requires the Item contained in the ItemStack to be an instanceof {@link IBindable}
*
* 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);
if (!(stack.getItem() instanceof IBindable))
return false;
if (Strings.isNullOrEmpty(stack.getTagCompound().getString(NBTHolder.NBT_OWNER))) {
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);
return true;
}
return false;
}
/**
* 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) {
stack = NBTHolder.checkNBT(stack);
stack.getTagCompound().setString(NBTHolder.NBT_OWNER, 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);
return stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
}
}

View file

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

View file

@ -0,0 +1,232 @@
package WayofTime.bloodmagic.api.util.helper;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.NBTHolder;
import WayofTime.bloodmagic.api.event.AddToNetworkEvent;
import WayofTime.bloodmagic.api.event.SoulNetworkEvent;
import WayofTime.bloodmagic.api.network.SoulNetwork;
import com.google.common.base.Strings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Event;
public class NetworkHelper {
// Get
public static SoulNetwork getSoulNetwork(String ownerName, World world) {
SoulNetwork network = (SoulNetwork) world.getMapStorage().loadData(SoulNetwork.class, ownerName);
if (network == null) {
network = new SoulNetwork(ownerName);
world.getMapStorage().setData(ownerName, network);
}
return network;
}
// Syphon
/**
* 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
* @return True if the action should be executed and false if it should not. Always returns false if client-sided.
*/
public static boolean syphonAndDamageFromNetwork(ItemStack stack, EntityPlayer player, int syphon) {
if (player.worldObj.isRemote)
return false;
stack = NBTHolder.checkNBT(stack);
String ownerName = stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
if (!Strings.isNullOrEmpty(ownerName)) {
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(player, ownerName, stack, syphon);
if(MinecraftForge.EVENT_BUS.post(event))
return false;
int drainAmount = syphonFromNetwork(event.ownerName, event.syphon);
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.
return event.getResult() != Event.Result.DENY;
}
int amount = NetworkHelper.syphonFromNetwork(stack, syphon);
hurtPlayer(player, syphon - amount);
return true;
}
public static boolean syphonFromNetworkWhileInContainer(ItemStack stack, int syphon) {
stack = NBTHolder.checkNBT(stack);
String ownerName = stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
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)
return false;
return syphonFromNetwork(event.ownerName, event.syphon) >= syphon;
}
public static int syphonFromNetwork(ItemStack stack, int syphon) {
stack = NBTHolder.checkNBT(stack);
String ownerName = stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
if (!Strings.isNullOrEmpty(ownerName))
return syphonFromNetwork(ownerName, syphon);
return 0;
}
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) {
network = new SoulNetwork(ownerName);
world.setItemData(ownerName, network);
}
if (network.getCurrentEssence() >= syphon) {
network.setCurrentEssence(network.getCurrentEssence() - syphon);
network.markDirty();
return syphon;
}
return 0;
}
// Add
/**
* A method to add to an owner's network up to a maximum value.
*
* @return amount added to the network
*/
public static int addCurrentEssenceToMaximum(String ownerName, int addedEssence, int maximum) {
AddToNetworkEvent event = new AddToNetworkEvent(ownerName, addedEssence, maximum);
if(MinecraftForge.EVENT_BUS.post(event))
return 0;
if (MinecraftServer.getServer() == null)
return 0;
World world = MinecraftServer.getServer().worldServers[0];
SoulNetwork data = (SoulNetwork) world.loadItemData(SoulNetwork.class, event.ownerNetwork);
if (data == null) {
data = new SoulNetwork(event.ownerNetwork);
world.setItemData(event.ownerNetwork, data);
}
int currEss = data.getCurrentEssence();
if (currEss >= event.maximum)
return 0;
int newEss = Math.min(event.maximum, currEss + event.addedAmount);
if(event.getResult() != Event.Result.DENY)
data.setCurrentEssence(newEss);
return newEss - currEss;
}
// Get
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) {
network = new SoulNetwork(ownerName);
world.setItemData(ownerName, network);
}
return network.getCurrentEssence();
}
// Do damage
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++) {
user.setHealth((user.getHealth() - 1));
if (user.getHealth() <= 0.0005f) {
user.onDeath(BloodMagicAPI.getDamageSource());
break;
}
}
}
}
}
public static void hurtPlayer(EntityPlayer user, float damage) {
if (!user.capabilities.isCreativeMode) {
user.setHealth((user.getHealth() - damage));
if (user.getHealth() <= 0.0005f)
user.onDeath(BloodMagicAPI.getDamageSource());
}
}
public static void setMaxOrbToMax(String ownerName, int maxOrb) {
if (MinecraftServer.getServer() == null)
return;
World world = MinecraftServer.getServer().worldServers[0];
SoulNetwork network = (SoulNetwork) world.loadItemData(SoulNetwork.class, ownerName);
if (network == null) {
network = new SoulNetwork(ownerName);
world.setItemData(ownerName, network);
}
network.setMaxOrb(Math.max(maxOrb, network.getMaxOrb()));
network.markDirty();
}
public static int getCurrentMaxOrb(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) {
network = new SoulNetwork(ownerName);
world.setItemData(ownerName, network);
}
return network.getMaxOrb();
}
}

View file

@ -0,0 +1,53 @@
package WayofTime.bloodmagic.api.util.helper;
import WayofTime.bloodmagic.api.NBTHolder;
import com.google.common.base.Strings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.util.FakePlayer;
import java.util.UUID;
import java.util.regex.Pattern;
public class PlayerHelper {
private static final Pattern FAKE_PLAYER_PATTERN = Pattern.compile("^(?:\\[.*\\])|(?:ComputerCraft)$");
public static String getUsernameFromPlayer(EntityPlayer player) {
return player.getGameProfile().getName();
}
public static EntityPlayer getPlayerFromUsername(String username) {
if (MinecraftServer.getServer() == null)
return null;
return MinecraftServer.getServer().getConfigurationManager().getPlayerByUsername(username);
}
public static UUID getUUIDFromPlayer(EntityPlayer player) {
return player.getGameProfile().getId();
}
public static boolean isFakePlayer(EntityPlayer player) {
return player instanceof FakePlayer || FAKE_PLAYER_PATTERN.matcher(getUsernameFromPlayer(player)).matches();
}
public static void causeNauseaToPlayer(ItemStack stack) {
stack = NBTHolder.checkNBT(stack);
if (!Strings.isNullOrEmpty(stack.getTagCompound().getString(NBTHolder.NBT_OWNER)))
causeNauseaToPlayer(stack.getTagCompound().getString(NBTHolder.NBT_OWNER));
}
public static void causeNauseaToPlayer(String ownerName) {
EntityPlayer player = getPlayerFromUsername(ownerName);
if (player == null)
return;
player.addPotionEffect(new PotionEffect(Potion.confusion.id, 80));
}
}

View file

@ -0,0 +1,131 @@
package WayofTime.bloodmagic.api.util.helper;
import WayofTime.bloodmagic.api.event.RitualEvent;
import WayofTime.bloodmagic.api.registry.RitualRegistry;
import WayofTime.bloodmagic.api.ritual.IMasterRitualStone;
import WayofTime.bloodmagic.api.ritual.Ritual;
import WayofTime.bloodmagic.api.ritual.imperfect.IImperfectRitualStone;
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.eventhandler.Event;
import sun.misc.Launcher;
import java.io.File;
import java.net.URL;
public class RitualHelper {
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);
}
public static boolean activate(IMasterRitualStone masterRitualStone, Ritual ritual, EntityPlayer player) {
String owner = masterRitualStone.getOwner();
RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(masterRitualStone, owner, ritual, player, player.getHeldItem(), player.getHeldItem().getItemDamage());
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
return false;
return RitualRegistry.ritualEnabled(ritual) && ritual.startRitual(masterRitualStone, player);
}
public static void perform(IMasterRitualStone masterRitualStone, Ritual ritual) {
String owner = masterRitualStone.getOwner();
RitualEvent.RitualRunEvent event = new RitualEvent.RitualRunEvent(masterRitualStone, owner, ritual);
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
return;
if (RitualRegistry.ritualEnabled(ritual))
ritual.performEffect(masterRitualStone);
}
public static void stop(IMasterRitualStone masterRitualStone, Ritual ritual, Ritual.BreakType breakType) {
String owner = masterRitualStone.getOwner();
RitualEvent.RitualStopEvent event = new RitualEvent.RitualStopEvent(masterRitualStone, owner, ritual, breakType);
MinecraftForge.EVENT_BUS.post(event);
ritual.onRitualBroken(masterRitualStone, breakType);
}
/**
* 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}.
*
* 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.
*/
public static void checkRituals(Configuration config, String packageName, String category) {
String name = packageName;
if (!name.startsWith("/"))
name = "/" + name;
name = name.replace('.', '/');
URL url = Launcher.class.getResource(name);
File directory = new File(url.getFile());
if (directory.exists()) {
String[] files = directory.list();
for (String file : files) {
if (file.endsWith(".class")) {
String className = file.substring(0, file.length() - 6);
try {
Object o = Class.forName(packageName + "." + className).newInstance();
if (o instanceof Ritual)
RitualRegistry.enabledRituals.put((Ritual) o, config.get(category, className, true).getBoolean());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
}
public static class Imperfect {
public static boolean activate(IImperfectRitualStone imperfectRitualStone, ImperfectRitual imperfectRitual, EntityPlayer player) {
String owner = imperfectRitualStone.getOwner();
RitualEvent.ImperfectRitualActivatedEvent event = new RitualEvent.ImperfectRitualActivatedEvent(imperfectRitualStone, owner, imperfectRitual);
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
return false;
return imperfectRitual.onActivate(imperfectRitualStone, player);
}
}
}

View file

@ -0,0 +1,23 @@
package WayofTime.bloodmagic.block;
import WayofTime.bloodmagic.BloodMagic;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class BlockAltar extends BlockContainer {
public BlockAltar() {
super(Material.rock);
setUnlocalizedName(BloodMagic.MODID + ".altar");
setCreativeTab(BloodMagic.tabBloodMagic);
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
// return new TileAltar();
return null;
}
}

View file

@ -0,0 +1,61 @@
package WayofTime.bloodmagic.block;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import lombok.Getter;
import net.minecraft.block.material.Material;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import java.awt.*;
public class BlockLifeEssence extends BlockFluidClassic {
@Getter
private static Fluid lifeEssence = new FluidLifeEssence();
public BlockLifeEssence() {
super(lifeEssence, Material.water);
setUnlocalizedName(BloodMagic.MODID + ".fluid.lifeEssence");
lifeEssence.setBlock(this);
BloodMagicAPI.setLifeEssence(lifeEssence);
}
@Override
public boolean canDisplace(IBlockAccess world, BlockPos blockPos) {
return !world.getBlockState(blockPos).getBlock().getMaterial().isLiquid() && super.canDisplace(world, blockPos);
}
@Override
public boolean displaceIfPossible(World world, BlockPos blockPos) {
return !world.getBlockState(blockPos).getBlock().getMaterial().isLiquid() && super.displaceIfPossible(world, blockPos);
}
public static class FluidLifeEssence extends Fluid {
public FluidLifeEssence() {
super("lifeEssence", new ResourceLocation(BloodMagic.DOMAIN + "blocks/lifeEssenceStill"), new ResourceLocation(BloodMagic.DOMAIN + "blocks/lifeEssenceFlowing"));
setDensity(2000);
setViscosity(2000);
}
@Override
public int getColor() {
return Color.WHITE.getRGB();
}
@Override
public String getLocalizedName(FluidStack fluidStack) {
return StatCollector.translateToLocal("tile.BloodMagic.fluid.lifeEssence.name");
}
}
}

View file

@ -0,0 +1,74 @@
package WayofTime.bloodmagic.block;
import WayofTime.bloodmagic.BloodMagic;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public class BlockRitualController extends BlockContainer {
public static final String[] names = { "master", "imperfect" };
public static final PropertyInteger META = PropertyInteger.create("meta", 0, names.length - 1);
public BlockRitualController() {
super(Material.rock);
setUnlocalizedName(BloodMagic.MODID + ".stone.ritual.");
setCreativeTab(BloodMagic.tabBloodMagic);
setStepSound(soundTypeStone);
setHardness(2.0F);
setHarvestLevel("pickaxe", 2);
}
@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public void getSubBlocks(Item item, CreativeTabs tab, List list) {
for (int i = 0; i < names.length; i++)
list.add(new ItemStack(this, 1, i));
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(META, meta);
}
@Override
public int getMetaFromState(IBlockState state) {
return (Integer) state.getValue(META);
}
@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
@Override
protected BlockState createBlockState() {
return new BlockState(this, META);
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) {
return new ItemStack(this, 1, this.getMetaFromState(world.getBlockState(pos)));
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return meta == 0 ? null : null;
}
}

View file

@ -0,0 +1,31 @@
package WayofTime.bloodmagic.client.gui;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.ConfigHandler;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.fml.client.config.GuiConfig;
import net.minecraftforge.fml.client.config.IConfigElement;
import java.util.ArrayList;
import java.util.List;
public class ConfigGui extends GuiConfig {
public ConfigGui(GuiScreen parentScreen) {
super(parentScreen, getConfigElements(parentScreen), BloodMagic.MODID, false, false, "BloodMagic Configuration");
}
@SuppressWarnings("rawtypes")
private static List<IConfigElement> getConfigElements(GuiScreen parent) {
List<IConfigElement> list = new ArrayList<IConfigElement>();
// adds sections declared in ConfigHandler. toLowerCase() is used because the configuration class automatically does this, so must we.
list.add(new ConfigElement(ConfigHandler.config.getCategory("Potions".toLowerCase())));
list.add(new ConfigElement(ConfigHandler.config.getCategory("Teleposer Blacklist".toLowerCase())));
list.add(new ConfigElement(ConfigHandler.config.getCategory("Item/Block Blacklisting".toLowerCase())));
list.add(new ConfigElement(ConfigHandler.config.getCategory("General".toLowerCase())));
return list;
}
}

View file

@ -0,0 +1,30 @@
package WayofTime.bloodmagic.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.client.IModGuiFactory;
import java.util.Set;
public class ConfigGuiFactory implements IModGuiFactory {
@Override
public void initialize(Minecraft minecraftInstance) {
}
@Override
public Class<? extends GuiScreen> mainConfigGuiClass() {
return ConfigGui.class;
}
@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
return null;
}
@Override
public RuntimeOptionGuiHandler getHandlerFor(IModGuiFactory.RuntimeOptionCategoryElement element) {
return null;
}
}

View file

@ -0,0 +1,67 @@
package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.util.helper.TextHelper;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public class ItemActivationCrystal extends ItemBindable {
public static String[] names = { "weak", "awakened", "creative" };
public ItemActivationCrystal() {
super();
setUnlocalizedName(BloodMagic.MODID + ".activationCrystal.");
setHasSubtypes(true);
setEnergyUsed(100);
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return super.getUnlocalizedName(stack) + names[stack.getItemDamage()];
}
@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public void getSubItems(Item id, CreativeTabs creativeTab, List list) {
for (int i = 0; i < names.length; i++)
list.add(new ItemStack(id, 1, i));
}
@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) {
tooltip.add(TextHelper.localize("tooltip.BloodMagic.activationCrystal." + names[stack.getItemDamage()]));
super.addInformation(stack, player, tooltip, advanced);
// if (stack.getItemDamage() == 1) {
// if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
// ItemStack[] recipe = AlchemyRecipeRegistry.getRecipeForItemStack(stack);
//
// if (recipe != null) {
// tooltip.add(TextHelper.getFormattedText(StatCollector.translateToLocal("tooltip.alchemy.recipe")));
//
// for (ItemStack item : recipe)
// if (item != null)
// tooltip.add(item.getDisplayName());
// }
// } else {
// tooltip.add(TextHelper.getFormattedText(StatCollector.translateToLocal("tooltip.alchemy.pressShift")));
// }
// }
}
public int getCrystalLevel(ItemStack stack) {
return stack.getItemDamage() > 1 ? Integer.MAX_VALUE : stack.getItemDamage() + 1;
}
}

View file

@ -0,0 +1,141 @@
package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.NBTHolder;
import WayofTime.bloodmagic.api.iface.IBindable;
import WayofTime.bloodmagic.api.util.helper.BindableHelper;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.base.Strings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public class ItemBindable extends Item implements IBindable {
private int energyUsed;
public ItemBindable() {
super();
setCreativeTab(BloodMagic.tabBloodMagic);
setMaxStackSize(1);
}
@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) {
NBTHolder.checkNBT(stack);
if (!Strings.isNullOrEmpty(stack.getTagCompound().getString(NBTHolder.NBT_OWNER)))
tooltip.add(TextHelper.getFormattedText(String.format(StatCollector.translateToLocal("tooltip.BloodMagic.currentOwner"), stack.getTagCompound().getString(NBTHolder.NBT_OWNER))));
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
BindableHelper.checkAndSetItemOwner(stack, player);
return stack;
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
BindableHelper.checkAndSetItemOwner(stack, player);
return false;
}
public static boolean syphonBatteries(ItemStack ist, EntityPlayer player, int damageToBeDone) {
if (!player.worldObj.isRemote) {
return NetworkHelper.syphonAndDamageFromNetwork(ist, player, damageToBeDone);
} else {
double posX = player.posX;
double posY = player.posY;
double posZ = player.posZ;
// SpellHelper.sendIndexedParticleToAllAround(player.worldObj, posX, posY, posZ, 20, player.worldObj.provider.getDimensionId(), 4, posX, posY, posZ);
player.worldObj.playSoundEffect((double) ((float) player.posX + 0.5F), (double) ((float) player.posY + 0.5F), (double) ((float) player.posZ + 0.5F), "random.fizz", 0.5F, 2.6F + (player.worldObj.rand.nextFloat() - player.worldObj.rand.nextFloat()) * 0.8F);
}
return true;
}
public static void hurtPlayer(EntityPlayer user, int energySyphoned) {
if (energySyphoned < 100 && energySyphoned > 0) {
if (!user.capabilities.isCreativeMode) {
user.attackEntityFrom(BloodMagicAPI.getDamageSource(), 0F); // Emulate an attack
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++) {
user.attackEntityFrom(BloodMagicAPI.getDamageSource(), 0F); // Emulate an attack
user.setHealth(user.getHealth() - 1);
if (user.getHealth() <= 0.0005f) {
user.onDeath(BloodMagicAPI.getDamageSource());
break;
}
}
}
}
}
protected void damagePlayer(World world, EntityPlayer player, int damage) {
if (world != null) {
double posX = player.posX;
double posY = player.posY;
double posZ = player.posZ;
world.playSoundEffect((double) ((float) posX + 0.5F), (double) ((float) posY + 0.5F), (double) ((float) posZ + 0.5F), "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
float f = 1.0F;
float f1 = f * 0.6F + 0.4F;
float f2 = f * f * 0.7F - 0.5F;
float f3 = f * f * 0.6F - 0.7F;
for (int l = 0; l < 8; ++l)
world.spawnParticle(EnumParticleTypes.REDSTONE, posX + Math.random() - Math.random(), posY + Math.random() - Math.random(), posZ + Math.random() - Math.random(), f1, f2, f3);
}
for (int i = 0; i < damage; i++) {
player.attackEntityFrom(BloodMagicAPI.getDamageSource(), 0F); // Emulate an attack
player.setHealth(player.getHealth() - 1);
if (player.getHealth() <= 0.0005) {
player.inventory.dropAllItems();
break;
}
}
}
public int getEnergyUsed() {
return this.energyUsed;
}
protected void setEnergyUsed(int energyUsed) {
this.energyUsed = energyUsed;
}
public String getBindableOwner(ItemStack stack) {
stack = NBTHolder.checkNBT(stack);
return stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
}
// IBindable
@Override
public boolean onBind(EntityPlayer player, ItemStack stack) {
return true;
}
}

View file

@ -0,0 +1,118 @@
package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.NBTHolder;
import WayofTime.bloodmagic.api.iface.IBindable;
import WayofTime.bloodmagic.api.orb.BloodOrb;
import WayofTime.bloodmagic.api.orb.IBloodOrb;
import WayofTime.bloodmagic.api.registry.OrbRegistry;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
import com.google.common.base.Strings;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public class ItemBloodOrb extends ItemBindable implements IBloodOrb, IBindable {
public ItemBloodOrb() {
setUnlocalizedName(BloodMagic.MODID + ".orb.");
setHasSubtypes(true);
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return super.getUnlocalizedName(stack) + OrbRegistry.getOrb(stack.getItemDamage()).getName();
}
@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public void getSubItems(Item id, CreativeTabs creativeTab, List list) {
for (int i = 0; i < OrbRegistry.getSize(); i++)
list.add(new ItemStack(id, 1, i));
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
super.onItemRightClick(stack, world, player);
if (world == null)
return stack;
double posX = player.posX;
double posY = player.posY;
double posZ = player.posZ;
world.playSoundEffect((double) ((float) posX + 0.5F), (double) ((float) posY + 0.5F), (double) ((float) posZ + 0.5F), "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
// SpellHelper.sendIndexedParticleToAllAround(world, posX, posY, posZ, 20, world.provider.getDimensionId(), 4, posX, posY, posZ);
if(PlayerHelper.isFakePlayer(player))
return stack;
if (Strings.isNullOrEmpty(stack.getTagCompound().getString(NBTHolder.NBT_OWNER)))
return stack;
if (world.isRemote)
return stack;
if(stack.getTagCompound().getString(NBTHolder.NBT_OWNER).equals(PlayerHelper.getUsernameFromPlayer(player)))
NetworkHelper.setMaxOrbToMax(stack.getTagCompound().getString(NBTHolder.NBT_OWNER), getOrbLevel(stack.getItemDamage()));
NetworkHelper.addCurrentEssenceToMaximum(stack.getTagCompound().getString(NBTHolder.NBT_OWNER), 200, getMaxEssence(stack.getItemDamage()));
hurtPlayer(player, 200);
return stack;
}
@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) {
tooltip.add(StatCollector.translateToLocal("tooltip.BloodMagic.orb.desc"));
if (advanced)
tooltip.add(String.format(StatCollector.translateToLocal("tooltip.BloodMagic.orb.owner"), getOrb(stack.getItemDamage()).getOwner()));
super.addInformation(stack, player, tooltip, advanced);
}
@Override
public ItemStack getContainerItem(ItemStack stack) {
return stack;
}
@Override
public boolean hasContainerItem(ItemStack stack) {
return true;
}
// IBindable
@Override
public boolean onBind(EntityPlayer player, ItemStack stack) {
return true;
}
// IBloodOrb
@Override
public BloodOrb getOrb(int meta) {
return OrbRegistry.getOrb(meta);
}
@Override
public int getMaxEssence(int meta) {
return OrbRegistry.getOrb(meta).getCapacity();
}
@Override
public int getOrbLevel(int meta) {
return OrbRegistry.getOrb(meta).getTier();
}
}

View file

@ -0,0 +1,17 @@
package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.registry.ModBlocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemBucket;
public class ItemBucketEssence extends ItemBucket {
public ItemBucketEssence() {
super(ModBlocks.lifeEssence);
setUnlocalizedName(BloodMagic.MODID + ".bucket.lifeEssence");
setContainerItem(Items.bucket);
setCreativeTab(BloodMagic.tabBloodMagic);
}
}

View file

@ -0,0 +1,25 @@
package WayofTime.bloodmagic.item.block;
import WayofTime.bloodmagic.block.BlockRitualController;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
public class ItemBlockRitualHome extends ItemBlock {
public ItemBlockRitualHome(Block block) {
super(block);
setHasSubtypes(true);
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return super.getUnlocalizedName(stack) + BlockRitualController.names[stack.getItemDamage()];
}
@Override
public int getMetadata(int meta) {
return meta;
}
}

View file

@ -0,0 +1,93 @@
package WayofTime.bloodmagic.item.sigil;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.NBTHolder;
import WayofTime.bloodmagic.api.iface.ISigil;
import WayofTime.bloodmagic.util.helper.TextHelper;
import WayofTime.bloodmagic.item.ItemBindable;
import lombok.Getter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
@Getter
public class ItemSigilBase extends ItemBindable implements ISigil {
private final String name;
private boolean toggleable;
protected final String tooltipBase;
public ItemSigilBase(String name, int energyUsed) {
super();
setUnlocalizedName(BloodMagic.MODID + ".sigil." + name);
setEnergyUsed(energyUsed);
this.name = name;
this.tooltipBase = "tooltip.BloodMagic.sigil." + name + ".";
}
public ItemSigilBase(String name) {
this(name, 0);
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
super.onItemRightClick(stack, world, player);
return stack;
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
super.onItemRightClick(stack, world, player);
return false;
}
@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("unchecked")
public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) {
if (StatCollector.canTranslate(tooltipBase + "desc"))
tooltip.add(TextHelper.localize(tooltipBase + "desc"));
super.addInformation(stack, player, tooltip, advanced);
}
public void setToggleable() {
this.toggleable = true;
}
public boolean isUnusable(ItemStack stack) {
NBTHolder.checkNBT(stack);
return stack.getTagCompound().getBoolean(NBTHolder.NBT_UNUSABLE);
}
public ItemStack setUnusable(ItemStack stack, boolean unusable) {
NBTHolder.checkNBT(stack);
stack.getTagCompound().setBoolean(NBTHolder.NBT_UNUSABLE, unusable);
return stack;
}
public boolean getActivated(ItemStack stack) {
return stack.getItemDamage() > 0;
}
public ItemStack setActivated(ItemStack stack, boolean activated) {
if (this.toggleable)
stack.setItemDamage(activated ? 1 : 0);
return stack;
}
}

View file

@ -0,0 +1,46 @@
package WayofTime.bloodmagic.item.sigil;
import WayofTime.bloodmagic.api.altar.IBloodAltar;
import WayofTime.bloodmagic.api.util.helper.BindableHelper;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.ChatUtil;
import WayofTime.bloodmagic.util.helper.TextHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class ItemSigilDivination extends ItemSigilBase {
public ItemSigilDivination() {
super("divination");
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
super.onItemRightClick(stack, world, player);
if (!world.isRemote && syphonBatteries(stack, player, getEnergyUsed())) {
MovingObjectPosition position = getMovingObjectPositionFromPlayer(world, player, false);
int currentEssence = NetworkHelper.getCurrentEssence(BindableHelper.getOwnerName(stack));
if (position == null) {
ChatUtil.sendNoSpam(player, new ChatComponentText(TextHelper.localize(tooltipBase + "currentEssence", currentEssence)));
return stack;
} else {
if (position.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
TileEntity tile = world.getTileEntity(position.getBlockPos());
if (!(tile instanceof IBloodAltar)) {
ChatUtil.sendNoSpam(player, new ChatComponentText(TextHelper.localize(tooltipBase + "currentEssence", currentEssence)));
return stack;
}
}
}
}
return stack;
}
}

View file

@ -0,0 +1,31 @@
package WayofTime.bloodmagic.network;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.util.ChatUtil;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;
public class AlchemicalWizardryPacketHandler {
public static final SimpleNetworkWrapper INSTANCE = new SimpleNetworkWrapper(BloodMagic.MODID);
public static void init() {
INSTANCE.registerMessage(ChatUtil.PacketNoSpamChat.Handler.class, ChatUtil.PacketNoSpamChat.class, 0, Side.CLIENT);
}
public static void sendToAllAround(IMessage message, TileEntity te, int range) {
INSTANCE.sendToAllAround(message, new NetworkRegistry.TargetPoint(te.getWorld().provider.getDimensionId(), te.getPos().getX(), te.getPos().getY(), te.getPos().getZ(), range));
}
public static void sendToAllAround(IMessage message, TileEntity te) {
sendToAllAround(message, te, 64);
}
public static void sendTo(IMessage message, EntityPlayerMP player) {
INSTANCE.sendTo(message, player);
}
}

View file

@ -0,0 +1,23 @@
package WayofTime.bloodmagic.proxy;
import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.registry.ModItems;
public class ClientProxy extends CommonProxy {
@Override
public void preInit() {
ModBlocks.initRenders();
ModItems.initRenders();
}
@Override
public void init() {
}
@Override
public void postInit() {
}
}

View file

@ -0,0 +1,16 @@
package WayofTime.bloodmagic.proxy;
public class CommonProxy {
public void preInit() {
}
public void init() {
}
public void postInit() {
}
}

View file

@ -0,0 +1,69 @@
package WayofTime.bloodmagic.registry;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.ConfigHandler;
import WayofTime.bloodmagic.block.BlockAltar;
import WayofTime.bloodmagic.block.BlockLifeEssence;
import WayofTime.bloodmagic.block.BlockRitualController;
import WayofTime.bloodmagic.item.block.ItemBlockRitualHome;
import WayofTime.bloodmagic.util.helper.InventoryRenderHelper;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class ModBlocks {
public static Block altar;
public static Block ritualStone;
public static Block lifeEssence;
public static Block crystal;
public static Block rune;
public static Block bloodStone;
public static void init() {
FluidRegistry.registerFluid(BlockLifeEssence.getLifeEssence());
lifeEssence = registerBlock(new BlockLifeEssence());
altar = registerBlock(new BlockAltar());
ritualStone = registerBlock(new BlockRitualController(), ItemBlockRitualHome.class);
initTiles();
}
public static void initTiles() {
}
public static void initRenders() {
InventoryRenderHelper renderHelper = BloodMagic.instance.getRenderHelper();
renderHelper.fluidRender(lifeEssence);
renderHelper.itemRender(InventoryRenderHelper.getItemFromBlock(ritualStone), 0);
renderHelper.itemRender(InventoryRenderHelper.getItemFromBlock(ritualStone), 1);
}
private static Block registerBlock(Block block, Class<? extends ItemBlock> itemBlock, String name) {
if (!ConfigHandler.blockBlacklist.contains(name))
GameRegistry.registerBlock(block, itemBlock, name);
return block;
}
private static Block registerBlock(Block block, Class<? extends ItemBlock> itemBlock) {
return registerBlock(block, itemBlock, block.getClass().getSimpleName());
}
private static Block registerBlock(Block block, String name) {
if (!ConfigHandler.blockBlacklist.contains(name))
GameRegistry.registerBlock(block, name);
return block;
}
private static Block registerBlock(Block block) {
return registerBlock(block, block.getClass().getSimpleName());
}
}

View file

@ -0,0 +1,8 @@
package WayofTime.bloodmagic.registry;
public class ModEntities {
public static void init() {
}
}

View file

@ -0,0 +1,84 @@
package WayofTime.bloodmagic.registry;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.ConfigHandler;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.orb.BloodOrb;
import WayofTime.bloodmagic.api.registry.OrbRegistry;
import WayofTime.bloodmagic.item.ItemActivationCrystal;
import WayofTime.bloodmagic.item.ItemBloodOrb;
import WayofTime.bloodmagic.item.ItemBucketEssence;
import WayofTime.bloodmagic.item.sigil.ItemSigilDivination;
import WayofTime.bloodmagic.util.helper.InventoryRenderHelper;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class ModItems {
public static Item bloodOrb;
public static BloodOrb orbWeak;
public static BloodOrb orbApprentice;
public static BloodOrb orbMagician;
public static BloodOrb orbMaster;
public static BloodOrb orbArchmage;
public static BloodOrb orbTranscendent;
public static Item bucketEssence;
public static Item activationCrystal;
public static Item sigilDivination;
public static void init() {
bloodOrb = registerItem(new ItemBloodOrb());
BloodMagicAPI.setOrbItem(bloodOrb);
orbWeak = new BloodOrb("weak", 1, 5000);
OrbRegistry.registerOrb(orbWeak);
orbApprentice = new BloodOrb("apprentice", 2, 25000);
OrbRegistry.registerOrb(orbApprentice);
orbMagician = new BloodOrb("magician", 3, 150000);
OrbRegistry.registerOrb(orbMagician);
orbMaster = new BloodOrb("master", 4, 1000000);
OrbRegistry.registerOrb(orbMaster);
orbArchmage = new BloodOrb("archmage", 5, 10000000);
OrbRegistry.registerOrb(orbArchmage);
orbTranscendent = new BloodOrb("transcendent", 6, 30000000);
OrbRegistry.registerOrb(orbTranscendent);
bucketEssence = registerItem(new ItemBucketEssence());
activationCrystal = registerItem(new ItemActivationCrystal());
sigilDivination = registerItem(new ItemSigilDivination());
}
public static void initRenders() {
InventoryRenderHelper renderHelper = BloodMagic.instance.getRenderHelper();
renderHelper.itemRenderAll(bloodOrb);
OrbRegistry.registerOrbTexture(orbWeak, BloodMagic.DOMAIN + "ItemBloodOrbWeak");
OrbRegistry.registerOrbTexture(orbApprentice, BloodMagic.DOMAIN + "ItemBloodOrbApprentice");
OrbRegistry.registerOrbTexture(orbMagician, BloodMagic.DOMAIN + "ItemBloodOrbMagician");
OrbRegistry.registerOrbTexture(orbMaster, BloodMagic.DOMAIN + "ItemBloodOrbMaster");
OrbRegistry.registerOrbTexture(orbArchmage, BloodMagic.DOMAIN + "ItemBloodOrbArchmage");
OrbRegistry.registerOrbTexture(orbTranscendent, BloodMagic.DOMAIN + "ItemBloodOrbTranscendent");
renderHelper.itemRender(bucketEssence);
renderHelper.itemRender(activationCrystal, 0);
renderHelper.itemRender(activationCrystal, 1);
renderHelper.itemRender(sigilDivination);
}
private static Item registerItem(Item item, String name) {
if (!ConfigHandler.itemBlacklist.contains(name))
GameRegistry.registerItem(item, name);
return item;
}
private static Item registerItem(Item item) {
return registerItem(item, item.getClass().getSimpleName());
}
}

View file

@ -0,0 +1,14 @@
package WayofTime.bloodmagic.registry;
public class ModPotions {
private static int POTION_ARRAY_SIZE = 256;
public static void init() {
}
public static int getArraySize() {
return POTION_ARRAY_SIZE;
}
}

View file

@ -0,0 +1,143 @@
package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.altar.AltarUpgrade;
import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.*;
public class TileAltar extends TileInventory implements IUpdatePlayerListBox, IFluidTank, IFluidHandler {
private int tier;
private AltarUpgrade upgrade = new AltarUpgrade();
private FluidStack fluid = new FluidStack(BloodMagicAPI.getLifeEssence(), 0);
private int capacity;
public TileAltar() {
super(1, "altar");
this.capacity = 10000;
}
@Override
public void update() {}
// @Override
// public void update() {
// if (getWorld().isRemote)
// return;
//
// if (getWorld().getTotalWorldTime() % (Math.max(20 - getUpgrade().getSpeedCount(), 1)) == 0) {
// everySecond();
// }
//
// if (getWorld().getTotalWorldTime() % 100 == 0) {
// everyFiveSeconds();
// }
// }
//
// private void everySecond() {
//
// // Do recipes
// if (AltarRecipeRegistry.getRecipes().containsKey(getStackInSlot(0))) {
// AltarRecipe recipe = AltarRecipeRegistry.getRecipeForInput(getStackInSlot(0));
//
// if (!(tier >= recipe.minTier))
// return;
//
//
// }
// }
//
// private void everyFiveSeconds() {
// checkTier();
// }
//
// private void checkTier() {
// // TODO - Write checking for tier stuff
// }
public TileAltar setUpgrade(AltarUpgrade upgrade) {
this.upgrade = upgrade;
return this;
}
public AltarUpgrade getUpgrade() {
return upgrade;
}
public TileAltar setTier(int tier) {
this.tier = tier;
return this;
}
public int getTier() {
return tier;
}
// IFluidHandler
@Override
public FluidTankInfo[] getTankInfo(EnumFacing from) {
return new FluidTankInfo[0];
}
@Override
public int fill(EnumFacing from, FluidStack resource, boolean doFill) {
return 0;
}
@Override
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain) {
return null;
}
@Override
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain) {
return null;
}
@Override
public boolean canFill(EnumFacing from, Fluid fluid) {
return false;
}
@Override
public boolean canDrain(EnumFacing from, Fluid fluid) {
return false;
}
// IFluidTank
@Override
public FluidStack getFluid() {
return fluid;
}
@Override
public int getFluidAmount() {
return fluid.amount;
}
@Override
public int getCapacity() {
return capacity;
}
@Override
public FluidTankInfo getInfo() {
return new FluidTankInfo(this);
}
@Override
public int fill(FluidStack resource, boolean doFill) {
return 0;
}
@Override
public FluidStack drain(int maxDrain, boolean doDrain) {
return null;
}
}

View file

@ -0,0 +1,124 @@
package WayofTime.bloodmagic.tile;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.StatCollector;
public class TileInventory extends TileEntity implements IInventory {
private ItemStack[] inventory;
private int size;
private String name;
public TileInventory(int size, String name) {
this.inventory = new ItemStack[size];
this.size = size;
this.name = name;
}
public void dropItems() {
for (ItemStack stack : inventory)
getWorld().spawnEntityInWorld(new EntityItem(getWorld(), getPos().getX(), pos.getY(), pos.getZ(), stack));
}
// IInventory
@Override
public int getSizeInventory() {
return size;
}
@Override
public ItemStack getStackInSlot(int index) {
return inventory[index];
}
@Override
public ItemStack decrStackSize(int index, int count) {
ItemStack slotStack = getStackInSlot(index);
if (slotStack.stackSize > count)
slotStack.stackSize -= count;
else if (slotStack.stackSize <= count)
return null;
return slotStack;
}
@Override
public ItemStack getStackInSlotOnClosing(int index) {
return inventory[index];
}
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return true;
}
@Override
public void openInventory(EntityPlayer player) {
}
@Override
public void closeInventory(EntityPlayer player) {
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
return true;
}
@Override
public int getField(int id) {
return 0;
}
@Override
public void setField(int id, int value) {
}
@Override
public int getFieldCount() {
return 0;
}
@Override
public void clear() {
this.inventory = new ItemStack[size];
}
// IWorldNameable
@Override
public String getName() {
return StatCollector.translateToLocal("tile.BloodMagic." + name + ".name");
}
@Override
public boolean hasCustomName() {
return true;
}
@Override
public IChatComponent getDisplayName() {
return new ChatComponentTranslation("tile.BloodMagic." + name + ".name");
}
}

View file

@ -0,0 +1,154 @@
package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.api.NBTHolder;
import WayofTime.bloodmagic.api.event.RitualEvent;
import WayofTime.bloodmagic.api.network.SoulNetwork;
import WayofTime.bloodmagic.api.registry.RitualRegistry;
import WayofTime.bloodmagic.api.ritual.IMasterRitualStone;
import WayofTime.bloodmagic.api.ritual.LocalRitualStorage;
import WayofTime.bloodmagic.api.ritual.Ritual;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import WayofTime.bloodmagic.item.ItemActivationCrystal;
import WayofTime.bloodmagic.util.ChatUtil;
import com.google.common.base.Strings;
import lombok.Getter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Event;
@Getter
public class TileMasterRitualStone extends TileEntity implements IMasterRitualStone, IUpdatePlayerListBox {
public static final int REFRESH_TIME = 0;
private String owner;
private boolean active;
private int activeTime;
private int cooldown;
private Ritual currentRitual;
private EnumFacing direction;
public LocalRitualStorage storage;
public NBTTagCompound customTag;
public TileMasterRitualStone() {
}
public void readClientNBT(NBTTagCompound tag) {
currentRitual = RitualRegistry.getRitualForId(tag.getString(NBTHolder.NBT_CURRENTRITUAL));
active = tag.getBoolean(NBTHolder.NBT_RUNNING);
activeTime = tag.getInteger(NBTHolder.NBT_RUNTIME);
}
public void writeClientNBT(NBTTagCompound tag) {
tag.setString(NBTHolder.NBT_CURRENTRITUAL, RitualRegistry.getIdForRitual(currentRitual));
tag.setBoolean(NBTHolder.NBT_RUNNING, active);
tag.setInteger(NBTHolder.NBT_RUNTIME, activeTime);
}
@Override
public void update() {
}
public void activateRitual(ItemStack activationCrystal, EntityPlayer activator) {
activationCrystal = NBTHolder.checkNBT(activationCrystal);
String crystalOwner = activationCrystal.getTagCompound().getString(NBTHolder.NBT_OWNER);
Ritual ritual = null;
if (!Strings.isNullOrEmpty(crystalOwner)) {
if (activationCrystal.getItem() instanceof ItemActivationCrystal) {
int crystalLevel = ((ItemActivationCrystal) activationCrystal.getItem()).getCrystalLevel(activationCrystal);
RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(this, crystalOwner, ritual, activator, activationCrystal, crystalLevel);
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) {
ChatUtil.sendNoSpamUnloc(activator, "chat.BloodMagic.ritual.prevent");
return;
}
}
}
}
@Override
public void performRitual(World world, BlockPos pos, Ritual ritual) {
if (ritual != null && RitualRegistry.ritualEnabled(ritual)) {
SoulNetwork network = NetworkHelper.getSoulNetwork(getOwner(), getWorld());
network.syphonAndDamage(ritual.getRefreshCost());
ritual.performEffect(this);
}
}
@Override
public void setCooldown(int cooldown) {
this.cooldown = cooldown;
}
@Override
public int getCooldown() {
return cooldown;
}
@Override
public void setActive(boolean active) {
this.active = active;
}
@Override
public EnumFacing getDirection() {
return direction;
}
@Override
public NBTTagCompound getCustomRitualTag() {
return customTag;
}
@Override
public void setCustomRitualTag(NBTTagCompound tag) {
this.customTag = tag;
}
@Override
public boolean areTanksEmpty() {
return false;
}
@Override
public int getRunningTime() {
return activeTime;
}
@Override
public LocalRitualStorage getLocalStorage() {
return storage;
}
@Override
public void setLocalStorage(LocalRitualStorage storage) {
this.storage = storage;
}
@Override
public String getOwner() {
return owner;
}
@Override
public World getWorld() {
return super.getWorld();
}
@Override
public BlockPos getPos() {
return super.getPos();
}
}

View file

@ -0,0 +1,238 @@
package WayofTime.bloodmagic.util;
import WayofTime.bloodmagic.network.AlchemicalWizardryPacketHandler;
import WayofTime.bloodmagic.util.helper.TextHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiNewChat;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class ChatUtil {
/**
* @author tterrag1098
*
* Ripped from EnderCore (and slightly altered)
*/
public static class PacketNoSpamChat implements IMessage {
private IChatComponent[] chatLines;
public PacketNoSpamChat() {
chatLines = new IChatComponent[0];
}
private PacketNoSpamChat(IChatComponent... lines) {
// this is guaranteed to be >1 length by accessing methods
this.chatLines = lines;
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(chatLines.length);
for (IChatComponent c : chatLines) {
ByteBufUtils.writeUTF8String(buf, IChatComponent.Serializer.componentToJson(c));
}
}
@Override
public void fromBytes(ByteBuf buf) {
chatLines = new IChatComponent[buf.readInt()];
for (int i = 0; i < chatLines.length; i++) {
chatLines[i] = IChatComponent.Serializer.jsonToComponent(ByteBufUtils.readUTF8String(buf));
}
}
public static class Handler implements IMessageHandler<PacketNoSpamChat, IMessage> {
@Override
public IMessage onMessage(PacketNoSpamChat message, MessageContext ctx) {
sendNoSpamMessages(message.chatLines);
return null;
}
}
}
private static final int DELETION_ID = 2525277;
private static int lastAdded;
private static void sendNoSpamMessages(IChatComponent[] messages) {
GuiNewChat chat = Minecraft.getMinecraft().ingameGUI.getChatGUI();
for (int i = DELETION_ID + messages.length - 1; i <= lastAdded; i++) {
chat.deleteChatLine(i);
}
for (int i = 0; i < messages.length; i++) {
chat.printChatMessageWithOptionalDeletion(messages[i], DELETION_ID + i);
}
lastAdded = DELETION_ID + messages.length - 1;
}
/**
* Returns a standard {@link ChatComponentText} for the given {@link String}.
*
* @param s
* The string to wrap.
* @return An {@link IChatComponent} containing the string.
*/
public static IChatComponent wrap(String s) {
return new ChatComponentText(s);
}
/**
* @see #wrap(String)
*/
public static IChatComponent[] wrap(String... s) {
IChatComponent[] ret = new IChatComponent[s.length];
for (int i = 0; i < ret.length; i++) {
ret[i] = wrap(s[i]);
}
return ret;
}
/**
* Returns a translatable chat component for the given string and format args.
*
* @param s
* The string to format
* @param args
* The args to apply to the format
*/
public static IChatComponent wrapFormatted(String s, Object... args) {
return new ChatComponentTranslation(s, args);
}
/**
* Simply sends the passed lines to the player in a chat message.
*
* @param player
* The player to send the chat to
* @param lines
* The lines to send
*/
public static void sendChat(EntityPlayer player, String... lines) {
sendChat(player, wrap(lines));
}
/**
* Localizes the lines before sending them.
*
* @see #sendChat(EntityPlayer, String...)
*/
public static void sendChatUnloc(EntityPlayer player, String... unlocLines) {
sendChat(player, TextHelper.localizeAll(unlocLines));
}
/**
* Sends all passed chat components to the player.
*
* @param player
* The player to send the chat lines to.
* @param lines
* The {@link IChatComponent chat components} to send.yes
*/
public static void sendChat(EntityPlayer player, IChatComponent... lines) {
for (IChatComponent c : lines) {
player.addChatComponentMessage(c);
}
}
/**
* Localizes the strings before sending them.
*
* @see #sendNoSpamClient(String...)
*/
public static void sendNoSpamClientUnloc(String... unlocLines) {
sendNoSpamClient(TextHelper.localizeAll(unlocLines));
}
/**
* Same as {@link #sendNoSpamClient(IChatComponent...)}, but wraps the Strings
* automatically.
*
* @param lines
* The chat lines to send
* @see #wrap(String)
*/
public static void sendNoSpamClient(String... lines) {
sendNoSpamClient(wrap(lines));
}
/**
* Skips the packet sending, unsafe to call on servers.
*
* @see #sendNoSpam(EntityPlayerMP, IChatComponent...)
*/
public static void sendNoSpamClient(IChatComponent... lines) {
sendNoSpamMessages(lines);
}
/**
* Localizes the strings before sending them.
*
* @see #sendNoSpam(EntityPlayer, String...)
*/
public static void sendNoSpamUnloc(EntityPlayer player, String... unlocLines) {
sendNoSpam(player, TextHelper.localizeAll(unlocLines));
}
/**
* @see #wrap(String)
* @see #sendNoSpam(EntityPlayer, IChatComponent...)
*/
public static void sendNoSpam(EntityPlayer player, String... lines) {
sendNoSpam(player, wrap(lines));
}
/**
* First checks if the player is instanceof {@link EntityPlayerMP} before
* casting.
*
* @see #sendNoSpam(EntityPlayerMP, IChatComponent...)
*/
public static void sendNoSpam(EntityPlayer player, IChatComponent... lines) {
if (player instanceof EntityPlayerMP) {
sendNoSpam((EntityPlayerMP) player, lines);
}
}
/**
* Localizes the strings before sending them.
*
* @see #sendNoSpam(EntityPlayerMP, String...)
*/
public static void sendNoSpamUnloc(EntityPlayerMP player, String... unlocLines) {
sendNoSpam(player, TextHelper.localizeAll(unlocLines));
}
/**
* @see #wrap(String)
* @see #sendNoSpam(EntityPlayerMP, IChatComponent...)
*/
public static void sendNoSpam(EntityPlayerMP player, String... lines) {
sendNoSpam(player, wrap(lines));
}
/**
* Sends a chat message to the client, deleting past messages also sent via
* this method.
* <p>
* Credit to RWTema for the idea
*
* @param player
* The player to send the chat message to
* @param lines
* The chat lines to send.
*/
public static void sendNoSpam(EntityPlayerMP player, IChatComponent... lines) {
if (lines.length > 0)
AlchemicalWizardryPacketHandler.INSTANCE.sendTo(new PacketNoSpamChat(lines), player);
}
}

View file

@ -0,0 +1,16 @@
package WayofTime.bloodmagic.util;
public class Utils {
public static boolean isInteger(String integer) {
try {
Integer.parseInt(integer);
} catch(NumberFormatException e) {
return false;
} catch(NullPointerException e) {
return false;
}
// only got here if we didn't return false
return true;
}
}

View file

@ -0,0 +1,34 @@
package WayofTime.bloodmagic.util.handler;
import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.registry.ModItems;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.FillBucketEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class EventHandler {
@SubscribeEvent
public void onBucketFill(FillBucketEvent event) {
if (event.current.getItem() != Items.bucket)
return;
ItemStack result = null;
Block block = event.world.getBlockState(event.target.getBlockPos()).getBlock();
if (block != null && (block.equals(ModBlocks.lifeEssence)) && block.getMetaFromState(event.world.getBlockState(event.target.getBlockPos())) == 0) {
event.world.setBlockToAir(event.target.getBlockPos());
result = new ItemStack(ModItems.bucketEssence);
}
if (result == null)
return;
event.result = result;
event.setResult(Event.Result.ALLOW);
}
}

View file

@ -0,0 +1,128 @@
package WayofTime.bloodmagic.util.helper;
import WayofTime.bloodmagic.BloodMagic;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.model.ModelLoader;
/**
* @author <a href="https://github.com/TehNut">TehNut</a>
*
* The goal of this class is to make registering the inventory renders
* for your Items/Blocks a much simpler and easier process.
*
* You must call this at the post initialization stage on
* the clientside only.
*
* If you pass a Block through here that uses the default
* ItemBlock, you should specify a custom name.
*/
public class InventoryRenderHelper {
/**
* This is the base string for your resources. It will usually be
* your modid in all lowercase with a colon at the end.
*/
private final String domain;
public InventoryRenderHelper(String domain) {
this.domain = domain;
}
/**
* Registers a Model for the given Item and meta.
*
* @param item - Item to register Model for
* @param meta - Meta of Item
* @param name - Name of the model JSON
*/
public void itemRender(Item item, int meta, String name) {
String resName = domain + name;
ModelBakery.addVariantName(item, resName);
ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(resName, "inventory"));
}
/**
* Shorthand of {@code itemRender(Item, int, String)}
*
* @param item - Item to register Model for
* @param meta - Meta of Item
*/
public void itemRender(Item item, int meta) {
itemRender(item, meta, getClassName(item) + meta);
}
public void itemRender(Item item, String name) {
itemRender(item, 0, name);
}
/**
* Shorthand of {@code itemRender(Item, int)}
*
* @param item - Item to register Model for
*/
public void itemRender(Item item) {
itemRender(item, 0, getClassName(item));
}
/**
* Registers a model for the item across all Meta's that get used for the item
*
* @param item - Item to register Model for
*/
public void itemRenderAll(Item item) {
final Item toRender = item;
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return new ModelResourceLocation(domain + getClassName(toRender), "inventory");
}
});
}
public void itemRenderToggle(Item item, String name) {
itemRender(item, 0, name + "_deactivated");
itemRender(item, 1, name + "_activated");
}
public void fluidRender(Block block) {
final Block toRender = block;
ModelBakery.addVariantName(InventoryRenderHelper.getItemFromBlock(block));
ModelLoader.setCustomMeshDefinition(InventoryRenderHelper.getItemFromBlock(block), new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return new ModelResourceLocation(BloodMagic.DOMAIN + toRender.getClass().getSimpleName(), "fluid");
}
});
ModelLoader.setCustomStateMapper(block, new StateMapperBase() {
@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
return new ModelResourceLocation(domain + toRender.getClass().getSimpleName(), "fluid");
}
});
}
/**
*
* @param block - Block to get Item of
* @return - The ItemBlock that corresponds to the Block.
*/
public static Item getItemFromBlock(Block block) {
return Item.getItemFromBlock(block);
}
private static String getClassName(Item item) {
return item instanceof ItemBlock ? Block.getBlockFromItem(item).getClass().getSimpleName() : item.getClass().getSimpleName();
}
}

View file

@ -0,0 +1,40 @@
package WayofTime.bloodmagic.util.helper;
import com.google.common.collect.Lists;
import net.minecraft.util.StatCollector;
import java.util.List;
public class TextHelper {
public static String getFormattedText(String string) {
return string.replaceAll("&", "\u00A7");
}
public static String localize(String key, Object ... format) {
return getFormattedText(StatCollector.translateToLocalFormatted(key, format));
}
/**
* Localizes all strings in a list, using the prefix.
*
* @param unloc
* The list of unlocalized strings.
* @return A list of localized versions of the passed strings.
*/
public static List<String> localizeAll(List<String> unloc) {
List<String> ret = Lists.newArrayList();
for (String s : unloc)
ret.add(localize(s));
return ret;
}
public static String[] localizeAll(String... unloc) {
String[] ret = new String[unloc.length];
for (int i = 0; i < ret.length; i++)
ret[i] = localize(unloc[i]);
return ret;
}
}