82 lines
2.4 KiB
Java
Executable file
82 lines
2.4 KiB
Java
Executable file
package game.item;
|
|
|
|
import game.enchantment.Enchantment;
|
|
import game.enchantment.EnchantmentHelper;
|
|
import game.entity.npc.EntityNPC;
|
|
import game.entity.projectile.EntityBullet;
|
|
import game.init.SoundEvent;
|
|
import game.renderer.blockmodel.Transforms;
|
|
import game.world.World;
|
|
|
|
public abstract class ItemGunBase extends Item
|
|
{
|
|
public abstract ItemAmmo getAmmo();
|
|
public abstract float getVelocity();
|
|
|
|
public ItemGunBase(int durability)
|
|
{
|
|
this.maxStackSize = 1;
|
|
this.setMaxDamage(durability);
|
|
this.setTab(CheatTab.tabCombat);
|
|
}
|
|
|
|
public ItemAction getItemPosition(ItemStack stack)
|
|
{
|
|
return ItemAction.AIM;
|
|
}
|
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World worldIn, EntityNPC playerIn)
|
|
{
|
|
if(stack.getItemDamage() >= this.getMaxDamage())
|
|
return stack;
|
|
boolean flag = // playerIn.creative ||
|
|
EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
|
|
if (flag || playerIn.inventory.hasItem(this.getAmmo()))
|
|
{
|
|
EntityBullet bullet = new EntityBullet(worldIn, playerIn, this.getVelocity());
|
|
bullet.setDamage(this.getAmmo().getDamage(stack));
|
|
|
|
int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
|
|
|
|
if (j > 0)
|
|
{
|
|
bullet.setDamage(bullet.getDamage() + j);
|
|
}
|
|
|
|
// int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
|
|
//
|
|
// if (k > 0)
|
|
// {
|
|
// entityarrow.setKnockbackStrength(k);
|
|
// }
|
|
|
|
// if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
|
|
// {
|
|
// entityarrow.setFire(100);
|
|
// }
|
|
|
|
stack.damageItem(1, playerIn);
|
|
worldIn.playSoundAtEntity(playerIn, SoundEvent.EXPLODE_ALT, 1.0F);
|
|
|
|
if(!flag)
|
|
playerIn.inventory.consumeInventoryItem(this.getAmmo());
|
|
|
|
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
|
|
|
if (!worldIn.client)
|
|
{
|
|
worldIn.spawnEntityInWorld(bullet);
|
|
}
|
|
}
|
|
return stack;
|
|
}
|
|
|
|
public int getItemEnchantability()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
public Transforms getTransform() {
|
|
return Transforms.RANGED;
|
|
}
|
|
}
|