From 73d3dc95bc9734ca0b88b7772346263c3b876913 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 22 Nov 2016 00:11:58 +0100 Subject: [PATCH] Made potion rings require blaze and work in the off hand --- .../mod/crafting/InitCrafting.java | 4 + .../mod/crafting/ItemCrafting.java | 9 +- .../crafting/RecipePotionRingCharging.java | 93 +++++++++++++++++++ .../mod/items/ItemPotionRing.java | 74 ++++++++++++++- .../assets/actuallyadditions/lang/en_US.lang | 2 +- 5 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/crafting/RecipePotionRingCharging.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java index 73e8f526c..fe0b6b823 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java @@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems; import de.ellpeck.actuallyadditions.mod.util.ModUtil; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.oredict.RecipeSorter; 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+":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"); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ItemCrafting.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ItemCrafting.java index 19fcab77c..addbdc7e1 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ItemCrafting.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ItemCrafting.java @@ -25,10 +25,13 @@ import net.minecraft.enchantment.EnchantmentData; import net.minecraft.init.Blocks; import net.minecraft.init.Enchantments; import net.minecraft.init.Items; +import net.minecraft.init.PotionTypes; import net.minecraft.item.Item; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; +import net.minecraft.potion.PotionHelper; +import net.minecraft.potion.PotionUtils; import net.minecraftforge.common.IPlantable; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.oredict.OreDictionary; @@ -669,8 +672,12 @@ public final class ItemCrafting{ } 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()); + 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()); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/RecipePotionRingCharging.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/RecipePotionRingCharging.java new file mode 100644 index 000000000..4fdf041b2 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/RecipePotionRingCharging.java @@ -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 getRemainingItems(InventoryCrafting inv){ + return ForgeHooks.defaultRecipeGetRemainingItems(inv); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPotionRing.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPotionRing.java index 8691006fd..b0df60b67 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPotionRing.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPotionRing.java @@ -25,11 +25,13 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.NonNullList; import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; 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 int MAX_BLAZE = 800; private final boolean isAdvanced; public ItemPotionRing(boolean isAdvanced, String name){ @@ -55,12 +58,28 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem, IDi 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 public String getUnlocalizedName(ItemStack stack){ 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 public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean 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(player instanceof EntityPlayer){ 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 public String getItemStackDisplayName(ItemStack stack){ 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){ for(int j = 0; j < ALL_RINGS.length; 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 public boolean update(ItemStack stack, TileEntity tile, int elapsedTicks){ boolean advanced = ((ItemPotionRing)stack.getItem()).isAdvanced; - int range = advanced ? 96 : 16; + int range = advanced ? 48 : 16; List 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(advanced){ @@ -161,7 +217,7 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem, IDi 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()]; Potion potion = Potion.getPotionById(effect.effectID); PotionEffect activeEffect = thePlayer.getActivePotionEffect(potion); @@ -169,11 +225,21 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem, IDi if(!((ItemPotionRing)stack.getItem()).isAdvanced){ if(canUseBasic){ thePlayer.addPotionEffect(new PotionEffect(potion, effect.activeTime, effect.normalAmplifier, true, false)); + return true; } } else{ thePlayer.addPotionEffect(new PotionEffect(potion, effect.activeTime, effect.advancedAmplifier, true, false)); + return true; } } + return false; + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced){ + super.addInformation(stack, playerIn, tooltip, advanced); + + tooltip.add(this.getStoredBlaze(stack)+"/"+MAX_BLAZE+" Blaze stored"); } } diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index 62adda4be..960ff8e3e 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -903,7 +903,7 @@ booklet.actuallyadditions.chapter.jams.text.2=A Jam House and its inh booklet.actuallyadditions.chapter.jams.text.3=So. You're probably wondering what the names of the jams mean. Now, let me tell you: -Honeydew Melon and Kiwi -Honeydew Melon and Coconut -Pineapple and Coconut -Cherry, Apple and Cinnamon -Plum, Apple and Lemon -Grape, Kiwi and Banana -Currant, Banana and Raspberry Now, which one is which, you may ask? Figure it out yourself. booklet.actuallyadditions.chapter.potionRings.name=Potion Rings -booklet.actuallyadditions.chapter.potionRings.text.1=The Potion Rings have two versions: A normal version and an advanced version. The normal version, when you have it in your hand, will give you a Potion Effect 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=Potion Rings can permanenty grant a set of potion effects. A Potion Ring has two tiers. The first tier needs to be held in any hand and gives an effect of level one while the second tier can be anywhere inside the inventory and grants an effect of level two. To be able to use Potion Rings they first have to be filled up with Blaze Powder. To do this, put the ring into a Crafting Grid with one or more Blaze Powder. Over time, the powder inside the ring will be used up to grant you the effect. booklet.actuallyadditions.chapter.drill.name=Drills booklet.actuallyadditions.chapter.drill.text.1=The Drill works like a Pickaxe and a Shovel. It uses RF per block. It can be charged in an Energizer and upgraded by sneak-right-clicking with it in your hand. There is a lot of upgrades, but here is an explanation of some of them: The Mining Uprgades enlarge the hole which the Drill digs. The Placement Upgrade, after you right-click it in any slot of your hotbar, will make the Drill able to place a block from that slot by right-clicking. You can also put a Battery inside the Drill to give it more charge.