use of net.minecraft.potion.PotionType in project GregTech by GregTechCE.
the class PotionItemFluidHandler method getFluid.
@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);
}
use of net.minecraft.potion.PotionType in project GregTech by GregTechCE.
the class RecipeMapBrewer method findRecipe.
@Nullable
@Override
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, int outputFluidTankCapacity, MatchingMode mode) {
Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs, outputFluidTankCapacity, mode);
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) {
// do not return recipes if not enough fluid or fluid doesn't match
return null;
}
ItemStack potionStack = new ItemStack(Items.POTIONITEM);
PotionUtils.addPotionToItemStack(potionStack, potionType);
ItemStack resultStack = BrewingRecipeRegistry.getOutput(potionStack, ingredientStack);
if (resultStack.isEmpty() || resultStack.getItem() != Items.POTIONITEM) {
// if no recipe matches, or output is not a simple potion, return null
return null;
}
PotionType resultingType = PotionUtils.getPotionFromItem(resultStack);
if (resultingType == null || resultingType == PotionTypes.EMPTY) {
// if output is not a simple potion or empty potion, return null
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(// we can reuse recipe only if ingredient fully matches,
new CountableIngredient(new NBTIngredient(ingredientStack), 1)).fluidInputs(GTUtility.copyAmount(POTION_PER_INGREDIENT, potionFluid)).fluidOutputs(new FluidStack(outputFluid, POTION_PER_INGREDIENT)).build().getResult();
}
use of net.minecraft.potion.PotionType in project GregTech by GregTechCE.
the class PotionFluids method initPotionFluids.
public static void initPotionFluids() {
MinecraftForge.EVENT_BUS.register(new PotionFluids());
for (ResourceLocation registryName : ForgeRegistries.POTION_TYPES.getKeys()) {
if (registryName.getNamespace().equals("minecraft") && registryName.getPath().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.getNamespace(), registryName.getPath());
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);
}
}
use of net.minecraft.potion.PotionType in project GregTech by GregTechCE.
the class GlassBottleFluidHandler method fillImpl.
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;
}
use of net.minecraft.potion.PotionType in project takumicraft by TNTModders.
the class EntityStrayCreeper method setEquipmentBasedOnDifficulty.
@Override
protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) {
super.setEquipmentBasedOnDifficulty(difficulty);
ItemStack stack = new ItemStack(Items.POTIONITEM);
PotionType type = null;
while (type == null || type.hasInstantEffect() || type.getEffects().isEmpty()) {
type = PotionType.REGISTRY.getRandomObject(this.rand);
}
PotionUtils.addPotionToItemStack(stack, type);
this.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, stack);
}
Aggregations