Made potion rings require blaze and work in the off hand

This commit is contained in:
Ellpeck 2016-11-22 00:11:58 +01:00
parent ba91bc35c0
commit 73d3dc95bc
5 changed files with 176 additions and 6 deletions

View file

@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.RecipeSorter; import net.minecraftforge.oredict.RecipeSorter;
public final class InitCrafting{ public final class InitCrafting{
@ -40,6 +41,9 @@ public final class InitCrafting{
RecipeSorter.register(ModUtil.MOD_ID+":recipeKeepDataShaped", RecipeKeepDataShaped.class, RecipeSorter.Category.SHAPED, "after:minecraft:shaped"); RecipeSorter.register(ModUtil.MOD_ID+":recipeKeepDataShaped", RecipeKeepDataShaped.class, RecipeSorter.Category.SHAPED, "after:minecraft:shaped");
RecipeSorter.register(ModUtil.MOD_ID+":recipeKeepDataShapeless", RecipeKeepDataShapeless.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless"); RecipeSorter.register(ModUtil.MOD_ID+":recipeKeepDataShapeless", RecipeKeepDataShapeless.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless");
GameRegistry.addRecipe(new RecipePotionRingCharging());
RecipeSorter.register(ModUtil.MOD_ID+":recipePotionRingCharging", RecipePotionRingCharging.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless");
} }
} }

View file

@ -25,10 +25,13 @@ import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.init.Enchantments; import net.minecraft.init.Enchantments;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.init.PotionTypes;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemFood; import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.potion.PotionHelper;
import net.minecraft.potion.PotionUtils;
import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.IPlantable;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
@ -669,8 +672,12 @@ public final class ItemCrafting{
} }
public static void addRingRecipeWithStack(ItemStack mainStack, int meta){ public static void addRingRecipeWithStack(ItemStack mainStack, int meta){
GameRegistry.addShapelessRecipe(new ItemStack(InitItems.itemPotionRing, 1, meta), mainStack, mainStack, mainStack, mainStack, new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.DIAMOND.ordinal()), new ItemStack(Items.NETHER_WART), new ItemStack(Items.POTIONITEM), new ItemStack(InitItems.itemMisc, 1, TheMiscItems.RING.ordinal())); ItemStack potion = new ItemStack(Items.POTIONITEM);
PotionUtils.addPotionToItemStack(potion, PotionTypes.AWKWARD);
GameRegistry.addShapelessRecipe(new ItemStack(InitItems.itemPotionRing, 1, meta), mainStack, mainStack, mainStack, mainStack, new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.DIAMOND.ordinal()), new ItemStack(Items.NETHER_WART), potion, new ItemStack(InitItems.itemMisc, 1, TheMiscItems.RING.ordinal()));
RECIPES_POTION_RINGS.add(RecipeUtil.lastIRecipe()); RECIPES_POTION_RINGS.add(RecipeUtil.lastIRecipe());
GameRegistry.addShapelessRecipe(new ItemStack(InitItems.itemPotionRingAdvanced, 1, meta), new ItemStack(InitItems.itemPotionRing, 1, meta), new ItemStack(InitItems.itemMisc, 1, TheMiscItems.ENDER_STAR.ordinal())); GameRegistry.addShapelessRecipe(new ItemStack(InitItems.itemPotionRingAdvanced, 1, meta), new ItemStack(InitItems.itemPotionRing, 1, meta), new ItemStack(InitItems.itemMisc, 1, TheMiscItems.ENDER_STAR.ordinal()));
RECIPES_POTION_RINGS.add(RecipeUtil.lastIRecipe()); RECIPES_POTION_RINGS.add(RecipeUtil.lastIRecipe());
} }

View file

@ -0,0 +1,93 @@
/*
* This file ("RecipePotionRingCharging.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.crafting;
import de.ellpeck.actuallyadditions.mod.items.ItemPotionRing;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
public class RecipePotionRingCharging implements IRecipe{
@Override
public boolean matches(InventoryCrafting inv, World worldIn){
boolean hasRing = false;
for(int i = 0; i < inv.getSizeInventory(); i++){
ItemStack stack = inv.getStackInSlot(i);
if(StackUtil.isValid(stack)){
if(stack.getItem() instanceof ItemPotionRing){
if(!hasRing){
hasRing = true;
}
else{
return false;
}
}
else if(stack.getItem() != Items.BLAZE_POWDER){
return false;
}
}
}
return hasRing;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inv){
ItemStack inputRing = StackUtil.getNull();
int totalBlaze = 0;
for(int i = 0; i < inv.getSizeInventory(); i++){
ItemStack stack = inv.getStackInSlot(i);
if(StackUtil.isValid(stack)){
if(stack.getItem() instanceof ItemPotionRing){
inputRing = stack;
}
else if(stack.getItem() == Items.BLAZE_POWDER){
totalBlaze += 20;
}
}
}
if(StackUtil.isValid(inputRing) && totalBlaze > 0){
ItemStack copy = inputRing.copy();
int total = ItemPotionRing.getStoredBlaze(copy)+totalBlaze;
if(total <= ItemPotionRing.MAX_BLAZE){
ItemPotionRing.setStoredBlaze(copy, total);
return copy;
}
}
return StackUtil.getNull();
}
@Override
public int getRecipeSize(){
return 0;
}
@Override
public ItemStack getRecipeOutput(){
return StackUtil.getNull();
}
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv){
return ForgeHooks.defaultRecipeGetRemainingItems(inv);
}
}

View file

@ -25,11 +25,13 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion; import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -41,6 +43,7 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem, IDi
public static final ThePotionRings[] ALL_RINGS = ThePotionRings.values(); public static final ThePotionRings[] ALL_RINGS = ThePotionRings.values();
public static final int MAX_BLAZE = 800;
private final boolean isAdvanced; private final boolean isAdvanced;
public ItemPotionRing(boolean isAdvanced, String name){ public ItemPotionRing(boolean isAdvanced, String name){
@ -55,12 +58,28 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem, IDi
return damage; return damage;
} }
@Override
public double getDurabilityForDisplay(ItemStack stack){
double diff = MAX_BLAZE-this.getStoredBlaze(stack);
return diff/MAX_BLAZE;
}
@Override
public int getRGBDurabilityForDisplay(ItemStack stack){
int curr = this.getStoredBlaze(stack);
return MathHelper.hsvToRGB(Math.max(0.0F, (float)curr/MAX_BLAZE)/3.0F, 1.0F, 1.0F);
}
@Override @Override
public String getUnlocalizedName(ItemStack stack){ public String getUnlocalizedName(ItemStack stack){
return stack.getItemDamage() >= ALL_RINGS.length ? StringUtil.BUGGED_ITEM_NAME : this.getUnlocalizedName()+ALL_RINGS[stack.getItemDamage()].name; return stack.getItemDamage() >= ALL_RINGS.length ? StringUtil.BUGGED_ITEM_NAME : this.getUnlocalizedName()+ALL_RINGS[stack.getItemDamage()].name;
} }
@Override
public boolean showDurabilityBar(ItemStack itemStack){
return true;
}
@Override @Override
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){ public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){
super.onUpdate(stack, world, player, par4, par5); super.onUpdate(stack, world, player, par4, par5);
@ -68,12 +87,27 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem, IDi
if(!world.isRemote && stack.getItemDamage() < ALL_RINGS.length){ if(!world.isRemote && stack.getItemDamage() < ALL_RINGS.length){
if(player instanceof EntityPlayer){ if(player instanceof EntityPlayer){
EntityPlayer thePlayer = (EntityPlayer)player; EntityPlayer thePlayer = (EntityPlayer)player;
ItemStack equippedStack = thePlayer.getHeldItemMainhand();
this.effectEntity(thePlayer, stack, StackUtil.isValid(equippedStack) && stack == equippedStack); int storedBlaze = getStoredBlaze(stack);
if(storedBlaze > 0){
ItemStack equippedStack = thePlayer.getHeldItemMainhand();
ItemStack offhandStack = thePlayer.getHeldItemOffhand();
if(this.effectEntity(thePlayer, stack, (StackUtil.isValid(equippedStack) && stack == equippedStack) || (StackUtil.isValid(offhandStack) && stack == offhandStack))){
if(world.getTotalWorldTime()%10 == 0){
setStoredBlaze(stack, storedBlaze-1);
}
}
}
} }
} }
} }
@Override
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged){
return slotChanged || !ItemStack.areItemsEqual(oldStack, newStack);
}
@Override @Override
public String getItemStackDisplayName(ItemStack stack){ public String getItemStackDisplayName(ItemStack stack){
String standardName = StringUtil.localize(this.getUnlocalizedName()+".name"); String standardName = StringUtil.localize(this.getUnlocalizedName()+".name");
@ -95,6 +129,10 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem, IDi
public void getSubItems(Item item, CreativeTabs tab, NonNullList list){ public void getSubItems(Item item, CreativeTabs tab, NonNullList list){
for(int j = 0; j < ALL_RINGS.length; j++){ for(int j = 0; j < ALL_RINGS.length; j++){
list.add(new ItemStack(this, 1, j)); list.add(new ItemStack(this, 1, j));
ItemStack full = new ItemStack(this, 1, j);
setStoredBlaze(full, MAX_BLAZE);
list.add(full);
} }
} }
@ -116,10 +154,28 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem, IDi
}; };
} }
public static int getStoredBlaze(ItemStack stack){
if(!StackUtil.isValid(stack) || !stack.hasTagCompound()){
return 0;
}
else{
return stack.getTagCompound().getInteger("Blaze");
}
}
public static void setStoredBlaze(ItemStack stack, int amount){
if(StackUtil.isValid(stack)){
if(!stack.hasTagCompound()){
stack.setTagCompound(new NBTTagCompound());
}
stack.getTagCompound().setInteger("Blaze", amount);
}
}
@Override @Override
public boolean update(ItemStack stack, TileEntity tile, int elapsedTicks){ public boolean update(ItemStack stack, TileEntity tile, int elapsedTicks){
boolean advanced = ((ItemPotionRing)stack.getItem()).isAdvanced; boolean advanced = ((ItemPotionRing)stack.getItem()).isAdvanced;
int range = advanced ? 96 : 16; int range = advanced ? 48 : 16;
List<EntityLivingBase> entities = tile.getWorld().getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(tile.getPos().getX()-range, tile.getPos().getY()-range, tile.getPos().getZ()-range, tile.getPos().getX()+range, tile.getPos().getY()+range, tile.getPos().getZ()+range)); List<EntityLivingBase> entities = tile.getWorld().getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(tile.getPos().getX()-range, tile.getPos().getY()-range, tile.getPos().getZ()-range, tile.getPos().getX()+range, tile.getPos().getY()+range, tile.getPos().getZ()+range));
if(entities != null && !entities.isEmpty()){ if(entities != null && !entities.isEmpty()){
if(advanced){ if(advanced){
@ -161,7 +217,7 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem, IDi
return 325; return 325;
} }
private void effectEntity(EntityLivingBase thePlayer, ItemStack stack, boolean canUseBasic){ private boolean effectEntity(EntityLivingBase thePlayer, ItemStack stack, boolean canUseBasic){
ThePotionRings effect = ThePotionRings.values()[stack.getItemDamage()]; ThePotionRings effect = ThePotionRings.values()[stack.getItemDamage()];
Potion potion = Potion.getPotionById(effect.effectID); Potion potion = Potion.getPotionById(effect.effectID);
PotionEffect activeEffect = thePlayer.getActivePotionEffect(potion); PotionEffect activeEffect = thePlayer.getActivePotionEffect(potion);
@ -169,11 +225,21 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem, IDi
if(!((ItemPotionRing)stack.getItem()).isAdvanced){ if(!((ItemPotionRing)stack.getItem()).isAdvanced){
if(canUseBasic){ if(canUseBasic){
thePlayer.addPotionEffect(new PotionEffect(potion, effect.activeTime, effect.normalAmplifier, true, false)); thePlayer.addPotionEffect(new PotionEffect(potion, effect.activeTime, effect.normalAmplifier, true, false));
return true;
} }
} }
else{ else{
thePlayer.addPotionEffect(new PotionEffect(potion, effect.activeTime, effect.advancedAmplifier, true, false)); thePlayer.addPotionEffect(new PotionEffect(potion, effect.activeTime, effect.advancedAmplifier, true, false));
return true;
} }
} }
return false;
}
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced){
super.addInformation(stack, playerIn, tooltip, advanced);
tooltip.add(this.getStoredBlaze(stack)+"/"+MAX_BLAZE+" Blaze stored");
} }
} }

View file

@ -903,7 +903,7 @@ booklet.actuallyadditions.chapter.jams.text.2=A <imp>Jam House<r> and <n>its inh
booklet.actuallyadditions.chapter.jams.text.3=So. <n>You're probably wondering what the names of the jams mean. <n>Now, let me tell you: <n><n><i>-Honeydew Melon and Kiwi <n>-Honeydew Melon and Coconut <n>-Pineapple and Coconut <n>-Cherry, Apple and Cinnamon <n>-Plum, Apple and Lemon <n>-Grape, Kiwi and Banana <n>-Currant, Banana and Raspberry <n><n><r>Now, which one is which, you may ask? Figure it out yourself. booklet.actuallyadditions.chapter.jams.text.3=So. <n>You're probably wondering what the names of the jams mean. <n>Now, let me tell you: <n><n><i>-Honeydew Melon and Kiwi <n>-Honeydew Melon and Coconut <n>-Pineapple and Coconut <n>-Cherry, Apple and Cinnamon <n>-Plum, Apple and Lemon <n>-Grape, Kiwi and Banana <n>-Currant, Banana and Raspberry <n><n><r>Now, which one is which, you may ask? Figure it out yourself.
booklet.actuallyadditions.chapter.potionRings.name=Potion Rings booklet.actuallyadditions.chapter.potionRings.name=Potion Rings
booklet.actuallyadditions.chapter.potionRings.text.1=The <item>Potion Rings<r> have two versions: A <imp>normal version<r> and an <imp>advanced version<r>. <n>The normal version, when you have it in your hand, will give you a <imp>Potion Effect<r> of Level 1. The advanced version can be anywhere in your inventory and gives you an effect of Level 2! booklet.actuallyadditions.chapter.potionRings.text.1=<item>Potion Rings<r> can permanenty grant a set of potion effects. <n>A <item>Potion Ring<r> has <imp>two tiers<r>. The first tier needs to be <imp>held in any hand<r> and gives an effect of <imp>level one<r> while the second tier can be <imp>anywhere inside the inventory<r> and grants an effect of <imp>level two<r>. <n>To be able to use <item>Potion Rings<r> they first have to be <imp>filled up<r> with <item>Blaze Powder<r>. To do this, put the ring into a <imp>Crafting Grid<r> with <imp>one or more<r> Blaze Powder. <n>Over time, the powder inside the ring will be <imp>used up<r> to grant you the effect.
booklet.actuallyadditions.chapter.drill.name=Drills booklet.actuallyadditions.chapter.drill.name=Drills
booklet.actuallyadditions.chapter.drill.text.1=The <item>Drill<r> works like a Pickaxe and a Shovel. It uses <imp>RF<r> per block. It can be <imp>charged in an Energizer<r> and upgraded by <imp>sneak-right-clicking<r> with it in your hand. There is <imp>a lot of upgrades<r>, but here is an explanation of some of them: <n>The <item>Mining Uprgades<r> enlarge the hole which the Drill digs. <n>The <item>Placement Upgrade<r>, after you right-click it in any slot of your hotbar, will make the Drill able to <imp>place a block from that slot by right-clicking<r>. You can also put a <item>Battery<r> inside the Drill to give it more charge. booklet.actuallyadditions.chapter.drill.text.1=The <item>Drill<r> works like a Pickaxe and a Shovel. It uses <imp>RF<r> per block. It can be <imp>charged in an Energizer<r> and upgraded by <imp>sneak-right-clicking<r> with it in your hand. There is <imp>a lot of upgrades<r>, but here is an explanation of some of them: <n>The <item>Mining Uprgades<r> enlarge the hole which the Drill digs. <n>The <item>Placement Upgrade<r>, after you right-click it in any slot of your hotbar, will make the Drill able to <imp>place a block from that slot by right-clicking<r>. You can also put a <item>Battery<r> inside the Drill to give it more charge.