Initial stab at API structuring (#1711)

This commit is contained in:
Arcaratus 2020-11-18 13:53:20 -05:00 committed by GitHub
parent 546215ab37
commit 1ae356c886
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
88 changed files with 149 additions and 120 deletions

View file

@ -0,0 +1,102 @@
package wayoftime.bloodmagic.impl;
import java.util.List;
import javax.annotation.Nonnull;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.block.BlockState;
import wayoftime.bloodmagic.altar.ComponentType;
import wayoftime.bloodmagic.api.IBloodMagicAPI;
import wayoftime.bloodmagic.util.BMLog;
public class BloodMagicAPI implements IBloodMagicAPI
{
public static final BloodMagicAPI INSTANCE = new BloodMagicAPI();
// private final BloodMagicBlacklist blacklist;
private final BloodMagicRecipeRegistrar recipeRegistrar;
private final BloodMagicValueManager valueManager;
private final Multimap<ComponentType, BlockState> altarComponents;
public BloodMagicAPI()
{
// this.blacklist = new BloodMagicBlacklist();
this.recipeRegistrar = new BloodMagicRecipeRegistrar();
this.valueManager = new BloodMagicValueManager();
this.altarComponents = ArrayListMultimap.create();
}
// @Nonnull
// @Override
// public BloodMagicBlacklist getBlacklist()
// {
// return blacklist;
// }
//
@Nonnull
@Override
public BloodMagicRecipeRegistrar getRecipeRegistrar()
{
return recipeRegistrar;
}
//
@Nonnull
@Override
public BloodMagicValueManager getValueManager()
{
return valueManager;
}
@Override
public void registerAltarComponent(@Nonnull BlockState state, @Nonnull String componentType)
{
ComponentType component = null;
for (ComponentType type : ComponentType.VALUES)
{
if (type.name().equalsIgnoreCase(componentType))
{
component = type;
break;
}
}
if (component != null)
{
BMLog.API_VERBOSE.info("Registered {} as a {} altar component.", state, componentType);
altarComponents.put(component, state);
} else
BMLog.API.warn("Invalid Altar component type: {}.", componentType);
}
@Override
public void unregisterAltarComponent(@Nonnull BlockState state, @Nonnull String componentType)
{
ComponentType component = null;
for (ComponentType type : ComponentType.VALUES)
{
if (type.name().equalsIgnoreCase(componentType))
{
component = type;
break;
}
}
if (component != null)
{
BMLog.API_VERBOSE.info("Unregistered {} from being a {} altar component.", state, componentType);
altarComponents.remove(component, state);
} else
BMLog.API.warn("Invalid Altar component type: {}.", componentType);
}
@Nonnull
public List<BlockState> getComponentStates(ComponentType component)
{
return (List<BlockState>) altarComponents.get(component);
}
}