use of net.minecraft.entity.projectile.PersistentProjectileEntity in project HWG by cybercat-mods.
the class GrenadeLauncherItem method shoot.
private static void shoot(World world, LivingEntity shooter, Hand hand, ItemStack stack, ItemStack projectile, float soundPitch, boolean creative, float speed, float divergence, float simulated) {
if (!world.isClient) {
boolean bl = projectile.getItem() == HWGItems.G_EMP;
boolean b2 = projectile.getItem() == HWGItems.G_FRAG;
boolean b3 = projectile.getItem() == HWGItems.G_NAPALM;
boolean b4 = projectile.getItem() == HWGItems.G_STUN;
GrenadeEntity projectileEntity2 = new GrenadeEntity(world, projectile, shooter, shooter.getX(), shooter.getEyeY() - 0.15000000596046448D, shooter.getZ(), true);
projectileEntity2.setState(0);
if (bl) {
projectileEntity2.setVariant(1);
} else if (b2) {
projectileEntity2.setVariant(2);
} else if (b3) {
projectileEntity2.setVariant(3);
} else if (b4) {
projectileEntity2.setVariant(5);
} else {
projectileEntity2.setVariant(4);
}
Vec3d vec3d = shooter.getOppositeRotationVector(1.0F);
Quaternion quaternion = new Quaternion(new Vec3f(vec3d), simulated, true);
Vec3d vec3d2 = shooter.getRotationVec(1.0F);
Vec3f vector3f = new Vec3f(vec3d2);
vector3f.rotate(quaternion);
((PersistentProjectileEntity) projectileEntity2).setVelocity((double) vector3f.getX(), (double) vector3f.getY(), (double) vector3f.getZ(), speed, divergence);
stack.damage(1, shooter, p -> p.sendToolBreakStatus(shooter.getActiveHand()));
world.spawnEntity((Entity) projectileEntity2);
world.playSound((PlayerEntity) null, shooter.getX(), shooter.getY(), shooter.getZ(), HWGSounds.GLAUNCHERFIRE, SoundCategory.PLAYERS, 1.0F, 0.9F);
}
}
use of net.minecraft.entity.projectile.PersistentProjectileEntity in project gobber_fabric-1.17 by kwpugh.
the class SwordEndSniper method use.
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getStackInHand(hand);
ItemStack stack2 = player.getMainHandStack();
boolean hasQuickUse = stack2.getEnchantments().toString().contains("quickuse");
if (!hasQuickUse) {
player.getItemCooldownManager().set(this, cooldown);
}
if (!world.isClient) {
ArrowItem itemarrow = (ArrowItem) Items.ARROW;
PersistentProjectileEntity persistentProjectileEntity = itemarrow.createArrow(world, new ItemStack(Items.ARROW), player);
float arrowVelocity = 60.0F;
persistentProjectileEntity.setVelocity(player, player.getPitch(), player.getYaw(), 0.0F, arrowVelocity, 0.0F);
persistentProjectileEntity.setDamage(1);
if (EnchantmentHelper.getLevel(Enchantments.FIRE_ASPECT, stack) > 0) {
persistentProjectileEntity.setOnFireFor(100);
}
world.spawnEntity(persistentProjectileEntity);
persistentProjectileEntity.pickupType = PickupPermission.DISALLOWED;
}
return TypedActionResult.success(stack);
}
use of net.minecraft.entity.projectile.PersistentProjectileEntity in project gobber_fabric-1.17 by kwpugh.
the class BowEnd method onStoppedUsing.
@Override
public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) {
if (user instanceof PlayerEntity) {
PlayerEntity playerEntity = (PlayerEntity) user;
boolean bl = playerEntity.getAbilities().creativeMode || EnchantmentHelper.getLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemStack = playerEntity.getArrowType(stack);
if (!itemStack.isEmpty() || bl) {
if (itemStack.isEmpty()) {
itemStack = new ItemStack(Items.ARROW);
}
int i = getMaxUseTime(stack) - remainingUseTicks;
float f = getPullProgress(i);
if (f >= 0.1D) {
boolean bl2 = bl && itemStack.getItem() == Items.ARROW;
if (!world.isClient) {
ArrowItem arrowItem = (ArrowItem) (itemStack.getItem() instanceof ArrowItem ? itemStack.getItem() : Items.ARROW);
PersistentProjectileEntity persistentProjectileEntity = arrowItem.createArrow(world, itemStack, playerEntity);
persistentProjectileEntity.setVelocity(playerEntity, playerEntity.getPitch(), playerEntity.getYaw(), 0.0F, f * 6.0F, 0.0F);
if (f == 1.0F) {
persistentProjectileEntity.setCritical(true);
}
int j = EnchantmentHelper.getLevel(Enchantments.POWER, stack);
if (j > 0) {
persistentProjectileEntity.setDamage(persistentProjectileEntity.getDamage() + j * 0.5D + 0.5D);
}
persistentProjectileEntity.setDamage(persistentProjectileEntity.getDamage() + j * 0.5D + 0.5D);
int k = EnchantmentHelper.getLevel(Enchantments.PUNCH, stack);
if (k > 0) {
persistentProjectileEntity.setPunch(k);
}
if (EnchantmentHelper.getLevel(Enchantments.FLAME, stack) > 0) {
persistentProjectileEntity.setOnFireFor(100);
}
stack.damage(1, (LivingEntity) playerEntity, (Consumer<LivingEntity>) (p) -> {
p.sendToolBreakStatus(playerEntity.getActiveHand());
});
if (bl2 || playerEntity.getAbilities().creativeMode && (itemStack.getItem() == Items.SPECTRAL_ARROW || itemStack.getItem() == Items.TIPPED_ARROW)) {
persistentProjectileEntity.pickupType = PersistentProjectileEntity.PickupPermission.CREATIVE_ONLY;
}
world.spawnEntity(persistentProjectileEntity);
}
world.playSound((PlayerEntity) null, playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (world.random.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (!bl2 && !playerEntity.getAbilities().creativeMode) {
itemStack.decrement(1);
if (itemStack.isEmpty()) {
playerEntity.getInventory().removeOne(itemStack);
}
}
playerEntity.incrementStat(Stats.USED.getOrCreateStat(this));
}
}
}
}
use of net.minecraft.entity.projectile.PersistentProjectileEntity in project gobber_fabric-1.17 by kwpugh.
the class StaffSniper method use.
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getStackInHand(hand);
ItemStack stack2 = player.getMainHandStack();
boolean hasQuickUse = stack2.getEnchantments().toString().contains("quickuse");
if (!hasQuickUse) {
player.getItemCooldownManager().set(this, cooldown);
}
if (!world.isClient) {
ArrowItem itemarrow = (ArrowItem) Items.ARROW;
PersistentProjectileEntity persistentProjectileEntity = itemarrow.createArrow(world, new ItemStack(Items.ARROW), player);
float arrowVelocity = 60.0F;
persistentProjectileEntity.setVelocity(player, player.getPitch(), player.getYaw(), 0.0F, arrowVelocity, 0.0F);
persistentProjectileEntity.setDamage(1);
world.spawnEntity(persistentProjectileEntity);
persistentProjectileEntity.pickupType = PickupPermission.DISALLOWED;
}
return TypedActionResult.success(stack);
}
use of net.minecraft.entity.projectile.PersistentProjectileEntity in project gobber_fabric-1.17 by kwpugh.
the class ModBow method onStoppedUsing.
@Override
public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) {
if (user instanceof PlayerEntity) {
PlayerEntity playerEntity = (PlayerEntity) user;
boolean bl = playerEntity.getAbilities().creativeMode || EnchantmentHelper.getLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemStack = playerEntity.getArrowType(stack);
if (!itemStack.isEmpty() || bl) {
if (itemStack.isEmpty()) {
itemStack = new ItemStack(Items.ARROW);
}
int i = getMaxUseTime(stack) - remainingUseTicks;
float f = getPullProgress(i);
if (f >= 0.1D) {
boolean bl2 = bl && itemStack.getItem() == Items.ARROW;
if (!world.isClient) {
ArrowItem arrowItem = (ArrowItem) (itemStack.getItem() instanceof ArrowItem ? itemStack.getItem() : Items.ARROW);
PersistentProjectileEntity persistentProjectileEntity = arrowItem.createArrow(world, itemStack, playerEntity);
persistentProjectileEntity.setVelocity(playerEntity, playerEntity.getPitch(), playerEntity.getYaw(), 0.0F, f * 6.0F, 0.0F);
if (f == 1.0F) {
persistentProjectileEntity.setCritical(true);
}
int j = EnchantmentHelper.getLevel(Enchantments.POWER, stack);
if (j > 0) {
persistentProjectileEntity.setDamage(persistentProjectileEntity.getDamage() + j * 0.5D + 0.5D);
}
persistentProjectileEntity.setDamage(persistentProjectileEntity.getDamage() + j * 0.5D + 0.5D);
int k = EnchantmentHelper.getLevel(Enchantments.PUNCH, stack);
if (k > 0) {
persistentProjectileEntity.setPunch(k);
}
if (EnchantmentHelper.getLevel(Enchantments.FLAME, stack) > 0) {
persistentProjectileEntity.setOnFireFor(100);
}
stack.damage(1, (LivingEntity) playerEntity, (Consumer<LivingEntity>) (p) -> {
p.sendToolBreakStatus(playerEntity.getActiveHand());
});
if (bl2 || playerEntity.getAbilities().creativeMode && (itemStack.getItem() == Items.SPECTRAL_ARROW || itemStack.getItem() == Items.TIPPED_ARROW)) {
persistentProjectileEntity.pickupType = PersistentProjectileEntity.PickupPermission.CREATIVE_ONLY;
}
world.spawnEntity(persistentProjectileEntity);
}
world.playSound((PlayerEntity) null, playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (world.random.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (!bl2 && !playerEntity.getAbilities().creativeMode) {
itemStack.decrement(1);
if (itemStack.isEmpty()) {
playerEntity.getInventory().removeOne(itemStack);
}
}
playerEntity.incrementStat(Stats.USED.getOrCreateStat(this));
}
}
}
}
Aggregations