2016-05-14 13:51:18 +02:00
|
|
|
package de.ellpeck.actuallyadditions.mod.misc;
|
2016-01-05 04:47:35 +01:00
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
|
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
|
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
|
|
|
|
import de.ellpeck.actuallyadditions.api.internal.IEntrySet;
|
|
|
|
import de.ellpeck.actuallyadditions.api.internal.IMethodHandler;
|
|
|
|
import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.booklet.entry.EntrySet;
|
2016-01-05 04:47:35 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.potion.Potion;
|
2016-01-05 04:47:35 +01:00
|
|
|
import net.minecraft.potion.PotionEffect;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
public class MethodHandler implements IMethodHandler{
|
2016-01-05 04:47:35 +01:00
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
@Override
|
|
|
|
public boolean addEffectToStack(ItemStack stack, CoffeeIngredient ingredient){
|
2016-01-05 04:47:35 +01:00
|
|
|
boolean worked = false;
|
|
|
|
if(ingredient != null){
|
|
|
|
PotionEffect[] effects = ingredient.getEffects();
|
|
|
|
if(effects != null && effects.length > 0){
|
|
|
|
for(PotionEffect effect : effects){
|
2016-05-14 13:51:18 +02:00
|
|
|
PotionEffect effectHas = this.getSameEffectFromStack(stack, effect);
|
2016-01-05 04:47:35 +01:00
|
|
|
if(effectHas != null){
|
|
|
|
if(effectHas.getAmplifier() < ingredient.maxAmplifier-1){
|
2016-05-14 13:51:18 +02:00
|
|
|
this.addEffectProperties(stack, effect, false, true);
|
2016-01-05 04:47:35 +01:00
|
|
|
worked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2016-05-14 13:51:18 +02:00
|
|
|
this.addEffectToStack(stack, effect);
|
2016-01-05 04:47:35 +01:00
|
|
|
worked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return worked;
|
|
|
|
}
|
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
@Override
|
|
|
|
public PotionEffect getSameEffectFromStack(ItemStack stack, PotionEffect effect){
|
|
|
|
PotionEffect[] effectsStack = this.getEffectsFromStack(stack);
|
2016-01-05 04:47:35 +01:00
|
|
|
if(effectsStack != null && effectsStack.length > 0){
|
|
|
|
for(PotionEffect effectStack : effectsStack){
|
2016-03-18 23:47:22 +01:00
|
|
|
if(effect.getPotion() == effectStack.getPotion()){
|
2016-01-05 04:47:35 +01:00
|
|
|
return effectStack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
@Override
|
|
|
|
public void addEffectProperties(ItemStack stack, PotionEffect effect, boolean addDur, boolean addAmp){
|
|
|
|
PotionEffect[] effects = this.getEffectsFromStack(stack);
|
2016-01-05 04:47:35 +01:00
|
|
|
stack.setTagCompound(new NBTTagCompound());
|
|
|
|
for(int i = 0; i < effects.length; i++){
|
2016-03-18 23:47:22 +01:00
|
|
|
if(effects[i].getPotion() == effect.getPotion()){
|
|
|
|
effects[i] = new PotionEffect(effects[i].getPotion(), effects[i].getDuration()+(addDur ? effect.getDuration() : 0), effects[i].getAmplifier()+(addAmp ? (effect.getAmplifier() > 0 ? effect.getAmplifier() : 1) : 0));
|
2016-01-05 04:47:35 +01:00
|
|
|
}
|
2016-05-14 13:51:18 +02:00
|
|
|
this.addEffectToStack(stack, effects[i]);
|
2016-01-05 04:47:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
@Override
|
|
|
|
public void addEffectToStack(ItemStack stack, PotionEffect effect){
|
2016-01-05 04:47:35 +01:00
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
if(tag == null){
|
|
|
|
tag = new NBTTagCompound();
|
|
|
|
}
|
|
|
|
|
|
|
|
int prevCounter = tag.getInteger("Counter");
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
2016-03-18 23:47:22 +01:00
|
|
|
compound.setInteger("ID", Potion.getIdFromPotion(effect.getPotion()));
|
2016-01-05 04:47:35 +01:00
|
|
|
compound.setInteger("Duration", effect.getDuration());
|
|
|
|
compound.setInteger("Amplifier", effect.getAmplifier());
|
|
|
|
|
|
|
|
int counter = prevCounter+1;
|
|
|
|
tag.setTag(counter+"", compound);
|
|
|
|
tag.setInteger("Counter", counter);
|
|
|
|
|
|
|
|
stack.setTagCompound(tag);
|
|
|
|
}
|
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
@Override
|
|
|
|
public PotionEffect[] getEffectsFromStack(ItemStack stack){
|
2016-01-05 04:47:35 +01:00
|
|
|
ArrayList<PotionEffect> effects = new ArrayList<PotionEffect>();
|
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
if(tag != null){
|
|
|
|
int counter = tag.getInteger("Counter");
|
|
|
|
while(counter > 0){
|
|
|
|
NBTTagCompound compound = (NBTTagCompound)tag.getTag(counter+"");
|
2016-03-18 23:47:22 +01:00
|
|
|
PotionEffect effect = new PotionEffect(Potion.getPotionById(compound.getInteger("ID")), compound.getInteger("Duration"), compound.getByte("Amplifier"));
|
|
|
|
effects.add(effect);
|
2016-01-05 04:47:35 +01:00
|
|
|
counter--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return effects.size() > 0 ? effects.toArray(new PotionEffect[effects.size()]) : null;
|
|
|
|
}
|
|
|
|
}
|