Add IMC support for some API methods

This commit is contained in:
Nick 2016-01-30 14:58:37 -08:00
parent 2220cc1819
commit 007e415c36
2 changed files with 61 additions and 1 deletions

View file

@ -2,13 +2,19 @@ package WayofTime.bloodmagic;
import java.io.File;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.compat.ICompatibility;
import WayofTime.bloodmagic.util.Utils;
import lombok.Getter;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInterModComms;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
@ -26,6 +32,7 @@ import WayofTime.bloodmagic.registry.ModPotions;
import WayofTime.bloodmagic.registry.ModRecipes;
import WayofTime.bloodmagic.registry.ModRituals;
import WayofTime.bloodmagic.registry.ModTranquilityHandlers;
import net.minecraftforge.fml.common.registry.GameRegistry;
@Mod(modid = Constants.Mod.MODID, name = Constants.Mod.NAME, version = Constants.Mod.VERSION, dependencies = Constants.Mod.DEPEND, guiFactory = "WayofTime.bloodmagic.client.gui.config.ConfigGuiFactory")
@Getter
@ -98,4 +105,38 @@ public class BloodMagic
proxy.postInit();
}
@Mod.EventHandler
public void onIMCRecieved(FMLInterModComms.IMCEvent event)
{
for (FMLInterModComms.IMCMessage message : event.getMessages()) {
if (message.key.equals("teleposerBlacklist") && message.isItemStackMessage())
{
ItemStack stack = message.getItemStackValue();
if (stack.getItem() instanceof ItemBlock)
{
Block block = Block.getBlockFromItem(stack.getItem());
BloodMagicAPI.addToTeleposerBlacklist(block, stack.getItemDamage());
}
}
if (message.key.equals("sacrificeValue") && message.isStringMessage())
{
String[] splitInfo = message.getStringValue().split(";");
if (splitInfo.length == 2 && Utils.isInteger(splitInfo[1]))
BloodMagicAPI.setEntitySacrificeValue(splitInfo[0], Integer.parseInt(splitInfo[1]));
}
if (message.key.equals("greenGroveBlacklist") && message.isStringMessage())
{
String[] splitInfo = message.getStringValue().split(":");
if (splitInfo.length == 2)
{
Block block = GameRegistry.findBlock(splitInfo[0], splitInfo[1]);
if (block != null)
BloodMagicAPI.blacklistFromGreenGrove(block);
}
}
}
}
}

View file

@ -4,7 +4,6 @@ import WayofTime.bloodmagic.api.util.helper.LogHelper;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.util.DamageSource;
@ -16,6 +15,17 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The primary API class. Includes helper methods and blacklists.
*
* Some API methods can be used via IMC instead. The supported methods are:
*
* <ul>
* <li>{@link #addToTeleposerBlacklist(BlockStack)}</li>
* <li>{@link #blacklistFromGreenGrove(Block)}</li>
* <li>{@link #setEntitySacrificeValue(Class, int)}</li>
* </ul>
*/
public class BloodMagicAPI
{
@Getter
@ -94,6 +104,9 @@ public class BloodMagicAPI
/**
* Used to add a {@link BlockStack} to the Teleposer blacklist that cannot
* be changed via Configuration files.
*
* IMC: {@code FMLInterModComs.sendMessage("BloodMagic", "teleposerBlacklist", ItemStack)}
* Example: {@code FMLInterModComs.sendMessage("BloodMagic", "teleposerBlacklist", new ItemStack(Blocks.bedrock))}
*
* @param blockStack
* - The BlockStack to blacklist.
@ -136,6 +149,9 @@ public class BloodMagicAPI
*
* The default value for any unset Entity is 500 LP per sacrifice.
*
* IMC: {@code FMLInterModComs.sendMessage("BloodMagic", "sacrificeValue", "ClassName;Value")}
* Example: {@code FMLInterModComs.sendMessage("BloodMagic", "sacrificeValue", "EntityVillager;2000")}
*
* @param entityClass
* - The class of the entity to blacklist.
* @param sacrificeValue
@ -164,6 +180,9 @@ public class BloodMagicAPI
/**
* Blacklists a block from the Green Grove Ritual and Sigil.
*
* IMC: {@code FMLInterModComs.sendMessage("BloodMagic", "greenGroveBlacklist", "domain:name")}
* Example: {@code FMLInterModComs.sendMessage("BloodMagic", "greenGroveBlacklist", "minecraft:wheat")}
*
* @param block - Block to blacklist
*/
public static void blacklistFromGreenGrove(Block block) {