forked from AlmuraDev/mocreaturesdev
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa743c8
commit 42f9944
Showing
14 changed files
with
301 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* GNU GENERAL PUBLIC LICENSE Version 3 | ||
*/ | ||
package drzhark.mocreatures.item; | ||
|
||
import drzhark.mocreatures.MoCConstants; | ||
import drzhark.mocreatures.MoCreatures; | ||
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.ItemArrow; | ||
import net.minecraft.item.ItemBow; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.crafting.Ingredient; | ||
import net.minecraft.stats.StatList; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.util.SoundCategory; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.event.ForgeEventFactory; | ||
|
||
public class MoCItemBow extends ItemBow { | ||
public float damageMult; | ||
public float velocityMult; | ||
public float inaccuracy; | ||
public float drawTimeMult; | ||
public Ingredient repairMaterial; | ||
|
||
public MoCItemBow(String name, int durability, float damageMult, float velocityMult, float drawTimeMult, float inaccuracy, Ingredient repairMaterial) { | ||
this.setCreativeTab(MoCreatures.tabMoC); | ||
this.setRegistryName(MoCConstants.MOD_ID, name); | ||
this.setTranslationKey(name); | ||
this.maxStackSize = 1; | ||
this.setMaxDamage(durability); | ||
this.damageMult = damageMult; | ||
this.velocityMult = velocityMult; | ||
this.drawTimeMult = drawTimeMult; | ||
this.inaccuracy = inaccuracy; | ||
this.repairMaterial = repairMaterial; | ||
this.addPropertyOverride(new ResourceLocation("pull"), (ItemStack bow, World world, EntityLivingBase entity) -> { | ||
if (entity == null) | ||
return 0; | ||
|
||
float drawTime = 20 * drawTimeMult; | ||
|
||
return (this.getMaxItemUseDuration(bow) - entity.getItemInUseCount()) / drawTime; | ||
}); | ||
} | ||
|
||
@Override | ||
public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityLivingBase entityLiving, int timeInUse) { | ||
if (entityLiving instanceof EntityPlayer) { | ||
EntityPlayer player = (EntityPlayer) entityLiving; | ||
boolean isInfinityEnchant = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, itemStack) > 0; | ||
ItemStack stack = this.findAmmo(player); | ||
|
||
float chargeDivider = 1 * drawTimeMult; | ||
|
||
int charge = (int) ((this.getMaxItemUseDuration(itemStack) - timeInUse) / chargeDivider); | ||
charge = ForgeEventFactory.onArrowLoose(itemStack, world, player, charge, !stack.isEmpty() || isInfinityEnchant); | ||
if (charge < 0) return; | ||
|
||
if ((!stack.isEmpty() || isInfinityEnchant)) { | ||
if (stack.isEmpty()) { | ||
stack = new ItemStack(Items.ARROW); | ||
} | ||
|
||
float arrowVelocity = getArrowVelocity(charge); | ||
|
||
if ((double) arrowVelocity >= 0.1D) { | ||
boolean arrowInfinite = player.capabilities.isCreativeMode || (stack.getItem() instanceof ItemArrow && ((ItemArrow) stack.getItem()).isInfinite(stack, itemStack, player)); | ||
|
||
if (!world.isRemote) { | ||
ItemArrow itemArrow = (ItemArrow) (stack.getItem() instanceof ItemArrow ? stack.getItem() : Items.ARROW); | ||
EntityArrow entityArrow = itemArrow.createArrow(world, stack, player); | ||
entityArrow = this.customizeArrow(entityArrow); | ||
entityArrow.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, (arrowVelocity * 3.0F) * velocityMult, inaccuracy); | ||
|
||
if (arrowVelocity == 1.0F) { | ||
entityArrow.setIsCritical(true); | ||
} | ||
|
||
entityArrow.setDamage(entityArrow.getDamage() * damageMult); | ||
|
||
int power = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, itemStack); | ||
|
||
if (power > 0) { | ||
entityArrow.setDamage(entityArrow.getDamage() + (double) power * 0.5D + 0.5D); | ||
} | ||
|
||
int punch = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, itemStack); | ||
|
||
if (punch > 0) { | ||
entityArrow.setKnockbackStrength(punch); | ||
} | ||
|
||
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, itemStack) > 0) { | ||
entityArrow.setFire(100); | ||
} | ||
|
||
itemStack.damageItem(1, player); | ||
|
||
if (arrowInfinite || player.capabilities.isCreativeMode && (stack.getItem() == Items.SPECTRAL_ARROW || stack.getItem() == Items.TIPPED_ARROW)) { | ||
entityArrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY; | ||
} | ||
|
||
world.spawnEntity(entityArrow); | ||
} | ||
|
||
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1, 1 / (itemRand.nextFloat() * 0.4F + 1.2F) + arrowVelocity * 0.5F); | ||
|
||
if (!arrowInfinite && !player.capabilities.isCreativeMode) { | ||
stack.shrink(1); | ||
|
||
if (stack.isEmpty()) { | ||
player.inventory.deleteStack(stack); | ||
} | ||
} | ||
|
||
player.addStat(StatList.getObjectUseStats(this)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) { | ||
return repairMaterial.test(repair) || super.getIsRepairable(toRepair, repair); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/resources/assets/mocreatures/models/item/ancient_silver_bow.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"parent": "item/generated", | ||
"textures": { | ||
"layer0": "mocreatures:items/ancient_silver_bow_standby" | ||
}, | ||
"display": { | ||
"thirdperson_righthand": { | ||
"rotation": [ -80, 260, -40 ], | ||
"translation": [ -1, -2, 2.5 ], | ||
"scale": [ 0.9, 0.9, 0.9 ] | ||
}, | ||
"thirdperson_lefthand": { | ||
"rotation": [ -80, -280, 40 ], | ||
"translation": [ -1, -2, 2.5 ], | ||
"scale": [ 0.9, 0.9, 0.9 ] | ||
}, | ||
"firstperson_righthand": { | ||
"rotation": [ 0, -90, 25 ], | ||
"translation": [ 1.13, 3.2, 1.13], | ||
"scale": [ 0.68, 0.68, 0.68 ] | ||
}, | ||
"firstperson_lefthand": { | ||
"rotation": [ 0, 90, -25 ], | ||
"translation": [ 1.13, 3.2, 1.13], | ||
"scale": [ 0.68, 0.68, 0.68 ] | ||
} | ||
}, | ||
"overrides": [ | ||
{ | ||
"predicate": { | ||
"pulling": 1 | ||
}, | ||
"model": "mocreatures:item/ancient_silver_bow_pulling_0" | ||
}, | ||
{ | ||
"predicate": { | ||
"pulling": 1, | ||
"pull": 0.65 | ||
}, | ||
"model": "mocreatures:item/ancient_silver_bow_pulling_1" | ||
}, | ||
{ | ||
"predicate": { | ||
"pulling": 1, | ||
"pull": 0.9 | ||
}, | ||
"model": "mocreatures:item/ancient_silver_bow_pulling_2" | ||
} | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/mocreatures/models/item/ancient_silver_bow_pulling_0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "mocreatures:item/ancient_silver_bow", | ||
"textures": { | ||
"layer0": "mocreatures:items/ancient_silver_bow_pulling_0" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/mocreatures/models/item/ancient_silver_bow_pulling_1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "mocreatures:item/ancient_silver_bow", | ||
"textures": { | ||
"layer0": "mocreatures:items/ancient_silver_bow_pulling_1" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/mocreatures/models/item/ancient_silver_bow_pulling_2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "mocreatures:item/ancient_silver_bow", | ||
"textures": { | ||
"layer0": "mocreatures:items/ancient_silver_bow_pulling_2" | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/resources/assets/mocreatures/recipes/ancient_silver_bow.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"type": "forge:ore_shaped", | ||
"pattern": [ | ||
" S*", | ||
"I *", | ||
" S*" | ||
], | ||
"key": { | ||
"S": { | ||
"item": "mocreatures:ancientsilveringot" | ||
}, | ||
"I": { | ||
"type": "forge:ore_dict", | ||
"ore": "ingotIron" | ||
}, | ||
"*": { | ||
"type": "forge:ore_dict", | ||
"ore": "string" | ||
} | ||
}, | ||
"result": { | ||
"item": "mocreatures:ancient_silver_bow" | ||
} | ||
} |
Binary file added
BIN
+300 Bytes
...in/resources/assets/mocreatures/textures/items/ancient_silver_bow_pulling_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+296 Bytes
...in/resources/assets/mocreatures/textures/items/ancient_silver_bow_pulling_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+289 Bytes
...in/resources/assets/mocreatures/textures/items/ancient_silver_bow_pulling_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+259 Bytes
...main/resources/assets/mocreatures/textures/items/ancient_silver_bow_standby.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.