From 034ab4b8d09aa1101c50067407d6c45645f794e8 Mon Sep 17 00:00:00 2001 From: Mohammad-Ali Minaie Date: Mon, 3 Jul 2017 00:20:17 -0400 Subject: [PATCH] gotta go wash my hair --- .../primal/forgecraft/blocks/YewStave.java | 13 +- .../nmd/primal/forgecraft/init/ModItems.java | 5 + .../forgecraft/items/weapons/Longbow.java | 264 ++++++++++++++++++ .../forgecraft/models/item/e_particle.png | Bin 159 -> 0 bytes .../forgecraft/models/item/e_texture.png | Bin 141 -> 0 bytes .../forgecraft/models/item/longbow.json | 25 ++ .../models/item/longbow/longbow_0.json | 9 + .../models/item/{ => longbow}/longbow_1.json | 6 +- .../models/item/{ => longbow}/longbow_2.json | 6 +- .../models/item/{ => longbow}/longbow_3.json | 6 +- .../models/item/{ => longbow}/longbow_4.json | 6 +- .../models/item/{ => longbow}/longbow_5.json | 6 +- .../models/item/{ => longbow}/longbow_6.json | 160 +++++------ .../models/item/{ => longbow}/longbow_7.json | 244 ++++++++-------- .../models/item/{ => longbow}/longbow_8.json | 48 +++- .../models/item/longbow_default.json | 6 +- ...bow_unstrung.json => unstrunglongbow.json} | 6 +- .../forgecraft/textures/items/bowstring.png | Bin 0 -> 438 bytes 18 files changed, 564 insertions(+), 246 deletions(-) create mode 100644 kfc/src/main/java/nmd/primal/forgecraft/items/weapons/Longbow.java delete mode 100644 kfc/src/main/resources/assets/forgecraft/models/item/e_particle.png delete mode 100644 kfc/src/main/resources/assets/forgecraft/models/item/e_texture.png create mode 100644 kfc/src/main/resources/assets/forgecraft/models/item/longbow.json create mode 100644 kfc/src/main/resources/assets/forgecraft/models/item/longbow/longbow_0.json rename kfc/src/main/resources/assets/forgecraft/models/item/{ => longbow}/longbow_1.json (99%) rename kfc/src/main/resources/assets/forgecraft/models/item/{ => longbow}/longbow_2.json (99%) rename kfc/src/main/resources/assets/forgecraft/models/item/{ => longbow}/longbow_3.json (99%) rename kfc/src/main/resources/assets/forgecraft/models/item/{ => longbow}/longbow_4.json (99%) rename kfc/src/main/resources/assets/forgecraft/models/item/{ => longbow}/longbow_5.json (99%) rename kfc/src/main/resources/assets/forgecraft/models/item/{ => longbow}/longbow_6.json (87%) rename kfc/src/main/resources/assets/forgecraft/models/item/{ => longbow}/longbow_7.json (81%) rename kfc/src/main/resources/assets/forgecraft/models/item/{ => longbow}/longbow_8.json (94%) rename kfc/src/main/resources/assets/forgecraft/models/item/{longbow_unstrung.json => unstrunglongbow.json} (99%) create mode 100644 kfc/src/main/resources/assets/forgecraft/textures/items/bowstring.png diff --git a/kfc/src/main/java/nmd/primal/forgecraft/blocks/YewStave.java b/kfc/src/main/java/nmd/primal/forgecraft/blocks/YewStave.java index e1b00dfc..18224dbe 100644 --- a/kfc/src/main/java/nmd/primal/forgecraft/blocks/YewStave.java +++ b/kfc/src/main/java/nmd/primal/forgecraft/blocks/YewStave.java @@ -3,25 +3,29 @@ package nmd.primal.forgecraft.blocks; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import nmd.primal.core.api.PrimalSounds; import nmd.primal.core.common.helper.PlayerHelper; import nmd.primal.core.common.items.tools.WorkBlade; import nmd.primal.core.common.helper.CommonUtils; import nmd.primal.forgecraft.init.ModItems; +import nmd.primal.forgecraft.init.ModSounds; /** * Created by mminaie on 7/2/17. */ public class YewStave extends BlockCustomBase { - public AxisAlignedBB AABBSTAVE = new AxisAlignedBB(13/32D, 0.0D, 13/32/16D, 19/32D, 1.0D, 19/32D); + public AxisAlignedBB AABBSTAVE = new AxisAlignedBB(13/32D, 0.0D, 13/32D, 19/32D, 1.0D, 19/32D); public YewStave(Material material, String registryName, Float hardness) { super(material, registryName, hardness); @@ -40,13 +44,16 @@ public class YewStave extends BlockCustomBase { if (world.isRemote) return true; - ItemStack pItem = player.getActiveItemStack(); + ItemStack pItem = player.inventory.getCurrentItem(); if(pItem.getItem() instanceof WorkBlade){ if(world.getBlockState(pos.up()).getBlock() instanceof YewStave ) { - //TODO play sound, swingArm + //world.playSound(player, player.posX, player.posY, player.posZ, PrimalSounds.TOOL_BLADE_SCRAPE, SoundCategory.PLAYERS, 1.0F, 1F); + world.playSound(null, pos, PrimalSounds.TOOL_BLADE_SCRAPE, SoundCategory.PLAYERS, 1.0F, 1.0F); if(CommonUtils.randomCheck(3) ) { PlayerHelper.spawnItemOnGround(world, pos, new ItemStack(ModItems.unstrunglongbow, 1)); + world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2); + world.setBlockState(pos.up(), Blocks.AIR.getDefaultState(), 2); return true; } } diff --git a/kfc/src/main/java/nmd/primal/forgecraft/init/ModItems.java b/kfc/src/main/java/nmd/primal/forgecraft/init/ModItems.java index a7b26aa1..05442258 100644 --- a/kfc/src/main/java/nmd/primal/forgecraft/init/ModItems.java +++ b/kfc/src/main/java/nmd/primal/forgecraft/init/ModItems.java @@ -21,6 +21,7 @@ import nmd.primal.forgecraft.items.parts.ToolPart; import nmd.primal.forgecraft.items.tools.*; import nmd.primal.forgecraft.items.weapons.CustomShield; import nmd.primal.forgecraft.items.weapons.CustomSword; +import nmd.primal.forgecraft.items.weapons.Longbow; import nmd.primal.forgecraft.items.weapons.SlayerSword; /** @@ -136,6 +137,7 @@ public class ModItems { castingmud = new BaseItem("castingmud"); unstrunglongbow = new BaseItem("unstrunglongbow"); + longbow = new Longbow("longbow"); //matchlockmusket = new Musket("matchlock_musket"); @@ -334,6 +336,7 @@ public class ModItems { GameRegistry.register(steelslayer); GameRegistry.register(unstrunglongbow); + GameRegistry.register(longbow); //GameRegistry.register(matchlockmusket); //GameRegistry.register(forgingmanual); @@ -435,6 +438,8 @@ public class ModItems { registerRender(cleanironslayer); registerRender(steelslayer); + registerRender(unstrunglongbow); + registerRender(longbow); //registerRender(forgingmanual); //registerRender(matchlockmusket); } diff --git a/kfc/src/main/java/nmd/primal/forgecraft/items/weapons/Longbow.java b/kfc/src/main/java/nmd/primal/forgecraft/items/weapons/Longbow.java new file mode 100644 index 00000000..8a9a5808 --- /dev/null +++ b/kfc/src/main/java/nmd/primal/forgecraft/items/weapons/Longbow.java @@ -0,0 +1,264 @@ +package nmd.primal.forgecraft.items.weapons; + +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.init.Enchantments; +import net.minecraft.init.Items; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.*; +import net.minecraft.stats.StatList; +import net.minecraft.util.*; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import nmd.primal.forgecraft.ModInfo; +import nmd.primal.forgecraft.items.BaseItem; + +import javax.annotation.Nullable; + +/** + * Created by mminaie on 7/2/17. + */ +public class Longbow extends BaseItem { + + int mod=5; + + public Longbow(String name) { + super(name); + this.setMaxDamage(9000); + this.setMaxStackSize(1); + this.setNoRepair(); + + this.addPropertyOverride(new ResourceLocation("type"), new IItemPropertyGetter() { + + @SideOnly(Side.CLIENT) + public float apply(ItemStack item, @Nullable World worldIn, @Nullable EntityLivingBase player) { + int time = item.getMaxItemUseDuration() - player.getItemInUseCount(); + System.out.println(time); + if(time < 1*mod){ + return 0.0F; + } + if(time>=1*mod && time<2*mod){ + return 0.1F; + } + if(time>=2*mod && time<3*mod){ + return 0.2F; + } + if(time>=3*mod && time<4*mod){ + return 0.3F; + } + if(time>=4*mod && time<5*mod){ + return 0.4F; + } + if(time>=5*mod && time<6*mod){ + return 0.5F; + } + if(time>=6*mod && time<7*mod){ + return 0.6F; + } + if(time>=7*mod && time<8*mod){ + return 0.7F; + } + if(time>=8*mod && time<72000 ){ + return 0.8F; + } + return 0.0f; + } + }); + } + + + 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; + } + } + + protected boolean isArrow(ItemStack stack) + { + return stack.getItem() instanceof ItemArrow; + } + + /** + * Called when the player stops using an Item (stops holding the right mouse button). + */ + @Override + public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) + { + 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(Items.ARROW); + } + + float f = getArrowVelocity(i); + + 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)((ItemArrow)(itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW)); + EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer); + entityarrow.setAim(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F); + + if (f == 1.0F) + { + entityarrow.setIsCritical(true); + } + + int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack); + + if (j > 0) + { + entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D); + } + + int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack); + + if (k > 0) + { + entityarrow.setKnockbackStrength(k); + } + + if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) + { + entityarrow.setFire(100); + } + + 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, SoundEvents.ENTITY_ARROW_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)); + } + } + //entityLiving.stopActiveHand(); + if(!worldIn.isRemote){ + entityLiving.resetActiveHand(); + } + if(worldIn.isRemote){ + entityLiving.resetActiveHand(); + } + + } + } + + /** + * Gets the velocity of the arrow entity from the bow's charge + */ + + public static float getArrowVelocity(int charge) + { + float f = (float)charge / 20.0F; + f = (f * f + f * 2.0F) / 3.0F; + + if (f > 1.0F) + { + f = 1.0F; + } + + return f; + } + + /** + * How long it takes to use or consume an item + */ + @Override + public int getMaxItemUseDuration(ItemStack stack) + { + return 72000; + } + + + + /** + * returns the action that specifies what animation to play when the items is being used + */ + @Override + public EnumAction getItemUseAction(ItemStack stack) + { + return EnumAction.BOW; + } + + /** + * Called when the equipped item is right clicked. + */ + @Override + public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) + { + ItemStack itemstack = playerIn.getHeldItem(handIn); + boolean flag = !this.findAmmo(playerIn).isEmpty(); + + ActionResult 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(EnumActionResult.SUCCESS, itemstack); + } + } + + @Override + public int getItemEnchantability() + { + return 0; + } +} \ No newline at end of file diff --git a/kfc/src/main/resources/assets/forgecraft/models/item/e_particle.png b/kfc/src/main/resources/assets/forgecraft/models/item/e_particle.png deleted file mode 100644 index e557878f9b0081df0e6c571ed915f4780bf1a2fc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 159 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|X`U{QAsV7vCj@daC~~-LPd)$i z?$?xTj^-IIp9ACFK7V={aJAiXe!J@v0mIGT4Z3dBCY+nlAN}mLRowa~J3GYg{eRVX zXUUaN&3PXSznt{pUt?*oMTj?KX|GSjMcIr5t;EiVqsx9UI;{|T9DHPlG0;W^Pgg&e IbxsLQ03WwL?f?J) diff --git a/kfc/src/main/resources/assets/forgecraft/models/item/e_texture.png b/kfc/src/main/resources/assets/forgecraft/models/item/e_texture.png deleted file mode 100644 index 7291f2ea2b524eccecb6678f7bd40262c849bf2f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 141 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|A)YRdAsV8|HWeQfm^B+%SKK&v zuFpfaoliDNDM&L$@~vsZp9Y?WbuQ1CZf4l2-1K~5=5VI@Msu3kk+ey<5-m~}Y=y49eO2q|bVRUgzhAFXVE`%Xe zI^K)3W^OFCt*weaCrFoOi3LxK8Y{kGv(wqj_{7#QjDs6cYBD4Hb`6Ak?lbIi_CRl? z{U18u0!0zBb9Q_@8n>-ErxyXWG8+uS*=^2T?g*FT;Sj`18ge(r=~ghd_bjtL53uaS zBHzE0&FBVav~k6+!?WFL(A+WSft$jXu%vp~JoxAck>a~WDC51IY6f^s4UK}B#JHLR z)XoS8wTOb1X@L+2P!vF>>@a*Hm0{~>e2wg8w{Uwu