Skip to content
This repository has been archived by the owner on Jan 25, 2020. It is now read-only.

Commit

Permalink
Nanomite arrow gun has now 4 modes
Browse files Browse the repository at this point in the history
  • Loading branch information
robin4002 committed Nov 2, 2013
1 parent 8283674 commit db29c7b
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 74 deletions.
@@ -1,24 +1,26 @@
package fr.mcnanotech.kevin_68.nanotech_mod.main.items;

import java.util.List;

import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.command.IEntitySelector;
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.entity.projectile.EntityArrow;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraft.util.Vec3;
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 ItemNanomiteArrowGun extends ItemBow
{
private Icon[] iconbuffer;
private static String[] bowpullname = new String[] {"nanomitebow_pull1", "nanomitebow_pull2", "nanomitebow_pull3"};
private int timer = 0;

public ItemNanomiteArrowGun(int id)
{
Expand All @@ -29,105 +31,202 @@ public ItemNanomiteArrowGun(int id)

public void registerIcons(IconRegister iconregister)
{
iconbuffer = new Icon[bowpullname.length];
for(int i = 0; i < bowpullname.length; i++)
{
iconbuffer[i] = iconregister.registerIcon("nanotech_mod:" + bowpullname[i]);
}
itemIcon = iconregister.registerIcon("nanotech_mod:nanomitebow");
}

public Icon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining)
{
if(usingItem != null && usingItem.getItem().itemID == NanotechItem.nanomiteBow.itemID)
{
int k = usingItem.getMaxItemUseDuration() - useRemaining;
if(k >= 5)
return iconbuffer[2];
if(k > 2)
return iconbuffer[1];
if(k > 0)
return iconbuffer[0];
}
return getIconIndex(stack);
}

public ItemStack onFoodEaten(ItemStack stack, World world, EntityPlayer player)
{
return stack;
}

public int getMaxItemUseDuration(ItemStack stack)
{
return 144000;
}

public EnumAction getItemUseAction(ItemStack stack)
{
return EnumAction.bow;
}

public String getTextureFile()
{
return "/fr/mcnanotech/kevin_68/nanotech_mod/client/textures/items.png";
}

public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
if(!world.isRemote)
{
boolean creativeorinfinity = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
if(!stack.hasTagCompound())
{
stack.setTagCompound(new NBTTagCompound());
}

if(creativeorinfinity || player.inventory.hasItem(Item.arrow.itemID))
if(player.isSneaking())
{
float var7 = 1.0F;
EntityArrow var8 = new EntityArrow(world, player, var7 * 6.0F);
if(var7 == 1.0F)
if(stack.getTagCompound().hasKey("Mode"))
{
var8.setIsCritical(true);
if(stack.getTagCompound().getByte("Mode") < 3)
{
stack.getTagCompound().setByte("Mode", (byte)(stack.getTagCompound().getByte("Mode") + 1));
}
else
{
stack.getTagCompound().setByte("Mode", (byte)0);
}
player.addChatMessage(this.getInfo(stack.getTagCompound().getByte("Mode")));
}

int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);

if(var9 > 0)
else
{
var8.setDamage(var8.getDamage() + (double)var9 * 0.5D + 0.5D);
stack.getTagCompound().setByte("Mode", (byte)1);
player.addChatMessage(this.getInfo((byte)1));
}

int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);

if(var10 > 0)
return stack;
}
else
{
if(!stack.getTagCompound().hasKey("Mode"))
{
var8.setKnockbackStrength(var10);
this.shot(stack, world, player);
return stack;
}

if(EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
else
{
var8.setFire(100);
if(stack.getTagCompound().getByte("Mode") == 0)
{
this.shot(stack, world, player);
return stack;
}
}
}
}
return stack;
}

stack.damageItem(1, player);
world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F);

if(creativeorinfinity)
{
var8.canBePickedUp = 2;
}
else
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isCurrentItem)
{
if(isCurrentItem && entity instanceof EntityPlayer && !world.isRemote)
{
EntityPlayer player = (EntityPlayer)entity;
if(stack.hasTagCompound())
{
if(stack.getTagCompound().hasKey("Mode"))
{
player.inventory.consumeInventoryItem(Item.arrow.itemID);
byte mode = stack.getTagCompound().getByte("Mode");
if(mode == 1 || mode == 2)
{
if(this.timer == 0)
{
this.shot(stack, world, player);
this.timer = (mode == 1 ? 16 : 4);
}
else
{
this.timer--;
}
}
else if(mode == 3)
{
final IEntitySelector livingFilter = new NanoArrowGunEntityFilter();
List entityTagetList = world.selectEntitiesWithinAABB(Entity.class, player.boundingBox.expand(64.0D, 64.0D, 64.0D), livingFilter);
for(int i = 0; i < entityTagetList.size(); i++)
{
Entity entityTarget = (Entity)entityTagetList.get(i);
if (entityTarget != player && entityTarget instanceof EntityLivingBase)
{
EntityLivingBase entityLivingTarget = (EntityLivingBase)entityTarget;
Vec3 vec3 = player.getLook(1.0F).normalize();
Vec3 vec31 = entityLivingTarget.worldObj.getWorldVec3Pool().getVecFromPool(entityLivingTarget.posX - player.posX, entityLivingTarget.boundingBox.minY + (double)(entityLivingTarget.height / 2.0F) - (player.posY + (double)player.getEyeHeight()), entityLivingTarget.posZ - player.posZ);
double d0 = vec31.lengthVector();
vec31 = vec31.normalize();
double d1 = vec3.dotProduct(vec31);
if(d1 > 1.0D - 0.025D / d0 && player.canEntityBeSeen(entityLivingTarget))
{
if(this.timer == 0)
{
this.shot(stack, world, player);
this.timer = 6;
}
else
{
this.timer --;
}
}
}
}
}
}
world.spawnEntityInWorld(var8);
return stack;
}
}
return stack;
}

public void shot(ItemStack stack, World world, EntityPlayer player)
{
boolean creativeOrInfinity = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;

if(creativeOrInfinity || player.inventory.hasItem(Item.arrow.itemID))
{
float power = 1.0F;
EntityArrow arrow = new EntityArrow(world, player, power * 6.0F);
arrow.setIsCritical(true);

int powerLvl = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);

if(powerLvl > 0)
{
arrow.setDamage(arrow.getDamage() + (double)powerLvl * 0.5D + 0.5D);
}

int punchLvl = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);

if(punchLvl > 0)
{
arrow.setKnockbackStrength(punchLvl);
}

if(EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
{
arrow.setFire(100);
}

stack.damageItem(1, player);
world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + power * 0.5F);

if(creativeOrInfinity)
{
arrow.canBePickedUp = 2;
}
else
{
player.inventory.consumeInventoryItem(Item.arrow.itemID);
}
world.spawnEntityInWorld(arrow);
}
}

public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
{
if(stack.hasTagCompound())
{
if(stack.getTagCompound().hasKey("Mode"))
{
byte mode = stack.getTagCompound().getByte("Mode");
list.add(this.getInfo(mode));
return;
}
list.add(getInfo((byte)0));
}
}

public int getItemEnchantability()
{
return 1;
}

}
private String getInfo(byte mode)
{
String info = "";
switch(mode)
{
case 0:
info = "nanomiteGun.manual";
break;
case 1:
info = "nanomiteGun.auto.slow";
break;
case 2:
info = "nanomiteGun.auto.fast";
break;
case 3:
info = "nanomiteGun.auto.detect";
break;
}
return StatCollector.translateToLocal(info);
}
}
@@ -0,0 +1,14 @@
package fr.mcnanotech.kevin_68.nanotech_mod.main.items;

import net.minecraft.command.IEntitySelector;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;

public class NanoArrowGunEntityFilter implements IEntitySelector
{
@Override
public boolean isEntityApplicable(Entity entity)
{
return entity instanceof EntityLivingBase;
}
}
5 changes: 5 additions & 0 deletions resources/assets/nanotech_mod/lang/en_US.lang
Expand Up @@ -115,6 +115,11 @@ info.void.1=Item for empty barrel
info.void.2=100 % cobblestone
info.void.3=100 % recyclable

nanomiteGun.manual=Shoot mode : Manual
nanomiteGun.auto.slow=Shoot mode : Automatic (slow)
nanomiteGun.auto.fast=Shoot mode : Automatic (fast)
nanomiteGun.auto.detect=Shoot mode : Automatic (mob detection)

#Achievement
achievement.installMod=Install Nanotech_mod
achievement.installMod.desc=Thank's for download!
Expand Down
5 changes: 5 additions & 0 deletions resources/assets/nanotech_mod/lang/fr_FR.lang
Expand Up @@ -116,6 +116,11 @@ info.void.1=Item pour barrel vide
info.void.2=100% cobblestone
info.void.3=100% recyclable

nanomiteGun.manual=Mode de tire : manuel
nanomiteGun.auto.slow=Mode de tire : automatique (lent)
nanomiteGun.auto.fast=Mode de tire : automatique (rapide)
nanomiteGun.auto.detect=Mode de tire : automatique (détection de mob)

#Achievement
achievement.installMod=Install Nanotech_mod
achievement.installMod.desc=Merci de l'avoir installé!
Expand Down

0 comments on commit db29c7b

Please sign in to comment.