Merge apibutnotreally with the main packages
Do not consider anything outside of the true API safe to use. And even then, I'm changing things. Just wait. Please I beg you.
This commit is contained in:
parent
616c08094b
commit
2fecb427fd
399 changed files with 958 additions and 977 deletions
|
@ -1,8 +1,8 @@
|
|||
package WayofTime.bloodmagic.core;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.apibutnotreally.orb.BloodOrb;
|
||||
import WayofTime.bloodmagic.apibutnotreally.registry.OrbRegistry;
|
||||
import WayofTime.bloodmagic.orb.BloodOrb;
|
||||
import WayofTime.bloodmagic.core.registry.OrbRegistry;
|
||||
import WayofTime.bloodmagic.entity.mob.*;
|
||||
import WayofTime.bloodmagic.entity.projectile.EntityBloodLight;
|
||||
import WayofTime.bloodmagic.entity.projectile.EntityMeteor;
|
||||
|
|
|
@ -2,10 +2,10 @@ package WayofTime.bloodmagic.core;
|
|||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.api.impl.BloodMagicRecipeRegistrar;
|
||||
import WayofTime.bloodmagic.apibutnotreally.altar.EnumAltarTier;
|
||||
import WayofTime.bloodmagic.apibutnotreally.registry.OrbRegistry;
|
||||
import WayofTime.bloodmagic.apibutnotreally.ritual.EnumRuneType;
|
||||
import WayofTime.bloodmagic.apibutnotreally.soul.EnumDemonWillType;
|
||||
import WayofTime.bloodmagic.altar.EnumAltarTier;
|
||||
import WayofTime.bloodmagic.core.registry.OrbRegistry;
|
||||
import WayofTime.bloodmagic.ritual.data.EnumRuneType;
|
||||
import WayofTime.bloodmagic.soul.EnumDemonWillType;
|
||||
import WayofTime.bloodmagic.block.BlockLifeEssence;
|
||||
import WayofTime.bloodmagic.item.alchemy.ItemCuttingFluid;
|
||||
import WayofTime.bloodmagic.item.alchemy.ItemLivingArmourPointsUpgrade;
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package WayofTime.bloodmagic.core.data;
|
||||
|
||||
import WayofTime.bloodmagic.util.helper.PlayerHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.storage.WorldSavedData;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BMWorldSavedData extends WorldSavedData {
|
||||
public static final String ID = "BloodMagic-SoulNetworks";
|
||||
|
||||
private Map<UUID, SoulNetwork> soulNetworks = new HashMap<UUID, SoulNetwork>();
|
||||
|
||||
public BMWorldSavedData(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public BMWorldSavedData() {
|
||||
this(ID);
|
||||
}
|
||||
|
||||
public SoulNetwork getNetwork(EntityPlayer player) {
|
||||
return getNetwork(PlayerHelper.getUUIDFromPlayer(player));
|
||||
}
|
||||
|
||||
public SoulNetwork getNetwork(UUID playerId) {
|
||||
if (!soulNetworks.containsKey(playerId))
|
||||
soulNetworks.put(playerId, SoulNetwork.newEmpty(playerId).setParent(this));
|
||||
return soulNetworks.get(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
||||
NBTTagList networkData = tagCompound.getTagList("networkData", 10);
|
||||
|
||||
for (int i = 0; i < networkData.tagCount(); i++) {
|
||||
NBTTagCompound data = networkData.getCompoundTagAt(i);
|
||||
SoulNetwork network = SoulNetwork.fromNBT(data);
|
||||
network.setParent(this);
|
||||
soulNetworks.put(network.getPlayerId(), network);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
||||
NBTTagList networkData = new NBTTagList();
|
||||
for (SoulNetwork soulNetwork : soulNetworks.values())
|
||||
networkData.appendTag(soulNetwork.serializeNBT());
|
||||
|
||||
tagCompound.setTag("networkData", networkData);
|
||||
|
||||
return tagCompound;
|
||||
}
|
||||
}
|
211
src/main/java/WayofTime/bloodmagic/core/data/SoulNetwork.java
Normal file
211
src/main/java/WayofTime/bloodmagic/core/data/SoulNetwork.java
Normal file
|
@ -0,0 +1,211 @@
|
|||
package WayofTime.bloodmagic.core.data;
|
||||
|
||||
import WayofTime.bloodmagic.util.PleaseStopUsingMe;
|
||||
import WayofTime.bloodmagic.event.AddToNetworkEvent;
|
||||
import WayofTime.bloodmagic.event.SoulNetworkEvent;
|
||||
import WayofTime.bloodmagic.util.helper.PlayerHelper;
|
||||
import com.google.common.base.Strings;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.MobEffects;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SoulNetwork implements INBTSerializable<NBTTagCompound> {
|
||||
private BMWorldSavedData parent;
|
||||
private EntityPlayer cachedPlayer;
|
||||
private UUID playerId;
|
||||
private int currentEssence;
|
||||
private int orbTier;
|
||||
|
||||
private SoulNetwork() {
|
||||
// No-op - For creation via NBT only
|
||||
}
|
||||
|
||||
public int add(int toAdd, int maximum) {
|
||||
AddToNetworkEvent event = new AddToNetworkEvent(playerId.toString(), toAdd, maximum);
|
||||
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
return 0;
|
||||
|
||||
if (FMLCommonHandler.instance().getMinecraftServerInstance() == null)
|
||||
return 0;
|
||||
|
||||
int currEss = getCurrentEssence();
|
||||
|
||||
if (currEss >= event.maximum)
|
||||
return 0;
|
||||
|
||||
int newEss = Math.min(event.maximum, currEss + event.addedAmount);
|
||||
if (event.getResult() != Event.Result.DENY)
|
||||
setCurrentEssence(newEss);
|
||||
|
||||
return newEss - currEss;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - Please use {@link #add(int, int)}
|
||||
*/
|
||||
@Deprecated
|
||||
public int addLifeEssence(int toAdd, int maximum) {
|
||||
return add(toAdd, maximum);
|
||||
}
|
||||
|
||||
public int syphon(int syphon) {
|
||||
if (getCurrentEssence() >= syphon) {
|
||||
setCurrentEssence(getCurrentEssence() - syphon);
|
||||
return syphon;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean syphonAndDamage(EntityPlayer user, int toSyphon) {
|
||||
if (user != null) {
|
||||
if (user.getEntityWorld().isRemote)
|
||||
return false;
|
||||
|
||||
if (!Strings.isNullOrEmpty(playerId.toString())) {
|
||||
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(user, playerId.toString(), null, toSyphon);
|
||||
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
return false;
|
||||
|
||||
int drainAmount = syphon(event.syphon);
|
||||
|
||||
if (drainAmount <= 0 || event.shouldDamage)
|
||||
hurtPlayer(user, event.syphon);
|
||||
|
||||
return event.getResult() != Event.Result.DENY;
|
||||
}
|
||||
|
||||
int amount = syphon(toSyphon);
|
||||
hurtPlayer(user, toSyphon - amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void causeNausea() {
|
||||
if (getPlayer() != null)
|
||||
getPlayer().addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 99));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - Please use {@link #causeNausea()}
|
||||
*/
|
||||
@Deprecated
|
||||
public void causeNauseaToPlayer() {
|
||||
causeNausea();
|
||||
}
|
||||
|
||||
public void hurtPlayer(EntityPlayer user, float syphon) {
|
||||
if (user != null) {
|
||||
if (syphon < 100 && syphon > 0) {
|
||||
if (!user.capabilities.isCreativeMode) {
|
||||
user.hurtResistantTime = 0;
|
||||
user.attackEntityFrom(PleaseStopUsingMe.damageSource, 1.0F);
|
||||
}
|
||||
|
||||
} else if (syphon >= 100) {
|
||||
if (!user.capabilities.isCreativeMode) {
|
||||
for (int i = 0; i < ((syphon + 99) / 100); i++) {
|
||||
user.hurtResistantTime = 0;
|
||||
user.attackEntityFrom(PleaseStopUsingMe.damageSource, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void markDirty() {
|
||||
if (getParent() != null)
|
||||
getParent().markDirty();
|
||||
else
|
||||
PleaseStopUsingMe.logger.error("A SoulNetwork was created, but a parent was not set to allow saving.");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public EntityPlayer getPlayer() {
|
||||
if (cachedPlayer == null)
|
||||
cachedPlayer = PlayerHelper.getPlayerFromUUID(playerId);
|
||||
|
||||
return cachedPlayer;
|
||||
}
|
||||
|
||||
public BMWorldSavedData getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public SoulNetwork setParent(BMWorldSavedData parent) {
|
||||
this.parent = parent;
|
||||
markDirty();
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPlayer getCachedPlayer() {
|
||||
return cachedPlayer;
|
||||
}
|
||||
|
||||
public UUID getPlayerId() {
|
||||
return playerId;
|
||||
}
|
||||
|
||||
public int getCurrentEssence() {
|
||||
return currentEssence;
|
||||
}
|
||||
|
||||
public SoulNetwork setCurrentEssence(int currentEssence) {
|
||||
this.currentEssence = currentEssence;
|
||||
markDirty();
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getOrbTier() {
|
||||
return orbTier;
|
||||
}
|
||||
|
||||
public SoulNetwork setOrbTier(int orbTier) {
|
||||
this.orbTier = orbTier;
|
||||
markDirty();
|
||||
return this;
|
||||
}
|
||||
|
||||
// INBTSerializable
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeNBT() {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
tagCompound.setString("playerId", getPlayerId().toString());
|
||||
tagCompound.setInteger("currentEssence", getCurrentEssence());
|
||||
tagCompound.setInteger("orbTier", getOrbTier());
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(NBTTagCompound nbt) {
|
||||
this.playerId = UUID.fromString(nbt.getString("playerId"));
|
||||
this.currentEssence = nbt.getInteger("currentEssence");
|
||||
this.orbTier = nbt.getInteger("orbTier");
|
||||
}
|
||||
|
||||
public static SoulNetwork fromNBT(NBTTagCompound tagCompound) {
|
||||
SoulNetwork soulNetwork = new SoulNetwork();
|
||||
soulNetwork.deserializeNBT(tagCompound);
|
||||
return soulNetwork;
|
||||
}
|
||||
|
||||
public static SoulNetwork newEmpty(UUID uuid) {
|
||||
SoulNetwork network = new SoulNetwork();
|
||||
network.playerId = uuid;
|
||||
return network;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package WayofTime.bloodmagic.core.recipe;
|
||||
|
||||
import WayofTime.bloodmagic.apibutnotreally.orb.BloodOrb;
|
||||
import WayofTime.bloodmagic.apibutnotreally.orb.IBloodOrb;
|
||||
import WayofTime.bloodmagic.apibutnotreally.registry.OrbRegistry;
|
||||
import WayofTime.bloodmagic.orb.BloodOrb;
|
||||
import WayofTime.bloodmagic.orb.IBloodOrb;
|
||||
import WayofTime.bloodmagic.core.registry.OrbRegistry;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntComparators;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
|
|
|
@ -0,0 +1,350 @@
|
|||
package WayofTime.bloodmagic.core.registry;
|
||||
|
||||
import WayofTime.bloodmagic.util.ItemStackWrapper;
|
||||
import WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect;
|
||||
import WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectCrafting;
|
||||
import WayofTime.bloodmagic.alchemyArray.AlchemyCircleRenderer;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class AlchemyArrayRecipeRegistry {
|
||||
public static final AlchemyCircleRenderer DEFAULT_RENDERER = new AlchemyCircleRenderer(new ResourceLocation("bloodmagic", "textures/models/AlchemyArrays/BaseArray.png"));
|
||||
|
||||
private static BiMap<List<ItemStack>, AlchemyArrayRecipe> recipes = HashBiMap.create();
|
||||
private static HashMap<String, AlchemyArrayEffect> effectMap = new HashMap<String, AlchemyArrayEffect>();
|
||||
|
||||
/**
|
||||
* General case for creating an AlchemyArrayEffect for a given input.
|
||||
*
|
||||
* @param input - Input item(s) that is used to change the Alchemy Circle into the
|
||||
* circle that you are making
|
||||
* @param catalystStack - Catalyst item that, when right-clicked onto the array, will
|
||||
* cause an effect
|
||||
* @param arrayEffect - The effect that will be activated once the array is activated
|
||||
* @param circleRenderer - Circle rendered when the array is passive - can be substituted
|
||||
* for a special renderer
|
||||
*/
|
||||
public static void registerRecipe(List<ItemStack> input, @Nullable ItemStack catalystStack, AlchemyArrayEffect arrayEffect, AlchemyCircleRenderer circleRenderer) {
|
||||
effectMap.put(arrayEffect.getKey(), arrayEffect);
|
||||
|
||||
for (Entry<List<ItemStack>, AlchemyArrayRecipe> entry : recipes.entrySet()) {
|
||||
AlchemyArrayRecipe arrayRecipe = entry.getValue();
|
||||
if (arrayRecipe.doesInputMatchRecipe(input)) {
|
||||
AlchemyArrayEffect eff = arrayRecipe.getAlchemyArrayEffectForCatalyst(catalystStack);
|
||||
if (eff != null) {
|
||||
return; // Recipe already exists!
|
||||
} else {
|
||||
arrayRecipe.catalystMap.put(ItemStackWrapper.getHolder(catalystStack), arrayEffect);
|
||||
if (circleRenderer != null) {
|
||||
if (arrayRecipe.defaultCircleRenderer == null) {
|
||||
arrayRecipe.defaultCircleRenderer = circleRenderer;
|
||||
} else {
|
||||
arrayRecipe.circleMap.put(ItemStackWrapper.getHolder(catalystStack), circleRenderer);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
recipes.put(input, new AlchemyArrayRecipe(input, catalystStack, arrayEffect, circleRenderer == null ? DEFAULT_RENDERER : circleRenderer));
|
||||
}
|
||||
|
||||
public static AlchemyArrayEffect getAlchemyArrayEffect(String key) {
|
||||
return effectMap.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @return an array of two ItemStacks - first index is the input stack,
|
||||
* second is the catalyst stack. Returns {null, null} if no recipe
|
||||
* is valid.
|
||||
*/
|
||||
public static ItemStack[] getRecipeForArrayEffect(String key) {
|
||||
for (Entry<List<ItemStack>, AlchemyArrayRecipe> entry : recipes.entrySet()) {
|
||||
AlchemyArrayRecipe recipe = entry.getValue();
|
||||
if (recipe != null && entry.getKey().size() > 0) {
|
||||
for (Entry<ItemStackWrapper, AlchemyArrayEffect> effectEntry : recipe.catalystMap.entrySet()) {
|
||||
if (effectEntry.getValue() != null && effectEntry.getValue().key.equals(key)) {
|
||||
return new ItemStack[]{entry.getKey().get(0), effectEntry.getKey().toStack()};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ItemStack[]{null, null};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stack of the recipe
|
||||
* @return an array of two ItemStacks - first index is the input stack,
|
||||
* second is the catalyst stack. Returns {null, null} if no recipe
|
||||
* is valid.
|
||||
*/
|
||||
public static ItemStack[] getRecipeForOutputStack(ItemStack stack) {
|
||||
for (Entry<List<ItemStack>, AlchemyArrayRecipe> entry : recipes.entrySet()) {
|
||||
AlchemyArrayRecipe recipe = entry.getValue();
|
||||
if (recipe != null && entry.getKey().size() > 0) {
|
||||
for (Entry<ItemStackWrapper, AlchemyArrayEffect> effectEntry : recipe.catalystMap.entrySet()) {
|
||||
if (effectEntry.getValue() instanceof AlchemyArrayEffectCrafting) {
|
||||
AlchemyArrayEffectCrafting craftingEffect = (AlchemyArrayEffectCrafting) effectEntry.getValue();
|
||||
ItemStack resultStack = craftingEffect.outputStack;
|
||||
if (!resultStack.isEmpty()) {
|
||||
if (resultStack.getItem() == stack.getItem() && resultStack.getItemDamage() == stack.getItemDamage()) {
|
||||
return new ItemStack[]{entry.getKey().get(0), effectEntry.getKey().toStack()};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ItemStack[]{null, null};
|
||||
}
|
||||
|
||||
public static void registerCraftingRecipe(ItemStack input, ItemStack catalystStack, ItemStack outputStack, ResourceLocation arrayResource) {
|
||||
registerRecipe(input, catalystStack, new AlchemyArrayEffectCrafting(outputStack), arrayResource);
|
||||
}
|
||||
|
||||
public static void registerCraftingRecipe(List<ItemStack> inputStacks, ItemStack catalystStack, ItemStack outputStack, ResourceLocation arrayResource) {
|
||||
registerRecipe(inputStacks, catalystStack, new AlchemyArrayEffectCrafting(outputStack), arrayResource);
|
||||
}
|
||||
|
||||
public static void registerCraftingRecipe(String inputOreDict, ItemStack catalystStack, ItemStack outputStack, ResourceLocation arrayResource) {
|
||||
registerRecipe(OreDictionary.doesOreNameExist(inputOreDict) && OreDictionary.getOres(inputOreDict).size() > 0 ? OreDictionary.getOres(inputOreDict) : Collections.<ItemStack>emptyList(), catalystStack, new AlchemyArrayEffectCrafting(outputStack), arrayResource);
|
||||
}
|
||||
|
||||
public static void registerCraftingRecipe(ItemStack input, ItemStack catalystStack, ItemStack outputStack) {
|
||||
registerRecipe(input, catalystStack, new AlchemyArrayEffectCrafting(outputStack));
|
||||
}
|
||||
|
||||
public static void registerCraftingRecipe(List<ItemStack> inputStacks, ItemStack catalystStack, ItemStack outputStack) {
|
||||
registerRecipe(inputStacks, catalystStack, new AlchemyArrayEffectCrafting(outputStack));
|
||||
}
|
||||
|
||||
public static void registerCraftingRecipe(String inputOreDict, ItemStack catalystStack, ItemStack outputStack) {
|
||||
registerRecipe(OreDictionary.doesOreNameExist(inputOreDict) && OreDictionary.getOres(inputOreDict).size() > 0 ? OreDictionary.getOres(inputOreDict) : Collections.<ItemStack>emptyList(), catalystStack, new AlchemyArrayEffectCrafting(outputStack));
|
||||
}
|
||||
|
||||
public static void registerRecipe(ItemStack inputStacks, ItemStack catalystStack, AlchemyArrayEffect arrayEffect, ResourceLocation arrayResource) {
|
||||
AlchemyCircleRenderer circleRenderer = arrayResource == null ? DEFAULT_RENDERER : new AlchemyCircleRenderer(arrayResource);
|
||||
registerRecipe(Collections.singletonList(inputStacks), catalystStack, arrayEffect, circleRenderer);
|
||||
}
|
||||
|
||||
public static void registerRecipe(ItemStack inputStacks, ItemStack catalystStack, AlchemyArrayEffect arrayEffect, AlchemyCircleRenderer circleRenderer) {
|
||||
registerRecipe(Collections.singletonList(inputStacks), catalystStack, arrayEffect, circleRenderer);
|
||||
}
|
||||
|
||||
public static void registerRecipe(List<ItemStack> inputStacks, ItemStack catalystStack, AlchemyArrayEffect arrayEffect, ResourceLocation arrayResource) {
|
||||
AlchemyCircleRenderer circleRenderer = arrayResource == null ? DEFAULT_RENDERER : new AlchemyCircleRenderer(arrayResource);
|
||||
registerRecipe(inputStacks, catalystStack, arrayEffect, circleRenderer);
|
||||
}
|
||||
|
||||
public static void registerRecipe(String inputOreDict, ItemStack catalystStack, AlchemyArrayEffect arrayEffect, ResourceLocation arrayResource) {
|
||||
AlchemyCircleRenderer circleRenderer = arrayResource == null ? DEFAULT_RENDERER : new AlchemyCircleRenderer(arrayResource);
|
||||
registerRecipe(OreDictionary.doesOreNameExist(inputOreDict) && OreDictionary.getOres(inputOreDict).size() > 0 ? OreDictionary.getOres(inputOreDict) : Collections.<ItemStack>emptyList(), catalystStack, arrayEffect, circleRenderer);
|
||||
}
|
||||
|
||||
public static void registerRecipe(ItemStack input, ItemStack catalystStack, AlchemyArrayEffect arrayEffect) {
|
||||
registerRecipe(Collections.singletonList(input), catalystStack, arrayEffect, (AlchemyCircleRenderer) null);
|
||||
}
|
||||
|
||||
public static void registerRecipe(List<ItemStack> inputStacks, ItemStack catalystStack, AlchemyArrayEffect arrayEffect) {
|
||||
registerRecipe(inputStacks, catalystStack, arrayEffect, (AlchemyCircleRenderer) null);
|
||||
}
|
||||
|
||||
public static void registerRecipe(String inputOreDict, ItemStack catalystStack, AlchemyArrayEffect arrayEffect) {
|
||||
registerRecipe(OreDictionary.doesOreNameExist(inputOreDict) && OreDictionary.getOres(inputOreDict).size() > 0 ? OreDictionary.getOres(inputOreDict) : Collections.<ItemStack>emptyList(), catalystStack, arrayEffect, (AlchemyCircleRenderer) null);
|
||||
}
|
||||
|
||||
public static void replaceAlchemyCircle(List<ItemStack> input, AlchemyCircleRenderer circleRenderer) {
|
||||
if (circleRenderer == null)
|
||||
return;
|
||||
|
||||
for (Entry<List<ItemStack>, AlchemyArrayRecipe> entry : recipes.entrySet()) {
|
||||
AlchemyArrayRecipe arrayRecipe = entry.getValue();
|
||||
if (arrayRecipe.doesInputMatchRecipe(input))
|
||||
arrayRecipe.defaultCircleRenderer = circleRenderer;
|
||||
}
|
||||
}
|
||||
|
||||
public static AlchemyArrayRecipe getRecipeForInput(List<ItemStack> input) {
|
||||
return recipes.get(input);
|
||||
}
|
||||
|
||||
public static AlchemyArrayEffect getAlchemyArrayEffect(List<ItemStack> input, @Nullable ItemStack catalystStack) {
|
||||
for (Entry<List<ItemStack>, AlchemyArrayRecipe> entry : recipes.entrySet()) {
|
||||
AlchemyArrayRecipe arrayRecipe = entry.getValue();
|
||||
if (input.size() == 1 && arrayRecipe.getInput().size() == 1) {
|
||||
if (ItemStack.areItemsEqual(input.get(0), arrayRecipe.input.get(0))) {
|
||||
AlchemyArrayEffect effect = arrayRecipe.getAlchemyArrayEffectForCatalyst(catalystStack);
|
||||
if (effect != null) {
|
||||
return effect.getNewCopy();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (input.equals(arrayRecipe.getInput())) {
|
||||
AlchemyArrayEffect effect = arrayRecipe.getAlchemyArrayEffectForCatalyst(catalystStack);
|
||||
if (effect != null) {
|
||||
return effect.getNewCopy();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AlchemyArrayEffect getAlchemyArrayEffect(ItemStack input, @Nullable ItemStack catalystStack) {
|
||||
return getAlchemyArrayEffect(Collections.singletonList(input), catalystStack);
|
||||
}
|
||||
|
||||
public static AlchemyCircleRenderer getAlchemyCircleRenderer(List<ItemStack> input, @Nullable ItemStack catalystStack) {
|
||||
for (Entry<List<ItemStack>, AlchemyArrayRecipe> entry : recipes.entrySet()) {
|
||||
AlchemyArrayRecipe arrayRecipe = entry.getValue();
|
||||
if (arrayRecipe.doesInputMatchRecipe(input)) {
|
||||
return arrayRecipe.getAlchemyArrayRendererForCatalyst(catalystStack);
|
||||
}
|
||||
}
|
||||
|
||||
return DEFAULT_RENDERER;
|
||||
}
|
||||
|
||||
public static AlchemyCircleRenderer getAlchemyCircleRenderer(ItemStack itemStack, @Nullable ItemStack catalystStack) {
|
||||
return getAlchemyCircleRenderer(Collections.singletonList(itemStack), catalystStack);
|
||||
}
|
||||
|
||||
public static BiMap<List<ItemStack>, AlchemyArrayRecipe> getRecipes() {
|
||||
return HashBiMap.create(recipes);
|
||||
}
|
||||
|
||||
public static class AlchemyArrayRecipe {
|
||||
public final List<ItemStack> input;
|
||||
public final BiMap<ItemStackWrapper, AlchemyArrayEffect> catalystMap = HashBiMap.create();
|
||||
public final BiMap<ItemStackWrapper, AlchemyCircleRenderer> circleMap = HashBiMap.create();
|
||||
public AlchemyCircleRenderer defaultCircleRenderer;
|
||||
|
||||
private AlchemyArrayRecipe(List<ItemStack> input, ItemStack catalystStack, AlchemyArrayEffect arrayEffect, AlchemyCircleRenderer circleRenderer, boolean useless) {
|
||||
this.input = input;
|
||||
|
||||
catalystMap.put(ItemStackWrapper.getHolder(catalystStack), arrayEffect);
|
||||
|
||||
this.defaultCircleRenderer = circleRenderer;
|
||||
}
|
||||
|
||||
public AlchemyArrayRecipe(ItemStack inputStack, ItemStack catalystStack, AlchemyArrayEffect arrayEffect, AlchemyCircleRenderer circleRenderer) {
|
||||
this(Collections.singletonList(inputStack), catalystStack, arrayEffect, circleRenderer, false);
|
||||
}
|
||||
|
||||
public AlchemyArrayRecipe(String inputOreDict, ItemStack catalystStack, AlchemyArrayEffect arrayEffect, AlchemyCircleRenderer circleRenderer) {
|
||||
this(OreDictionary.doesOreNameExist(inputOreDict) && OreDictionary.getOres(inputOreDict).size() > 0 ? OreDictionary.getOres(inputOreDict) : Collections.<ItemStack>emptyList(), catalystStack, arrayEffect, circleRenderer, false);
|
||||
}
|
||||
|
||||
public AlchemyArrayRecipe(List<ItemStack> inputStacks, ItemStack catalystStack, AlchemyArrayEffect arrayEffect, AlchemyCircleRenderer circleRenderer) {
|
||||
this(inputStacks, catalystStack, arrayEffect, circleRenderer, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the inputed list of ItemStacks to see if it matches with the
|
||||
* recipe's list.
|
||||
*
|
||||
* @param comparedList - The list to compare with
|
||||
* @return - True if the ItemStack(s) is a compatible item
|
||||
*/
|
||||
public boolean doesInputMatchRecipe(List<ItemStack> comparedList) {
|
||||
return !(comparedList == null || this.input == null) && (this.input.size() == 1 && comparedList.size() == 1 ? this.input.get(0).isItemEqual(comparedList.get(0)) : this.input.equals(comparedList));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the actual AlchemyArrayEffect for the given catalyst.
|
||||
*
|
||||
* @param comparedStack The catalyst that is being checked
|
||||
* @return - The effect
|
||||
*/
|
||||
public AlchemyArrayEffect getAlchemyArrayEffectForCatalyst(@Nullable ItemStack comparedStack) {
|
||||
for (Entry<ItemStackWrapper, AlchemyArrayEffect> entry : catalystMap.entrySet()) {
|
||||
ItemStack catalystStack = entry.getKey().toStack();
|
||||
|
||||
if (comparedStack == null && catalystStack == null)
|
||||
return entry.getValue();
|
||||
|
||||
if (comparedStack == null || catalystStack == null)
|
||||
continue;
|
||||
|
||||
if (catalystStack.isItemEqual(comparedStack))
|
||||
return entry.getValue();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public AlchemyCircleRenderer getAlchemyArrayRendererForCatalyst(@Nullable ItemStack comparedStack) {
|
||||
for (Entry<ItemStackWrapper, AlchemyCircleRenderer> entry : circleMap.entrySet()) {
|
||||
ItemStack catalystStack = entry.getKey().toStack();
|
||||
|
||||
if (comparedStack == null && catalystStack == null)
|
||||
return entry.getValue();
|
||||
|
||||
if (comparedStack == null || catalystStack == null)
|
||||
continue;
|
||||
|
||||
if (catalystStack.isItemEqual(comparedStack))
|
||||
return entry.getValue();
|
||||
}
|
||||
|
||||
return defaultCircleRenderer;
|
||||
}
|
||||
|
||||
public AlchemyCircleRenderer getDefaultCircleRenderer() {
|
||||
return defaultCircleRenderer;
|
||||
}
|
||||
|
||||
public List<ItemStack> getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
public BiMap<ItemStackWrapper, AlchemyArrayEffect> getCatalystMap() {
|
||||
return catalystMap;
|
||||
}
|
||||
|
||||
public BiMap<ItemStackWrapper, AlchemyCircleRenderer> getCircleMap() {
|
||||
return circleMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof AlchemyArrayRecipe)) return false;
|
||||
|
||||
AlchemyArrayRecipe that = (AlchemyArrayRecipe) o;
|
||||
|
||||
if (defaultCircleRenderer != null ? !defaultCircleRenderer.equals(that.defaultCircleRenderer) : that.defaultCircleRenderer != null)
|
||||
return false;
|
||||
if (input != null ? !input.equals(that.input) : that.input != null) return false;
|
||||
if (catalystMap != null ? !catalystMap.equals(that.catalystMap) : that.catalystMap != null) return false;
|
||||
return circleMap != null ? circleMap.equals(that.circleMap) : that.circleMap == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = defaultCircleRenderer != null ? defaultCircleRenderer.hashCode() : 0;
|
||||
result = 31 * result + (input != null ? input.hashCode() : 0);
|
||||
result = 31 * result + (catalystMap != null ? catalystMap.hashCode() : 0);
|
||||
result = 31 * result + (circleMap != null ? circleMap.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package WayofTime.bloodmagic.core.registry;
|
||||
|
||||
import WayofTime.bloodmagic.recipe.AlchemyTableRecipe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AlchemyTableRecipeRegistry {
|
||||
private static List<AlchemyTableRecipe> recipeList = new ArrayList<AlchemyTableRecipe>();
|
||||
|
||||
public static void registerRecipe(AlchemyTableRecipe recipe) {
|
||||
recipeList.add(recipe);
|
||||
}
|
||||
|
||||
public static void registerRecipe(ItemStack outputStack, int lpDrained, int ticksRequired, int tierRequired, Object... objects) {
|
||||
registerRecipe(new AlchemyTableRecipe(outputStack, lpDrained, ticksRequired, tierRequired, objects));
|
||||
}
|
||||
|
||||
public static void removeRecipe(AlchemyTableRecipe recipe) {
|
||||
recipeList.remove(recipe);
|
||||
}
|
||||
|
||||
public static AlchemyTableRecipe getMatchingRecipe(List<ItemStack> itemList, World world, BlockPos pos) {
|
||||
for (AlchemyTableRecipe recipe : recipeList) {
|
||||
if (recipe.matches(itemList, world, pos)) {
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<AlchemyTableRecipe> getRecipeList() {
|
||||
return new ArrayList<AlchemyTableRecipe>(recipeList);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,215 @@
|
|||
package WayofTime.bloodmagic.core.registry;
|
||||
|
||||
import WayofTime.bloodmagic.util.PleaseStopUsingMe;
|
||||
import WayofTime.bloodmagic.util.ItemStackWrapper;
|
||||
import WayofTime.bloodmagic.altar.EnumAltarTier;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AltarRecipeRegistry {
|
||||
private static BiMap<List<ItemStackWrapper>, AltarRecipe> recipes = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* Registers an {@link AltarRecipe} for the Blood Altar. This can be a
|
||||
* {@code ItemStack}, {@code List<Itemstack>}, or {@code String}
|
||||
* OreDictionary entry.
|
||||
* <p>
|
||||
* If the OreDictionary entry does not exist or is empty, it will not be
|
||||
* registered.
|
||||
*
|
||||
* @param altarRecipe - The AltarRecipe to register
|
||||
*/
|
||||
public static void registerRecipe(AltarRecipe altarRecipe) {
|
||||
if (!recipes.containsValue(altarRecipe) && altarRecipe.getInput().size() > 0)
|
||||
recipes.put(altarRecipe.getInput(), altarRecipe);
|
||||
else
|
||||
PleaseStopUsingMe.logger.error("Error adding altar recipe for input [{}].", altarRecipe.toString());
|
||||
}
|
||||
|
||||
public static void registerFillRecipe(ItemStack orbStack, EnumAltarTier tier, int maxForOrb, int consumeRate, int drainRate) {
|
||||
registerRecipe(new AltarRecipe(orbStack, orbStack, tier, maxForOrb, consumeRate, drainRate, true));
|
||||
}
|
||||
|
||||
public static void removeRecipe(AltarRecipe altarRecipe) {
|
||||
recipes.remove(altarRecipe.getInput());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the recipe that the provided input is registered to.
|
||||
*
|
||||
* @param input - The input ItemStack to get the recipe for
|
||||
* @return - The recipe that the provided input is registered to.
|
||||
*/
|
||||
public static AltarRecipe getRecipeForInput(List<ItemStack> input) {
|
||||
List<ItemStackWrapper> wrapperList = ItemStackWrapper.toWrapperList(input);
|
||||
if (recipes.keySet().contains(wrapperList))
|
||||
return recipes.get(wrapperList);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//TODO: Determine a more time-effective method
|
||||
public static AltarRecipe getRecipeForInput(ItemStack input) {
|
||||
for (AltarRecipe recipe : recipes.values()) {
|
||||
if (recipe.doesRequiredItemMatch(input, recipe.getMinTier())) {
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AltarRecipe getRecipeForInput(String input) {
|
||||
return getRecipeForInput(OreDictionary.getOres(input));
|
||||
}
|
||||
|
||||
public static BiMap<List<ItemStackWrapper>, AltarRecipe> getRecipes() {
|
||||
return HashBiMap.create(recipes);
|
||||
}
|
||||
|
||||
public static class AltarRecipe {
|
||||
private final List<ItemStackWrapper> input;
|
||||
private final ItemStack output;
|
||||
private final EnumAltarTier minTier;
|
||||
private final int syphon, consumeRate, drainRate;
|
||||
private final boolean fillable;
|
||||
|
||||
/**
|
||||
* 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 fillable - Whether the input item can be filled with LP. IE: Orbs
|
||||
*/
|
||||
public AltarRecipe(List<ItemStack> input, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean fillable) {
|
||||
this.input = ItemStackWrapper.toWrapperList(input);
|
||||
this.output = output;
|
||||
this.minTier = minTier;
|
||||
this.syphon = syphon < 0 ? -syphon : syphon;
|
||||
this.consumeRate = consumeRate < 0 ? -consumeRate : consumeRate;
|
||||
this.drainRate = drainRate < 0 ? -drainRate : drainRate;
|
||||
this.fillable = fillable;
|
||||
}
|
||||
|
||||
public AltarRecipe(List<ItemStack> input, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate) {
|
||||
this(input, output, minTier, syphon, consumeRate, drainRate, false);
|
||||
}
|
||||
|
||||
public AltarRecipe(ItemStack input, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean fillable) {
|
||||
this(Collections.singletonList(input), output, minTier, syphon, consumeRate, drainRate, fillable);
|
||||
}
|
||||
|
||||
public AltarRecipe(ItemStack input, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate) {
|
||||
this(Collections.singletonList(input), output, minTier, syphon, consumeRate, drainRate, false);
|
||||
}
|
||||
|
||||
public AltarRecipe(String inputEntry, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean fillable) {
|
||||
this(OreDictionary.doesOreNameExist(inputEntry) && OreDictionary.getOres(inputEntry).size() > 0 ? OreDictionary.getOres(inputEntry) : Collections.<ItemStack>emptyList(), output, minTier, syphon, consumeRate, drainRate, fillable);
|
||||
}
|
||||
|
||||
public AltarRecipe(String inputEntry, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate) {
|
||||
this(OreDictionary.doesOreNameExist(inputEntry) && OreDictionary.getOres(inputEntry).size() > 0 ? OreDictionary.getOres(inputEntry) : Collections.<ItemStack>emptyList(), output, minTier, syphon, consumeRate, drainRate, false);
|
||||
}
|
||||
|
||||
public boolean doesRequiredItemMatch(ItemStack comparedStack, EnumAltarTier tierCheck) {
|
||||
if (comparedStack == null || this.input == null)
|
||||
return false;
|
||||
|
||||
if (tierCheck.ordinal() < minTier.ordinal())
|
||||
return false;
|
||||
|
||||
for (ItemStackWrapper stack : input) {
|
||||
if (comparedStack.isItemEqual(stack.toStack()))
|
||||
return true;
|
||||
|
||||
if (comparedStack.getItem() == stack.item && stack.meta == OreDictionary.WILDCARD_VALUE)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<ItemStackWrapper> getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
public ItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
public EnumAltarTier getMinTier() {
|
||||
return minTier;
|
||||
}
|
||||
|
||||
public int getSyphon() {
|
||||
return syphon;
|
||||
}
|
||||
|
||||
public int getConsumeRate() {
|
||||
return consumeRate;
|
||||
}
|
||||
|
||||
public int getDrainRate() {
|
||||
return drainRate;
|
||||
}
|
||||
|
||||
public boolean isFillable() {
|
||||
return fillable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof AltarRecipe)) return false;
|
||||
|
||||
AltarRecipe that = (AltarRecipe) o;
|
||||
|
||||
if (syphon != that.syphon) return false;
|
||||
if (consumeRate != that.consumeRate) return false;
|
||||
if (drainRate != that.drainRate) return false;
|
||||
if (fillable != that.fillable) return false;
|
||||
if (input != null ? !input.equals(that.input) : that.input != null) return false;
|
||||
if (output != null ? !output.equals(that.output) : that.output != null) return false;
|
||||
return minTier == that.minTier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = input != null ? input.hashCode() : 0;
|
||||
result = 31 * result + (output != null ? output.hashCode() : 0);
|
||||
result = 31 * result + (minTier != null ? minTier.hashCode() : 0);
|
||||
result = 31 * result + syphon;
|
||||
result = 31 * result + consumeRate;
|
||||
result = 31 * result + drainRate;
|
||||
result = 31 * result + (fillable ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("input", input)
|
||||
.append("output", output)
|
||||
.append("minTier", minTier)
|
||||
.append("syphon", syphon)
|
||||
.append("consumeRate", consumeRate)
|
||||
.append("drainRate", drainRate)
|
||||
.append("fillable", fillable)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package WayofTime.bloodmagic.core.registry;
|
||||
|
||||
import WayofTime.bloodmagic.util.BlockStack;
|
||||
import WayofTime.bloodmagic.iface.IHarvestHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockStem;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class HarvestRegistry {
|
||||
private static List<IHarvestHandler> handlerList = new ArrayList<IHarvestHandler>();
|
||||
private static Map<Block, Integer> standardCrops = new HashMap<Block, Integer>();
|
||||
private static Set<BlockStack> tallCrops = new HashSet<BlockStack>();
|
||||
private static Map<BlockStack, BlockStack> stemCrops = new HashMap<BlockStack, BlockStack>();
|
||||
private static Map<BlockStack, Integer> amplifierMap = new HashMap<BlockStack, Integer>();
|
||||
|
||||
/**
|
||||
* Registers a handler for the Harvest Ritual to call.
|
||||
*
|
||||
* @param handler - The custom handler to register
|
||||
*/
|
||||
public static void registerHandler(IHarvestHandler handler) {
|
||||
if (!handlerList.contains(handler))
|
||||
handlerList.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a standard crop (IE: Wheat, Carrots, Potatoes, Netherwart, etc)
|
||||
* for the
|
||||
* {@link WayofTime.bloodmagic.ritual.harvest.HarvestHandlerPlantable}
|
||||
* handler to handle.
|
||||
*
|
||||
* @param crop - The crop block to handle.
|
||||
* @param matureMeta - The meta value at which the crop is considered mature and ready
|
||||
* to be harvested.
|
||||
*/
|
||||
public static void registerStandardCrop(Block crop, int matureMeta) {
|
||||
if (!standardCrops.containsKey(crop))
|
||||
standardCrops.put(crop, matureMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a tall crop (Sugar Cane and Cactus) for the
|
||||
* {@link WayofTime.bloodmagic.ritual.harvest.HarvestHandlerTall} handler to
|
||||
* handle.
|
||||
*
|
||||
* @param crop - The crop block to handle.
|
||||
*/
|
||||
public static void registerTallCrop(BlockStack crop) {
|
||||
if (!tallCrops.contains(crop))
|
||||
tallCrops.add(crop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a stem crop (Melon and Pumpkin) for the
|
||||
* {@link WayofTime.bloodmagic.ritual.harvest.HarvestHandlerStem} handler to
|
||||
* handle.
|
||||
* <p>
|
||||
* Use {@link net.minecraftforge.oredict.OreDictionary#WILDCARD_VALUE} to
|
||||
* accept any meta for the crop block.
|
||||
* <p>
|
||||
* The Stem must be instanceof {@link BlockStem}
|
||||
*
|
||||
* @param crop - The crop block to handle.
|
||||
* @param stem - The stem of the crop
|
||||
*/
|
||||
public static void registerStemCrop(BlockStack crop, BlockStack stem) {
|
||||
if (!stemCrops.containsKey(crop) && stem.getBlock() instanceof BlockStem)
|
||||
stemCrops.put(stem, crop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a range amplifier for the Harvest Ritual.
|
||||
*
|
||||
* @param blockStack - The block for the amplifier.
|
||||
* @param range - The range the amplifier provides.
|
||||
*/
|
||||
public static void registerRangeAmplifier(BlockStack blockStack, int range) {
|
||||
if (!amplifierMap.containsKey(blockStack))
|
||||
amplifierMap.put(blockStack, range);
|
||||
}
|
||||
|
||||
public static List<IHarvestHandler> getHandlerList() {
|
||||
return new ArrayList<IHarvestHandler>(handlerList);
|
||||
}
|
||||
|
||||
public static Map<Block, Integer> getStandardCrops() {
|
||||
return new HashMap<Block, Integer>(standardCrops);
|
||||
}
|
||||
|
||||
public static Set<BlockStack> getTallCrops() {
|
||||
return new HashSet<BlockStack>(tallCrops);
|
||||
}
|
||||
|
||||
public static Map<BlockStack, BlockStack> getStemCrops() {
|
||||
return new HashMap<BlockStack, BlockStack>(stemCrops);
|
||||
}
|
||||
|
||||
public static Map<BlockStack, Integer> getAmplifierMap() {
|
||||
return new HashMap<BlockStack, Integer>(amplifierMap);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package WayofTime.bloodmagic.core.registry;
|
||||
|
||||
import WayofTime.bloodmagic.util.BlockStack;
|
||||
import WayofTime.bloodmagic.util.PleaseStopUsingMe;
|
||||
import WayofTime.bloodmagic.ritual.data.imperfect.ImperfectRitual;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ImperfectRitualRegistry {
|
||||
public static final Map<ImperfectRitual, Boolean> enabledRituals = new HashMap<ImperfectRitual, Boolean>();
|
||||
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, boolean enabled) {
|
||||
if (imperfectRitual != null) {
|
||||
if (registry.containsKey(id))
|
||||
PleaseStopUsingMe.logger.error("Duplicate imperfect ritual id: %s", id);
|
||||
else {
|
||||
registry.put(id, imperfectRitual);
|
||||
enabledRituals.put(imperfectRitual, enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerRitual(ImperfectRitual imperfectRitual, String id) {
|
||||
registerRitual(imperfectRitual, id, true);
|
||||
}
|
||||
|
||||
public static void registerRitual(ImperfectRitual imperfectRitual, boolean enabled) {
|
||||
registerRitual(imperfectRitual, imperfectRitual.getName(), enabled);
|
||||
}
|
||||
|
||||
public static void registerRitual(ImperfectRitual imperfectRitual) {
|
||||
registerRitual(imperfectRitual, imperfectRitual.getName());
|
||||
}
|
||||
|
||||
public static ImperfectRitual getRitualForBlock(BlockStack blockStack) {
|
||||
for (ImperfectRitual imperfectRitual : getRegistry().values())
|
||||
if (imperfectRitual.getRequiredBlock().equals(blockStack))
|
||||
return imperfectRitual;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
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) {
|
||||
try {
|
||||
return enabledRituals.get(imperfectRitual);
|
||||
} catch (NullPointerException e) {
|
||||
PleaseStopUsingMe.logger.error("Invalid Imperfect Ritual was called");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean ritualEnabled(String id) {
|
||||
return ritualEnabled(getRitualForId(id));
|
||||
}
|
||||
|
||||
public static BiMap<String, ImperfectRitual> getRegistry() {
|
||||
return HashBiMap.create(registry);
|
||||
}
|
||||
|
||||
public static BiMap<ImperfectRitual, Boolean> getEnabledMap() {
|
||||
return HashBiMap.create(enabledRituals);
|
||||
}
|
||||
|
||||
public static ArrayList<String> getIds() {
|
||||
return new ArrayList<String>(registry.keySet());
|
||||
}
|
||||
|
||||
public static ArrayList<ImperfectRitual> getRituals() {
|
||||
return new ArrayList<ImperfectRitual>(registry.values());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package WayofTime.bloodmagic.core.registry;
|
||||
|
||||
import WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade;
|
||||
import WayofTime.bloodmagic.recipe.LivingArmourDowngradeRecipe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class LivingArmourDowngradeRecipeRegistry {
|
||||
private static List<LivingArmourDowngradeRecipe> recipeList = new ArrayList<LivingArmourDowngradeRecipe>();
|
||||
private static Map<ItemStack, Map<Integer, List<ITextComponent>>> dialogueMap = new HashMap<ItemStack, Map<Integer, List<ITextComponent>>>();
|
||||
|
||||
public static void registerRecipe(LivingArmourDowngradeRecipe recipe) {
|
||||
recipeList.add(recipe);
|
||||
}
|
||||
|
||||
public static void registerDialog(ItemStack keyStack, Map<Integer, List<ITextComponent>> map) {
|
||||
dialogueMap.put(keyStack, map);
|
||||
}
|
||||
|
||||
public static List<ITextComponent> getDialogForProcessTick(ItemStack keyStack, int tick) {
|
||||
for (Entry<ItemStack, Map<Integer, List<ITextComponent>>> entry : dialogueMap.entrySet()) {
|
||||
ItemStack key = entry.getKey();
|
||||
if (OreDictionary.itemMatches(key, keyStack, false)) {
|
||||
Map<Integer, List<ITextComponent>> map = entry.getValue();
|
||||
if (map.containsKey(tick)) {
|
||||
return map.get(tick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void registerRecipe(LivingArmourUpgrade upgrade, ItemStack keyStack, Object... recipe) {
|
||||
registerRecipe(new LivingArmourDowngradeRecipe(upgrade, keyStack, recipe));
|
||||
}
|
||||
|
||||
public static LivingArmourDowngradeRecipe getMatchingRecipe(ItemStack keyStack, List<ItemStack> itemList, World world, BlockPos pos) {
|
||||
for (LivingArmourDowngradeRecipe recipe : recipeList) {
|
||||
if (recipe.matches(keyStack, itemList, world, pos)) {
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<LivingArmourDowngradeRecipe> getRecipeList() {
|
||||
return new ArrayList<LivingArmourDowngradeRecipe>(recipeList);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package WayofTime.bloodmagic.core.registry;
|
||||
|
||||
import WayofTime.bloodmagic.altar.EnumAltarTier;
|
||||
import WayofTime.bloodmagic.orb.BloodOrb;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
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.
|
||||
*/
|
||||
@Deprecated
|
||||
public class OrbRegistry {
|
||||
@GameRegistry.ObjectHolder("bloodmagic:blood_orb")
|
||||
private static final Item ORB_ITEM = null;
|
||||
public static ArrayListMultimap<Integer, ItemStack> tierMap = ArrayListMultimap.create();
|
||||
private static List<BloodOrb> orbs = new ArrayList<BloodOrb>();
|
||||
|
||||
public static List<ItemStack> getOrbsForTier(int tier) {
|
||||
if (getTierMap().containsKey(tier))
|
||||
return getTierMap().get(tier);
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public static List<ItemStack> getOrbsUpToTier(int tier) {
|
||||
List<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
|
||||
for (int i = 1; i <= tier; i++)
|
||||
ret.addAll(getOrbsForTier(i));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<ItemStack> getOrbsDownToTier(int tier) {
|
||||
List<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
|
||||
for (int i = EnumAltarTier.MAXTIERS; i >= tier; i--)
|
||||
ret.addAll(getOrbsForTier(i));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ItemStack getOrbStack(BloodOrb orb) {
|
||||
ItemStack ret = new ItemStack(ORB_ITEM);
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setString("orb", orb.getRegistryName().toString());
|
||||
ret.setTagCompound(tag);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ArrayListMultimap<Integer, ItemStack> getTierMap() {
|
||||
return ArrayListMultimap.create(tierMap);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
package WayofTime.bloodmagic.core.registry;
|
||||
|
||||
import WayofTime.bloodmagic.util.PleaseStopUsingMe;
|
||||
import WayofTime.bloodmagic.ritual.data.Ritual;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
public class RitualRegistry {
|
||||
public static final Map<Ritual, Boolean> enabledRituals = new HashMap<Ritual, Boolean>();
|
||||
private static final BiMap<String, Ritual> registry = HashBiMap.create();
|
||||
private static final List<String> lookupList = new ArrayList<String>();
|
||||
/**
|
||||
* Ordered list for actions that depend on the order that the rituals were
|
||||
* registered in
|
||||
*/
|
||||
private static final ArrayList<String> orderedIdList = new ArrayList<String>();
|
||||
|
||||
private static boolean locked;
|
||||
|
||||
/**
|
||||
* 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, boolean enabled) {
|
||||
if (locked) {
|
||||
PleaseStopUsingMe.logger.error("This registry has been locked. Please register your ritual earlier.");
|
||||
PleaseStopUsingMe.logger.error("If you reflect this, I will hunt you down. - TehNut");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ritual != null) {
|
||||
if (registry.containsKey(id))
|
||||
PleaseStopUsingMe.logger.error("Duplicate ritual id: %s", id);
|
||||
else {
|
||||
registry.put(id, ritual);
|
||||
enabledRituals.put(ritual, enabled);
|
||||
orderedIdList.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerRitual(Ritual ritual, boolean enabled) {
|
||||
registerRitual(ritual, ritual.getName(), enabled);
|
||||
}
|
||||
|
||||
public static void registerRitual(Ritual ritual, String id) {
|
||||
registerRitual(ritual, id, true);
|
||||
}
|
||||
|
||||
public static void registerRitual(Ritual ritual) {
|
||||
registerRitual(ritual, ritual.getName());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Ritual getRitualForId(String id) {
|
||||
Ritual ritual = registry.get(id);
|
||||
return ritual != null ? ritual.getNewCopy() : null;
|
||||
}
|
||||
|
||||
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) {
|
||||
try {
|
||||
return enabledRituals.get(ritual);
|
||||
} catch (NullPointerException e) {
|
||||
PleaseStopUsingMe.logger.error("Invalid Ritual was called");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean ritualEnabled(String id) {
|
||||
return ritualEnabled(getRitualForId(id));
|
||||
}
|
||||
|
||||
public static BiMap<String, Ritual> getRegistry() {
|
||||
return HashBiMap.create(registry);
|
||||
}
|
||||
|
||||
public static Map<Ritual, Boolean> getEnabledMap() {
|
||||
return new HashMap<Ritual, Boolean>(enabledRituals);
|
||||
}
|
||||
|
||||
public static ArrayList<String> getIds() {
|
||||
return new ArrayList<String>(lookupList);
|
||||
}
|
||||
|
||||
public static ArrayList<String> getOrderedIds() {
|
||||
return orderedIdList;
|
||||
}
|
||||
|
||||
public static ArrayList<Ritual> getRituals() {
|
||||
return new ArrayList<Ritual>(registry.values());
|
||||
}
|
||||
|
||||
public static void orderLookupList() {
|
||||
locked = true; // Lock registry so no no rituals can be registered
|
||||
lookupList.clear(); // Make sure it's empty
|
||||
lookupList.addAll(registry.keySet());
|
||||
Collections.sort(lookupList, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
Ritual ritual1 = registry.get(o1);
|
||||
Ritual ritual2 = registry.get(o2);
|
||||
return ritual1.getComponents().size() > ritual2.getComponents().size() ? -1 : 0; // Put earlier if bigger
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package WayofTime.bloodmagic.core.registry;
|
||||
|
||||
import WayofTime.bloodmagic.recipe.TartaricForgeRecipe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TartaricForgeRecipeRegistry {
|
||||
private static List<TartaricForgeRecipe> recipeList = new ArrayList<TartaricForgeRecipe>();
|
||||
|
||||
public static void registerRecipe(TartaricForgeRecipe recipe) {
|
||||
recipeList.add(recipe);
|
||||
}
|
||||
|
||||
public static void registerRecipe(ItemStack outputStack, double minimulSouls, double drain, Object... objects) {
|
||||
registerRecipe(new TartaricForgeRecipe(outputStack, minimulSouls, drain, objects));
|
||||
}
|
||||
|
||||
public static void removeRecipe(TartaricForgeRecipe recipe) {
|
||||
recipeList.remove(recipe);
|
||||
}
|
||||
|
||||
public static TartaricForgeRecipe getMatchingRecipe(List<ItemStack> itemList, World world, BlockPos pos) {
|
||||
for (TartaricForgeRecipe recipe : recipeList) {
|
||||
if (recipe.matches(itemList, world, pos)) {
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<TartaricForgeRecipe> getRecipeList() {
|
||||
return new ArrayList<TartaricForgeRecipe>(recipeList);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue