From 7096fbb57c18e5d4a1d5080e4ceeed16b15aab9a Mon Sep 17 00:00:00 2001 From: Otho Date: Fri, 5 Dec 2014 11:04:04 -0200 Subject: [PATCH] Updating drop logic from blocks and crops, Adding multiple effects for foods and adding isWolfFood propertie to food --- .../configuration/Cfg_PotionEffect.java | 108 ++++++++++++++++ .../customItems/configuration/Cfg_block.java | 2 +- .../customItems/configuration/Cfg_food.java | 9 +- ...ideTextures.java => Cfg_sideTextures.java} | 2 +- .../configuration/RegisterCustomItems.java | 117 ++---------------- .../customItems/mod/blocks/CustomBlock.java | 8 +- .../customItems/mod/blocks/CustomCrop.java | 6 +- .../mod/items/armor/CustomArmor.java | 33 +++-- .../mod/items/food/CustomFood.java | 29 ++++- 9 files changed, 177 insertions(+), 137 deletions(-) create mode 100644 src/main/java/com/Otho/customItems/configuration/Cfg_PotionEffect.java rename src/main/java/com/Otho/customItems/configuration/{SideTextures.java => Cfg_sideTextures.java} (84%) diff --git a/src/main/java/com/Otho/customItems/configuration/Cfg_PotionEffect.java b/src/main/java/com/Otho/customItems/configuration/Cfg_PotionEffect.java new file mode 100644 index 0000000..e1fe73a --- /dev/null +++ b/src/main/java/com/Otho/customItems/configuration/Cfg_PotionEffect.java @@ -0,0 +1,108 @@ +package com.Otho.customItems.configuration; + +public class Cfg_PotionEffect { + public String effect = "moveSpeed"; + public int potionDuration = 30; + public int potionAmplifier = 0; + public float potionEffectProbability = 1; + + public static int potionEffectId (String effect) + { + if(effect.equals("moveSpeed")) + { + return 1; + } + else if(effect.equals("moveSlowdown")) + { + return 2; + } + else if(effect.equals("digSpeed")) + { + return 3; + } + else if(effect.equals("digSlowdown")) + { + return 4; + } + else if(effect.equals("damageBoost")) + { + return 5; + } + else if(effect.equals("heal")) + { + return 6; + } + else if(effect.equals("harm")) + { + return 7; + } + else if(effect.equals("jump")) + { + return 8; + } + else if(effect.equals("confusion")) + { + return 9; + } + else if(effect.equals("regeneration")) + { + return 10; + } + else if(effect.equals("resistance")) + { + return 11; + } + else if(effect.equals("fireResistance")) + { + return 12; + } + else if(effect.equals("waterBreathing")) + { + return 13; + } + else if(effect.equals("invisibility")) + { + return 14; + } + else if(effect.equals("blindness")) + { + return 15; + } + else if(effect .equals("nightVision")) + { + return 16; + } + else if(effect.equals("hunger")) + { + return 17; + } + else if(effect.equals("weakness")) + { + return 18; + } + else if(effect.equals("poison")) + { + return 19; + } + else if(effect.equals("wither")) + { + return 20; + } + else if(effect.equals("healthBoost")) + { + return 21; + } + else if(effect.equals("healthBoost")) + { + return 22; + } + else if(effect.equals("healthBoost")) + { + return 23; + } + else + { + return 6; + } + } +} diff --git a/src/main/java/com/Otho/customItems/configuration/Cfg_block.java b/src/main/java/com/Otho/customItems/configuration/Cfg_block.java index 76c953f..23b6d74 100644 --- a/src/main/java/com/Otho/customItems/configuration/Cfg_block.java +++ b/src/main/java/com/Otho/customItems/configuration/Cfg_block.java @@ -10,7 +10,7 @@ public class Cfg_block extends Cfg_basicData public float hardness = 2; public float lightLevel = 0; public int harvestLevel = 0; - public SideTextures multipleTextures; + public Cfg_sideTextures multipleTextures; public String stepSound = "stone"; diff --git a/src/main/java/com/Otho/customItems/configuration/Cfg_food.java b/src/main/java/com/Otho/customItems/configuration/Cfg_food.java index 72d7e13..c86b86a 100644 --- a/src/main/java/com/Otho/customItems/configuration/Cfg_food.java +++ b/src/main/java/com/Otho/customItems/configuration/Cfg_food.java @@ -7,13 +7,8 @@ public class Cfg_food extends Cfg_item public int healAmount = 1; public float saturationModifier = 1; public boolean alwaysEdible = false; - public PotionEffect potionEffect; + public boolean isWolfFood = false; + public Cfg_PotionEffect[] potionEffects; - public class PotionEffect{ - public String effect = "moveSpeed"; - public int potionDuration = 20; - public int potionAmplifier = 1; - public float potionEffectProbability = 1; - } } \ No newline at end of file diff --git a/src/main/java/com/Otho/customItems/configuration/SideTextures.java b/src/main/java/com/Otho/customItems/configuration/Cfg_sideTextures.java similarity index 84% rename from src/main/java/com/Otho/customItems/configuration/SideTextures.java rename to src/main/java/com/Otho/customItems/configuration/Cfg_sideTextures.java index 46ca4e3..8a346f6 100644 --- a/src/main/java/com/Otho/customItems/configuration/SideTextures.java +++ b/src/main/java/com/Otho/customItems/configuration/Cfg_sideTextures.java @@ -1,6 +1,6 @@ package com.Otho.customItems.configuration; -public class SideTextures { +public class Cfg_sideTextures { public String ypos; public String yneg; public String xpos; diff --git a/src/main/java/com/Otho/customItems/configuration/RegisterCustomItems.java b/src/main/java/com/Otho/customItems/configuration/RegisterCustomItems.java index 90bdadd..47dc618 100644 --- a/src/main/java/com/Otho/customItems/configuration/RegisterCustomItems.java +++ b/src/main/java/com/Otho/customItems/configuration/RegisterCustomItems.java @@ -449,17 +449,14 @@ private static void registerSingleFood(Cfg_food foodData) String registerName = StringUtil.parseRegisterName(foodData.name); - CustomFood food = new CustomFood(foodData.healAmount, foodData.saturationModifier, false); + CustomFood food = new CustomFood(foodData.healAmount, foodData.saturationModifier, foodData.isWolfFood); if(foodData.alwaysEdible) food.setAlwaysEdible(); - if(foodData.potionEffect != null) + if(foodData.potionEffects.length > 0) { - food.setPotionEffect(potionEffectId(foodData.potionEffect.effect), - foodData.potionEffect.potionDuration, - foodData.potionEffect.potionAmplifier, - foodData.potionEffect.potionEffectProbability); + food.setFoodEffectsArray(foodData.potionEffects); } @@ -664,7 +661,7 @@ private static void registerSingleHelmet(Cfg_helmet helmetData) reduction[0] = helmetData.reductionNum; ItemArmor.ArmorMaterial material = EnumHelper.addArmorMaterial(helmetData.textureName, helmetData.durability, reduction, helmetData.enchantability); - CustomArmor armor = new CustomArmor(material, 0, 0, helmetData.textureName); + CustomArmor armor = new CustomArmor(material, 0, 0, helmetData.textureName, helmetData.durability); //Register Armor itemsList.add(armor); @@ -686,7 +683,7 @@ private static void registerSingleChestplate(Cfg_chestplate chestplateData) reduction[1] = chestplateData.reductionNum; ItemArmor.ArmorMaterial material = EnumHelper.addArmorMaterial(chestplateData.textureName, chestplateData.durability, reduction, chestplateData.enchantability); - CustomArmor armor = new CustomArmor(material, 0, 1, chestplateData.textureName); + CustomArmor armor = new CustomArmor(material, 0, 1, chestplateData.textureName, chestplateData.durability); //Register Armor itemsList.add(armor); @@ -707,7 +704,7 @@ private static void registerSingleLeggings(Cfg_leggings leggingData) reduction[2] = leggingData.reductionNum; ItemArmor.ArmorMaterial material = EnumHelper.addArmorMaterial(leggingData.textureName, leggingData.durability, reduction, leggingData.enchantability); - CustomArmor armor = new CustomArmor(material, 0, 2, leggingData.textureName); + CustomArmor armor = new CustomArmor(material, 0, 2, leggingData.textureName, leggingData.durability); //Register Armor itemsList.add(armor); @@ -729,7 +726,7 @@ private static void registerSingleBoots(Cfg_boots bootsData) reduction[3] = bootsData.reductionNum; ItemArmor.ArmorMaterial material = EnumHelper.addArmorMaterial(bootsData.textureName, bootsData.durability, reduction, bootsData.enchantability); - CustomArmor armor = new CustomArmor(material, 0, 3, bootsData.textureName); + CustomArmor armor = new CustomArmor(material, 0, 3, bootsData.textureName, bootsData.durability); //Register Armor itemsList.add(armor); @@ -823,104 +820,4 @@ public static String validateToolClass(String toolClass){ return "pickaxe"; } } - - public static int potionEffectId (String effect) - { - if(effect.equals("moveSpeed")) - { - return 1; - } - else if(effect.equals("moveSlowdown")) - { - return 2; - } - else if(effect.equals("digSpeed")) - { - return 3; - } - else if(effect.equals("digSlowdown")) - { - return 4; - } - else if(effect.equals("damageBoost")) - { - return 5; - } - else if(effect.equals("heal")) - { - return 6; - } - else if(effect.equals("harm")) - { - return 7; - } - else if(effect.equals("jump")) - { - return 8; - } - else if(effect.equals("confusion")) - { - return 9; - } - else if(effect.equals("regeneration")) - { - return 10; - } - else if(effect.equals("resistance")) - { - return 11; - } - else if(effect.equals("fireResistance")) - { - return 12; - } - else if(effect.equals("waterBreathing")) - { - return 13; - } - else if(effect.equals("invisibility")) - { - return 14; - } - else if(effect.equals("blindness")) - { - return 15; - } - else if(effect .equals("nightVision")) - { - return 16; - } - else if(effect.equals("hunger")) - { - return 17; - } - else if(effect.equals("weakness")) - { - return 18; - } - else if(effect.equals("poison")) - { - return 19; - } - else if(effect.equals("wither")) - { - return 20; - } - else if(effect.equals("healthBoost")) - { - return 21; - } - else if(effect.equals("healthBoost")) - { - return 22; - } - else if(effect.equals("healthBoost")) - { - return 23; - } - else - { - return 6; - } - } } diff --git a/src/main/java/com/Otho/customItems/mod/blocks/CustomBlock.java b/src/main/java/com/Otho/customItems/mod/blocks/CustomBlock.java index 92df573..68da96c 100644 --- a/src/main/java/com/Otho/customItems/mod/blocks/CustomBlock.java +++ b/src/main/java/com/Otho/customItems/mod/blocks/CustomBlock.java @@ -78,18 +78,16 @@ private int getItemDropQuantity(World world, int fortune) { int ret = 0; int i; - for(i=0;i < this.maxItemDrop + fortune;i++) + ret = this.minItemDrop; + for(i= this.minItemDrop;i < this.maxItemDrop + fortune;i++) { boolean willDrop = world.rand.nextInt(100) < this.eachExtraItemDropChance; if(willDrop) ret++; } - if(ret < this.minItemDrop) - ret = this.minItemDrop; return ret; - } - + } public void setMaxItemDrop(int maxItemDrop) { this.maxItemDrop = maxItemDrop; diff --git a/src/main/java/com/Otho/customItems/mod/blocks/CustomCrop.java b/src/main/java/com/Otho/customItems/mod/blocks/CustomCrop.java index 5d5c3ca..5a9a733 100644 --- a/src/main/java/com/Otho/customItems/mod/blocks/CustomCrop.java +++ b/src/main/java/com/Otho/customItems/mod/blocks/CustomCrop.java @@ -77,14 +77,14 @@ private int getSeedDropQuantity(World world, int fortune) { int ret = 0; int i; - for(i=0;i < this.maxSeedDrop + fortune;i++) + ret = this.minSeedDrop; + + for(i=this.minSeedDrop;i < this.maxSeedDrop + fortune;i++) { boolean willDrop = world.rand.nextInt(100) < this.eachExtraSeedDropChance; if(willDrop) ret++; } - if(ret < this.minSeedDrop) - ret = this.minSeedDrop; return ret; } diff --git a/src/main/java/com/Otho/customItems/mod/items/armor/CustomArmor.java b/src/main/java/com/Otho/customItems/mod/items/armor/CustomArmor.java index 6a7d4c8..c7c0774 100644 --- a/src/main/java/com/Otho/customItems/mod/items/armor/CustomArmor.java +++ b/src/main/java/com/Otho/customItems/mod/items/armor/CustomArmor.java @@ -13,17 +13,32 @@ public class CustomArmor extends ItemArmor { protected int type; - protected String name = ""; - public CustomArmor(ArmorMaterial mat,int id,int type,String name) { + private String typeName; + protected String textureName = ""; + + public CustomArmor(ArmorMaterial mat, int id,int type, String textureName, int durability) { super(mat,id,type); this.type=type; - this.name=name; + this.textureName= textureName; + this.setMaxDamage(durability); + + if(type == 0){ + typeName = "helmet"; + }else if(type == 1){ + typeName = "chestplate"; + }else if(type == 2){ + typeName = "leggings"; + }else if(type == 3){ + typeName = "boots"; + } + + } @Override public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) { if(stack.getItem() instanceof CustomArmor) { - String path = ModReference.MOD_ID.toLowerCase() + ":textures/models/armor/" + this.name + "layer"; + String path = ModReference.MOD_ID.toLowerCase() + ":textures/models/armor/" + this.textureName + "_layer_"; String end = slot == 2 ? "2.png" : "1.png"; return path + end; } @@ -31,16 +46,16 @@ public String getArmorTexture(ItemStack stack, Entity entity, int slot, String t return null; } } - + @SideOnly(Side.CLIENT) @Override public void registerIcons(IIconRegister iconRegister) { - if(this.iconString == null) + if(this.textureName == null) { - itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".")+1)); + itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".")+1)); }else { - itemIcon = iconRegister.registerIcon(ModReference.MOD_ID.toLowerCase() + ":" + this.iconString); - } + itemIcon = iconRegister.registerIcon(ModReference.MOD_ID.toLowerCase() + ":" + this.textureName + "_" + this.typeName); + } } } diff --git a/src/main/java/com/Otho/customItems/mod/items/food/CustomFood.java b/src/main/java/com/Otho/customItems/mod/items/food/CustomFood.java index 1a5c552..963502a 100644 --- a/src/main/java/com/Otho/customItems/mod/items/food/CustomFood.java +++ b/src/main/java/com/Otho/customItems/mod/items/food/CustomFood.java @@ -1,18 +1,25 @@ package com.Otho.customItems.mod.items.food; +import com.Otho.customItems.configuration.Cfg_PotionEffect; import com.Otho.customItems.lib.ModReference; import com.Otho.customItems.mod.creativeTab.customItemsTab; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemSeedFood; import net.minecraft.item.ItemSeeds; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; +import net.minecraft.world.World; public class CustomFood extends ItemFood{ + private Cfg_PotionEffect[] effectsArray; + public CustomFood (int healAmount, float saturationModifier, boolean isWolfsFavoriteMeat){ super(healAmount, saturationModifier, isWolfsFavoriteMeat); } @@ -32,6 +39,26 @@ public void registerIcons(IIconRegister iconRegister) { { itemIcon = iconRegister.registerIcon(ModReference.MOD_ID.toLowerCase() + ":" + this.iconString); } - } + } + + @Override + protected void onFoodEaten(ItemStack p_77849_1_, World p_77849_2_, EntityPlayer p_77849_3_) + { + if (!p_77849_2_.isRemote) + { + //TODO: Make loop trhough all potion effects array adding each effect on the player based on each effect probability + //p_77849_3_.addPotionEffect(new PotionEffect(this.potionId, this.potionDuration * 20, this.potionAmplifier)); + for(int i = 0; i < effectsArray.length; i++){ + Cfg_PotionEffect effect = effectsArray[i]; + if(p_77849_2_.rand.nextFloat() < effect.potionEffectProbability){ + p_77849_3_.addPotionEffect(new PotionEffect(Cfg_PotionEffect.potionEffectId(effect.effect), effect.potionDuration * 20, effect.potionAmplifier)); + } + } + } + } + + public void setFoodEffectsArray(Cfg_PotionEffect[] effectsArray){ + this.effectsArray = effectsArray; + } }