Advertisement
JDtheman19

Cant get it to shoot

Jul 6th, 2018
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.97 KB | None | 0 0
  1. package JDtheman19.jdsweirdbutusefulmod.item.tools;
  2.  
  3. import JDtheman19.jdsweirdbutusefulmod.Mainmod;
  4. import JDtheman19.jdsweirdbutusefulmod.init.ModItems;
  5. import JDtheman19.jdsweirdbutusefulmod.item.ItemBase;
  6. import JDtheman19.jdsweirdbutusefulmod.util.IHasModel;
  7. import JDtheman19.jdsweirdbutusefulmod.util.Reference;
  8. import JDtheman19.jdsweirdbutusefulmod.util.handler.SoundHandler;
  9. import net.minecraft.block.Block;
  10. import net.minecraft.creativetab.CreativeTabs;
  11. import net.minecraft.enchantment.EnchantmentHelper;
  12. import net.minecraft.entity.Entity;
  13. import net.minecraft.entity.EntityLiving;
  14. import net.minecraft.entity.EntityLivingBase;
  15. import net.minecraft.entity.player.EntityPlayer;
  16. import net.minecraft.entity.projectile.EntityArrow;
  17. import net.minecraft.entity.projectile.EntityTippedArrow;
  18. import net.minecraft.init.Blocks;
  19. import net.minecraft.init.Enchantments;
  20. import net.minecraft.init.Items;
  21. import net.minecraft.init.SoundEvents;
  22. import net.minecraft.item.EnumAction;
  23. import net.minecraft.item.Item;
  24. import net.minecraft.item.ItemArrow;
  25. import net.minecraft.item.ItemBow;
  26. import net.minecraft.item.ItemStack;
  27. import net.minecraft.stats.StatList;
  28. import net.minecraft.util.ActionResult;
  29. import net.minecraft.util.EnumActionResult;
  30. import net.minecraft.util.EnumHand;
  31. import net.minecraft.util.ResourceLocation;
  32. import net.minecraft.util.SoundCategory;
  33. import net.minecraft.util.SoundEvent;
  34. import net.minecraft.util.math.BlockPos;
  35. import net.minecraft.util.math.MathHelper;
  36. import net.minecraft.world.World;
  37.  
  38.  
  39. public class ToolWeapons extends ItemBow implements IHasModel {
  40.    
  41.     public ToolWeapons(String name) {
  42.        
  43.         setMaxDamage(100);
  44.         maxStackSize = 1;
  45.         setUnlocalizedName(name);
  46.         setRegistryName(name);
  47.         setCreativeTab(CreativeTabs.COMBAT);
  48.        
  49.         ModItems.ITEMS.add(this);
  50.     }
  51.  
  52.     @Override
  53.     public void registerModels() {
  54. Mainmod.proxy.registerItemRenderer(this, 0, "inventory");
  55.     }
  56.     public int getMaxItemUseDuration(ItemStack par1ItemStack) {
  57.         return 72000;
  58.     }
  59.      private ItemStack findAmmo(EntityPlayer player)
  60.         {
  61.             if (this.isArrow(player.getHeldItem(EnumHand.OFF_HAND)))
  62.             {
  63.                 return player.getHeldItem(EnumHand.OFF_HAND);
  64.             }
  65.             else if (this.isArrow(player.getHeldItem(EnumHand.MAIN_HAND)))
  66.             {
  67.                 return player.getHeldItem(EnumHand.MAIN_HAND);
  68.             }
  69.             else
  70.             {
  71.                 for (int i = 0; i < player.inventory.getSizeInventory(); ++i)
  72.                 {
  73.                     ItemStack itemstack = player.inventory.getStackInSlot(i);
  74.  
  75.                     if (this.isArrow(itemstack))
  76.                     {
  77.                         return itemstack;
  78.                     }
  79.                 }
  80.  
  81.                 return ItemStack.EMPTY;
  82.             }
  83.         }
  84.      public EnumAction getItemUseAction(ItemStack stack)
  85.         {
  86.             return EnumAction.BOW;
  87.         }
  88.      public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
  89.         {
  90.          float f = 5.0F;
  91.             EntityBullet entityarrow = new EntityBullet(worldIn, entityLiving);
  92.             entityarrow.shoot(entityLiving.getLookVec().x, entityLiving.getLookVec().y, entityLiving.getLookVec().z, f * 2.0F, 0);
  93.             entityarrow.setIsCritical(false);
  94.             entityarrow.setDamage(7.0);
  95.             entityarrow.setKnockbackStrength(1);
  96.             if (entityLiving instanceof EntityPlayer)
  97.             {
  98.                 EntityPlayer entityplayer = (EntityPlayer)entityLiving;
  99.                 boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
  100.                 ItemStack itemstack = this.findAmmo(entityplayer);
  101.  
  102.                 int i = this.getMaxItemUseDuration(stack) - timeLeft;
  103.                 i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, entityplayer, i, !itemstack.isEmpty() || flag);
  104.                 if (i < 0) return;
  105.  
  106.                 if (!itemstack.isEmpty() || flag)
  107.                 {
  108.                     if (itemstack.isEmpty())
  109.                     {
  110.                         itemstack = new ItemStack(ModItems.MUSKET_BULLET);
  111.                     }
  112.  
  113.                     if ((double)f >= 0.1D)
  114.                     {
  115.                         boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer));
  116.  
  117.                         if (!worldIn.isRemote)
  118.                         {
  119.                             ItemArrow itemarrow = (ItemArrow)(itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : ModItems.MUSKET_BULLET);
  120.                             entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
  121.  
  122.                             stack.damageItem(1, entityplayer);
  123.  
  124.                             if (flag1 || entityplayer.capabilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW))
  125.                             {
  126.                                 entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
  127.                             }
  128.  
  129.                             worldIn.spawnEntity(entityarrow);
  130.                         }
  131.  
  132.                         worldIn.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundHandler.MUSKET_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
  133.  
  134.                         if (!flag1 && !entityplayer.capabilities.isCreativeMode)
  135.                         {
  136.                             itemstack.shrink(1);
  137.  
  138.                             if (itemstack.isEmpty())
  139.                             {
  140.                                 entityplayer.inventory.deleteStack(itemstack);
  141.                             }
  142.                         }
  143.  
  144.                         entityplayer.addStat(StatList.getObjectUseStats(this));
  145.                     }
  146.                 }
  147.             }
  148.         }
  149.    
  150.      public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
  151.      {
  152.             ItemStack itemstack = playerIn.getHeldItem(handIn);
  153.             boolean flag = !this.findAmmo(playerIn).isEmpty();
  154.  
  155.             ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemstack, worldIn, playerIn, handIn, flag);
  156.             if (ret != null) return ret;
  157.  
  158.             if (!playerIn.capabilities.isCreativeMode && !flag)
  159.             {
  160.                 return flag ? new ActionResult(EnumActionResult.PASS, itemstack) : new ActionResult(EnumActionResult.FAIL, itemstack);
  161.             }
  162.             else
  163.             {
  164.                 playerIn.setActiveHand(handIn);
  165.                 return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
  166.             }
  167.         }
  168.     }
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182. package JDtheman19.jdsweirdbutusefulmod.item.tools;
  183.  
  184. import net.minecraft.block.Block;
  185. import net.minecraft.entity.EntityLivingBase;
  186. import net.minecraft.entity.player.EntityPlayer;
  187. import net.minecraft.entity.projectile.EntityTippedArrow;
  188. import net.minecraft.init.Blocks;
  189. import net.minecraft.util.math.BlockPos;
  190. import net.minecraft.util.math.MathHelper;
  191. import net.minecraft.world.World;
  192.  
  193. public class EntityBullet extends EntityTippedArrow
  194. {
  195.     public EntityBullet(World a) {
  196.         super(a);
  197.     }
  198.  
  199.     public EntityBullet(World worldIn, double x, double y, double z) {
  200.         super(worldIn, x, y, z);
  201.     }
  202.  
  203.     public EntityBullet(World worldIn, EntityLivingBase shooter) {
  204.         super(worldIn, shooter);
  205.     }
  206.  
  207.  
  208.     public void onCollideWithPlayer(EntityPlayer entity) {
  209.         super.onCollideWithPlayer(entity);
  210.         int i = MathHelper.floor(this.getEntityBoundingBox().minX + 0.001D);
  211.         int j = MathHelper.floor(this.getEntityBoundingBox().minY + 0.001D);
  212.         int k = MathHelper.floor(this.getEntityBoundingBox().minZ + 0.001D);
  213.         World world = this.world;
  214.     }
  215.  
  216.     @Override
  217.     public void onUpdate() {
  218.         super.onUpdate();
  219.         int i = MathHelper.floor(this.getEntityBoundingBox().minX + 0.001D);
  220.         int j = MathHelper.floor(this.getEntityBoundingBox().minY + 0.001D);
  221.         int k = MathHelper.floor(this.getEntityBoundingBox().minZ + 0.001D);
  222.         World world = this.world;
  223.  
  224.         if (getBlock(this.world, i, j, k) != Blocks.AIR || getBlock(this.world, i, j - 1, k) != Blocks.AIR
  225.                 || getBlock(this.world, i, j + 1, k) != Blocks.AIR || getBlock(this.world, i + 1, j, k) != Blocks.AIR
  226.                 || getBlock(this.world, i - 1, j, k) != Blocks.AIR || getBlock(this.world, i, j, k + 1) != Blocks.AIR
  227.                 || getBlock(this.world, i, j, k - 1) != Blocks.AIR ||getBlock(this.world, i, j, k) != Blocks.TALLGRASS
  228.                 || getBlock(this.world, i, j - 1, k) != Blocks.TALLGRASS || getBlock(this.world, i, j + 1, k) != Blocks.TALLGRASS
  229.                 || getBlock(this.world, i + 1, j, k) != Blocks.TALLGRASS || getBlock(this.world, i - 1, j, k) != Blocks.TALLGRASS
  230.                 || getBlock(this.world, i, j, k + 1) != Blocks.TALLGRASS || getBlock(this.world, i, j, k - 1) != Blocks.TALLGRASS) {
  231.             this.world.removeEntity(this);
  232.         }
  233.     }
  234.  
  235.     public Block getBlock(World par1World, int i, int j, int k) {
  236.         return par1World.getBlockState(new BlockPos(i, j, k)).getBlock();
  237.     }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement