Java Code Examples for net.minecraft.potion.PotionEffect#getPotionID()

The following examples show how to use net.minecraft.potion.PotionEffect#getPotionID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AboveHeadDisplay.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean loadOrRender(EntityPlayer player) {
    for (PotionEffect effect : player.getActivePotionEffects()) {
        if (effect.getPotionID() == 14) return false;
    }

    if (!renderFromTeam(player) || player.riddenByEntity != null) {
        return false;
    }

    int renderDistance = Levelhead.getInstance().getDisplayManager().getMasterConfig().getRenderDistance();
    int min = Math.min(64 * 64, renderDistance * renderDistance);
    return !(player.getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) > min) &&
        (!player.hasCustomName() || !player.getCustomNameTag().isEmpty()) &&
        !player.getDisplayName().toString().isEmpty() &&
        existedMoreThan5Seconds.contains(player.getUniqueID()) &&
        !player.getDisplayName().getFormattedText().contains(ChatColor.COLOR_CHAR + "k") &&
        !player.isInvisible() &&
        !player.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer) &&
        !player.isSneaking();
}
 
Example 2
Source File: EntityLingeringEffect.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@Override
public void applyEntityCollision(Entity e) {
	if (!(e instanceof EntityLivingBase))
		return;
	EntityLivingBase entity = (EntityLivingBase) e;
	List<PotionEffect> effects = ((LingeringPotion) ModItems.lingering_potion).getEffects(stack);
	boolean addedEffect = false;

	for (PotionEffect effect : effects) {
		int effectID = effect.getPotionID();
		if (Potion.potionTypes[effectID].isInstant()) {
			Potion.potionTypes[effectID].affectEntity(thrower, entity, effect.getAmplifier(), 0.25);
			addedEffect = true;
		} else if (!entity.isPotionActive(effectID)) {
			entity.addPotionEffect(effect);
			addedEffect = true;
		}
	}

	if (addedEffect) {
		int ticks = dataWatcher.getWatchableObjectInt(TICKS_DATA_WATCHER);
		if (setTickCount(ticks + 5 * 20)) // Add 5 seconds to the expiration time (decreasing radius by 0.5 blocks)
			return;
	}
}
 
Example 3
Source File: ContainerPotionCreator.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void handleInputPacket(PacketCustom packet) {
    ItemStack potion = potionInv.getStackInSlot(0);
    if (potion == null)
        return;

    boolean add = packet.readBoolean();
    int effectID = packet.readUByte();

    NBTTagList effects = potion.getTagCompound().getTagList("CustomPotionEffects", 10);
    NBTTagList newEffects = new NBTTagList();
    for(int i = 0; i < effects.tagCount(); i++) {
        NBTTagCompound tag = effects.getCompoundTagAt(i);
        PotionEffect e = PotionEffect.readCustomPotionEffectFromNBT(tag);
        if(e.getPotionID() != effectID)
            newEffects.appendTag(tag);
    }
    if(add)
        newEffects.appendTag(new PotionEffect(effectID, packet.readInt(), packet.readUByte()).writeCustomPotionEffectToNBT(new NBTTagCompound()));
    potion.getTagCompound().setTag("CustomPotionEffects", newEffects);
}
 
Example 4
Source File: FovModifier.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
@InvokeEvent
public void fovChange(FovUpdateEvent event) {
    float base = 1.0F;

    if (event.getPlayer().isSprinting()) {
        base += (float) (0.15000000596046448 * Settings.SPRINTING_FOV_MODIFIER);
    }

    if (event.getPlayer().getItemInUse() != null && event.getPlayer().getItemInUse().getItem().equals(Items.bow)) {
        int duration = (int) Math.min(event.getPlayer().getItemInUseDuration(), MAX_BOW_TICKS);
        float modifier = MODIFIER_BY_TICK.get(duration);
        base -= modifier * Settings.BOW_FOV_MODIFIER;
    }

    Collection<PotionEffect> effects = event.getPlayer().getActivePotionEffects();
    for (PotionEffect effect : effects) {
        if (effect.getPotionID() == 1) {
            base += (MODIFIER_SPEED * (effect.getAmplifier() + 1) * Settings.SPEED_FOV_MODIFIER);
        }

        if (effect.getPotionID() == 2) {
            base += (MODIFIER_SLOWNESS * (effect.getAmplifier() + 1) * Settings.SLOWNESS_FOV_MODIFIER);
        }
    }

    event.setNewFov(base);
}
 
Example 5
Source File: ShowArmor.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
private void drawPotionEffects(EntityLiving entity) {
    int i = 100;
    int j = 10;
    boolean flag = true;
    Collection collection = entity.getActivePotionEffects();
    if (!collection.isEmpty()) {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glDisable(GL11.GL_LIGHTING);
        int k = 33;

        if (collection.size() > 5) {
            k = 132 / (collection.size() - 1);
        }

        for (Iterator iterator = entity.getActivePotionEffects().iterator(); iterator.hasNext(); j += k) {
            PotionEffect potioneffect = (PotionEffect) iterator.next();
            Potion potion = Potion.potionTypes[potioneffect.getPotionID()];
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            Wrapper.INSTANCE.mc().getTextureManager().bindTexture(new ResourceLocation("textures/gui/container/inventory.png"));
            this.drawTexturedModalRect(i, j, 0, 166, 140, 32);

            if (potion.hasStatusIcon()) {
                int l = potion.getStatusIconIndex();
                this.drawTexturedModalRect(i + 6, j + 7, l % 8 * 18, 198 + l / 8 * 18, 18, 18);
            }

            potion.renderInventoryEffect(i, j, potioneffect, Wrapper.INSTANCE.mc());
            String s1 = I18n.format(potion.getName());

            s1 += " " + potioneffect.getAmplifier();

            Wrapper.INSTANCE.fontRenderer().drawStringWithShadow(s1, i + 10 + 18, j + 6, 16777215);
            String s = Potion.getDurationString(potioneffect);
            Wrapper.INSTANCE.fontRenderer().drawStringWithShadow(s, i + 10 + 18, j + 6 + 10, 8355711);
        }
    }
}
 
Example 6
Source File: TippedArrow.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack stack, int pass) {
	PotionEffect effect = getEffect(stack);
	if (effect == null || effect.getPotionID() < 0 || effect.getPotionID() >= Potion.potionTypes.length)
		return super.getColorFromItemStack(stack, pass);
	return pass == 0 ? Potion.potionTypes[effect.getPotionID()].getLiquidColor() : super.getColorFromItemStack(stack, pass);
}
 
Example 7
Source File: TippedArrow.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@Override
public String getUnlocalizedName(ItemStack stack) {
	PotionEffect effect = getEffect(stack);
	if (effect == null || effect.getPotionID() < 0 || effect.getPotionID() >= Potion.potionTypes.length)
		return super.getUnlocalizedName(stack);

	Potion potion = Potion.potionTypes[effect.getPotionID()];
	return "tipped_arrow." + potion.getName();
}
 
Example 8
Source File: GuiPotionCreator.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private PotionEffect getEffect(int id) {
    ItemStack potion = container.potionInv.getStackInSlot(0);
    if (potion != null && potion.hasTagCompound() && potion.getTagCompound().hasKey("CustomPotionEffects")) {
        NBTTagList potionTagList = potion.getTagCompound().getTagList("CustomPotionEffects", 10);
        for (int i = 0; i < potionTagList.tagCount(); i++) {
            PotionEffect effect = PotionEffect.readCustomPotionEffectFromNBT(potionTagList.getCompoundTagAt(i));
            if (effect.getPotionID() == id)
                return effect;
        }
    }
    return null;
}
 
Example 9
Source File: PotionEffects.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void draw(int x, double y, boolean isConfig) {
    int row = 0;
    double scale = ElementRenderer.getCurrentScale();
    Collection<PotionEffect> effects = new ArrayList<>();

    if (isConfig) {
        effects.add(new PotionEffect(1, 100, 1));
        effects.add(new PotionEffect(3, 100, 2));
    } else {
        effects = Minecraft.getMinecraft().thePlayer.getActivePotionEffects();
    }

    List<String> tmp = new ArrayList<>();

    for (PotionEffect potioneffect : effects) {
        Potion potion = Potion.potionTypes[potioneffect.getPotionID()];

        if (potionIcon) {
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
            Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/gui/container/inventory.png"));

            if (potion.hasStatusIcon()) {
                int potionStatusIconIndex = potion.getStatusIconIndex();
                drawTexturedModalRect(!ElementRenderer.getCurrent().isRightSided() ? (int) (x / scale) - 20 :
                        (int) (x / scale), (int) ((y + row * 16)) - 4, potionStatusIconIndex % 8 * 18,
                    198 + potionStatusIconIndex / 8 * 18, 18, 18);
            }
        }

        StringBuilder s1 = new StringBuilder(I18n.format(potion.getName()));

        switch (potioneffect.getAmplifier()) {
            case 1:
                s1.append(" ").append(I18n.format("enchantment.level.2"));
                break;
            case 2:
                s1.append(" ").append(I18n.format("enchantment.level.3"));
                break;
            case 3:
                s1.append(" ").append(I18n.format("enchantment.level.4"));
                break;
        }

        String s = Potion.getDurationString(potioneffect);
        String text = s1 + " - " + s;
        tmp.add(text);
        ElementRenderer.draw((int) (x / scale), ((y + row * 16)), text);
        row++;
    }

    width = isConfig ? ElementRenderer.maxWidth(tmp) : 0;
    height = row * 16;
}
 
Example 10
Source File: LingeringPotion.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings({ "rawtypes", "unchecked" })
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isComplex) {
	if (stack.getItemDamage() == 0)
		return;

	List<PotionEffect> effects = getEffects(stack);
	HashMultimap<String, AttributeModifier> attributes = HashMultimap.create();

	if (effects == null || effects.isEmpty()) {
		String s = StatCollector.translateToLocal("potion.empty").trim();
		list.add(EnumChatFormatting.GRAY + s);
	} else
		for (PotionEffect potioneffect : effects) {
			String s1 = StatCollector.translateToLocal(potioneffect.getEffectName()).trim();
			Potion potion = Potion.potionTypes[potioneffect.getPotionID()];
			Map<IAttribute, AttributeModifier> map = potion.func_111186_k();

			if (map != null && map.size() > 0)
				for (Entry<IAttribute, AttributeModifier> entry : map.entrySet()) {
					AttributeModifier attributemodifier = entry.getValue();
					AttributeModifier attributemodifier1 = new AttributeModifier(attributemodifier.getName(), potion.func_111183_a(potioneffect.getAmplifier(), attributemodifier), attributemodifier.getOperation());
					attributes.put(entry.getKey().getAttributeUnlocalizedName(), attributemodifier1);
				}

			if (potioneffect.getAmplifier() > 0)
				s1 = s1 + " " + StatCollector.translateToLocal("potion.potency." + potioneffect.getAmplifier()).trim();
			if (potioneffect.getDuration() > 20)
				s1 = s1 + " (" + Potion.getDurationString(potioneffect) + ")";

			if (potion.isBadEffect())
				list.add(EnumChatFormatting.RED + s1);
			else
				list.add(EnumChatFormatting.GRAY + s1);
		}

	if (!attributes.isEmpty()) {
		list.add("");
		list.add(EnumChatFormatting.DARK_PURPLE + StatCollector.translateToLocal("potion.effects.whenDrank"));

		for (Entry<String, AttributeModifier> entry1 : attributes.entries()) {
			AttributeModifier attributemodifier2 = entry1.getValue();
			double d0 = attributemodifier2.getAmount();
			double d1;

			if (attributemodifier2.getOperation() != 1 && attributemodifier2.getOperation() != 2)
				d1 = attributemodifier2.getAmount();
			else
				d1 = attributemodifier2.getAmount() * 100.0D;

			if (d0 > 0.0D)
				list.add(EnumChatFormatting.BLUE + StatCollector.translateToLocalFormatted("attribute.modifier.plus." + attributemodifier2.getOperation(), new Object[] { ItemStack.field_111284_a.format(d1), StatCollector.translateToLocal("attribute.name." + entry1.getKey()) }));
			else if (d0 < 0.0D) {
				d1 *= -1.0D;
				list.add(EnumChatFormatting.RED + StatCollector.translateToLocalFormatted("attribute.modifier.take." + attributemodifier2.getOperation(), new Object[] { ItemStack.field_111284_a.format(d1), StatCollector.translateToLocal("attribute.name." + entry1.getKey()) }));
			}
		}
	}
}
 
Example 11
Source File: ItemQuantumGoggles.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
    int refill = player.getAir();
    if (ElectricItem.manager.canUse(itemStack, 1000) && refill < 100) {
        player.setAir(refill + 200);
        ElectricItem.manager.use(itemStack, 1000, null);
    }

    Iterator i$ = (new LinkedList(player.getActivePotionEffects())).iterator();
    do {
        if (!i$.hasNext()) {
            break;
        }
        {
            PotionEffect effect = (PotionEffect) i$.next();
            int id = effect.getPotionID();
            Integer cost = (Integer) potionCost.get(Integer.valueOf(id));
            if (cost != null) {
                cost = Integer.valueOf(cost.intValue() * (effect.getAmplifier() + 1));
                if (ElectricItem.manager.canUse(itemStack, cost.intValue())) {
                    ElectricItem.manager.use(itemStack, cost.intValue(), null);
                    ItemStack milk = (new ItemStack(Items.milk_bucket));
                    player.curePotionEffects(milk);
                }
            }
        }
    } while (true);

    if (ConfigHandler.nightVisionOff == false) {
        if (ElectricItem.manager.canUse(itemStack, 1 / 1000)) {
            int x = MathHelper.floor_double(player.posX);
            int z = MathHelper.floor_double(player.posZ);
            int y = MathHelper.floor_double(player.posY);
            int lightlevel = player.worldObj.getBlockLightValue(x, y, z);
            if (lightlevel >= 0)
                player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 300, -3));
            ElectricItem.manager.use(itemStack, 1 / 1000, player);
        } else {
            player.addPotionEffect(new PotionEffect(Potion.blindness.id, 300, 0, true));
        }
    }
}