自分のMODでアドオン的なのを作っているんですが、
独自の弓を追加するとき、テクスチャ等はできたのですが
攻撃力(射撃ダメージ)の変更方法がわかりません。
ItemBow.classを変えればいいのか、EntityArrow.classを変えればいいのか・・・
ソースコードを張っておきます。
(コードがわかりにくかったり、邪魔な変数があったりします・・・)
SobaWeaponArmor.java
package com.soba.weaponarmor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraftforge.common.util.EnumHelper;
@Mod(modid = SobaWeaponArmor.MODID, version = SobaWeaponArmor.VERSION)
public class SobaWeaponArmor
{
public static final String MODID = "SobaWeaponArmor";
public static final String VERSION = "1.0.5";
public static Logger logger = LogManager.getLogger("SobaWeaponArmor");
public static CreativeTabs tabSobaWeaponArmor = new WeArTab("WeArtab");
public static Item swordSoba;
public static Item shovelSoba;
public static Item pickaxeSoba;
public static Item axeSoba;
public static Item hoeSoba;
public static Item bowSoba;
public static Item diaSwordSoba;
public static Item diaShovelSoba;
public static Item diaPickaxeSoba;
public static Item diaAxeSoba;
public static Item diaHoeSoba;
public static Item diaBowSoba;
public static Item goldSwordSoba;
public static Item goldShovelSoba;
public static Item goldPickaxeSoba;
public static Item goldAxeSoba;
public static Item goldHoeSoba;
public static Item goldBowSoba;
public static Item ironSwordSoba;
public static Item ironShovelSoba;
public static Item ironPickaxeSoba;
public static Item ironAxeSoba;
public static Item ironHoeSoba;
public static Item ironBowSoba;
public static Item stoneSwordSoba;
public static Item stoneShovelSoba;
public static Item stonePickaxeSoba;
public static Item stoneAxeSoba;
public static Item stoneHoeSoba;
public static Item stoneBowSoba;
public static Item helmetSoba;
public static Item chestPlateSoba;
public static Item leggingsSoba;
public static Item bootsSoba;
public static Item diaHelmetSoba;
public static Item diaChestPlateSoba;
public static Item diaLeggingsSoba;
public static Item diaBootsSoba;
public static Item goldHelmetSoba;
public static Item goldChestPlateSoba;
public static Item goldLeggingsSoba;
public static Item goldBootsSoba;
public static Item ironHelmetSoba;
public static Item ironChestPlateSoba;
public static Item ironLeggingsSoba;
public static Item ironBootsSoba;
public static Item stoneHelmetSoba;
public static Item stoneChestPlateSoba;
public static Item stoneLeggingsSoba;
public static Item stoneBootsSoba;
public static Item yudetasoba;
public static Item kittakizi;
public static ToolMaterial SOBA;
public static ToolMaterial DIASOBA;
public static ToolMaterial GOLDSOBA;
public static ToolMaterial IRONSOBA;
public static ToolMaterial STONESOBA;
public static ArmorMaterial SOBAARMOR;
public static ArmorMaterial DIASOBAARMOR;
public static ArmorMaterial GOLDSOBAARMOR;
public static ArmorMaterial IRONSOBAARMOR;
public static ArmorMaterial STONESOBAARMOR;
@EventHandler
public void init(FMLInitializationEvent event)
{
SOBA = EnumHelper.addToolMaterial("SOBA", 2, 1000, 100.0F, 100.0F, 20)
.setRepairItem(new ItemStack(this.yudetasoba));
DIASOBA = EnumHelper.addToolMaterial("DIASOBA", 10, 5000, 500.0F, 500.0F, 100)
.setRepairItem(new ItemStack(this.yudetasoba));
GOLDSOBA = EnumHelper.addToolMaterial("GOLDSOBA", 8, 4000, 400.0F, 400.0F, 80)
.setRepairItem(new ItemStack(this.yudetasoba));
IRONSOBA = EnumHelper.addToolMaterial("IRONSOBA", 6, 3000, 300.0F, 300.0F, 60)
.setRepairItem(new ItemStack(this.yudetasoba));
STONESOBA = EnumHelper.addToolMaterial("STONESOBA", 4, 2000, 200.0F, 200.0F, 40)
.setRepairItem(new ItemStack(this.yudetasoba));
SOBAARMOR = EnumHelper.addArmorMaterial("SOBAARMOR", 100, new int[] { 10, 10, 10, 10 }, 100);
SOBAARMOR.customCraftingMaterial = yudetasoba;
swordSoba = new ItemSword(SOBA)
.setCreativeTab(this.tabSobaWeaponArmor)
.setUnlocalizedName("swordSoba")
.setTextureName("firstaddon:soba_sword");
GameRegistry.registerItem(swordSoba, "swordSoba");
shovelSoba = new ItemSpade(SOBA)
.setCreativeTab(this.tabSobaWeaponArmor)
.setUnlocalizedName("shovelSoba")
.setTextureName("firstaddon:soba_shovel");
GameRegistry.registerItem(shovelSoba, "shovelSoba");
pickaxeSoba = new SobaPickaxe(SOBA)
.setCreativeTab(this.tabSobaWeaponArmor)
.setUnlocalizedName("pickaxeSoba")
.setTextureName("firstaddon:soba_pickaxe");
GameRegistry.registerItem(pickaxeSoba, "pickaxeSoba");
axeSoba = new SobaAxe(SOBA)
.setCreativeTab(this.tabSobaWeaponArmor)
.setUnlocalizedName("axeSoba")
.setTextureName("firstaddon:soba_axe");
GameRegistry.registerItem(axeSoba, "axeSoba");
hoeSoba = new ItemHoe(SOBA)
.setCreativeTab(this.tabSobaWeaponArmor)
.setUnlocalizedName("hoeSoba")
.setTextureName("firstaddon:soba_hoe");
GameRegistry.registerItem(hoeSoba, "hoeSoba");
bowSoba = new SobaBow()
.setCreativeTab(this.tabSobaWeaponArmor)
.setUnlocalizedName("bowSoba")
.setFull3D()
.setTextureName("firstaddon:soba_bow");
GameRegistry.registerItem(bowSoba, "bowSoba");
helmetSoba = new ItemSobaArmor(0)
.setUnlocalizedName("helmetSoba")
.setTextureName("firstaddon:helmetSoba");
GameRegistry.registerItem(helmetSoba, "helmetSoba");
chestPlateSoba = new ItemSobaArmor(1)
.setUnlocalizedName("chestPlateSoba")
.setTextureName("firstaddon:chestPlateSoba");
GameRegistry.registerItem(chestPlateSoba, "chestPlateSoba");
leggingsSoba = new ItemSobaArmor(2)
.setUnlocalizedName("leggingsSoba")
.setTextureName("firstaddon:leggingsSoba");
GameRegistry.registerItem(leggingsSoba, "leggingsSoba");
bootsSoba = new ItemSobaArmor(3)
.setUnlocalizedName("bootsSoba")
.setTextureName("firstaddon:bootsSoba");
GameRegistry.registerItem(bootsSoba, "bootsSoba");
}
@EventHandler
public void postInit (FMLPostInitializationEvent event)
{
if(Loader.isModLoaded("SobaMod"))
{
try
{
this.yudetasoba = GameRegistry.findItem("SobaMod", "yudetasoba");
this.kittakizi = GameRegistry.findItem("SobaMod", "kittakizi");
GameRegistry.addRecipe(new ItemStack(this.swordSoba),
"Y",
"Y",
"S",
'Y', this.yudetasoba,
'S', Items.stick
);
GameRegistry.addRecipe(new ItemStack(this.shovelSoba),
"Y",
"S",
"S",
'Y', this.yudetasoba,
'S', Items.stick
);
GameRegistry.addRecipe(new ItemStack(this.pickaxeSoba),
"YYY",
" S ",
" S ",
'Y', this.yudetasoba,
'S', Items.stick
);
GameRegistry.addRecipe(new ItemStack(this.axeSoba),
"YY",
"YS",
" S",
'Y', this.yudetasoba,
'S', Items.stick
);
GameRegistry.addRecipe(new ItemStack(this.hoeSoba),
"YY",
" S",
" S",
'Y', this.yudetasoba,
'S', Items.stick
);
GameRegistry.addRecipe(new ItemStack(this.helmetSoba),
"YYY",
"Y Y",
'Y', this.yudetasoba
);
GameRegistry.addRecipe(new ItemStack(this.chestPlateSoba),
"Y Y",
"YYY",
"YYY",
'Y', this.yudetasoba
);
GameRegistry.addRecipe(new ItemStack(this.leggingsSoba),
"YYY",
"Y Y",
"Y Y",
'Y', this.yudetasoba
);
GameRegistry.addRecipe(new ItemStack(this.bootsSoba),
"Y Y",
"Y Y",
'Y', this.yudetasoba
);
GameRegistry.addRecipe(new ItemStack(this.bowSoba),
" YK",
"Y K",
" YK",
'Y', this.yudetasoba,
'K', this.kittakizi
);
}
catch (Throwable t)
{
logger.warn("Failed to get items of SobaMod.");
}
finally{}
}
}
}
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraftforge.common.util.EnumHelper;
@Mod(modid = SobaWeaponArmor.MODID, version = SobaWeaponArmor.VERSION)
public class SobaWeaponArmor
{
public static final String MODID = "SobaWeaponArmor";
public static final String VERSION = "1.0.5";
public static Logger logger = LogManager.getLogger("SobaWeaponArmor");
public static CreativeTabs tabSobaWeaponArmor = new WeArTab("WeArtab");
public static Item swordSoba;
public static Item shovelSoba;
public static Item pickaxeSoba;
public static Item axeSoba;
public static Item hoeSoba;
public static Item bowSoba;
public static Item diaSwordSoba;
public static Item diaShovelSoba;
public static Item diaPickaxeSoba;
public static Item diaAxeSoba;
public static Item diaHoeSoba;
public static Item diaBowSoba;
public static Item goldSwordSoba;
public static Item goldShovelSoba;
public static Item goldPickaxeSoba;
public static Item goldAxeSoba;
public static Item goldHoeSoba;
public static Item goldBowSoba;
public static Item ironSwordSoba;
public static Item ironShovelSoba;
public static Item ironPickaxeSoba;
public static Item ironAxeSoba;
public static Item ironHoeSoba;
public static Item ironBowSoba;
public static Item stoneSwordSoba;
public static Item stoneShovelSoba;
public static Item stonePickaxeSoba;
public static Item stoneAxeSoba;
public static Item stoneHoeSoba;
public static Item stoneBowSoba;
public static Item helmetSoba;
public static Item chestPlateSoba;
public static Item leggingsSoba;
public static Item bootsSoba;
public static Item diaHelmetSoba;
public static Item diaChestPlateSoba;
public static Item diaLeggingsSoba;
public static Item diaBootsSoba;
public static Item goldHelmetSoba;
public static Item goldChestPlateSoba;
public static Item goldLeggingsSoba;
public static Item goldBootsSoba;
public static Item ironHelmetSoba;
public static Item ironChestPlateSoba;
public static Item ironLeggingsSoba;
public static Item ironBootsSoba;
public static Item stoneHelmetSoba;
public static Item stoneChestPlateSoba;
public static Item stoneLeggingsSoba;
public static Item stoneBootsSoba;
public static Item yudetasoba;
public static Item kittakizi;
public static ToolMaterial SOBA;
public static ToolMaterial DIASOBA;
public static ToolMaterial GOLDSOBA;
public static ToolMaterial IRONSOBA;
public static ToolMaterial STONESOBA;
public static ArmorMaterial SOBAARMOR;
public static ArmorMaterial DIASOBAARMOR;
public static ArmorMaterial GOLDSOBAARMOR;
public static ArmorMaterial IRONSOBAARMOR;
public static ArmorMaterial STONESOBAARMOR;
@EventHandler
public void init(FMLInitializationEvent event)
{
SOBA = EnumHelper.addToolMaterial("SOBA", 2, 1000, 100.0F, 100.0F, 20)
.setRepairItem(new ItemStack(this.yudetasoba));
DIASOBA = EnumHelper.addToolMaterial("DIASOBA", 10, 5000, 500.0F, 500.0F, 100)
.setRepairItem(new ItemStack(this.yudetasoba));
GOLDSOBA = EnumHelper.addToolMaterial("GOLDSOBA", 8, 4000, 400.0F, 400.0F, 80)
.setRepairItem(new ItemStack(this.yudetasoba));
IRONSOBA = EnumHelper.addToolMaterial("IRONSOBA", 6, 3000, 300.0F, 300.0F, 60)
.setRepairItem(new ItemStack(this.yudetasoba));
STONESOBA = EnumHelper.addToolMaterial("STONESOBA", 4, 2000, 200.0F, 200.0F, 40)
.setRepairItem(new ItemStack(this.yudetasoba));
SOBAARMOR = EnumHelper.addArmorMaterial("SOBAARMOR", 100, new int[] { 10, 10, 10, 10 }, 100);
SOBAARMOR.customCraftingMaterial = yudetasoba;
swordSoba = new ItemSword(SOBA)
.setCreativeTab(this.tabSobaWeaponArmor)
.setUnlocalizedName("swordSoba")
.setTextureName("firstaddon:soba_sword");
GameRegistry.registerItem(swordSoba, "swordSoba");
shovelSoba = new ItemSpade(SOBA)
.setCreativeTab(this.tabSobaWeaponArmor)
.setUnlocalizedName("shovelSoba")
.setTextureName("firstaddon:soba_shovel");
GameRegistry.registerItem(shovelSoba, "shovelSoba");
pickaxeSoba = new SobaPickaxe(SOBA)
.setCreativeTab(this.tabSobaWeaponArmor)
.setUnlocalizedName("pickaxeSoba")
.setTextureName("firstaddon:soba_pickaxe");
GameRegistry.registerItem(pickaxeSoba, "pickaxeSoba");
axeSoba = new SobaAxe(SOBA)
.setCreativeTab(this.tabSobaWeaponArmor)
.setUnlocalizedName("axeSoba")
.setTextureName("firstaddon:soba_axe");
GameRegistry.registerItem(axeSoba, "axeSoba");
hoeSoba = new ItemHoe(SOBA)
.setCreativeTab(this.tabSobaWeaponArmor)
.setUnlocalizedName("hoeSoba")
.setTextureName("firstaddon:soba_hoe");
GameRegistry.registerItem(hoeSoba, "hoeSoba");
bowSoba = new SobaBow()
.setCreativeTab(this.tabSobaWeaponArmor)
.setUnlocalizedName("bowSoba")
.setFull3D()
.setTextureName("firstaddon:soba_bow");
GameRegistry.registerItem(bowSoba, "bowSoba");
helmetSoba = new ItemSobaArmor(0)
.setUnlocalizedName("helmetSoba")
.setTextureName("firstaddon:helmetSoba");
GameRegistry.registerItem(helmetSoba, "helmetSoba");
chestPlateSoba = new ItemSobaArmor(1)
.setUnlocalizedName("chestPlateSoba")
.setTextureName("firstaddon:chestPlateSoba");
GameRegistry.registerItem(chestPlateSoba, "chestPlateSoba");
leggingsSoba = new ItemSobaArmor(2)
.setUnlocalizedName("leggingsSoba")
.setTextureName("firstaddon:leggingsSoba");
GameRegistry.registerItem(leggingsSoba, "leggingsSoba");
bootsSoba = new ItemSobaArmor(3)
.setUnlocalizedName("bootsSoba")
.setTextureName("firstaddon:bootsSoba");
GameRegistry.registerItem(bootsSoba, "bootsSoba");
}
@EventHandler
public void postInit (FMLPostInitializationEvent event)
{
if(Loader.isModLoaded("SobaMod"))
{
try
{
this.yudetasoba = GameRegistry.findItem("SobaMod", "yudetasoba");
this.kittakizi = GameRegistry.findItem("SobaMod", "kittakizi");
GameRegistry.addRecipe(new ItemStack(this.swordSoba),
"Y",
"Y",
"S",
'Y', this.yudetasoba,
'S', Items.stick
);
GameRegistry.addRecipe(new ItemStack(this.shovelSoba),
"Y",
"S",
"S",
'Y', this.yudetasoba,
'S', Items.stick
);
GameRegistry.addRecipe(new ItemStack(this.pickaxeSoba),
"YYY",
" S ",
" S ",
'Y', this.yudetasoba,
'S', Items.stick
);
GameRegistry.addRecipe(new ItemStack(this.axeSoba),
"YY",
"YS",
" S",
'Y', this.yudetasoba,
'S', Items.stick
);
GameRegistry.addRecipe(new ItemStack(this.hoeSoba),
"YY",
" S",
" S",
'Y', this.yudetasoba,
'S', Items.stick
);
GameRegistry.addRecipe(new ItemStack(this.helmetSoba),
"YYY",
"Y Y",
'Y', this.yudetasoba
);
GameRegistry.addRecipe(new ItemStack(this.chestPlateSoba),
"Y Y",
"YYY",
"YYY",
'Y', this.yudetasoba
);
GameRegistry.addRecipe(new ItemStack(this.leggingsSoba),
"YYY",
"Y Y",
"Y Y",
'Y', this.yudetasoba
);
GameRegistry.addRecipe(new ItemStack(this.bootsSoba),
"Y Y",
"Y Y",
'Y', this.yudetasoba
);
GameRegistry.addRecipe(new ItemStack(this.bowSoba),
" YK",
"Y K",
" YK",
'Y', this.yudetasoba,
'K', this.kittakizi
);
}
catch (Throwable t)
{
logger.warn("Failed to get items of SobaMod.");
}
finally{}
}
}
}
SobaBow.java
package com.soba.weaponarmor;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
import net.minecraftforge.event.entity.player.ArrowNockEvent;
public class SobaBow extends ItemBow {
public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2"};
@SideOnly(Side.CLIENT)
private IIcon[] iconArray;
private static final String __OBFID = "CL_00001777";
public SobaBow()
{
this.setCreativeTab(SobaWeaponArmor.tabSobaWeaponArmor);
}
public void onPlayerStoppedUsing(ItemStack p_77615_1_, World p_77615_2_, EntityPlayer p_77615_3_, int p_77615_4_)
{
int j = this.getMaxItemUseDuration(p_77615_1_) - p_77615_4_;
ArrowLooseEvent event = new ArrowLooseEvent(p_77615_3_, p_77615_1_, j);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled())
{
return;
}
j = event.charge;
boolean flag = p_77615_3_.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, p_77615_1_) > 0;
if (flag || p_77615_3_.inventory.hasItem(Items.arrow))
{
float f = (float)j / 20.0F;
f = (f * f + f * 2.0F) / 3.0F;
if ((double)f < 0.1D)
{
return;
}
if (f > 1.0F)
{
f = 1.0F;
}
EntityArrow entityarrow = new EntityArrow(p_77615_2_, p_77615_3_, f * 2.0F);
if (f == 1.0F)
{
entityarrow.setIsCritical(true);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, p_77615_1_);
if (k > 0)
{
entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D);
}
int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, p_77615_1_);
if (l > 0)
{
entityarrow.setKnockbackStrength(l);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, p_77615_1_) > 0)
{
entityarrow.setFire(100);
}
p_77615_1_.damageItem(1, p_77615_3_);
p_77615_2_.playSoundAtEntity(p_77615_3_, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (flag)
{
entityarrow.canBePickedUp = 2;
}
else
{
p_77615_3_.inventory.consumeInventoryItem(Items.arrow);
}
if (!p_77615_2_.isRemote)
{
p_77615_2_.spawnEntityInWorld(entityarrow);
}
}
}
public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer p_77654_3_)
{
return p_77654_1_;
}
/**
* How long it takes to use or consume an item
*/
public int getMaxItemUseDuration(ItemStack p_77626_1_)
{
return 72000;
}
/**
* returns the action that specifies what animation to play when the items is being used
*/
public EnumAction getItemUseAction(ItemStack p_77661_1_)
{
return EnumAction.bow;
}
/**
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
*/
public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)
{
ArrowNockEvent event = new ArrowNockEvent(p_77659_3_, p_77659_1_);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled())
{
return event.result;
}
if (p_77659_3_.capabilities.isCreativeMode || p_77659_3_.inventory.hasItem(Items.arrow))
{
p_77659_3_.setItemInUse(p_77659_1_, this.getMaxItemUseDuration(p_77659_1_));
}
return p_77659_1_;
}
/**
* Return the enchantability factor of the item, most of the time is based on material.
*/
public int getItemEnchantability()
{
return 1;
}
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister p_94581_1_)
{
this.itemIcon = p_94581_1_.registerIcon(this.getIconString() + "_standby");
this.iconArray = new IIcon[bowPullIconNameArray.length];
for (int i = 0; i < this.iconArray.length; ++i)
{
this.iconArray[i] = p_94581_1_.registerIcon(this.getIconString() + "_" + bowPullIconNameArray[i]);
}
}
/**
* used to cycle through icons based on their used duration, i.e. for the bow
*/
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
if (usingItem == null) { return itemIcon; }
int ticksInUse = stack.getMaxItemUseDuration() - useRemaining;
if (ticksInUse > 17) {
return iconArray[2];
} else if (ticksInUse > 13) {
return iconArray[1];
} else if (ticksInUse > 0) {
return iconArray[0];
} else {
return itemIcon;
}
}
}
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
import net.minecraftforge.event.entity.player.ArrowNockEvent;
public class SobaBow extends ItemBow {
public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2"};
@SideOnly(Side.CLIENT)
private IIcon[] iconArray;
private static final String __OBFID = "CL_00001777";
public SobaBow()
{
this.setCreativeTab(SobaWeaponArmor.tabSobaWeaponArmor);
}
public void onPlayerStoppedUsing(ItemStack p_77615_1_, World p_77615_2_, EntityPlayer p_77615_3_, int p_77615_4_)
{
int j = this.getMaxItemUseDuration(p_77615_1_) - p_77615_4_;
ArrowLooseEvent event = new ArrowLooseEvent(p_77615_3_, p_77615_1_, j);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled())
{
return;
}
j = event.charge;
boolean flag = p_77615_3_.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, p_77615_1_) > 0;
if (flag || p_77615_3_.inventory.hasItem(Items.arrow))
{
float f = (float)j / 20.0F;
f = (f * f + f * 2.0F) / 3.0F;
if ((double)f < 0.1D)
{
return;
}
if (f > 1.0F)
{
f = 1.0F;
}
EntityArrow entityarrow = new EntityArrow(p_77615_2_, p_77615_3_, f * 2.0F);
if (f == 1.0F)
{
entityarrow.setIsCritical(true);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, p_77615_1_);
if (k > 0)
{
entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D);
}
int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, p_77615_1_);
if (l > 0)
{
entityarrow.setKnockbackStrength(l);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, p_77615_1_) > 0)
{
entityarrow.setFire(100);
}
p_77615_1_.damageItem(1, p_77615_3_);
p_77615_2_.playSoundAtEntity(p_77615_3_, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (flag)
{
entityarrow.canBePickedUp = 2;
}
else
{
p_77615_3_.inventory.consumeInventoryItem(Items.arrow);
}
if (!p_77615_2_.isRemote)
{
p_77615_2_.spawnEntityInWorld(entityarrow);
}
}
}
public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer p_77654_3_)
{
return p_77654_1_;
}
/**
* How long it takes to use or consume an item
*/
public int getMaxItemUseDuration(ItemStack p_77626_1_)
{
return 72000;
}
/**
* returns the action that specifies what animation to play when the items is being used
*/
public EnumAction getItemUseAction(ItemStack p_77661_1_)
{
return EnumAction.bow;
}
/**
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
*/
public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)
{
ArrowNockEvent event = new ArrowNockEvent(p_77659_3_, p_77659_1_);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled())
{
return event.result;
}
if (p_77659_3_.capabilities.isCreativeMode || p_77659_3_.inventory.hasItem(Items.arrow))
{
p_77659_3_.setItemInUse(p_77659_1_, this.getMaxItemUseDuration(p_77659_1_));
}
return p_77659_1_;
}
/**
* Return the enchantability factor of the item, most of the time is based on material.
*/
public int getItemEnchantability()
{
return 1;
}
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister p_94581_1_)
{
this.itemIcon = p_94581_1_.registerIcon(this.getIconString() + "_standby");
this.iconArray = new IIcon[bowPullIconNameArray.length];
for (int i = 0; i < this.iconArray.length; ++i)
{
this.iconArray[i] = p_94581_1_.registerIcon(this.getIconString() + "_" + bowPullIconNameArray[i]);
}
}
/**
* used to cycle through icons based on their used duration, i.e. for the bow
*/
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
if (usingItem == null) { return itemIcon; }
int ticksInUse = stack.getMaxItemUseDuration() - useRemaining;
if (ticksInUse > 17) {
return iconArray[2];
} else if (ticksInUse > 13) {
return iconArray[1];
} else if (ticksInUse > 0) {
return iconArray[0];
} else {
return itemIcon;
}
}
}
どなたか、ご教授願います。