net.minecraft.potion.PotionType Java Examples

The following examples show how to use net.minecraft.potion.PotionType. 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 vote down vote up
/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
public void writeEntityToNBT(NBTTagCompound compound) {
    super.writeEntityToNBT(compound);

    if (this.potion != PotionTypes.EMPTY && this.potion != null) {
        compound.setString("Potion", ((ResourceLocation) PotionType.REGISTRY.getNameForObject(this.potion)).toString());
    }

    if (this.fixedColor) {
        compound.setInteger("Color", this.getColor());
    }

    if (!this.customPotionEffects.isEmpty()) {
        NBTTagList nbttaglist = new NBTTagList();

        for (PotionEffect potioneffect : this.customPotionEffects) {
            nbttaglist.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound()));
        }

        compound.setTag("CustomPotionEffects", nbttaglist);
    }
}
 
Example #2
Source File: EntityMage.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
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 #3
Source File: EntityMage.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
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 #4
Source File: Potions.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public Potions() {
  withering = new PotionType(WITHERING, new PotionEffect(MobEffects.WITHER, 900)).setRegistryName(EnderZoo.MODID, WITHERING);
  witheringLong = new PotionType(WITHERING, new PotionEffect(MobEffects.WITHER, 2400)).setRegistryName(EnderZoo.MODID, WITHERING_LONG);

  confusion = new PotionType(CONFUSION, new PotionEffect(MobEffects.NAUSEA, 900)).setRegistryName(EnderZoo.MODID, CONFUSION);
  confusionLong = new PotionType(CONFUSION, new PotionEffect(MobEffects.NAUSEA, 2400)).setRegistryName(EnderZoo.MODID, CONFUSION_LONG);

  if (Config.floatingPotionEnabled) {
    floatingPotion = FloatingPotion.create();
    floating = new PotionType(FLOATING, new PotionEffect(floatingPotion, Config.floatingPotionDuration)).setRegistryName(EnderZoo.MODID, FLOATING);
    floatingLong = new PotionType(FLOATING, new PotionEffect(floatingPotion, Config.floatingPotionDurationLong)).setRegistryName(EnderZoo.MODID, FLOATING_TWO);
    floatingTwo = new PotionType(FLOATING, new PotionEffect(floatingPotion, Config.floatingPotionTwoDuration, 1)).setRegistryName(EnderZoo.MODID, FLOATING_LONG);
  }

}
 
Example #5
Source File: PotionRecipeHelper.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static PotionType getPotionTypeFromStack(ItemStack itemStack) {
    if (itemStack.hasTagCompound()) {
        NBTTagCompound tagCompound = itemStack.getTagCompound();
        if (tagCompound.hasKey("Potion")) {
            String potion = tagCompound.getString("Potion");
            PotionType type = PotionType.getPotionTypeForName(potion);
            if (type != null) {
                return type;
            }
        }
    }
    return null;
}
 
Example #6
Source File: Potions.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public void registerPotions(IForgeRegistry<PotionType> reg) {
  // wither potion

  Ingredient redstone = Ingredient.fromItem(Items.REDSTONE);
  Ingredient glowstone = Ingredient.fromItem(Items.GLOWSTONE_DUST);

  // Wither
  reg.register(withering);
  reg.register(witheringLong);

  Ingredient witheringDust = Ingredient.fromItem(EnderZoo.itemWitheringDust);
  registerPotionTypeConversion(PotionTypes.AWKWARD, witheringDust, withering);
  registerPotionTypeConversion(withering, redstone, witheringLong);

  // Confusion
  reg.register(confusion);
  reg.register(confusionLong);

  Ingredient confusionDust = Ingredient.fromItem(EnderZoo.itemConfusingDust);
  registerPotionTypeConversion(PotionTypes.AWKWARD, confusionDust, confusion);
  registerPotionTypeConversion(confusion, redstone, confusionLong);

  // Rising
  if (Config.floatingPotionEnabled) {
    reg.register(floating);
    reg.register(floatingLong);
    reg.register(floatingTwo);

    Ingredient owlEgg = Ingredient.fromItem(EnderZoo.itemOwlEgg);
    registerPotionTypeConversion(PotionTypes.AWKWARD, owlEgg, floating);
    registerPotionTypeConversion(floating, redstone, floatingLong);
    registerPotionTypeConversion(floating, glowstone, floatingTwo);
  }

}
 
Example #7
Source File: NEIInitialization.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static void loadPotionSubsets() {
    ArrayList<ItemStack> allPotions = new ArrayList<>();
    for (IPotionRecipe recipe : PotionRecipeHelper.getRecipes()) {
        allPotions.add(recipe.getRecipeOutput());
    }

    ItemStackSet positiveEffects = new ItemStackSet();
    ItemStackSet negativeEffects = new ItemStackSet();
    ItemStackSet neutralEffects = new ItemStackSet();
    for (ItemStack potionStack : allPotions) {
        PotionType potionType = PotionRecipeHelper.getPotionTypeFromStack(potionStack);
        if (potionType == null) {
            continue;
        }
        List<PotionEffect> stackEffects = potionType.getEffects();
        if (stackEffects.isEmpty()) {
            neutralEffects.add(potionStack);
            continue;
        }
        for (PotionEffect effect : stackEffects) {
            //If for some reason a vanilla potion has positive and negative effects, make sure we don't add it to the list more than once.
            if (effect.getPotion().isBadEffect()) {
                if (!negativeEffects.contains(potionStack)) {
                    negativeEffects.add(potionStack);
                }
            } else {
                if (!positiveEffects.contains(potionStack)) {
                    positiveEffects.add(potionStack);
                }
            }
        }
    }

    API.addSubset("Items.Potions", new ItemStackSet().with(Items.POTIONITEM).with(Items.SPLASH_POTION).with(Items.LINGERING_POTION));
    API.addSubset("Items.Potions.Splash", new ItemStackSet().with(Items.SPLASH_POTION));
    API.addSubset("Items.Potions.Lingering", new ItemStackSet().with(Items.LINGERING_POTION));
    API.addSubset("Items.Potions.Positive", positiveEffects);
    API.addSubset("Items.Potions.Negative", negativeEffects);
    API.addSubset("Items.Potions.Neutral", neutralEffects);
}
 
Example #8
Source File: PotionFluids.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #9
Source File: GlassBottleFluidHandler.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #10
Source File: PotionItemFluidHandler.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #11
Source File: Potions.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public PotionType getConfusionLong() {
  return confusionLong;
}
 
Example #12
Source File: Potions.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public PotionType getFloating() {
  return floating;
}
 
Example #13
Source File: Potions.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public PotionType getConfusion() {
  return confusion;
}
 
Example #14
Source File: Potions.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public PotionType getWitheringLong() {
  return witheringLong;
}
 
Example #15
Source File: Potions.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public PotionType getWithering() {
  return withering;
}
 
Example #16
Source File: Potions.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public PotionType getFloatingLong() {
  return floatingLong;
}
 
Example #17
Source File: Potions.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public PotionType getFloatingTwo() {
  return floatingTwo;
}
 
Example #18
Source File: PotionRecipeHelper.java    From NotEnoughItems with MIT License 4 votes vote down vote up
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 #19
Source File: RegistryHandler.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@SubscribeEvent
public void onPotionTypeRegister(Register<PotionType> e) {
	EnderZoo.potions.registerPotions(e.getRegistry());
}
 
Example #20
Source File: PotionTypeRecipe.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public PotionTypeRecipe(ItemStack input, Ingredient ingredient, PotionType outputType) {
    this.ingredient = ingredient;
    this.input = input.copy();
    this.output = PotionUtils.addPotionToItemStack(input, outputType);
}
 
Example #21
Source File: PotionRecipeHelper.java    From NotEnoughItems with MIT License 4 votes vote down vote up
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 #22
Source File: PotionRecipeHelper.java    From NotEnoughItems with MIT License 4 votes vote down vote up
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 #23
Source File: TQPotionTypes.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public static void registerPotionTypes(RegistryEvent.Register<PotionType> event) {
	event.getRegistry().registerAll(ROYALTY, ROYALTY_LONG, ROYALTY_STRONG, LOYALTY, LOYALTY_LONG, LOYALTY_STRONG);
}
 
Example #24
Source File: TQPotionTypes.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static PotionType createPotionType(PotionEffect potionEffect) {
	return createPotionType(potionEffect, null);
}
 
Example #25
Source File: PotionFluids.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static PotionType getPotionForFluid(Fluid potionFluid) {
    ResourceLocation registryName = potionFluidMap.inverse().get(potionFluid);
    return registryName == null ? null : ForgeRegistries.POTION_TYPES.getValue(registryName);
}
 
Example #26
Source File: PotionFluids.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Fluid getFluidForPotion(PotionType potion) {
    return potionFluidMap.get(potion.getRegistryName());
}
 
Example #27
Source File: BlockPotionFluid.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public BlockPotionFluid(Fluid fluid, PotionType potionType) {
    super(fluid, Material.WATER);
    this.potionType = potionType;
}
 
Example #28
Source File: RecipeMapBrewer.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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 #29
Source File: Potions.java    From EnderZoo with Creative Commons Zero v1.0 Universal 2 votes vote down vote up
/**
 * Registers a conversion from one PotionType to another PotionType, with the
 * given reagent
 */
private void registerPotionTypeConversion(PotionType input, Ingredient ingredient, PotionType output) {
    PotionHelper.addMix(input, ingredient, output);
}