70 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package net.minecraft.world.item.alchemy;
 | |
| 
 | |
| import com.mojang.serialization.Codec;
 | |
| import java.util.List;
 | |
| import net.minecraft.core.Holder;
 | |
| import net.minecraft.core.registries.BuiltInRegistries;
 | |
| import net.minecraft.core.registries.Registries;
 | |
| import net.minecraft.network.RegistryFriendlyByteBuf;
 | |
| import net.minecraft.network.codec.ByteBufCodecs;
 | |
| import net.minecraft.network.codec.StreamCodec;
 | |
| import net.minecraft.world.effect.MobEffectInstance;
 | |
| import net.minecraft.world.flag.FeatureElement;
 | |
| import net.minecraft.world.flag.FeatureFlag;
 | |
| import net.minecraft.world.flag.FeatureFlagSet;
 | |
| import net.minecraft.world.flag.FeatureFlags;
 | |
| 
 | |
| /**
 | |
|  * Defines a type of potion in the game. These are used to associate one or more effects with items such as the bottled potion or the tipped arrows.
 | |
|  */
 | |
| public class Potion implements FeatureElement {
 | |
| 	public static final Codec<Holder<Potion>> CODEC = BuiltInRegistries.POTION.holderByNameCodec();
 | |
| 	public static final StreamCodec<RegistryFriendlyByteBuf, Holder<Potion>> STREAM_CODEC = ByteBufCodecs.holderRegistry(Registries.POTION);
 | |
| 	/**
 | |
| 	 * The base name for the potion type.
 | |
| 	 */
 | |
| 	private final String name;
 | |
| 	private final List<MobEffectInstance> effects;
 | |
| 	private FeatureFlagSet requiredFeatures = FeatureFlags.VANILLA_SET;
 | |
| 
 | |
| 	public Potion(String name, MobEffectInstance... effects) {
 | |
| 		this.name = name;
 | |
| 		this.effects = List.of(effects);
 | |
| 	}
 | |
| 
 | |
| 	public Potion requiredFeatures(FeatureFlag... requiredFeatures) {
 | |
| 		this.requiredFeatures = FeatureFlags.REGISTRY.subset(requiredFeatures);
 | |
| 		return this;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public FeatureFlagSet requiredFeatures() {
 | |
| 		return this.requiredFeatures;
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Gets the base effects applied by the potion.
 | |
| 	 * @return The effects applied by the potion.
 | |
| 	 */
 | |
| 	public List<MobEffectInstance> getEffects() {
 | |
| 		return this.effects;
 | |
| 	}
 | |
| 
 | |
| 	public String name() {
 | |
| 		return this.name;
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * Checks if the potion contains any instant effects such as instant health or instant damage.
 | |
| 	 * @return Whether the potion contained an instant effect.
 | |
| 	 */
 | |
| 	public boolean hasInstantEffects() {
 | |
| 		for (MobEffectInstance mobEffectInstance : this.effects) {
 | |
| 			if (mobEffectInstance.getEffect().value().isInstantenous()) {
 | |
| 				return true;
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		return false;
 | |
| 	}
 | |
| }
 |