IMC API for adding new altar components (#1039)

CC @Drullkus

(cherry picked from commit 8a8bff8)
This commit is contained in:
Nicholas Ignoffo 2017-02-12 01:18:16 -08:00
parent 9010cebc40
commit f135dab7ba
3 changed files with 40 additions and 1 deletions

View file

@ -129,9 +129,12 @@ public class BloodAltar implements IFluidHandler
EnumAltarComponent component = ((IAltarComponent) worldBlock.getBlock()).getType(world, worldBlock.getState(), componentPos);
if (component == null || component != altarComponent.getComponent())
return false;
} else if (worldBlock.getBlock() != Utils.getBlockForComponent(altarComponent.getComponent()))
} else if (worldBlock.getBlock() != Utils.getBlockForComponent(altarComponent.getComponent())) // Special case Vanilla
{
return false;
} else if (BloodMagicAPI.getAltarComponents().get(worldBlock.getState()) != null) // Mod compat
{
return BloodMagicAPI.getAltarComponents().get(worldBlock.getState()) == altarComponent.getComponent();
}
} else
{

View file

@ -1,9 +1,11 @@
package WayofTime.bloodmagic.api;
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
import WayofTime.bloodmagic.api.util.helper.LogHelper;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -40,6 +42,8 @@ public class BloodMagicAPI
private static final Map<String, Integer> entitySacrificeValues = new HashMap<String, Integer>();
@Getter
private static final ArrayList<Block> greenGroveBlacklist = new ArrayList<Block>();
@Getter
private static final Map<IBlockState, EnumAltarComponent> altarComponents = new HashMap<IBlockState, EnumAltarComponent>();
@Getter
@Setter
@ -261,4 +265,24 @@ public class BloodMagicAPI
if (!greenGroveBlacklist.contains(block))
greenGroveBlacklist.add(block);
}
/**
* Marks an IBlockState as a specific {@link EnumAltarComponent} without needing to implement
* {@link WayofTime.bloodmagic.api.altar.IAltarComponent} on the block.
*
* IMC:
* {@code FMLInterModComs.sendMessage("BloodMagic", "altarComponent", "domain:name:meta:component")}
* Example:
* {@code FMLInterModComs.sendMessage("BloodMagic", "altarComponent", "minecraft:glowstone:0:GLOWSTONE")}
*
* @param state
* - The IBlockState for this component
* @param altarComponent
* - The EnumAltarComponent for this state
*/
public static void addAltarComponent(IBlockState state, EnumAltarComponent altarComponent)
{
if (!altarComponents.containsKey(state))
altarComponents.put(state, altarComponent);
}
}

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.util.handler;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
@ -54,6 +55,17 @@ public class IMCHandler
BloodMagicAPI.blacklistFromGreenGrove(block);
}
}
if (message.key.equals("altarComponent") && message.isStringMessage())
{
String[] splitInfo = message.getStringValue().split(":");
if (splitInfo.length == 4)
{
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(splitInfo[0], splitInfo[1]));
if (block != null)
BloodMagicAPI.addAltarComponent(block.getStateFromMeta(Integer.parseInt(splitInfo[2])), EnumAltarComponent.valueOf(splitInfo[3]));
}
}
}
}
}