Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public class ResourcePool<T> {

private final Map<Key, T> pool = new HashMap<>();
private final Map<Key, ResourcePath<T>> paths = new HashMap<>();
private final ResourcePoolMapper mapper;
private final Class<T> type;

public ResourcePool() {
this.type = null;
this.mapper = null;
}

public ResourcePool(Class<T> type, ResourcePoolMapper mapper) {
this.type = type;
this.mapper = mapper;
}

public void put(Key path, T value) {
put(new ResourcePath<>(path), value);
Expand Down Expand Up @@ -70,6 +82,9 @@ public Collection<T> values() {
}

public boolean contains(Key path) {
if (mapper != null) {
path = mapper.remapResource(type, path);
}
return paths.containsKey(path);
}

Expand All @@ -78,7 +93,7 @@ public boolean contains(Key path) {
}

public @Nullable T get(Key path) {
ResourcePath<T> rp = paths.get(path);
ResourcePath<T> rp = getPath(path);
return rp == null ? null : rp.getResource(this::get);
}

Expand All @@ -88,6 +103,9 @@ public synchronized void remove(Key path) {
}

public @Nullable ResourcePath<T> getPath(Key path) {
if (mapper != null) {
path = mapper.remapResource(type, path);
}
return paths.get(path);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.bluecolored.bluemap.core.resources.pack;

import de.bluecolored.bluemap.core.util.Key;

import java.lang.reflect.Type;

public interface ResourcePoolMapper {
Key remapResource(Type type, Key src);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import de.bluecolored.bluemap.core.resources.pack.Pack;
import de.bluecolored.bluemap.core.resources.pack.PackVersion;
import de.bluecolored.bluemap.core.resources.pack.ResourcePool;
import de.bluecolored.bluemap.core.resources.pack.ResourcePoolMapper;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.atlas.Atlas;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.blockstate.BlockState;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.entitystate.EntityState;
Expand All @@ -53,6 +54,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
Expand All @@ -63,7 +65,7 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;

public class ResourcePack extends Pack {
public class ResourcePack extends Pack implements ResourcePoolMapper {

public interface Extension<T extends ResourcePackExtension> extends Keyed {
Registry<Extension<?>> REGISTRY = new Registry<>();
Expand Down Expand Up @@ -94,12 +96,12 @@ public interface Extension<T extends ResourcePackExtension> extends Keyed {
public ResourcePack(PackVersion packVersion) {
super(packVersion);

this.atlases = new ResourcePool<>();
this.blockStates = new ResourcePool<>();
this.entityStates = new ResourcePool<>();
this.models = new ResourcePool<>();
this.textures = new ResourcePool<>();
this.colormaps = new ResourcePool<>();
this.atlases = new ResourcePool<>(Atlas.class, this);
this.blockStates = new ResourcePool<>(BlockState.class, this);
this.entityStates = new ResourcePool<>(EntityState.class, this);
this.models = new ResourcePool<>(Model.class, this);
this.textures = new ResourcePool<>(Texture.class, this);
this.colormaps = new ResourcePool<>(BufferedImage.class, this);

this.colorCalculatorFactory = new BlockColorCalculatorFactory();
this.blockPropertiesConfig = new BlockPropertiesConfig();
Expand All @@ -115,6 +117,14 @@ public ResourcePack(PackVersion packVersion) {
extensions.put(extensionType, extensionType.create(this));
}

@Override
public Key remapResource(Type type, Key src) {
for (ResourcePackExtension extension : extensions.values()) {
src = extension.remapResource(type, src);
}
return src;
}

@Override
public synchronized void loadResources(Iterable<Path> roots) throws IOException, InterruptedException {
Logger.global.logInfo("Loading resources...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import de.bluecolored.bluemap.core.resources.pack.PackExtension;
import de.bluecolored.bluemap.core.util.Key;

import java.lang.reflect.Type;
import java.util.Set;

public interface ResourcePackExtension extends PackExtension {
Expand All @@ -35,4 +36,7 @@ default Set<Key> collectUsedTextureKeys() {
return Set.of();
}

default Key remapResource(Type type, Key src) {
return src;
}
}
Loading