Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JDtheman19.jdsweirdbutusefulmod.item.tools;
- import JDtheman19.jdsweirdbutusefulmod.Mainmod;
- import JDtheman19.jdsweirdbutusefulmod.init.ModItems;
- import JDtheman19.jdsweirdbutusefulmod.item.ItemBase;
- import JDtheman19.jdsweirdbutusefulmod.util.IHasModel;
- import JDtheman19.jdsweirdbutusefulmod.util.Reference;
- import JDtheman19.jdsweirdbutusefulmod.util.handler.SoundHandler;
- import net.minecraft.block.Block;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.enchantment.EnchantmentHelper;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLiving;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.projectile.EntityArrow;
- import net.minecraft.entity.projectile.EntityTippedArrow;
- import net.minecraft.init.Blocks;
- import net.minecraft.init.Enchantments;
- import net.minecraft.init.Items;
- import net.minecraft.init.SoundEvents;
- import net.minecraft.item.EnumAction;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemArrow;
- import net.minecraft.item.ItemBow;
- import net.minecraft.item.ItemStack;
- import net.minecraft.stats.StatList;
- import net.minecraft.util.ActionResult;
- import net.minecraft.util.EnumActionResult;
- import net.minecraft.util.EnumHand;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.SoundCategory;
- import net.minecraft.util.SoundEvent;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.world.World;
- public class ToolWeapons extends ItemBow implements IHasModel {
- public ToolWeapons(String name) {
- setMaxDamage(100);
- maxStackSize = 1;
- setUnlocalizedName(name);
- setRegistryName(name);
- setCreativeTab(CreativeTabs.COMBAT);
- ModItems.ITEMS.add(this);
- }
- @Override
- public void registerModels() {
- Mainmod.proxy.registerItemRenderer(this, 0, "inventory");
- }
- public int getMaxItemUseDuration(ItemStack par1ItemStack) {
- return 72000;
- }
- private ItemStack findAmmo(EntityPlayer player)
- {
- if (this.isArrow(player.getHeldItem(EnumHand.OFF_HAND)))
- {
- return player.getHeldItem(EnumHand.OFF_HAND);
- }
- else if (this.isArrow(player.getHeldItem(EnumHand.MAIN_HAND)))
- {
- return player.getHeldItem(EnumHand.MAIN_HAND);
- }
- else
- {
- for (int i = 0; i < player.inventory.getSizeInventory(); ++i)
- {
- ItemStack itemstack = player.inventory.getStackInSlot(i);
- if (this.isArrow(itemstack))
- {
- return itemstack;
- }
- }
- return ItemStack.EMPTY;
- }
- }
- public EnumAction getItemUseAction(ItemStack stack)
- {
- return EnumAction.BOW;
- }
- public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
- {
- float f = 5.0F;
- EntityBullet entityarrow = new EntityBullet(worldIn, entityLiving);
- entityarrow.shoot(entityLiving.getLookVec().x, entityLiving.getLookVec().y, entityLiving.getLookVec().z, f * 2.0F, 0);
- entityarrow.setIsCritical(false);
- entityarrow.setDamage(7.0);
- entityarrow.setKnockbackStrength(1);
- if (entityLiving instanceof EntityPlayer)
- {
- EntityPlayer entityplayer = (EntityPlayer)entityLiving;
- boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
- ItemStack itemstack = this.findAmmo(entityplayer);
- int i = this.getMaxItemUseDuration(stack) - timeLeft;
- i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, entityplayer, i, !itemstack.isEmpty() || flag);
- if (i < 0) return;
- if (!itemstack.isEmpty() || flag)
- {
- if (itemstack.isEmpty())
- {
- itemstack = new ItemStack(ModItems.MUSKET_BULLET);
- }
- if ((double)f >= 0.1D)
- {
- boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer));
- if (!worldIn.isRemote)
- {
- ItemArrow itemarrow = (ItemArrow)(itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : ModItems.MUSKET_BULLET);
- entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
- stack.damageItem(1, entityplayer);
- if (flag1 || entityplayer.capabilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW))
- {
- entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
- }
- worldIn.spawnEntity(entityarrow);
- }
- 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);
- if (!flag1 && !entityplayer.capabilities.isCreativeMode)
- {
- itemstack.shrink(1);
- if (itemstack.isEmpty())
- {
- entityplayer.inventory.deleteStack(itemstack);
- }
- }
- entityplayer.addStat(StatList.getObjectUseStats(this));
- }
- }
- }
- }
- public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
- {
- ItemStack itemstack = playerIn.getHeldItem(handIn);
- boolean flag = !this.findAmmo(playerIn).isEmpty();
- ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemstack, worldIn, playerIn, handIn, flag);
- if (ret != null) return ret;
- if (!playerIn.capabilities.isCreativeMode && !flag)
- {
- return flag ? new ActionResult(EnumActionResult.PASS, itemstack) : new ActionResult(EnumActionResult.FAIL, itemstack);
- }
- else
- {
- playerIn.setActiveHand(handIn);
- return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
- }
- }
- }
- package JDtheman19.jdsweirdbutusefulmod.item.tools;
- import net.minecraft.block.Block;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.projectile.EntityTippedArrow;
- import net.minecraft.init.Blocks;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.world.World;
- public class EntityBullet extends EntityTippedArrow
- {
- public EntityBullet(World a) {
- super(a);
- }
- public EntityBullet(World worldIn, double x, double y, double z) {
- super(worldIn, x, y, z);
- }
- public EntityBullet(World worldIn, EntityLivingBase shooter) {
- super(worldIn, shooter);
- }
- public void onCollideWithPlayer(EntityPlayer entity) {
- super.onCollideWithPlayer(entity);
- int i = MathHelper.floor(this.getEntityBoundingBox().minX + 0.001D);
- int j = MathHelper.floor(this.getEntityBoundingBox().minY + 0.001D);
- int k = MathHelper.floor(this.getEntityBoundingBox().minZ + 0.001D);
- World world = this.world;
- }
- @Override
- public void onUpdate() {
- super.onUpdate();
- int i = MathHelper.floor(this.getEntityBoundingBox().minX + 0.001D);
- int j = MathHelper.floor(this.getEntityBoundingBox().minY + 0.001D);
- int k = MathHelper.floor(this.getEntityBoundingBox().minZ + 0.001D);
- World world = this.world;
- if (getBlock(this.world, i, j, k) != Blocks.AIR || getBlock(this.world, i, j - 1, k) != Blocks.AIR
- || getBlock(this.world, i, j + 1, k) != Blocks.AIR || getBlock(this.world, i + 1, j, k) != Blocks.AIR
- || getBlock(this.world, i - 1, j, k) != Blocks.AIR || getBlock(this.world, i, j, k + 1) != Blocks.AIR
- || getBlock(this.world, i, j, k - 1) != Blocks.AIR ||getBlock(this.world, i, j, k) != Blocks.TALLGRASS
- || getBlock(this.world, i, j - 1, k) != Blocks.TALLGRASS || getBlock(this.world, i, j + 1, k) != Blocks.TALLGRASS
- || getBlock(this.world, i + 1, j, k) != Blocks.TALLGRASS || getBlock(this.world, i - 1, j, k) != Blocks.TALLGRASS
- || getBlock(this.world, i, j, k + 1) != Blocks.TALLGRASS || getBlock(this.world, i, j, k - 1) != Blocks.TALLGRASS) {
- this.world.removeEntity(this);
- }
- }
- public Block getBlock(World par1World, int i, int j, int k) {
- return par1World.getBlockState(new BlockPos(i, j, k)).getBlock();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement