Swap the API packages

The new one is now built for the api jar and the old one is now internal.
It will slowly be moved around to sane places within the internal code. Most
of the features provided in the old "api" are addon specific features which
will generally rely on the main jar anyways. The new API will be specific
to compatibility features, such as blacklists, recipes, and value modification.
This commit is contained in:
Nicholas Ignoffo 2018-02-05 17:04:38 -08:00
parent 4fbcac6aa2
commit ddaadfbe52
421 changed files with 1006 additions and 999 deletions

View file

@ -0,0 +1,58 @@
package WayofTime.bloodmagic.api.impl;
import WayofTime.bloodmagic.apibutnotreally.altar.EnumAltarComponent;
import WayofTime.bloodmagic.api.IBloodMagicAPI;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.ResourceLocation;
import java.util.*;
public class BloodMagicAPI implements IBloodMagicAPI {
public static final BloodMagicAPI INSTANCE = new BloodMagicAPI();
private final BloodMagicBlacklist blacklist;
private final Map<ResourceLocation, Integer> sacrificialValues;
private final Multimap<EnumAltarComponent, IBlockState> altarComponents;
public BloodMagicAPI() {
this.blacklist = new BloodMagicBlacklist();
this.sacrificialValues = Maps.newHashMap();
this.altarComponents = ArrayListMultimap.create();
}
@Override
public BloodMagicBlacklist getBlacklist() {
return blacklist;
}
@Override
public void setSacrificialValue(ResourceLocation entityId, int value) {
sacrificialValues.put(entityId, value);
}
@Override
public void registerAltarComponent(IBlockState state, String componentType) {
EnumAltarComponent component = EnumAltarComponent.NOTAIR;
for (EnumAltarComponent type : EnumAltarComponent.VALUES) {
if (type.name().equalsIgnoreCase(componentType)) {
component = type;
break;
}
}
altarComponents.put(component, state);
}
public Map<ResourceLocation, Integer> getSacrificialValues() {
return ImmutableMap.copyOf(sacrificialValues);
}
public List<IBlockState> getComponentStates(EnumAltarComponent component) {
return (List<IBlockState>) altarComponents.get(component);
}
}

View file

@ -0,0 +1,98 @@
package WayofTime.bloodmagic.api.impl;
import WayofTime.bloodmagic.api.IBloodMagicBlacklist;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
import java.util.Set;
public class BloodMagicBlacklist implements IBloodMagicBlacklist {
private final Set<IBlockState> teleposer;
private final Set<ResourceLocation> teleposerEntities;
private final Set<IBlockState> transposition;
private final Set<IBlockState> greenGrove;
private final Set<ResourceLocation> sacrifice;
public BloodMagicBlacklist() {
this.teleposer = Sets.newHashSet();
this.teleposerEntities = Sets.newHashSet();
this.transposition = Sets.newHashSet();
this.greenGrove = Sets.newHashSet();
this.sacrifice = Sets.newHashSet();
}
@Override
public void addTeleposer(@Nonnull IBlockState state) {
if (!teleposer.contains(state))
teleposer.add(state);
}
@Override
public void addTeleposer(@Nonnull Block block) {
for (IBlockState state : block.getBlockState().getValidStates())
addTeleposer(state);
}
@Override
public void addTeleposer(@Nonnull ResourceLocation entityId) {
if (!teleposerEntities.contains(entityId))
teleposerEntities.add(entityId);
}
@Override
public void addTransposition(@Nonnull IBlockState state) {
if (!transposition.contains(state))
transposition.add(state);
}
@Override
public void addTransposition(@Nonnull Block block) {
for (IBlockState state : block.getBlockState().getValidStates())
addTransposition(state);
}
@Override
public void addGreenGrove(@Nonnull IBlockState state) {
if (!greenGrove.contains(state))
greenGrove.add(state);
}
@Override
public void addGreenGrove(@Nonnull Block block) {
for (IBlockState state : block.getBlockState().getValidStates())
addGreenGrove(state);
}
@Override
public void addWellOfSuffering(@Nonnull ResourceLocation entityId) {
if (!sacrifice.contains(entityId))
sacrifice.add(entityId);
}
// Internal use getters
public Set<IBlockState> getTeleposer() {
return ImmutableSet.copyOf(teleposer);
}
public Set<ResourceLocation> getTeleposerEntities() {
return ImmutableSet.copyOf(teleposerEntities);
}
public Set<IBlockState> getTransposition() {
return ImmutableSet.copyOf(transposition);
}
public Set<IBlockState> getGreenGrove() {
return ImmutableSet.copyOf(greenGrove);
}
public Set<ResourceLocation> getSacrifice() {
return ImmutableSet.copyOf(sacrifice);
}
}

View file

@ -0,0 +1,139 @@
package WayofTime.bloodmagic.api.impl;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.ConfigHandler;
import WayofTime.bloodmagic.apibutnotreally.altar.EnumAltarComponent;
import WayofTime.bloodmagic.api.BloodMagicPlugin;
import WayofTime.bloodmagic.api.IBloodMagicAPI;
import WayofTime.bloodmagic.api.IBloodMagicPlugin;
import WayofTime.bloodmagic.block.BlockBloodRune;
import WayofTime.bloodmagic.block.BlockDecorative;
import WayofTime.bloodmagic.block.enums.EnumBloodRune;
import WayofTime.bloodmagic.block.enums.EnumDecorative;
import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.EntityEntry;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
@BloodMagicPlugin
public class BloodMagicCorePlugin implements IBloodMagicPlugin {
@Override
public void register(IBloodMagicAPI api) {
// Add forced blacklistings
api.getBlacklist().addTeleposer(RegistrarBloodMagicBlocks.INPUT_ROUTING_NODE);
api.getBlacklist().addTransposition(RegistrarBloodMagicBlocks.INPUT_ROUTING_NODE);
api.getBlacklist().addTeleposer(RegistrarBloodMagicBlocks.OUTPUT_ROUTING_NODE);
api.getBlacklist().addTransposition(RegistrarBloodMagicBlocks.OUTPUT_ROUTING_NODE);
api.getBlacklist().addTeleposer(RegistrarBloodMagicBlocks.ITEM_ROUTING_NODE);
api.getBlacklist().addTransposition(RegistrarBloodMagicBlocks.ITEM_ROUTING_NODE);
api.getBlacklist().addTeleposer(RegistrarBloodMagicBlocks.MASTER_ROUTING_NODE);
api.getBlacklist().addTransposition(RegistrarBloodMagicBlocks.MASTER_ROUTING_NODE);
api.getBlacklist().addTeleposer(RegistrarBloodMagicBlocks.DEMON_CRYSTAL);
api.getBlacklist().addTransposition(RegistrarBloodMagicBlocks.DEMON_CRYSTAL);
api.getBlacklist().addTeleposer(RegistrarBloodMagicBlocks.INVERSION_PILLAR);
api.getBlacklist().addTransposition(RegistrarBloodMagicBlocks.INVERSION_PILLAR);
api.getBlacklist().addWellOfSuffering(new ResourceLocation("armor_stand"));
api.getBlacklist().addWellOfSuffering(new ResourceLocation(BloodMagic.MODID, "sentient_specter"));
api.setSacrificialValue(new ResourceLocation("armor_stand"), 0);
api.setSacrificialValue(new ResourceLocation(BloodMagic.MODID, "sentient_specter"), 0);
handleConfigValues(api);
// Add standard blocks for altar components
api.registerAltarComponent(Blocks.GLOWSTONE.getDefaultState(), EnumAltarComponent.GLOWSTONE.name());
api.registerAltarComponent(Blocks.SEA_LANTERN.getDefaultState(), EnumAltarComponent.GLOWSTONE.name());
api.registerAltarComponent(Blocks.BEACON.getDefaultState(), EnumAltarComponent.BEACON.name());
BlockDecorative decorative = (BlockDecorative) RegistrarBloodMagicBlocks.DECORATIVE_BRICK;
api.registerAltarComponent(decorative.getDefaultState().withProperty(decorative.getProperty(), EnumDecorative.BLOODSTONE_BRICK), EnumAltarComponent.BLOODSTONE.name());
api.registerAltarComponent(decorative.getDefaultState().withProperty(decorative.getProperty(), EnumDecorative.BLOODSTONE_TILE), EnumAltarComponent.BLOODSTONE.name());
api.registerAltarComponent(decorative.getDefaultState().withProperty(decorative.getProperty(), EnumDecorative.CRYSTAL_BRICK), EnumAltarComponent.CRYSTAL.name());
api.registerAltarComponent(decorative.getDefaultState().withProperty(decorative.getProperty(), EnumDecorative.CRYSTAL_TILE), EnumAltarComponent.CRYSTAL.name());
BlockBloodRune bloodRune = (BlockBloodRune) RegistrarBloodMagicBlocks.BLOOD_RUNE;
for (EnumBloodRune runeType : EnumBloodRune.values())
api.registerAltarComponent(bloodRune.getDefaultState().withProperty(bloodRune.getProperty(), runeType), EnumAltarComponent.BLOODRUNE.name());
}
private static void handleConfigValues(IBloodMagicAPI api) {
for (String value : ConfigHandler.values.sacrificialValues) {
String[] split = value.split(";");
if (split.length != 2) // Not valid format
continue;
api.setSacrificialValue(new ResourceLocation(split[0]), Integer.parseInt(split[1]));
}
for (String value : ConfigHandler.blacklist.teleposer) {
EntityEntry entityEntry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(value));
if (entityEntry == null) { // It's not an entity (or at least not a valid one), so let's try a block.
String[] blockData = value.split("\\[");
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockData[0]));
if (block == Blocks.AIR || block == null) // Not a valid block either
continue;
if (blockData.length > 1) { // We have properties listed, so let's build a state.
api.getBlacklist().addTeleposer(parseState(value));
continue;
}
api.getBlacklist().addTeleposer(block);
continue;
}
api.getBlacklist().addTeleposer(entityEntry.getRegistryName());
}
for (String value : ConfigHandler.blacklist.transposer) {
String[] blockData = value.split("\\[");
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockData[0]));
if (block == Blocks.AIR || block == null) // Not a valid block
continue;
if (blockData.length > 1) { // We have properties listed, so let's build a state.
api.getBlacklist().addTeleposer(parseState(value));
continue;
}
api.getBlacklist().addTeleposer(block);
}
for (String value : ConfigHandler.blacklist.wellOfSuffering) {
EntityEntry entityEntry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(value));
if (entityEntry == null) // Not a valid entity
continue;
api.getBlacklist().addWellOfSuffering(entityEntry.getRegistryName());
}
}
private static IBlockState parseState(String blockInfo) {
String[] split = blockInfo.split("\\[");
split[1] = split[1].substring(0, split[1].lastIndexOf("]")); // Make sure brackets are removed from state
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0])); // Find the block
if (block == Blocks.AIR)
return Blocks.AIR.getDefaultState(); // The block is air, so we're looking at invalid data
BlockStateContainer blockState = block.getBlockState();
IBlockState returnState = blockState.getBaseState();
// Force our values into the state
String[] stateValues = split[1].split(","); // Splits up each value
for (String value : stateValues) {
String[] valueSplit = value.split("="); // Separates property and value
IProperty property = blockState.getProperty(valueSplit[0]);
if (property != null)
returnState = returnState.withProperty(property, (Comparable) property.parseValue(valueSplit[1]).get()); // Force the property into the state
}
return returnState;
}
}

View file

@ -1,35 +0,0 @@
package WayofTime.bloodmagic.api.impl;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.IBindable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
/**
* Base class for all bindable items.
*/
public class ItemBindable extends Item implements IBindable {
public ItemBindable() {
super();
setMaxStackSize(1);
}
// IBindable
@Override
public boolean onBind(EntityPlayer player, ItemStack stack) {
return true;
}
@Override
public String getOwnerName(ItemStack stack) {
return !stack.isEmpty() ? stack.getTagCompound().getString(Constants.NBT.OWNER_NAME) : null;
}
@Override
public String getOwnerUUID(ItemStack stack) {
return !stack.isEmpty() ? stack.getTagCompound().getString(Constants.NBT.OWNER_UUID) : null;
}
}

View file

@ -1,48 +0,0 @@
package WayofTime.bloodmagic.api.impl;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.ISigil;
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
* Base class for all (static) sigils.
*/
public class ItemSigil extends ItemBindable implements ISigil {
private int lpUsed;
public ItemSigil(int lpUsed) {
super();
this.lpUsed = lpUsed;
}
public boolean isUnusable(ItemStack stack) {
NBTHelper.checkNBT(stack);
return stack.getTagCompound().getBoolean(Constants.NBT.UNUSABLE);
}
public ItemStack setUnusable(ItemStack stack, boolean unusable) {
NBTHelper.checkNBT(stack);
stack.getTagCompound().setBoolean(Constants.NBT.UNUSABLE, unusable);
return stack;
}
@Override
public boolean performArrayEffect(World world, BlockPos pos) {
return false;
}
@Override
public boolean hasArrayEffect() {
return false;
}
public int getLpUsed() {
return lpUsed;
}
}

View file

@ -1,92 +0,0 @@
package WayofTime.bloodmagic.api.impl;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.IActivatable;
import WayofTime.bloodmagic.api.iface.ISigil;
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
import com.google.common.base.Strings;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
* Base class for all toggleable sigils.
*/
public class ItemSigilToggleable extends ItemSigil implements IActivatable {
public ItemSigilToggleable(int lpUsed) {
super(lpUsed);
}
@Override
public boolean getActivated(ItemStack stack) {
return !stack.isEmpty() && NBTHelper.checkNBT(stack).getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
}
@Override
public ItemStack setActivatedState(ItemStack stack, boolean activated) {
if (!stack.isEmpty()) {
NBTHelper.checkNBT(stack).getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
return stack;
}
return stack;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (stack.getItem() instanceof ISigil.Holding)
stack = ((Holding) stack.getItem()).getHeldItem(stack, player);
if (PlayerHelper.isFakePlayer(player))
return ActionResult.newResult(EnumActionResult.FAIL, stack);
if (!world.isRemote && !isUnusable(stack)) {
if (player.isSneaking())
setActivatedState(stack, !getActivated(stack));
if (getActivated(stack) && NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, getLpUsed()))
return super.onItemRightClick(world, player, hand);
}
return super.onItemRightClick(world, player, hand);
}
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
if (stack.getItem() instanceof ISigil.Holding)
stack = ((Holding) stack.getItem()).getHeldItem(stack, player);
if (Strings.isNullOrEmpty(getOwnerUUID(stack)) || player.isSneaking()) // Make sure Sigils are bound before handling. Also ignores while toggling state
return EnumActionResult.PASS;
return (NetworkHelper.getSoulNetwork(getOwnerUUID(player.getHeldItem(hand))).syphonAndDamage(player, getLpUsed()) && onSigilUse(player.getHeldItem(hand), player, world, pos, side, hitX, hitY, hitZ)) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
}
public boolean onSigilUse(ItemStack itemStack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ) {
return false;
}
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (!worldIn.isRemote && entityIn instanceof EntityPlayerMP && getActivated(stack)) {
if (entityIn.ticksExisted % 100 == 0) {
if (!NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage((EntityPlayer) entityIn, getLpUsed())) {
setActivatedState(stack, false);
}
}
onSigilUpdate(stack, worldIn, (EntityPlayer) entityIn, itemSlot, isSelected);
}
}
public void onSigilUpdate(ItemStack stack, World world, EntityPlayer player, int itemSlot, boolean isSelected) {
}
}