Added the Ring of Correction.

This commit is contained in:
Lizbeth Rika committed 2015-02-23 19:57:43 +00:00
1 parent 4d311d2906
commit 82db71602c
14 files changed
+234 -8

No files matched your search

@@ -0,0 +1,47 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Feb 23, 2015, 7:03:48 PM (GMT)]
*/
package vazkii.botania.api.item;
import net.minecraft.item.ItemStack;
/**
* This interface describes a tool that can be sorted by the Ring of
* Correction.
*/
public interface ISortableTool {
/**
* Gets the type of tool that this is. A pick, axe or shovel.
*/
public ToolType getSortingType(ItemStack stack);
/**
* Gets the priority that this tool should have when being sorted. The
* tool with the highest priority will be picked. The way this is specified
* should be (tool-level) * 100 + (tool-modifier) * 10 + (efficiency-level).
* <br><br>
* For example, a <b>Manasteel Pickaxe</b> is tool-level 10 and it doesn't have
* modifiers. Assuming Efficiency 4, the priority should be 10 * 100 + 4 = <b>1004</b>.
* This will rate higher than a similar pickaxe with Efficiency 3.<br>
* A <b>Terra Shatterer</b> has a modifier, its rank and is tool-level 20. With Efficiency
* 5 and rank B (2) the priority should be 20 * 100 + 2 * 10 + 5 = <b>2025</b>.
* <br><br>
* All intermediate tool levels are there for other mod tools that wish to occupy the spots inbetween.
* Of course, you don't have to always adhere to this. Tools like the <b>Vitreous Pickaxe</b> don't,
* that one in particular is priority 0 so it's never picked.
*/
public int getSortingPriority(ItemStack stack);
public static enum ToolType {
PICK, AXE, SHOVEL
}
}
@@ -180,6 +180,7 @@ public final class BotaniaCreativeTab extends CreativeTabs {
addItem(ModItems.waterRing);
addItem(ModItems.miningRing);
addItem(ModItems.magnetRing);
addItem(ModItems.swapRing);
addItem(ModItems.reachRing);
addItem(ModItems.pixieRing);
addItem(ModItems.travelBelt);
@@ -318,4 +319,3 @@ public final class BotaniaCreativeTab extends CreativeTabs {
}
}
@@ -49,6 +49,7 @@ import vazkii.botania.common.item.equipment.bauble.ItemPixieRing;
import vazkii.botania.common.item.equipment.bauble.ItemReachRing;
import vazkii.botania.common.item.equipment.bauble.ItemSuperLavaPendant;
import vazkii.botania.common.item.equipment.bauble.ItemSuperTravelBelt;
import vazkii.botania.common.item.equipment.bauble.ItemSwapRing;
import vazkii.botania.common.item.equipment.bauble.ItemTinyPlanet;
import vazkii.botania.common.item.equipment.bauble.ItemTravelBelt;
import vazkii.botania.common.item.equipment.bauble.ItemUnholyCloak;
@@ -208,6 +209,7 @@ public final class ModItems {
public static Item livingwoodBow;
public static Item crystalBow;
public static Item cosmetic;
public static Item swapRing;
public static void init() {
lexicon = new ItemLexicon();
@@ -321,7 +323,8 @@ public final class ModItems {
livingwoodBow = new ItemLivingwoodBow();
crystalBow = new ItemCrystalBow();
cosmetic = new ItemBaubleCosmetic();
swapRing = new ItemSwapRing();
OreDictionary.registerOre(LibOreDict.LEXICON, lexicon);
for(int i = 0; i < 16; i++) {
OreDictionary.registerOre(LibOreDict.PETAL[i], new ItemStack(petal, 1, i));
@@ -0,0 +1,94 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Feb 23, 2015, 7:21:52 PM (GMT)]
*/
package vazkii.botania.common.item.equipment.bauble;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import vazkii.botania.api.item.ISortableTool;
import vazkii.botania.api.item.ISortableTool.ToolType;
import vazkii.botania.common.item.equipment.tool.ToolCommons;
import vazkii.botania.common.lib.LibItemNames;
import baubles.api.BaubleType;
public class ItemSwapRing extends ItemBauble {
public ItemSwapRing() {
super(LibItemNames.SWAP_RING);
}
@Override
public void onWornTick(ItemStack stack, EntityLivingBase entity) {
if(!(entity instanceof EntityPlayer))
return;
EntityPlayer player = (EntityPlayer) entity;
ItemStack currentStack = player.getCurrentEquippedItem();
if(currentStack == null || !(currentStack.getItem() instanceof ISortableTool))
return;
ISortableTool tool = (ISortableTool) currentStack.getItem();
MovingObjectPosition pos = ToolCommons.raytraceFromEntity(entity.worldObj, entity, true, 4.5F);
ToolType typeToFind = null;
if(player.isSwingInProgress && pos != null) {
Block block = entity.worldObj.getBlock(pos.blockX, pos.blockY, pos.blockZ);
if(block != null) {
Material mat = block.getMaterial();
if(ToolCommons.isRightMaterial(mat, ToolCommons.materialsPick))
typeToFind = ToolType.PICK;
else if(ToolCommons.isRightMaterial(mat, ToolCommons.materialsShovel))
typeToFind = ToolType.SHOVEL;
else if(ToolCommons.isRightMaterial(mat, ToolCommons.materialsAxe))
typeToFind = ToolType.AXE;
}
}
if(typeToFind == null)
return;
System.out.println(typeToFind);
ItemStack bestTool = currentStack;
int bestToolPriority = tool.getSortingType(currentStack) == typeToFind ? tool.getSortingPriority(currentStack) : -1;
int bestSlot = -1;
for(int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack stackInSlot = player.inventory.getStackInSlot(i);
if (stackInSlot != null && stackInSlot.getItem() instanceof ISortableTool && stackInSlot != currentStack) {
ISortableTool toolInSlot = (ISortableTool) stackInSlot.getItem();
if(toolInSlot.getSortingType(stackInSlot).equals(typeToFind)) {
int priority = toolInSlot.getSortingPriority(stackInSlot);
if(priority > bestToolPriority) {
bestTool = stackInSlot;
bestToolPriority = priority;
bestSlot = i;
}
}
}
}
if(bestSlot != -1) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, bestTool);
player.inventory.setInventorySlotContents(bestSlot, currentStack);
}
}
@Override
public BaubleType getBaubleType(ItemStack arg0) {
return BaubleType.RING;
}
}
@@ -83,5 +83,5 @@ public class ItemEnderDagger extends ItemManasteelSword {
public boolean usesMana(ItemStack stack) {
return false;
}
}
@@ -46,5 +46,10 @@ public class ItemGlassPick extends ItemManasteelPick {
public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) {
return par2ItemStack.getItem() == Item.getItemFromBlock(Blocks.glass) ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
}
@Override
public int getSortingPriority(ItemStack stack) {
return 0;
}
}
@@ -205,11 +205,15 @@ public class ItemTerraPick extends ItemManasteelPick implements IManaItem {
@Override
public int getMana(ItemStack stack) {
return getMana_(stack);
}
public static int getMana_(ItemStack stack) {
return ItemNBTHelper.getInt(stack, TAG_MANA, 0);
}
public int getLevel(ItemStack stack) {
int mana = getMana(stack);
public static int getLevel(ItemStack stack) {
int mana = getMana_(stack);
for(int i = LEVELS.length - 1; i > 0; i--)
if(mana >= LEVELS[i])
return i;
@@ -12,20 +12,31 @@ package vazkii.botania.common.item.equipment.tool;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.mana.ManaItemHandler;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.item.equipment.tool.elementium.ItemElementiumPick;
public final class ToolCommons {
public static Material[] materialsPick = new Material[]{ Material.rock, Material.iron, Material.ice, Material.glass, Material.piston, Material.anvil };
public static Material[] materialsShovel = new Material[]{ Material.grass, Material.ground, Material.sand, Material.snow, Material.craftedSnow, Material.clay };
public static Material[] materialsAxe = new Material[]{ Material.coral, Material.leaves, Material.plants, Material.wood };
public static void damageItem(ItemStack stack, int dmg, EntityLivingBase entity, int manaPerDamage) {
int manaToRequest = dmg * manaPerDamage;
boolean manaRequested = entity instanceof EntityPlayer ? ManaItemHandler.requestManaExactForTool(stack, (EntityPlayer) entity, manaToRequest, true) : false;
@@ -84,6 +95,32 @@ public final class ToolCommons {
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(blk) + (meta << 12));
}
}
public static int getToolPriority(ItemStack stack) {
if(stack == null)
return 0;
Item item = stack.getItem();
if(!(item instanceof ItemTool))
return 0;
ItemTool tool = (ItemTool) item;
ToolMaterial material = tool.func_150913_i();
int materialLevel = 0;
if(material == BotaniaAPI.manasteelToolMaterial)
materialLevel = 10;
if(material == BotaniaAPI.elementiumToolMaterial)
materialLevel = 11;
if(material == BotaniaAPI.terrasteelToolMaterial)
materialLevel = 20;
int modifier = 0;
if(item == ModItems.terraPick)
modifier = ItemTerraPick.getLevel(stack);
int efficiency = EnchantmentHelper.getEnchantmentLevel(Enchantment.efficiency.effectId, stack);
return materialLevel * 100 + modifier * 10 + efficiency;
}
/**
* @author mDiyo
@@ -23,6 +23,7 @@ import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.item.ISortableTool;
import vazkii.botania.api.mana.IManaUsingItem;
import vazkii.botania.api.mana.ManaItemHandler;
import vazkii.botania.client.core.handler.ItemsRemainingRenderHandler;
@@ -36,7 +37,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemManasteelAxe extends ItemAxe implements IManaUsingItem {
public class ItemManasteelAxe extends ItemAxe implements IManaUsingItem, ISortableTool {
private static final Pattern SAPLING_PATTERN = Pattern.compile("(?:(?:(?:[A-Z-_.:]|^)sapling)|(?:(?:[a-z-_.:]|^)Sapling))(?:[A-Z-_.:]|$)");
@@ -114,4 +115,14 @@ public class ItemManasteelAxe extends ItemAxe implements IManaUsingItem {
return true;
}
@Override
public ToolType getSortingType(ItemStack stack) {
return ToolType.AXE;
}
@Override
public int getSortingPriority(ItemStack stack) {
return ToolCommons.getToolPriority(stack);
}
}
@@ -23,6 +23,8 @@ import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.item.ISortableTool;
import vazkii.botania.api.item.ISortableTool.ToolType;
import vazkii.botania.api.mana.IManaUsingItem;
import vazkii.botania.api.mana.ManaItemHandler;
import vazkii.botania.client.core.handler.ItemsRemainingRenderHandler;
@@ -36,7 +38,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemManasteelPick extends ItemPickaxe implements IManaUsingItem {
public class ItemManasteelPick extends ItemPickaxe implements IManaUsingItem, ISortableTool {
private static final Pattern TORCH_PATTERN = Pattern.compile("(?:(?:(?:[A-Z-_.:]|^)torch)|(?:(?:[a-z-_.:]|^)Torch))(?:[A-Z-_.:]|$)");
@@ -116,5 +118,15 @@ public class ItemManasteelPick extends ItemPickaxe implements IManaUsingItem {
public boolean usesMana(ItemStack stack) {
return true;
}
@Override
public ToolType getSortingType(ItemStack stack) {
return ToolType.PICK;
}
@Override
public int getSortingPriority(ItemStack stack) {
return ToolCommons.getToolPriority(stack);
}
}
@@ -23,6 +23,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.item.ISortableTool;
import vazkii.botania.api.mana.IManaUsingItem;
import vazkii.botania.api.mana.ManaItemHandler;
import vazkii.botania.client.core.helper.IconHelper;
@@ -36,7 +37,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemManasteelShovel extends ItemSpade implements IManaUsingItem {
public class ItemManasteelShovel extends ItemSpade implements IManaUsingItem, ISortableTool {
private static final int MANA_PER_DAMAGE = 60;
@@ -130,4 +131,14 @@ public class ItemManasteelShovel extends ItemSpade implements IManaUsingItem {
return true;
}
@Override
public ToolType getSortingType(ItemStack stack) {
return ToolType.SHOVEL;
}
@Override
public int getSortingPriority(ItemStack stack) {
return ToolCommons.getToolPriority(stack);
}
}
@@ -124,6 +124,7 @@ public final class LibItemNames {
public static final String LIVINGWOOD_BOW = "livingwoodBow";
public static final String CRYSTAL_BOW = "crystalBow";
public static final String COSMETIC = "cosmetic";
public static final String SWAP_RING = "swapRing";
public static final String[] LENS_NAMES = new String[] {
"lensNormal",