mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Started on actual diggers' tools, added repairing
This commit is contained in:
parent
835e8734ab
commit
8c60f4110b
10 changed files with 396 additions and 53 deletions
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* This file ("EnchantmentCombo.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://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
||||
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||
*
|
||||
* © 2015 Ellpeck
|
||||
*/
|
||||
|
||||
package ellpeck.actuallyadditions.items.tools.table;
|
||||
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
|
||||
public class EnchantmentCombo{
|
||||
|
||||
public Enchantment enchantment;
|
||||
public int level;
|
||||
|
||||
public EnchantmentCombo(Enchantment ench, int level){
|
||||
this.enchantment = ench;
|
||||
this.level = level;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* This file ("IToolTableRepairItem.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://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
||||
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||
*
|
||||
* © 2015 Ellpeck
|
||||
*/
|
||||
|
||||
package ellpeck.actuallyadditions.items.tools.table;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IToolTableRepairItem{
|
||||
|
||||
ItemStack getRepairStack();
|
||||
|
||||
int repairPerStack();
|
||||
}
|
|
@ -10,22 +10,30 @@
|
|||
|
||||
package ellpeck.actuallyadditions.items.tools.table;
|
||||
|
||||
import ellpeck.actuallyadditions.items.tools.table.ItemPickaxeFixedEnchants.EnchantmentCombo;
|
||||
import ellpeck.actuallyadditions.util.ItemUtil;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class InitToolTableTools{
|
||||
|
||||
public static Item itemMinersPickaxe;
|
||||
public static Item itemSilkyMinersPickaxe;
|
||||
|
||||
public static void init(){
|
||||
itemMinersPickaxe = new ItemPickaxeFixedEnchants(Item.ToolMaterial.EMERALD, "itemMinersPickaxe", EnumRarity.rare, new EnchantmentCombo(Enchantment.fortune, 2), new EnchantmentCombo(Enchantment.efficiency, 2), new EnchantmentCombo(Enchantment.unbreaking, 1));
|
||||
ItemUtil.register(itemMinersPickaxe);
|
||||
public static Item itemDiggersShovel;
|
||||
public static Item itemFastDiggersShovel;
|
||||
|
||||
itemSilkyMinersPickaxe = new ItemPickaxeFixedEnchants(Item.ToolMaterial.EMERALD, "itemSilkyMinersPickaxe", EnumRarity.rare, new EnchantmentCombo(Enchantment.silkTouch, 1), new EnchantmentCombo(Enchantment.efficiency, 2), new EnchantmentCombo(Enchantment.unbreaking, 1));
|
||||
public static void init(){
|
||||
itemMinersPickaxe = new ItemPickaxeFixedEnchants(Item.ToolMaterial.EMERALD, "itemMinersPickaxe", EnumRarity.rare, new ItemStack(Items.diamond), 400, new EnchantmentCombo(Enchantment.fortune, 2), new EnchantmentCombo(Enchantment.efficiency, 2), new EnchantmentCombo(Enchantment.unbreaking, 1));
|
||||
ItemUtil.register(itemMinersPickaxe);
|
||||
itemSilkyMinersPickaxe = new ItemPickaxeFixedEnchants(Item.ToolMaterial.EMERALD, "itemSilkyMinersPickaxe", EnumRarity.epic, new ItemStack(Items.diamond), 400, new EnchantmentCombo(Enchantment.silkTouch, 1), new EnchantmentCombo(Enchantment.efficiency, 2), new EnchantmentCombo(Enchantment.unbreaking, 1));
|
||||
ItemUtil.register(itemSilkyMinersPickaxe);
|
||||
|
||||
itemDiggersShovel = new ItemShovelFixedEnchants(Item.ToolMaterial.EMERALD, "itemDiggersShovel", EnumRarity.rare, new ItemStack(Items.diamond), 400, new EnchantmentCombo(Enchantment.efficiency, 2), new EnchantmentCombo(Enchantment.unbreaking, 2));
|
||||
ItemUtil.register(itemDiggersShovel);
|
||||
itemFastDiggersShovel = new ItemShovelFixedEnchants(Item.ToolMaterial.EMERALD, "itemFastDiggersShovel", EnumRarity.epic, new ItemStack(Items.diamond), 400, new EnchantmentCombo(Enchantment.efficiency, 4), new EnchantmentCombo(Enchantment.unbreaking, 1));
|
||||
ItemUtil.register(itemFastDiggersShovel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,33 +13,47 @@ package ellpeck.actuallyadditions.items.tools.table;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ellpeck.actuallyadditions.items.tools.ItemAxeAA;
|
||||
import ellpeck.actuallyadditions.util.ItemUtil;
|
||||
import ellpeck.actuallyadditions.util.ModUtil;
|
||||
import ellpeck.actuallyadditions.util.StringUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemAxeFixedEnchants extends ItemAxeAA{
|
||||
public class ItemAxeFixedEnchants extends ItemAxeAA implements IToolTableRepairItem{
|
||||
|
||||
public static class EnchantmentCombo{
|
||||
public Enchantment enchantment;
|
||||
public int level;
|
||||
private final int maxToolDamage;
|
||||
private final EnchantmentCombo[] enchantments;
|
||||
|
||||
public EnchantmentCombo(Enchantment ench, int level){
|
||||
this.enchantment = ench;
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
private ItemStack repairStack;
|
||||
private int repairPerStack;
|
||||
|
||||
private EnchantmentCombo[] enchantments;
|
||||
private IIcon iconBroken;
|
||||
|
||||
public ItemAxeFixedEnchants(ToolMaterial toolMat, String unlocalizedName, EnumRarity rarity, EnchantmentCombo... enchantments){
|
||||
public ItemAxeFixedEnchants(ToolMaterial toolMat, String unlocalizedName, EnumRarity rarity, ItemStack repairStack, int repairPerStack, EnchantmentCombo... enchantments){
|
||||
super(toolMat, "", unlocalizedName, rarity);
|
||||
this.enchantments = enchantments;
|
||||
this.maxToolDamage = this.getMaxDamage();
|
||||
this.setMaxDamage(this.maxToolDamage+1);
|
||||
this.repairStack = repairStack;
|
||||
this.repairPerStack = repairPerStack;
|
||||
}
|
||||
|
||||
public boolean isBroken(ItemStack stack){
|
||||
return this.isBroken(stack.getItemDamage());
|
||||
}
|
||||
|
||||
private boolean isBroken(int damage){
|
||||
return damage > this.maxToolDamage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,6 +83,15 @@ public class ItemAxeFixedEnchants extends ItemAxeAA{
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){
|
||||
for(EnchantmentCombo combo : this.enchantments){
|
||||
if(!ItemUtil.hasEnchantment(stack, combo.enchantment)){
|
||||
stack.addEnchantment(combo.enchantment, combo.level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -79,4 +102,47 @@ public class ItemAxeFixedEnchants extends ItemAxeAA{
|
|||
}
|
||||
list.add(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack stack){
|
||||
return super.getItemStackDisplayName(stack)+(this.isBroken(stack) ? " ("+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".broken.desc")+")" : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDigSpeed(ItemStack stack, Block block, int meta){
|
||||
return this.isBroken(stack) ? 0.0F : super.getDigSpeed(stack, block, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHarvestBlock(Block block, ItemStack stack){
|
||||
return !this.isBroken(stack) && super.canHarvestBlock(block, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack useItem, int useRemaining){
|
||||
return this.isBroken(stack) ? this.iconBroken : this.itemIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIconFromDamage(int damage){
|
||||
return this.isBroken(damage) ? this.iconBroken : this.itemIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IIconRegister iconReg){
|
||||
this.iconBroken = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()+"Broken");
|
||||
this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRepairStack(){
|
||||
return this.repairStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int repairPerStack(){
|
||||
return this.repairPerStack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,33 +13,47 @@ package ellpeck.actuallyadditions.items.tools.table;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ellpeck.actuallyadditions.items.tools.ItemPickaxeAA;
|
||||
import ellpeck.actuallyadditions.util.ItemUtil;
|
||||
import ellpeck.actuallyadditions.util.ModUtil;
|
||||
import ellpeck.actuallyadditions.util.StringUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemPickaxeFixedEnchants extends ItemPickaxeAA{
|
||||
public class ItemPickaxeFixedEnchants extends ItemPickaxeAA implements IToolTableRepairItem{
|
||||
|
||||
public static class EnchantmentCombo{
|
||||
public Enchantment enchantment;
|
||||
public int level;
|
||||
private final int maxToolDamage;
|
||||
private final EnchantmentCombo[] enchantments;
|
||||
|
||||
public EnchantmentCombo(Enchantment ench, int level){
|
||||
this.enchantment = ench;
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
private ItemStack repairStack;
|
||||
private int repairPerStack;
|
||||
|
||||
private EnchantmentCombo[] enchantments;
|
||||
private IIcon iconBroken;
|
||||
|
||||
public ItemPickaxeFixedEnchants(ToolMaterial toolMat, String unlocalizedName, EnumRarity rarity, EnchantmentCombo... enchantments){
|
||||
public ItemPickaxeFixedEnchants(ToolMaterial toolMat, String unlocalizedName, EnumRarity rarity, ItemStack repairStack, int repairPerStack, EnchantmentCombo... enchantments){
|
||||
super(toolMat, "", unlocalizedName, rarity);
|
||||
this.enchantments = enchantments;
|
||||
this.maxToolDamage = this.getMaxDamage();
|
||||
this.setMaxDamage(this.maxToolDamage+1);
|
||||
this.repairStack = repairStack;
|
||||
this.repairPerStack = repairPerStack;
|
||||
}
|
||||
|
||||
public boolean isBroken(ItemStack stack){
|
||||
return this.isBroken(stack.getItemDamage());
|
||||
}
|
||||
|
||||
private boolean isBroken(int damage){
|
||||
return damage > this.maxToolDamage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,6 +83,15 @@ public class ItemPickaxeFixedEnchants extends ItemPickaxeAA{
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){
|
||||
for(EnchantmentCombo combo : this.enchantments){
|
||||
if(!ItemUtil.hasEnchantment(stack, combo.enchantment)){
|
||||
stack.addEnchantment(combo.enchantment, combo.level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -79,4 +102,47 @@ public class ItemPickaxeFixedEnchants extends ItemPickaxeAA{
|
|||
}
|
||||
list.add(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack stack){
|
||||
return super.getItemStackDisplayName(stack)+(this.isBroken(stack) ? " ("+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".broken.desc")+")" : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDigSpeed(ItemStack stack, Block block, int meta){
|
||||
return this.isBroken(stack) ? 0.0F : super.getDigSpeed(stack, block, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHarvestBlock(Block block, ItemStack stack){
|
||||
return !this.isBroken(stack) && super.canHarvestBlock(block, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack useItem, int useRemaining){
|
||||
return this.isBroken(stack) ? this.iconBroken : this.itemIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIconFromDamage(int damage){
|
||||
return this.isBroken(damage) ? this.iconBroken : this.itemIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IIconRegister iconReg){
|
||||
this.iconBroken = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()+"Broken");
|
||||
this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRepairStack(){
|
||||
return this.repairStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int repairPerStack(){
|
||||
return this.repairPerStack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,33 +13,47 @@ package ellpeck.actuallyadditions.items.tools.table;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ellpeck.actuallyadditions.items.tools.ItemShovelAA;
|
||||
import ellpeck.actuallyadditions.util.ItemUtil;
|
||||
import ellpeck.actuallyadditions.util.ModUtil;
|
||||
import ellpeck.actuallyadditions.util.StringUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemShovelFixedEnchants extends ItemShovelAA{
|
||||
public class ItemShovelFixedEnchants extends ItemShovelAA implements IToolTableRepairItem{
|
||||
|
||||
public static class EnchantmentCombo{
|
||||
public Enchantment enchantment;
|
||||
public int level;
|
||||
private final int maxToolDamage;
|
||||
private final EnchantmentCombo[] enchantments;
|
||||
|
||||
public EnchantmentCombo(Enchantment ench, int level){
|
||||
this.enchantment = ench;
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
private ItemStack repairStack;
|
||||
private int repairPerStack;
|
||||
|
||||
private EnchantmentCombo[] enchantments;
|
||||
private IIcon iconBroken;
|
||||
|
||||
public ItemShovelFixedEnchants(ToolMaterial toolMat, String unlocalizedName, EnumRarity rarity, EnchantmentCombo... enchantments){
|
||||
public ItemShovelFixedEnchants(ToolMaterial toolMat, String unlocalizedName, EnumRarity rarity, ItemStack repairStack, int repairPerStack, EnchantmentCombo... enchantments){
|
||||
super(toolMat, "", unlocalizedName, rarity);
|
||||
this.enchantments = enchantments;
|
||||
this.maxToolDamage = this.getMaxDamage();
|
||||
this.setMaxDamage(this.maxToolDamage+1);
|
||||
this.repairStack = repairStack;
|
||||
this.repairPerStack = repairPerStack;
|
||||
}
|
||||
|
||||
public boolean isBroken(ItemStack stack){
|
||||
return this.isBroken(stack.getItemDamage());
|
||||
}
|
||||
|
||||
private boolean isBroken(int damage){
|
||||
return damage > this.maxToolDamage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,6 +83,15 @@ public class ItemShovelFixedEnchants extends ItemShovelAA{
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){
|
||||
for(EnchantmentCombo combo : this.enchantments){
|
||||
if(!ItemUtil.hasEnchantment(stack, combo.enchantment)){
|
||||
stack.addEnchantment(combo.enchantment, combo.level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -79,4 +102,47 @@ public class ItemShovelFixedEnchants extends ItemShovelAA{
|
|||
}
|
||||
list.add(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack stack){
|
||||
return super.getItemStackDisplayName(stack)+(this.isBroken(stack) ? " ("+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".broken.desc")+")" : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDigSpeed(ItemStack stack, Block block, int meta){
|
||||
return this.isBroken(stack) ? 0.0F : super.getDigSpeed(stack, block, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHarvestBlock(Block block, ItemStack stack){
|
||||
return !this.isBroken(stack) && super.canHarvestBlock(block, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack useItem, int useRemaining){
|
||||
return this.isBroken(stack) ? this.iconBroken : this.itemIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIconFromDamage(int damage){
|
||||
return this.isBroken(damage) ? this.iconBroken : this.itemIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IIconRegister iconReg){
|
||||
this.iconBroken = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()+"Broken");
|
||||
this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRepairStack(){
|
||||
return this.repairStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int repairPerStack(){
|
||||
return this.repairPerStack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,33 +13,47 @@ package ellpeck.actuallyadditions.items.tools.table;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ellpeck.actuallyadditions.items.tools.ItemSwordAA;
|
||||
import ellpeck.actuallyadditions.util.ItemUtil;
|
||||
import ellpeck.actuallyadditions.util.ModUtil;
|
||||
import ellpeck.actuallyadditions.util.StringUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemSwordFixedEnchants extends ItemSwordAA{
|
||||
public class ItemSwordFixedEnchants extends ItemSwordAA implements IToolTableRepairItem{
|
||||
|
||||
public static class EnchantmentCombo{
|
||||
public Enchantment enchantment;
|
||||
public int level;
|
||||
private final int maxToolDamage;
|
||||
private final EnchantmentCombo[] enchantments;
|
||||
|
||||
public EnchantmentCombo(Enchantment ench, int level){
|
||||
this.enchantment = ench;
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
private ItemStack repairStack;
|
||||
private int repairPerStack;
|
||||
|
||||
private EnchantmentCombo[] enchantments;
|
||||
private IIcon iconBroken;
|
||||
|
||||
public ItemSwordFixedEnchants(ToolMaterial toolMat, String unlocalizedName, EnumRarity rarity, EnchantmentCombo... enchantments){
|
||||
public ItemSwordFixedEnchants(ToolMaterial toolMat, String unlocalizedName, EnumRarity rarity, ItemStack repairStack, int repairPerStack, EnchantmentCombo... enchantments){
|
||||
super(toolMat, "", unlocalizedName, rarity);
|
||||
this.enchantments = enchantments;
|
||||
this.maxToolDamage = this.getMaxDamage();
|
||||
this.setMaxDamage(this.maxToolDamage+1);
|
||||
this.repairStack = repairStack;
|
||||
this.repairPerStack = repairPerStack;
|
||||
}
|
||||
|
||||
public boolean isBroken(ItemStack stack){
|
||||
return this.isBroken(stack.getItemDamage());
|
||||
}
|
||||
|
||||
private boolean isBroken(int damage){
|
||||
return damage > this.maxToolDamage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,6 +83,15 @@ public class ItemSwordFixedEnchants extends ItemSwordAA{
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){
|
||||
for(EnchantmentCombo combo : this.enchantments){
|
||||
if(!ItemUtil.hasEnchantment(stack, combo.enchantment)){
|
||||
stack.addEnchantment(combo.enchantment, combo.level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -79,4 +102,47 @@ public class ItemSwordFixedEnchants extends ItemSwordAA{
|
|||
}
|
||||
list.add(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack stack){
|
||||
return super.getItemStackDisplayName(stack)+(this.isBroken(stack) ? " ("+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".broken.desc")+")" : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDigSpeed(ItemStack stack, Block block, int meta){
|
||||
return this.isBroken(stack) ? 0.0F : super.getDigSpeed(stack, block, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHarvestBlock(Block block, ItemStack stack){
|
||||
return !this.isBroken(stack) && super.canHarvestBlock(block, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack useItem, int useRemaining){
|
||||
return this.isBroken(stack) ? this.iconBroken : this.itemIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIconFromDamage(int damage){
|
||||
return this.isBroken(damage) ? this.iconBroken : this.itemIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IIconRegister iconReg){
|
||||
this.iconBroken = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()+"Broken");
|
||||
this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRepairStack(){
|
||||
return this.repairStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int repairPerStack(){
|
||||
return this.repairPerStack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
package ellpeck.actuallyadditions.recipe;
|
||||
|
||||
import ellpeck.actuallyadditions.items.tools.table.IToolTableRepairItem;
|
||||
import ellpeck.actuallyadditions.util.ItemUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
@ -29,11 +30,23 @@ public class ToolTableHandler{
|
|||
}
|
||||
|
||||
public static Recipe getRecipeFromSlots(ItemStack[] slots){
|
||||
//Normal Recipes
|
||||
for(Recipe recipe : recipes){
|
||||
if(ItemUtil.containsAll(slots, recipe.itemsNeeded)){
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
||||
//Repair Recipes
|
||||
for(ItemStack slot : slots){
|
||||
if(slot != null && slot.getItem() instanceof IToolTableRepairItem){
|
||||
if(ItemUtil.contains(slots, ((IToolTableRepairItem)slot.getItem()).getRepairStack()) && slot.getItemDamage() > 0){
|
||||
ItemStack returnStack = slot.copy();
|
||||
returnStack.setItemDamage(Math.max(0, returnStack.getItemDamage()-((IToolTableRepairItem)returnStack.getItem()).repairPerStack()));
|
||||
return new Recipe(returnStack, slot, ((IToolTableRepairItem)returnStack.getItem()).getRepairStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -92,4 +92,17 @@ public class ItemUtil{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasEnchantment(ItemStack stack, Enchantment e){
|
||||
NBTTagList ench = stack.getEnchantmentTagList();
|
||||
if(ench != null){
|
||||
for(int i = 0; i < ench.tagCount(); i++){
|
||||
short id = ench.getCompoundTagAt(i).getShort("id");
|
||||
if(id == e.effectId){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -276,6 +276,7 @@ tooltip.actuallyadditions.disablingInfo.desc=If you don't want this Information
|
|||
tooltip.actuallyadditions.ctrlForMoreInfo.desc=Press CTRL for Advanced Info
|
||||
tooltip.actuallyadditions.extraInfo.desc=Advanced Info
|
||||
tooltip.actuallyadditions.blockPhantomRange.desc=Range
|
||||
tooltip.actuallyadditions.broken.desc=Broken
|
||||
|
||||
#Gui Information
|
||||
info.actuallyadditions.gui.animals=Animals
|
||||
|
|
Loading…
Reference in a new issue