net.minecraft.potion.PotionUtils Java Examples
The following examples show how to use
net.minecraft.potion.PotionUtils.
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: EntityTippedChingerArrow.java From TofuCraftReload with MIT License | 6 votes |
public void setPotionEffect(ItemStack stack) { if (stack.getItem() == Items.TIPPED_ARROW) { this.potion = PotionUtils.getPotionFromItem(stack); Collection<PotionEffect> collection = PotionUtils.getFullEffectsFromItem(stack); if (!collection.isEmpty()) { for (PotionEffect potioneffect : collection) { this.customPotionEffects.add(new PotionEffect(potioneffect)); } } int i = getCustomColor(stack); if (i == -1) { this.refreshColor(); } else { this.setFixedColor(i); } } else if (stack.getItem() == ItemLoader.tofuchinger_tootharrow) { this.potion = PotionTypes.EMPTY; this.customPotionEffects.clear(); this.dataManager.set(COLOR, Integer.valueOf(-1)); } }
Example #2
Source File: EntityTippedChingerArrow.java From TofuCraftReload with MIT License | 6 votes |
/** * (abstract) Protected helper method to read subclass entity data from NBT. */ public void readEntityFromNBT(NBTTagCompound compound) { super.readEntityFromNBT(compound); if (compound.hasKey("Potion", 8)) { this.potion = PotionUtils.getPotionTypeFromNBT(compound); } for (PotionEffect potioneffect : PotionUtils.getFullEffectsFromTag(compound)) { this.addEffect(potioneffect); } if (compound.hasKey("Color", 99)) { this.setFixedColor(compound.getInteger("Color")); } else { this.refreshColor(); } }
Example #3
Source File: EntityMage.java From ToroQuest with GNU General Public License v3.0 | 6 votes |
protected void attackWithPotion(EntityLivingBase target) { double targetY = target.posY + (double) target.getEyeHeight() - 1.100000023841858D; double targetX = target.posX + target.motionX - this.posX; double d2 = targetY - this.posY; double targetZ = target.posZ + target.motionZ - this.posZ; float f = MathHelper.sqrt(targetX * targetX + targetZ * targetZ); PotionType potiontype = PotionTypes.HARMING; if (f >= 8.0F && !target.isPotionActive(MobEffects.SLOWNESS)) { potiontype = PotionTypes.SLOWNESS; } else if (target.getHealth() >= 8.0F && !target.isPotionActive(MobEffects.POISON)) { potiontype = PotionTypes.POISON; } else if (f <= 3.0F && !target.isPotionActive(MobEffects.WEAKNESS) && this.rand.nextFloat() < 0.25F) { potiontype = PotionTypes.WEAKNESS; } EntityPotion entitypotion = new EntityPotion(this.world, this, PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION), potiontype)); entitypotion.rotationPitch -= -20.0F; entitypotion.shoot(targetX, d2 + (double) (f * 0.2F), targetZ, 0.75F, 8.0F); this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_WITCH_THROW, this.getSoundCategory(), 1.0F, 0.8F + this.rand.nextFloat() * 0.4F); this.world.spawnEntity(entitypotion); }
Example #4
Source File: EntityMage.java From ToroQuest with GNU General Public License v3.0 | 6 votes |
protected void handleDrinkingPotionUpdate() { if (this.attackTimer-- <= 0) { this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_WITCH_DRINK, this.getSoundCategory(), 1.0F, 0.8F + this.rand.nextFloat() * 0.4F); this.setAggressive(false); ItemStack itemstack = this.getHeldItemOffhand(); this.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, ItemStack.EMPTY); if (itemstack != null && itemstack.getItem() == Items.POTIONITEM) { List<PotionEffect> list = PotionUtils.getEffectsFromStack(itemstack); if (list != null) { for (PotionEffect potioneffect : list) { this.addPotionEffect(new PotionEffect(potioneffect)); } } } this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).removeModifier(MODIFIER); } }
Example #5
Source File: EntityMage.java From ToroQuest with GNU General Public License v3.0 | 6 votes |
protected void handleAttackLogicUpdate() { PotionType potiontype = null; if (this.rand.nextFloat() < 0.15F && this.isInsideOfMaterial(Material.WATER) && !this.isPotionActive(MobEffects.WATER_BREATHING)) { potiontype = PotionTypes.WATER_BREATHING; } else if (this.rand.nextFloat() < 0.15F && this.isBurning() && !this.isPotionActive(MobEffects.FIRE_RESISTANCE)) { potiontype = PotionTypes.FIRE_RESISTANCE; } else if (this.rand.nextFloat() < 0.05F && this.getHealth() < this.getMaxHealth()) { potiontype = PotionTypes.HEALING; } else if (this.rand.nextFloat() < 0.5F && this.getAttackTarget() != null && !this.isPotionActive(MobEffects.SPEED) && this.getAttackTarget().getDistanceSq(this) > 121.0D) { potiontype = PotionTypes.SWIFTNESS; } if (potiontype != null) { this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_WITCH_DRINK, this.getSoundCategory(), 1.0F, 0.8F + this.rand.nextFloat() * 0.4F); this.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), potiontype)); this.attackTimer = 10; this.setAggressive(true); IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); iattributeinstance.removeModifier(MODIFIER); iattributeinstance.applyModifier(MODIFIER); } }
Example #6
Source File: BrewingUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static ItemStack createRegenerationPotion(boolean isProlonged, boolean isAugmented, boolean isSplash) { ItemStack res = getEmptyPotion(isSplash); if(isAugmented) { PotionUtils.addPotionToItemStack(res, PotionTypes.STRONG_REGENERATION); } else if(isProlonged) { PotionUtils.addPotionToItemStack(res, PotionTypes.LONG_REGENERATION); } else { PotionUtils.addPotionToItemStack(res, PotionTypes.REGENERATION); } return res; }
Example #7
Source File: BrewingUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static ItemStack createHealthPotion(boolean isProlonged, boolean isAugmented, boolean isSplash) { ItemStack res = getEmptyPotion(isSplash); if(isProlonged || isAugmented) { PotionUtils.addPotionToItemStack(res, PotionTypes.STRONG_HEALING); } else { PotionUtils.addPotionToItemStack(res, PotionTypes.HEALING); } return res; }
Example #8
Source File: BrewingUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static ItemStack createWitherPotion(boolean isProlonged, boolean isSplash) { ItemStack res = getEmptyPotion(isSplash); if(isProlonged) { PotionUtils.addPotionToItemStack(res, EnderZoo.potions.getWitheringLong()); } else { PotionUtils.addPotionToItemStack(res, EnderZoo.potions.getWithering()); } return res; }
Example #9
Source File: BrewingUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static ItemStack getEmptyPotion(boolean isSplash){ //in 1.11.2 brewing must start with potiontypes water //this was created to mimic vanilla ItemPotion.getDefaultInstance() ItemStack res; if(isSplash) { res = PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION), PotionTypes.WATER); } else { res = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER); } return res; }
Example #10
Source File: CraftThrownPotion.java From Kettle with GNU General Public License v3.0 | 5 votes |
public Collection<PotionEffect> getEffects() { ImmutableList.Builder<PotionEffect> builder = ImmutableList.builder(); for (net.minecraft.potion.PotionEffect effect : PotionUtils.getEffectsFromStack(getHandle().getPotion())) { builder.add(CraftPotionUtil.toBukkit(effect)); } return builder.build(); }
Example #11
Source File: PotionFluids.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
public static void initPotionFluids() { MinecraftForge.EVENT_BUS.register(new PotionFluids()); for (ResourceLocation registryName : ForgeRegistries.POTION_TYPES.getKeys()) { if (registryName.getResourceDomain().equals("minecraft") && registryName.getResourcePath().equals("empty")) continue; PotionType potion = ForgeRegistries.POTION_TYPES.getValue(registryName); Preconditions.checkNotNull(potion); Fluid potionFluid; if (potion != PotionTypes.WATER) { String fluidName = String.format("potion.%s.%s", registryName.getResourceDomain(), registryName.getResourcePath()); potionFluid = new Fluid(fluidName, AUTO_GENERATED_FLUID_TEXTURE, AUTO_GENERATED_FLUID_TEXTURE) { @Override public String getUnlocalizedName() { return potion.getNamePrefixed("potion.effect."); } }; potionFluid.setColor(GTUtility.convertRGBtoOpaqueRGBA_MC(PotionUtils.getPotionColor(potion))); FluidRegistry.registerFluid(potionFluid); FluidRegistry.addBucketForFluid(potionFluid); BlockFluidBase fluidBlock = new BlockPotionFluid(potionFluid, potion); fluidBlock.setRegistryName("fluid." + fluidName); MetaBlocks.FLUID_BLOCKS.add(fluidBlock); } else { potionFluid = FluidRegistry.WATER; } potionFluidMap.put(potion.getRegistryName(), potionFluid); } }
Example #12
Source File: GlassBottleFluidHandler.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private int fillImpl(FluidStack resource, boolean doFill) { PotionType potionType = PotionFluids.getPotionForFluid(resource.getFluid()); if (potionType != null && potionType != PotionTypes.EMPTY && resource.amount >= PotionFluids.POTION_ITEM_FLUID_AMOUNT) { if(doFill) { this.itemStack = new ItemStack(Items.POTIONITEM); PotionUtils.addPotionToItemStack(itemStack, potionType); } return PotionFluids.POTION_ITEM_FLUID_AMOUNT; } return 0; }
Example #13
Source File: PotionItemFluidHandler.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public FluidStack getFluid() { PotionType potionType = PotionUtils.getPotionFromItem(container); if (potionType == PotionTypes.EMPTY) return null; Fluid fluid = PotionFluids.getFluidForPotion(potionType); //because some mods are dumb enough to register potion types after block registry event if (fluid == null) return null; return new FluidStack(fluid, capacity); }
Example #14
Source File: PotionRecipeHelper.java From NotEnoughItems with MIT License | 4 votes |
public static void addNormalRecipe(Item potionItem, PotionType input, Ingredient ingredient, PotionType output) { IPotionRecipe recipe = new PotionTypeRecipe(PotionUtils.addPotionToItemStack(new ItemStack(potionItem), input), ingredient, output); normalRecipes.add(recipe); allRecipes.add(recipe); }
Example #15
Source File: PotionRecipeHelper.java From NotEnoughItems with MIT License | 4 votes |
public static void addSplashRecipe(Item potionItem, PotionType input, Ingredient ingredient, PotionType output) { IPotionRecipe recipe = new PotionTypeRecipe(PotionUtils.addPotionToItemStack(new ItemStack(potionItem), input), ingredient, output); splashRecipes.add(recipe); allRecipes.add(recipe); }
Example #16
Source File: PotionRecipeHelper.java From NotEnoughItems with MIT License | 4 votes |
public static void addLingeringRecipe(Item potionItem, PotionType input, Ingredient ingredient, PotionType output) { IPotionRecipe recipe = new PotionTypeRecipe(PotionUtils.addPotionToItemStack(new ItemStack(potionItem), input), ingredient, output); lingeringRecipes.add(recipe); allRecipes.add(recipe); }
Example #17
Source File: PotionTypeRecipe.java From NotEnoughItems with MIT License | 4 votes |
public PotionTypeRecipe(ItemStack input, Ingredient ingredient, PotionType outputType) { this.ingredient = ingredient; this.input = input.copy(); this.output = PotionUtils.addPotionToItemStack(input, outputType); }
Example #18
Source File: BrewingUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 4 votes |
public static ItemStack createHarmingPotion(boolean isAugmented, boolean isSplash) { ItemStack res = getEmptyPotion(isSplash); PotionUtils.addPotionToItemStack(res, PotionTypes.HARMING); return res; }
Example #19
Source File: RecipeMapBrewer.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Nullable @Override public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, int outputFluidTankCapacity) { Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs, outputFluidTankCapacity); if (recipe != null || GTUtility.amountOfNonNullElements(fluidInputs) < 1 || GTUtility.amountOfNonEmptyStacks(inputs) < 1) { return recipe; } ItemStack ingredientStack = inputs.get(0); FluidStack potionFluid = fluidInputs.get(0); PotionType potionType = PotionFluids.getPotionForFluid(potionFluid.getFluid()); if (potionType == null || potionFluid.amount < POTION_PER_INGREDIENT) { return null; //do not return recipes if not enough fluid or fluid doesn't match } ItemStack potionStack = new ItemStack(Items.POTIONITEM); PotionUtils.addPotionToItemStack(potionStack, potionType); ItemStack resultStack = BrewingRecipeRegistry.getOutput(potionStack, ingredientStack); if (resultStack.isEmpty() || resultStack.getItem() != Items.POTIONITEM) { return null; //if no recipe matches, or output is not a simple potion, return null } PotionType resultingType = PotionUtils.getPotionFromItem(resultStack); if (resultingType == null || resultingType == PotionTypes.EMPTY) { return null; //if output is not a simple potion or empty potion, return null } Fluid outputFluid = PotionFluids.getFluidForPotion(resultingType); if(outputFluid == null) { return null; } //otherwise, return recipe for fluid potion + ingredient -> new fluid potion return recipeBuilder() .inputs(new CountableIngredient(new NBTIngredient(ingredientStack), 1)) //we can reuse recipe only if ingredient fully matches, //because IBrewingRecipe logic is totally implementation-dependent and can easily depend on NBT for some recipes .fluidInputs(GTUtility.copyAmount(POTION_PER_INGREDIENT, potionFluid)) .fluidOutputs(new FluidStack(outputFluid, POTION_PER_INGREDIENT)) .build().getResult(); }
Example #20
Source File: EntityTippedChingerArrow.java From TofuCraftReload with MIT License | 4 votes |
public void addEffect(PotionEffect effect) { this.customPotionEffects.add(effect); this.getDataManager().set(COLOR, Integer.valueOf(PotionUtils.getPotionColorFromEffectList(PotionUtils.mergeEffects(this.potion, this.customPotionEffects)))); }
Example #21
Source File: EntityTippedChingerArrow.java From TofuCraftReload with MIT License | 4 votes |
private void refreshColor() { this.fixedColor = false; this.dataManager.set(COLOR, Integer.valueOf(PotionUtils.getPotionColorFromEffectList(PotionUtils.mergeEffects(this.potion, this.customPotionEffects)))); }