35 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package net.minecraft.commands;
 | |
| 
 | |
| import com.mojang.serialization.Codec;
 | |
| import java.util.Optional;
 | |
| import net.minecraft.commands.functions.CommandFunction;
 | |
| import net.minecraft.resources.ResourceLocation;
 | |
| import net.minecraft.server.ServerFunctionManager;
 | |
| 
 | |
| public class CacheableFunction {
 | |
| 	public static final Codec<CacheableFunction> CODEC = ResourceLocation.CODEC.xmap(CacheableFunction::new, CacheableFunction::getId);
 | |
| 	private final ResourceLocation id;
 | |
| 	private boolean resolved;
 | |
| 	private Optional<CommandFunction<CommandSourceStack>> function = Optional.empty();
 | |
| 
 | |
| 	public CacheableFunction(ResourceLocation id) {
 | |
| 		this.id = id;
 | |
| 	}
 | |
| 
 | |
| 	public Optional<CommandFunction<CommandSourceStack>> get(ServerFunctionManager functionManager) {
 | |
| 		if (!this.resolved) {
 | |
| 			this.function = functionManager.get(this.id);
 | |
| 			this.resolved = true;
 | |
| 		}
 | |
| 
 | |
| 		return this.function;
 | |
| 	}
 | |
| 
 | |
| 	public ResourceLocation getId() {
 | |
| 		return this.id;
 | |
| 	}
 | |
| 
 | |
| 	public boolean equals(Object object) {
 | |
| 		return object == this ? true : object instanceof CacheableFunction cacheableFunction && this.getId().equals(cacheableFunction.getId());
 | |
| 	}
 | |
| }
 |