Search in sources :

Example 6 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project MCDoom by AzureDoom.

the class ChaingunBulletEntity method onEntityHit.

@Override
protected void onEntityHit(EntityHitResult entityHitResult) {
    Entity entity = entityHitResult.getEntity();
    if (entityHitResult.getType() != HitResult.Type.ENTITY || !((EntityHitResult) entityHitResult).getEntity().isPartOf(entity)) {
        if (!this.world.isClient) {
            this.remove(Entity.RemovalReason.DISCARDED);
        }
    }
    Entity entity2 = this.getOwner();
    DamageSource damageSource2;
    if (entity2 == null) {
        damageSource2 = DamageSource.arrow(this, this);
    } else {
        damageSource2 = DamageSource.arrow(this, entity2);
        if (entity2 instanceof LivingEntity) {
            ((LivingEntity) entity2).onAttacking(entity);
        }
    }
    if (entity.damage(damageSource2, projectiledamage)) {
        if (entity instanceof LivingEntity) {
            LivingEntity livingEntity = (LivingEntity) entity;
            if (!this.world.isClient && entity2 instanceof LivingEntity) {
                EnchantmentHelper.onUserDamaged(livingEntity, entity2);
                EnchantmentHelper.onTargetDamaged((LivingEntity) entity2, livingEntity);
                this.remove(Entity.RemovalReason.DISCARDED);
            }
            this.onHit(livingEntity);
            if (entity2 != null && livingEntity != entity2 && livingEntity instanceof PlayerEntity && entity2 instanceof ServerPlayerEntity && !this.isSilent()) {
                ((ServerPlayerEntity) entity2).networkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.PROJECTILE_HIT_PLAYER, 0.0F));
            }
        }
    } else {
        if (!this.world.isClient) {
            this.remove(Entity.RemovalReason.DISCARDED);
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) IconofsinEntity(mod.azure.doom.entity.tierboss.IconofsinEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) GameStateChangeS2CPacket(net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket) DamageSource(net.minecraft.entity.damage.DamageSource) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 7 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project MCDoom by AzureDoom.

the class ShotgunShellEntity method onEntityHit.

@Override
protected void onEntityHit(EntityHitResult entityHitResult) {
    Entity entity = entityHitResult.getEntity();
    if (entityHitResult.getType() != HitResult.Type.ENTITY || !((EntityHitResult) entityHitResult).getEntity().isPartOf(entity)) {
        if (!this.world.isClient) {
            this.remove(Entity.RemovalReason.DISCARDED);
        }
    }
    Entity entity2 = this.getOwner();
    DamageSource damageSource2;
    if (entity2 == null) {
        damageSource2 = DamageSource.arrow(this, this);
    } else {
        damageSource2 = DamageSource.arrow(this, entity2);
        if (entity2 instanceof LivingEntity) {
            ((LivingEntity) entity2).onAttacking(entity);
        }
    }
    if (entity.damage(damageSource2, shelldamage)) {
        if (entity instanceof LivingEntity) {
            LivingEntity livingEntity = (LivingEntity) entity;
            if (!this.world.isClient && entity2 instanceof LivingEntity) {
                EnchantmentHelper.onUserDamaged(livingEntity, entity2);
                EnchantmentHelper.onTargetDamaged((LivingEntity) entity2, livingEntity);
                this.remove(Entity.RemovalReason.DISCARDED);
            }
            this.onHit(livingEntity);
            if (entity2 != null && livingEntity != entity2 && livingEntity instanceof PlayerEntity && entity2 instanceof ServerPlayerEntity && !this.isSilent()) {
                ((ServerPlayerEntity) entity2).networkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.PROJECTILE_HIT_PLAYER, 0.0F));
            }
        }
    } else {
        if (!this.world.isClient) {
            this.remove(Entity.RemovalReason.DISCARDED);
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) IconofsinEntity(mod.azure.doom.entity.tierboss.IconofsinEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) GameStateChangeS2CPacket(net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket) DamageSource(net.minecraft.entity.damage.DamageSource) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 8 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project SpeedRunIGT by RedLime.

the class TimerPacketHandler method sendInitS2C.

public static void sendInitS2C(List<ServerPlayerEntity> players, long startTime, RunCategory category) {
    PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
    passedData.writeLong(startTime);
    passedData.writeString(category.getID());
    CustomPayloadS2CPacket s2CPacket = new CustomPayloadS2CPacket(PACKET_TIMER_INIT_ID, passedData);
    for (ServerPlayerEntity player : players) {
        player.networkHandler.sendPacket(s2CPacket);
    }
}
Also used : CustomPayloadS2CPacket(net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 9 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project SpeedRunIGT by RedLime.

the class TimerPacketHandler method sendCompleteS2C.

public static void sendCompleteS2C(List<ServerPlayerEntity> players, long endTime) {
    PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
    passedData.writeLong(endTime);
    CustomPayloadS2CPacket s2CPacket = new CustomPayloadS2CPacket(PACKET_TIMER_COMPLETE_ID, passedData);
    for (ServerPlayerEntity player : players) {
        player.networkHandler.sendPacket(s2CPacket);
    }
}
Also used : CustomPayloadS2CPacket(net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 10 with ServerPlayerEntity

use of net.minecraft.server.network.ServerPlayerEntity in project Rug by RubixDev.

the class FrameCommand method register.

public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
    LiteralArgumentBuilder<ServerCommandSource> command = CommandManager.literal("frame").requires((player) -> SettingsManager.canUseCommand(player, RugSettings.commandFrame)).then(CommandManager.literal("hide").executes((context) -> {
        ServerCommandSource playerSource = context.getSource();
        ServerCommandSource source = playerSource.getServer().getCommandSource();
        ServerPlayerEntity playerEntity = playerSource.getPlayer();
        CommandManager manager = playerSource.getServer().getCommandManager();
        String playerName = playerEntity.getName().getString();
        manager.execute(source, "execute at " + playerName + " run tag @e[type=minecraft:item_frame,distance=..5] remove hasItem");
        manager.execute(source, "execute at " + playerName + " run tag @e[type=minecraft:item_frame,distance=..5,nbt={Item:{}}] add hasItem");
        manager.execute(source, "execute at " + playerName + " as @e[type=item_frame,distance=..5,tag=hasItem,limit=1,sort=nearest,nbt={Fixed:0b,Invisible:0b}]" + " run data merge entity @s {Invisible:1b,Fixed:1b}");
        manager.execute(source, "execute at " + playerName + " run tag @e[type=minecraft:item_frame,distance=..5] remove hasItem");
        return 1;
    })).then(CommandManager.literal("show").executes((context -> {
        ServerCommandSource playerSource = context.getSource();
        ServerCommandSource source = playerSource.getServer().getCommandSource();
        ServerPlayerEntity playerEntity = playerSource.getPlayer();
        CommandManager manager = playerSource.getServer().getCommandManager();
        String playerName = playerEntity.getName().getString();
        manager.execute(source, "execute at " + playerName + " as @e[type=item_frame,distance=..5,limit=1,sort=nearest,nbt={Fixed:1b,Invisible:1b}]" + " run data merge entity @s {Invisible:0b,Fixed:0b}");
        return 1;
    })));
    dispatcher.register(command);
}
Also used : CommandManager(net.minecraft.server.command.CommandManager) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource)

Aggregations

ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)169 LiteralText (net.minecraft.text.LiteralText)51 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)32 ItemStack (net.minecraft.item.ItemStack)23 PlayerEntity (net.minecraft.entity.player.PlayerEntity)19 Entity (net.minecraft.entity.Entity)15 UUID (java.util.UUID)14 LivingEntity (net.minecraft.entity.LivingEntity)14 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)12 TranslatableText (net.minecraft.text.TranslatableText)12 Inject (org.spongepowered.asm.mixin.injection.Inject)12 ServerWorld (net.minecraft.server.world.ServerWorld)11 PacketByteBuf (net.minecraft.network.PacketByteBuf)10 GameProfile (com.mojang.authlib.GameProfile)9 Formatting (net.minecraft.util.Formatting)9 BlockPos (net.minecraft.util.math.BlockPos)9 ArrayList (java.util.ArrayList)8 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)6 Collectors (java.util.stream.Collectors)6 ArmorStandEntity (net.minecraft.entity.decoration.ArmorStandEntity)6