A bunch of back-end for Potions, as well as a minor glitch fix on the Demon Crystals when broken in incorrect manners.

This commit is contained in:
WayofTime 2016-07-26 19:05:48 -04:00
parent 6790d39c7e
commit c618f27a87
12 changed files with 537 additions and 1 deletions

View file

@ -121,6 +121,10 @@ public class Constants
public static final String MOST_SIG = "mostSig";
public static final String LEAST_SIG = "leastSig";
public static final String COLOR = "color";
public static final String POTION_AUGMENT_LENGHT = "length:";
public static final String POTION_AUGMENT_STRENGTH = "strength:";
public static final String POTION_IMPURITY = "impurity";
}
public static class Mod
@ -239,7 +243,8 @@ public class Constants
SANGUINE_BOOK("ItemSanguineBook"),
SIGIL_HOLDING("ItemSigilHolding"),
ARMOUR_POINTS_UPGRADE("ItemLivingArmourPointsUpgrade"),
DEMON_WILL_GAUGE("ItemDemonWillGauge"), ;
DEMON_WILL_GAUGE("ItemDemonWillGauge"),
POTION_FLASK("ItemPotionFlask"), ;
@Getter
private final String regName;

View file

@ -77,6 +77,10 @@ public class BlockDemonCrystal extends BlockContainer
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
if (world.getTileEntity(pos) == null)
{
return state;
}
TileDemonCrystal tile = (TileDemonCrystal) world.getTileEntity(pos);
return state.withProperty(AGE, tile.getCrystalCountForRender()).withProperty(ATTACHED, tile.getPlacement());
}

View file

@ -0,0 +1,92 @@
package WayofTime.bloodmagic.potion;
import java.util.Collection;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTablePotionAugmentRecipe;
import com.google.common.base.Objects;
public class BMPotionUtils
{
public static double getLengthAugment(ItemStack flaskStack, Potion potion)
{
NBTHelper.checkNBT(flaskStack);
NBTTagCompound tag = flaskStack.getTagCompound();
return tag.getDouble(Constants.NBT.POTION_AUGMENT_LENGHT + potion.getName());
}
public static void setLengthAugment(ItemStack flaskStack, Potion potion, double value)
{
if (value < 0)
{
value = 0;
}
NBTHelper.checkNBT(flaskStack);
NBTTagCompound tag = flaskStack.getTagCompound();
tag.setDouble(Constants.NBT.POTION_AUGMENT_LENGHT + potion.getName(), value);
}
public static int getAugmentedLength(int originalLength, double lengthAugment, double powerAugment)
{
return Math.max((int) (originalLength * (Math.pow(8f / 3f, lengthAugment) * Math.pow(0.5, powerAugment))), 1);
}
/**
* Copied from PotionUtils
*
* @param stack
* @param effects
* @return
*/
public static ItemStack setEffects(ItemStack stack, Collection<PotionEffect> effects)
{
if (effects.isEmpty())
{
return stack;
} else
{
NBTTagCompound nbttagcompound = (NBTTagCompound) Objects.firstNonNull(stack.getTagCompound(), new NBTTagCompound());
NBTTagList nbttaglist = new NBTTagList();
for (PotionEffect potioneffect : effects)
{
nbttaglist.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound()));
}
nbttagcompound.setTag("CustomPotionEffects", nbttaglist);
stack.setTagCompound(nbttagcompound);
return stack;
}
}
public static AlchemyTablePotionAugmentRecipe getLengthAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, List<ItemStack> inputItems, PotionEffect baseEffect, double lengthAugment)
{
return new AlchemyTablePotionAugmentRecipe(lpDrained, ticksRequired, tierRequired, inputItems, baseEffect, lengthAugment, 0);
}
public static AlchemyTablePotionAugmentRecipe getPowerAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, List<ItemStack> inputItems, PotionEffect baseEffect, int powerAugment)
{
return new AlchemyTablePotionAugmentRecipe(lpDrained, ticksRequired, tierRequired, inputItems, baseEffect, 0, powerAugment);
}
public static AlchemyTablePotionAugmentRecipe getLengthAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, ItemStack inputItem, PotionEffect baseEffect, double lengthAugment)
{
return new AlchemyTablePotionAugmentRecipe(lpDrained, ticksRequired, tierRequired, inputItem, baseEffect, lengthAugment, 0);
}
public static AlchemyTablePotionAugmentRecipe getPowerAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, ItemStack inputItem, PotionEffect baseEffect, int powerAugment)
{
return new AlchemyTablePotionAugmentRecipe(lpDrained, ticksRequired, tierRequired, inputItem, baseEffect, 0, powerAugment);
}
}

View file

@ -0,0 +1,112 @@
package WayofTime.bloodmagic.potion.item;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.client.IVariantProvider;
public class ItemPotionFlask extends Item implements IVariantProvider
{
public ItemPotionFlask()
{
setUnlocalizedName(Constants.Mod.MODID + ".potionFlask");
setCreativeTab(BloodMagic.tabBloodMagic);
setMaxStackSize(1);
setMaxDamage(8);
}
@Override
public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase entityLiving)
{
EntityPlayer player = entityLiving instanceof EntityPlayer ? (EntityPlayer) entityLiving : null;
int remainingUses = stack.getMaxDamage() - stack.getItemDamage();
if (remainingUses <= 0)
{
return stack;
}
if (player == null || !player.capabilities.isCreativeMode)
{
stack.setItemDamage(stack.getItemDamage() + 1);
}
if (!world.isRemote)
{
for (PotionEffect potioneffect : PotionUtils.getEffectsFromStack(stack))
{
entityLiving.addPotionEffect(new PotionEffect(potioneffect));
}
}
return stack;
}
@Override
public int getMaxItemUseDuration(ItemStack stack)
{
return 32;
}
@Override
public EnumAction getItemUseAction(ItemStack stack)
{
return EnumAction.DRINK;
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
{
int remainingUses = stack.getMaxDamage() - stack.getItemDamage();
if (remainingUses <= 0)
{
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
player.setActiveHand(hand);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
{
PotionUtils.addPotionTooltip(stack, tooltip, 1.0F);
}
// @Override
// @SideOnly(Side.CLIENT)
// public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems)
// {
// for (PotionType potiontype : PotionType.REGISTRY)
// {
// subItems.add(PotionUtils.addPotionToItemStack(new ItemStack(itemIn), potiontype));
// }
// }
@Override
public List<Pair<Integer, String>> getVariants()
{
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
ret.add(new ImmutablePair<Integer, String>(0, "type=normal"));
return ret;
}
}

View file

@ -0,0 +1,114 @@
package WayofTime.bloodmagic.recipe.alchemyTable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionUtils;
import WayofTime.bloodmagic.potion.BMPotionUtils;
import WayofTime.bloodmagic.registry.ModItems;
public class AlchemyTablePotionAugmentRecipe extends AlchemyTablePotionRecipe
{
protected double lengthAugment = 0;
protected int powerAugment = 0;
protected Potion wantedPotion;
public AlchemyTablePotionAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, List<ItemStack> inputItems, PotionEffect baseEffect, double lengthAugment, int powerAugment)
{
super(lpDrained, ticksRequired, tierRequired, inputItems, baseEffect);
ArrayList<Object> recipe = new ArrayList<Object>();
for (ItemStack stack : inputItems)
{
recipe.add(stack);
}
recipe.add(getAugmentedPotionFlask(baseEffect));
this.input = recipe;
this.wantedPotion = baseEffect.getPotion();
this.lengthAugment = lengthAugment;
}
public AlchemyTablePotionAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, ItemStack inputItem, PotionEffect baseEffect, double lengthAugment, int powerAugment)
{
this(lpDrained, ticksRequired, tierRequired, Arrays.asList(inputItem), baseEffect, lengthAugment, powerAugment);
}
@Override
public boolean isPotionFlaskValidInput(ItemStack stack)
{
List<PotionEffect> effectList = PotionUtils.getEffectsFromStack(stack);
for (PotionEffect eff : effectList)
{
if (eff.getPotion() == wantedPotion)
{
double currentAugment = BMPotionUtils.getLengthAugment(stack, wantedPotion);
return currentAugment < lengthAugment || eff.getAmplifier() < powerAugment;
}
}
return false;
}
@Override
public ItemStack getModifiedFlaskForInput(ItemStack inputStack)
{
if (inputStack == null)
{
ItemStack outputStack = new ItemStack(ModItems.potionFlask);
List<PotionEffect> effectList = new ArrayList<PotionEffect>();
int potionLength = wantedPotion.isInstant() ? 1 : BMPotionUtils.getAugmentedLength(baseEffect.getDuration(), lengthAugment, powerAugment - baseEffect.getAmplifier());
effectList.add(new PotionEffect(wantedPotion, potionLength, baseEffect.getAmplifier()));
BMPotionUtils.setEffects(outputStack, effectList);
return outputStack;
}
ItemStack outputStack = inputStack.copy();
List<PotionEffect> effectList = PotionUtils.getEffectsFromStack(outputStack);
List<PotionEffect> newEffectList = new ArrayList<PotionEffect>();
Iterator<PotionEffect> effectIterator = effectList.iterator();
while (effectIterator.hasNext())
{
PotionEffect effect = effectIterator.next();
if (effect.getPotion() == wantedPotion)
{
double currentLengthAugment = Math.max(lengthAugment, BMPotionUtils.getLengthAugment(outputStack, wantedPotion));
int currentPowerAugment = Math.max(powerAugment, effect.getAmplifier());
int potionLength = wantedPotion.isInstant() ? 1 : BMPotionUtils.getAugmentedLength(baseEffect.getDuration(), currentLengthAugment, currentPowerAugment);
newEffectList.add(new PotionEffect(wantedPotion, potionLength, currentPowerAugment));
BMPotionUtils.setLengthAugment(outputStack, wantedPotion, currentLengthAugment);
} else
{
newEffectList.add(effect);
}
}
BMPotionUtils.setEffects(outputStack, newEffectList);
return outputStack;
}
public static ItemStack getAugmentedPotionFlask(PotionEffect baseEffect)
{
ItemStack outputStack = new ItemStack(ModItems.potionFlask);
List<PotionEffect> effectList = new ArrayList<PotionEffect>();
effectList.add(baseEffect);
BMPotionUtils.setEffects(outputStack, effectList);
return outputStack;
}
}

View file

@ -0,0 +1,174 @@
package WayofTime.bloodmagic.recipe.alchemyTable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import WayofTime.bloodmagic.api.recipe.AlchemyTableRecipe;
import WayofTime.bloodmagic.registry.ModItems;
public class AlchemyTablePotionRecipe extends AlchemyTableRecipe
{
public static final ItemStack basePotionFlaskStack = new ItemStack(ModItems.potionFlask, 1, OreDictionary.WILDCARD_VALUE);
protected PotionEffect baseEffect;
public static final int temporaryMaximumEffectsOnThePotionFlaskYesThisIsALongFieldItIsJustSoIRemember = 3;
protected double baseAddedImpurity = 5;
public AlchemyTablePotionRecipe(int lpDrained, int ticksRequired, int tierRequired, List<ItemStack> inputItems, PotionEffect baseEffect)
{
super(basePotionFlaskStack, lpDrained, ticksRequired, tierRequired);
ArrayList<Object> recipe = new ArrayList<Object>();
for (ItemStack stack : inputItems)
{
recipe.add(stack);
}
recipe.add(basePotionFlaskStack);
this.input = recipe;
this.baseEffect = baseEffect;
}
public AlchemyTablePotionRecipe(int lpDrained, int ticksRequired, int tierRequired, ItemStack inputItem, PotionEffect baseEffect)
{
this(lpDrained, ticksRequired, tierRequired, Arrays.asList(inputItem), baseEffect);
}
@Override
public ItemStack getRecipeOutput(List<ItemStack> inputList)
{
int flaskLocation = -1;
for (int x = 0; x < inputList.size(); x++)
{
ItemStack slot = inputList.get(x);
if (slot != null)
{
boolean match = slot.getItem() == ModItems.potionFlask;
if (match)
{
flaskLocation = x;
continue;
}
}
}
if (flaskLocation != -1)
{
return getModifiedFlaskForInput(inputList.get(flaskLocation));
}
return getModifiedFlaskForInput(null);
}
@Override
public boolean matches(List<ItemStack> checkedList, World world, BlockPos pos)
{
ArrayList<Object> required = new ArrayList<Object>(input);
for (int x = 0; x < checkedList.size(); x++)
{
ItemStack slot = checkedList.get(x);
if (slot != null)
{
boolean inRecipe = false;
Iterator<Object> req = required.iterator();
while (req.hasNext())
{
boolean match = false;
Object next = req.next();
if (next instanceof ItemStack)
{
match = OreDictionary.itemMatches((ItemStack) next, slot, false);
} else if (next instanceof List)
{
Iterator<ItemStack> itr = ((List<ItemStack>) next).iterator();
while (itr.hasNext() && !match)
{
match = OreDictionary.itemMatches(itr.next(), slot, false);
}
}
if (match)
{
if (next instanceof ItemStack && ((ItemStack) next).getItem() == ModItems.potionFlask)
{
if (!isPotionFlaskValidInput(slot))
{
break;
}
}
inRecipe = true;
required.remove(next);
break;
}
}
if (!inRecipe)
{
return false;
}
}
}
return required.isEmpty();
}
public boolean isPotionFlaskValidInput(ItemStack stack)
{
List<PotionEffect> effectList = PotionUtils.getEffectsFromStack(stack);
if (effectList.size() + 1 >= temporaryMaximumEffectsOnThePotionFlaskYesThisIsALongFieldItIsJustSoIRemember)
{
return false;
}
for (PotionEffect eff : effectList)
{
if (eff.getPotion() == baseEffect.getPotion())
{
return false;
}
}
return true;
}
public ItemStack getModifiedFlaskForInput(ItemStack inputStack)
{
if (inputStack == null)
{
ItemStack outputStack = new ItemStack(ModItems.potionFlask);
List<PotionEffect> effectList = new ArrayList<PotionEffect>();
effectList.add(baseEffect);
PotionUtils.appendEffects(outputStack, effectList);
return outputStack;
}
ItemStack outputStack = inputStack.copy();
List<PotionEffect> effectList = new ArrayList<PotionEffect>();
effectList.add(baseEffect);
PotionUtils.appendEffects(outputStack, effectList);
return outputStack;
}
}

View file

@ -78,6 +78,7 @@ import WayofTime.bloodmagic.item.soul.ItemSentientShovel;
import WayofTime.bloodmagic.item.soul.ItemSentientSword;
import WayofTime.bloodmagic.item.soul.ItemSoulGem;
import WayofTime.bloodmagic.item.soul.ItemSoulSnare;
import WayofTime.bloodmagic.potion.item.ItemPotionFlask;
import WayofTime.bloodmagic.util.helper.InventoryRenderHelper;
public class ModItems
@ -174,6 +175,8 @@ public class ModItems
public static Item demonWillGauge;
public static Item potionFlask;
public static Item.ToolMaterial boundToolMaterial = EnumHelper.addToolMaterial("BoundToolMaterial", 4, 1, 10, 8, 50);
public static Item.ToolMaterial soulToolMaterial = EnumHelper.addToolMaterial("SoulToolMaterial", 4, 520, 7, 8, 50);
@ -278,6 +281,8 @@ public class ModItems
itemPointsUpgrade = registerItem(new ItemLivingArmourPointsUpgrade(), Constants.BloodMagicItem.ARMOUR_POINTS_UPGRADE.getRegName());
demonWillGauge = registerItem(new ItemDemonWillGauge(), Constants.BloodMagicItem.DEMON_WILL_GAUGE.getRegName());
potionFlask = registerItem(new ItemPotionFlask(), Constants.BloodMagicItem.POTION_FLASK.getRegName());
}
@SideOnly(Side.CLIENT)

View file

@ -5,8 +5,10 @@ import java.util.List;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeModContainer;
import net.minecraftforge.fml.common.registry.GameRegistry;
@ -45,7 +47,9 @@ import WayofTime.bloodmagic.item.ItemDemonCrystal;
import WayofTime.bloodmagic.item.alchemy.ItemCuttingFluid;
import WayofTime.bloodmagic.item.alchemy.ItemLivingArmourPointsUpgrade;
import WayofTime.bloodmagic.item.soul.ItemSoulGem;
import WayofTime.bloodmagic.potion.BMPotionUtils;
import WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTableDyeableRecipe;
import WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTablePotionRecipe;
import WayofTime.bloodmagic.util.Utils;
import com.google.common.base.Stopwatch;
@ -67,6 +71,7 @@ public class ModRecipes
addSoulForgeRecipes();
addAlchemyTableRecipes();
addOreDoublingAlchemyRecipes();
addPotionRecipes();
}
public static void initOreDict()
@ -352,6 +357,8 @@ public class ModRecipes
AlchemyTableRecipeRegistry.registerRecipe(ItemLivingArmourPointsUpgrade.getStack(ItemLivingArmourPointsUpgrade.DRAFT_ANGELUS), 20000, 400, 3, ItemComponent.getStack(ItemComponent.NEURO_TOXIN), ItemComponent.getStack(ItemComponent.ANTISEPTIC), ItemComponent.getStack(ItemComponent.SAND_GOLD), Items.FERMENTED_SPIDER_EYE, new ItemStack(ModItems.bloodShard, 1, 0), Items.GHAST_TEAR);
AlchemyTableRecipeRegistry.registerRecipe(new AlchemyTableDyeableRecipe(0, 100, 0, new ItemStack(ModItems.sigilHolding)));
AlchemyTableRecipeRegistry.registerRecipe(new ItemStack(ModItems.potionFlask), 1000, 200, 2, new ItemStack(Items.POTIONITEM), Items.NETHER_WART, Items.REDSTONE, Items.GLOWSTONE_DUST);
}
public static void addOreDoublingAlchemyRecipes()
@ -374,4 +381,10 @@ public class ModRecipes
}
}
}
public static void addPotionRecipes()
{
AlchemyTableRecipeRegistry.registerRecipe(new AlchemyTablePotionRecipe(0, 100, 0, new ItemStack(Items.BLAZE_POWDER), new PotionEffect(MobEffects.STRENGTH, 3600, 0)));
AlchemyTableRecipeRegistry.registerRecipe(BMPotionUtils.getLengthAugmentRecipe(0, 100, 0, new ItemStack(Items.BLAZE_ROD), new PotionEffect(MobEffects.STRENGTH, 3600, 0), 1));
}
}

View file

@ -0,0 +1,16 @@
{
"forge_marker": 1,
"defaults": {
"model": "builtin/generated",
"transform": "forge:default-item"
},
"variants": {
"type": {
"normal": {
"textures": {
"layer0": "bloodmagic:items/PotionFlask"
}
}
}
}
}

View file

@ -175,6 +175,7 @@ item.BloodMagic.sanguineBook.name=Inspectoris Scandalum
item.BloodMagic.livingPointUpgrade.draftAngelus.name=Draft of Angelus
item.BloodMagic.willGauge.name=Demon Will Aura Gauge
item.BloodMagic.potionFlask.name=Potion Flask
# Blocks
tile.BloodMagic.fluid.lifeEssence.name=Life Essence

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB