Search in sources :

Example 16 with ServerWorld

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;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LiteralText(net.minecraft.text.LiteralText)

Example 17 with ServerWorld

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;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) HostileEntity(net.minecraft.entity.mob.HostileEntity) IronGolemEntity(net.minecraft.entity.passive.IronGolemEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) MerchantEntity(net.minecraft.entity.passive.MerchantEntity) MobEntity(net.minecraft.entity.mob.MobEntity) IllagerEntity(net.minecraft.entity.mob.IllagerEntity) RaiderEntity(net.minecraft.entity.raid.RaiderEntity) WitherEntity(net.minecraft.entity.boss.WitherEntity) RavagerEntity(net.minecraft.entity.mob.RavagerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ItemStackParticleEffect(net.minecraft.particle.ItemStackParticleEffect) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) IronGolemEntity(net.minecraft.entity.passive.IronGolemEntity) ItemStack(net.minecraft.item.ItemStack)

Example 18 with ServerWorld

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;
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ServerWorld(net.minecraft.server.world.ServerWorld) MerchantEntity(net.minecraft.entity.passive.MerchantEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) IronGolemEntity(net.minecraft.entity.passive.IronGolemEntity) RaiderEntity(net.minecraft.entity.raid.RaiderEntity) Entity(net.minecraft.entity.Entity) ItemStackParticleEffect(net.minecraft.particle.ItemStackParticleEffect) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) IronGolemEntity(net.minecraft.entity.passive.IronGolemEntity) ItemStack(net.minecraft.item.ItemStack)

Example 19 with ServerWorld

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);
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) ItemStack(net.minecraft.item.ItemStack)

Example 20 with ServerWorld

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);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ServerWorld(net.minecraft.server.world.ServerWorld) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) ZombieEntity(net.minecraft.entity.mob.ZombieEntity) ExplosiveProjectileEntity(net.minecraft.entity.projectile.ExplosiveProjectileEntity)

Aggregations

ServerWorld (net.minecraft.server.world.ServerWorld)210 BlockPos (net.minecraft.util.math.BlockPos)102 ItemStack (net.minecraft.item.ItemStack)47 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)38 Vec3d (net.minecraft.util.math.Vec3d)33 World (net.minecraft.world.World)33 BlockState (net.minecraft.block.BlockState)28 Direction (net.minecraft.util.math.Direction)23 Entity (net.minecraft.entity.Entity)21 Random (java.util.Random)20 Block (net.minecraft.block.Block)20 PlayerEntity (net.minecraft.entity.player.PlayerEntity)19 Inject (org.spongepowered.asm.mixin.injection.Inject)18 List (java.util.List)16 DispenserBlock (net.minecraft.block.DispenserBlock)16 Box (net.minecraft.util.math.Box)16 ChunkPos (net.minecraft.util.math.ChunkPos)16 LivingEntity (net.minecraft.entity.LivingEntity)13 BlockEntity (net.minecraft.block.entity.BlockEntity)11 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)11