use of net.minecraft.server.world.ServerWorld in project things by wisp-forest.
the class RecallPotionItem method finishUsing.
@Override
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) {
PlayerEntity player = user instanceof PlayerEntity ? (PlayerEntity) user : null;
if (player == null)
return new ItemStack(Items.GLASS_BOTTLE);
if (player instanceof ServerPlayerEntity) {
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
ServerWorld spawnWorld = serverPlayer.getServer().getWorld(serverPlayer.getSpawnPointDimension());
Criteria.CONSUME_ITEM.trigger(serverPlayer, stack);
if (serverPlayer.getSpawnPointPosition() != null) {
Optional<Vec3d> posOptional = PlayerEntity.findRespawnPosition(spawnWorld, serverPlayer.getSpawnPointPosition(), serverPlayer.getSpawnAngle(), true, false);
if (posOptional.isPresent()) {
BlockPos spawn = posOptional.map(BlockPos::new).get();
serverPlayer.teleport(spawnWorld, spawn.getX() + 0.5f, spawn.getY(), spawn.getZ() + 0.5f, serverPlayer.getSpawnAngle(), 0f);
} else {
serverPlayer.sendMessage(new LiteralText("No respawn point"), true);
}
} else {
serverPlayer.sendMessage(new LiteralText("No respawn point"), true);
}
}
if (!player.abilities.creativeMode) {
stack.decrement(1);
if (stack.isEmpty()) {
return new ItemStack(Items.GLASS_BOTTLE);
} else {
player.inventory.offerOrDrop(player.world, new ItemStack(Items.GLASS_BOTTLE));
}
}
return stack;
}
use of net.minecraft.server.world.ServerWorld in project Illager-Expansion by OhDricky.
the class BasherEntity method damage.
@Override
public boolean damage(final DamageSource source, final float amount) {
final Entity attacker = source.getAttacker();
final boolean hasShield = this.getMainHandStack().isOf(Items.SHIELD);
if (this.isAttacking()) {
if (attacker instanceof LivingEntity) {
final ItemStack item = ((LivingEntity) attacker).getMainHandStack();
final ItemStack basherItem = this.getMainHandStack();
final boolean isShield = basherItem.isOf(Items.SHIELD);
if ((BasherEntity.AXES.contains(item.getItem()) || attacker instanceof IronGolemEntity || this.blockedCount >= 4) && isShield) {
this.playSound(SoundEvents.ITEM_SHIELD_BREAK, 1.0f, 1.0f);
this.setStunnedState(true);
if (this.world instanceof ServerWorld) {
((ServerWorld) this.world).spawnParticles((ParticleEffect) new ItemStackParticleEffect(ParticleTypes.ITEM, basherItem), this.getX(), this.getY() + 1.5, this.getZ(), 30, 0.3, 0.2, 0.3, 0.003);
this.equipStack(EquipmentSlot.MAINHAND, new ItemStack(Items.STONE_AXE));
}
return super.damage(source, amount);
}
}
if (source.getSource() instanceof PersistentProjectileEntity && hasShield) {
this.playSound(SoundEvents.ITEM_SHIELD_BLOCK, 1.0f, 1.0f);
++this.blockedCount;
return false;
}
if (source.getSource() instanceof LivingEntity && hasShield) {
this.playSound(SoundEvents.ITEM_SHIELD_BLOCK, 1.0f, 1.0f);
++this.blockedCount;
return false;
}
}
boolean bl2 = super.damage(source, amount);
return bl2;
}
use of net.minecraft.server.world.ServerWorld in project Illager-Expansion by OhDricky.
the class InquisitorEntity method damage.
public boolean damage(final DamageSource source, final float amount) {
final Entity attacker = source.getAttacker();
final boolean hasShield = this.getOffHandStack().isOf(Items.SHIELD);
if (this.isAttacking()) {
if (attacker instanceof LivingEntity) {
final ItemStack item = ((LivingEntity) attacker).getMainHandStack();
final ItemStack basherItem = this.getOffHandStack();
final boolean isShield = basherItem.isOf(Items.SHIELD);
if ((InquisitorEntity.AXES.contains(item.getItem()) || attacker instanceof IronGolemEntity || this.blockedCount >= 4) && isShield) {
this.playSound(SoundEvents.ITEM_SHIELD_BREAK, 1.0f, 1.0f);
this.setStunnedState(true);
if (this.world instanceof ServerWorld) {
((ServerWorld) this.world).spawnParticles((ParticleEffect) new ItemStackParticleEffect(ParticleTypes.ITEM, basherItem), this.getX(), this.getY() + 1.5, this.getZ(), 30, 0.3, 0.2, 0.3, 0.003);
((ServerWorld) this.world).spawnParticles((ParticleEffect) ParticleTypes.CLOUD, this.getX(), this.getY() + 1.0, this.getZ(), 30, 0.3, 0.3, 0.3, 0.1);
this.playSound(SoundEvents.ENTITY_RAVAGER_ROAR, 1.0f, 1.0f);
this.equipStack(EquipmentSlot.OFFHAND, ItemStack.EMPTY);
}
this.getTargets().forEach(this::knockback);
return super.damage(source, amount);
}
}
if (source.getSource() instanceof PersistentProjectileEntity && hasShield) {
this.playSound(SoundEvents.ITEM_SHIELD_BLOCK, 1.0f, 1.0f);
++this.blockedCount;
return false;
}
if (source.getSource() instanceof LivingEntity && hasShield) {
++this.blockedCount;
this.playSound(SoundEvents.ITEM_SHIELD_BLOCK, 1.0f, 1.0f);
return false;
}
}
if (this.getHealth() <= this.getMaxHealth() / 3.0f && !hasShield && !this.getFinalRoarState() && this.isAlive()) {
this.setFinalRoarState(true);
this.setStunnedState(true);
if (this.world instanceof ServerWorld) {
((ServerWorld) this.world).spawnParticles((ParticleEffect) ParticleTypes.CLOUD, this.getX(), this.getY() + 1.0, this.getZ(), 30, 0.3, 0.3, 0.3, 0.1);
((ServerWorld) this.world).spawnParticles((ParticleEffect) ParticleTypes.ANGRY_VILLAGER, this.getX(), this.getY() + 1.0, this.getZ(), 8, 0.3, 0.3, 0.3, 0.1);
this.playSound(SoundEvents.ENTITY_RAVAGER_ROAR, 1.0f, 1.0f);
this.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED, 200, 0));
}
this.getTargets().forEach(this::knockback);
}
final boolean bl2 = super.damage(source, amount);
return bl2;
}
use of net.minecraft.server.world.ServerWorld in project Illager-Expansion by OhDricky.
the class IllusionaryDustItem method use.
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
ItemStack itemStack = playerEntity.getStackInHand(hand);
double x = playerEntity.getX();
double y = playerEntity.getY();
double z = playerEntity.getZ();
world.playSound(x, y, z, SoundEvents.ENTITY_ILLUSIONER_MIRROR_MOVE, SoundCategory.PLAYERS, 1.0f, 1.0f, false);
if (world instanceof ServerWorld) {
((ServerWorld) world).spawnParticles(ParticleTypes.CLOUD, x, y + 1, z, 15, 0.5D, 0.5D, 0.5D, 0.15D);
playerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.INVISIBILITY, 1200));
playerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED, 200));
playerEntity.getItemCooldownManager().set(this, 100);
if (!playerEntity.getAbilities().creativeMode) {
itemStack.decrement(1);
}
}
return TypedActionResult.success(itemStack);
}
use of net.minecraft.server.world.ServerWorld in project Illager-Expansion by OhDricky.
the class MagmaEntity method onEntityHit.
@Override
protected void onEntityHit(EntityHitResult entityHitResult) {
super.onEntityHit(entityHitResult);
if (this.world.isClient) {
return;
}
Entity entity = entityHitResult.getEntity();
Entity entity2 = this.getOwner();
entity.damage(DamageSource.magic(this, entity2), 12.0f);
if (entity2 instanceof LivingEntity) {
this.applyDamageEffects((LivingEntity) entity2, entity);
}
if (world instanceof ServerWorld) {
((ServerWorld) world).spawnParticles(ParticleTypes.LAVA, this.getX(), this.getY(), this.getZ(), 15, 0.4D, 0.4D, 0.4D, 0.15D);
}
}
Aggregations