-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathCTMConfig.java
64 lines (55 loc) · 2.56 KB
/
CTMConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package io.github.nuclearfarts.cbt.config;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
import java.util.function.Supplier;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockRenderView;
import io.github.nuclearfarts.cbt.sprite.SpriteProvider;
import io.github.nuclearfarts.cbt.tile.provider.TileProvider;
public interface CTMConfig extends Comparable<CTMConfig> {
TileProvider getTileProvider();
Predicate<Identifier> getTileMatcher();
Predicate<Direction> getFaceMatcher();
BiPredicate<BlockRenderView, BlockPos> getWorldConditions();
SpriteProvider createSpriteProvider(Sprite[] sprites);
boolean affectsModel(ModelIdentifier id, Supplier<Collection<SpriteIdentifier>> textureDeps);
int getResourcePackPriority();
int getWeight();
String getFileName();
static void registerConfigLoader(String formatName, Loader<?> loader) {
PrivateConstants.CTM_CONFIG_LOADERS.put(formatName, loader);
}
static CTMConfig load(Properties properties, Identifier location, ResourceManager manager, String packName) throws IOException {
Loader<?> loader;
if((loader = PrivateConstants.CTM_CONFIG_LOADERS.get(properties.getProperty("method"))) != null) {
return loader.load(properties, location, manager, packName);
}
throw new IllegalArgumentException("Invalid or unsupported CTM method " + properties.getProperty("method"));
}
static CTMConfig load(Identifier propertiesLocation, ResourceManager manager) throws IOException {
Properties properties = new Properties();
Resource resource = manager.getResource(propertiesLocation);
properties.load(resource.getInputStream());
return CTMConfig.load(properties, propertiesLocation, manager, resource.getResourcePackName());
}
@FunctionalInterface
public interface Loader<T extends CTMConfig> {
T load(Properties properties, Identifier location, ResourceManager manager, String packName) throws IOException;
}
public static final class PrivateConstants {
private PrivateConstants() { }
private static final Map<String, Loader<?>> CTM_CONFIG_LOADERS = new HashMap<>();
}
}