Search in sources :

Example 6 with MobEffectInstance

use of net.minecraft.world.effect.MobEffectInstance in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin method impl$postPortalForceChangeTasks.

@Override
protected final void impl$postPortalForceChangeTasks(final Entity entity, final net.minecraft.server.level.ServerLevel targetWorld, final boolean isNetherPortal) {
    // Standard vanilla processing
    this.gameMode.setLevel(targetWorld);
    this.connection.send(new ClientboundPlayerAbilitiesPacket(this.abilities));
    final PlayerList playerlist = this.server.getPlayerList();
    playerlist.sendLevelInfo((net.minecraft.server.level.ServerPlayer) (Object) this, targetWorld);
    playerlist.sendAllPlayerInfo((net.minecraft.server.level.ServerPlayer) (Object) this);
    // Sponge Start: teleport here after all data is sent to avoid any potential "stuttering" due to slow packets.
    final net.minecraft.world.phys.Vec3 finalPos = this.shadow$position();
    this.shadow$moveTo(finalPos.x, finalPos.y, finalPos.z);
    for (final MobEffectInstance effectinstance : this.shadow$getActiveEffects()) {
        this.connection.send(new ClientboundUpdateMobEffectPacket(this.shadow$getId(), effectinstance));
    }
    if (isNetherPortal) {
        // Sponge: only play the sound if we've got a vanilla teleporter that reports a nether portal
        this.connection.send(new ClientboundLevelEventPacket(1032, BlockPos.ZERO, 0, false));
    }
    // Sponge: end if
    this.lastSentExp = -1;
    this.lastSentHealth = -1.0F;
    this.lastSentFood = -1;
}
Also used : ClientboundPlayerAbilitiesPacket(net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket) PlayerList(net.minecraft.server.players.PlayerList) ClientboundLevelEventPacket(net.minecraft.network.protocol.game.ClientboundLevelEventPacket) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) ClientboundUpdateMobEffectPacket(net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket)

Example 7 with MobEffectInstance

use of net.minecraft.world.effect.MobEffectInstance in project Tropicraft by Tropicraft.

the class EntityKoaBase method mobInteract.

/*private static final Field _buyingPlayer = Util.findField(VillagerEntity.class, "field_70962_h", "buyingPlayer");
    private static final Field _buyingList = Util.findField(VillagerEntity.class, "field_70963_i", "buyingList");*/
@Override
public InteractionResult mobInteract(Player player, InteractionHand hand) {
    if (hand != InteractionHand.MAIN_HAND)
        return InteractionResult.PASS;
    InteractionResult ret = InteractionResult.PASS;
    try {
        boolean doTrade = true;
        if (!this.level.isClientSide) {
            ItemStack stack = player.getItemInHand(InteractionHand.MAIN_HAND);
            if (!stack.isEmpty() && stack.getItem() == TropicraftItems.POISON_FROG_SKIN.get()) {
                doTrade = false;
                // drug the koa and make him forget everything
                dbg("koa drugged, zapping memory");
                if (!player.isCreative()) {
                    stack.shrink(1);
                }
                zapMemory();
                druggedTime += 20 * 60 * 2;
                addEffect(new MobEffectInstance(MobEffects.CONFUSION, druggedTime));
                findAndSetDrums(true);
            }
            if (doTrade) {
                // Make the super method think this villager is already trading, to block the GUI from opening
                // _buyingPlayer.set(this, player);
                ret = super.mobInteract(player, hand);
            // _buyingPlayer.set(this, null);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return ret;
}
Also used : InteractionResult(net.minecraft.world.InteractionResult) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) ItemStack(net.minecraft.world.item.ItemStack)

Example 8 with MobEffectInstance

use of net.minecraft.world.effect.MobEffectInstance in project Tropicraft by Tropicraft.

the class PoisonBlotEntity method onHit.

@Override
protected void onHit(HitResult result) {
    if (result.getType() == HitResult.Type.ENTITY) {
        final Entity entity = ((EntityHitResult) result).getEntity();
        if (entity instanceof Player) {
            Player player = (Player) entity;
            player.addEffect(new MobEffectInstance(MobEffects.POISON, 12 * 20, 0));
            remove(RemovalReason.DISCARDED);
        }
    }
}
Also used : Entity(net.minecraft.world.entity.Entity) LivingEntity(net.minecraft.world.entity.LivingEntity) Player(net.minecraft.world.entity.player.Player) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) EntityHitResult(net.minecraft.world.phys.EntityHitResult)

Example 9 with MobEffectInstance

use of net.minecraft.world.effect.MobEffectInstance in project Tropicraft by Tropicraft.

the class BlowGunItem method getProjectile.

public static ItemStack getProjectile() {
    ItemStack itemStack = new ItemStack(Items.TIPPED_ARROW);
    itemStack = PotionUtils.setCustomEffects(itemStack, ImmutableList.of(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 3 * 20, 20)));
    return itemStack;
}
Also used : MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) ItemStack(net.minecraft.world.item.ItemStack)

Example 10 with MobEffectInstance

use of net.minecraft.world.effect.MobEffectInstance in project SpongeCommon by SpongePowered.

the class PotionItemStackData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(ItemStack.class).create(Keys.COLOR).get(h -> Color.ofRgb(PotionUtils.getColor(h))).set((h, v) -> {
        final CompoundTag tag = h.getOrCreateTag();
        tag.putInt(Constants.Item.CUSTOM_POTION_COLOR, v.rgb());
    }).delete(h -> h.removeTagKey(Constants.Item.CUSTOM_POTION_COLOR)).supports(h -> h.getItem() == Items.POTION || h.getItem() == Items.SPLASH_POTION || h.getItem() == Items.LINGERING_POTION).create(Keys.POTION_EFFECTS).get(h -> {
        final List<MobEffectInstance> effects = PotionUtils.getMobEffects(h);
        return effects.isEmpty() ? null : ImmutableList.copyOf((List<PotionEffect>) (Object) effects);
    }).set((h, v) -> {
        final CompoundTag tag = h.getOrCreateTag();
        final ListTag list = v.stream().map(effect -> {
            final CompoundTag potionTag = new CompoundTag();
            ((MobEffectInstance) effect).save(potionTag);
            return potionTag;
        }).collect(NBTCollectors.toTagList());
        tag.put(Constants.Item.CUSTOM_POTION_EFFECTS, list);
    }).delete(h -> h.removeTagKey(Constants.Item.CUSTOM_POTION_EFFECTS)).supports(h -> h.getItem() == Items.POTION || h.getItem() == Items.SPLASH_POTION || h.getItem() == Items.LINGERING_POTION || h.getItem() == Items.TIPPED_ARROW).create(Keys.POTION_TYPE).get(h -> (PotionType) PotionUtils.getPotion(h)).set((h, v) -> {
        h.getOrCreateTag();
        PotionUtils.setPotion(h, (Potion) v);
    }).delete(h -> {
        if (h.hasTag()) {
            PotionUtils.setPotion(h, Potions.EMPTY);
        }
    }).supports(h -> h.getItem() == Items.POTION || h.getItem() == Items.SPLASH_POTION || h.getItem() == Items.LINGERING_POTION || h.getItem() == Items.TIPPED_ARROW);
}
Also used : PotionUtils(net.minecraft.world.item.alchemy.PotionUtils) Items(net.minecraft.world.item.Items) Constants(org.spongepowered.common.util.Constants) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) Potions(net.minecraft.world.item.alchemy.Potions) Potion(net.minecraft.world.item.alchemy.Potion) Keys(org.spongepowered.api.data.Keys) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) ImmutableList(com.google.common.collect.ImmutableList) NBTCollectors(org.spongepowered.common.util.NBTCollectors) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) Color(org.spongepowered.api.util.Color) ItemStack(net.minecraft.world.item.ItemStack) ListTag(net.minecraft.nbt.ListTag) PotionType(org.spongepowered.api.item.potion.PotionType) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) PotionType(org.spongepowered.api.item.potion.PotionType) ItemStack(net.minecraft.world.item.ItemStack) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

MobEffectInstance (net.minecraft.world.effect.MobEffectInstance)13 ItemStack (net.minecraft.world.item.ItemStack)5 Keys (org.spongepowered.api.data.Keys)4 PotionEffect (org.spongepowered.api.effect.potion.PotionEffect)4 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)4 Constants (org.spongepowered.common.util.Constants)3 List (java.util.List)2 Set (java.util.Set)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 ListTag (net.minecraft.nbt.ListTag)2 ClientboundLevelEventPacket (net.minecraft.network.protocol.game.ClientboundLevelEventPacket)2 ClientboundPlayerAbilitiesPacket (net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket)2 ClientboundUpdateMobEffectPacket (net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket)2 PlayerList (net.minecraft.server.players.PlayerList)2 Entity (net.minecraft.world.entity.Entity)2 LivingEntity (net.minecraft.world.entity.LivingEntity)2 Player (net.minecraft.world.entity.player.Player)2 Items (net.minecraft.world.item.Items)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1