Skip to content
Merged
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 @@ -354,7 +354,7 @@ public class WorkerThread extends Thread {

private WorkerThread() {
this.id = RenderManager.this.nextWorkerThreadIndex.getAndIncrement();
this.setName("RenderManager-" + RenderManager.this.id + "-" + this.id);
this.setName("BlueMap-RenderThread-" + RenderManager.this.id + "-" + this.id);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/de/bluecolored/bluemap/core/map/BmMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public BmMap(String id, String name, World world, MapStorage storage, ResourcePa

Logger.global.logDebug("Loading textures for map '" + id + "'");
this.textureGallery = loadTextureGallery();
this.textureGallery.put(resourcePack);
this.textureGallery.put(resourcePack.getTextures());
saveTextureGallery();

this.hiresModelManager = new HiresModelManager(
Expand Down Expand Up @@ -197,7 +197,7 @@ private void saveTextureGallery() {

public synchronized void resetTextureGallery() {
this.textureGallery.clear();
this.textureGallery.put(this.resourcePack);
this.textureGallery.put(this.resourcePack.getTextures());
}

private void saveMapSettings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.gson.*;
import de.bluecolored.bluemap.core.resources.ResourcePath;
import de.bluecolored.bluemap.core.resources.adapter.ResourcesGson;
import de.bluecolored.bluemap.core.resources.pack.ResourcePool;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.ResourcePack;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.texture.Texture;
import de.bluecolored.bluemap.core.util.Key;
Expand Down Expand Up @@ -74,13 +75,13 @@ public synchronized void put(ResourcePath<Texture> textureResourcePath) {
});
}

public synchronized void put(ResourcePack resourcePack) {
public synchronized void put(ResourcePool<Texture> texturePool) {
this.put(ResourcePack.MISSING_TEXTURE); // put this first
resourcePack.getTextures().keySet()
texturePool.paths()
.stream()
.sorted(Comparator
.comparing((ResourcePath<Texture> r) -> {
Texture texture = r.getResource(resourcePack::getTexture);
Texture texture = r.getResource(texturePool::get);
return texture != null && texture.getColorPremultiplied().a < 1f;
})
.thenComparing(Key::getFormatted))
Expand Down Expand Up @@ -114,7 +115,7 @@ public static TextureGallery readTexturesFile(InputStream in) throws IOException
for (int ordinal = 0; ordinal < textures.length; ordinal++) {
Texture texture = textures[ordinal];
if (texture != null) {
gallery.textureMappings.put(texture.getResourcePath(), new TextureMapping(ordinal, texture));
gallery.textureMappings.put(texture.getKey(), new TextureMapping(ordinal, texture));
}
}
} catch (JsonParseException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import de.bluecolored.bluemap.core.world.World;
import de.bluecolored.bluemap.core.world.block.Block;
import de.bluecolored.bluemap.core.world.block.BlockNeighborhood;
import lombok.extern.flogger.Flogger;

public class HiresModelRenderer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import de.bluecolored.bluemap.core.map.hires.TileModelView;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.ResourcePack;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.blockstate.Variant;
import de.bluecolored.bluemap.core.util.Key;
import de.bluecolored.bluemap.core.util.math.Color;
import de.bluecolored.bluemap.core.world.BlockState;
import de.bluecolored.bluemap.core.world.block.BlockNeighborhood;
Expand Down Expand Up @@ -81,7 +82,7 @@ public void render(BlockNeighborhood block, BlockState blockState, TileModelView
private void renderModel(BlockNeighborhood block, BlockState blockState, TileModelView tileModel, Color blockColor) {
int modelStart = tileModel.getStart();

var stateResource = resourcePack.getBlockState(blockState);
var stateResource = resourcePack.getBlockStates().get(blockState.getId());
if (stateResource == null) return;

float blockColorOpacity = 0;
Expand Down Expand Up @@ -109,6 +110,6 @@ private void renderModel(BlockNeighborhood block, BlockState blockState, TileMod
tileModel.initialize(modelStart);
}

private final static BlockState WATERLOGGED_BLOCKSTATE = new BlockState("minecraft:water");
private final static BlockState WATERLOGGED_BLOCKSTATE = new BlockState(Key.minecraft("water"));

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import de.bluecolored.bluemap.core.resources.BlockColorCalculatorFactory;
import de.bluecolored.bluemap.core.resources.ResourcePath;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.ResourcePack;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.blockstate.Variant;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.model.Model;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.model.TextureVariable;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.blockstate.Variant;
import de.bluecolored.bluemap.core.resources.pack.resourcepack.texture.Texture;
import de.bluecolored.bluemap.core.util.Direction;
import de.bluecolored.bluemap.core.util.math.Color;
Expand All @@ -46,6 +46,8 @@
import de.bluecolored.bluemap.core.world.block.BlockNeighborhood;
import de.bluecolored.bluemap.core.world.block.ExtendedBlock;

import java.util.function.Function;

/**
* A model builder for all liquid blocks
*/
Expand All @@ -58,7 +60,8 @@ public class LiquidModelRenderer implements BlockRenderer {
.scale(0.5f, 0.5f, 1)
.translate(0.5f, 0.5f);

private final ResourcePack resourcePack;
private final Function<ResourcePath<Model>, Model> modelProvider;
private final Function<ResourcePath<Texture>, Texture> textureProvider;
private final TextureGallery textureGallery;
private final RenderSettings renderSettings;
private final BlockColorCalculatorFactory.BlockColorCalculator blockColorCalculator;
Expand All @@ -74,7 +77,8 @@ public class LiquidModelRenderer implements BlockRenderer {
private Color blockColor;

public LiquidModelRenderer(ResourcePack resourcePack, TextureGallery textureGallery, RenderSettings renderSettings) {
this.resourcePack = resourcePack;
this.modelProvider = resourcePack.getModels()::get;
this.textureProvider = resourcePack.getTextures()::get;
this.textureGallery = textureGallery;
this.renderSettings = renderSettings;
this.blockColorCalculator = resourcePack.getColorCalculatorFactory().createCalculator();
Expand All @@ -98,7 +102,7 @@ public void render(BlockNeighborhood block, Variant variant, TileModelView block
this.blockState = block.getBlockState();
this.isWaterlogged = blockState.isWaterlogged() || block.getProperties().isAlwaysWaterlogged();
this.isWaterLike = blockState.isWater() || isWaterlogged;
this.modelResource = variant.getModel().getResource(resourcePack::getModel);
this.modelResource = variant.getModel().getResource(modelProvider);
this.blockModel = blockModel;
this.blockColor = color;

Expand Down Expand Up @@ -162,7 +166,7 @@ private void build() {

//calculate mapcolor
if (upFaceRendered) {
Texture stillTexture = stillTexturePath == null ? null : stillTexturePath.getResource(resourcePack::getTexture);
Texture stillTexture = stillTexturePath == null ? null : stillTexturePath.getResource(textureProvider);

if (stillTexture != null) {
blockColor.set(stillTexture.getColorPremultiplied());
Expand Down Expand Up @@ -224,14 +228,13 @@ private boolean isLiquidBlockingBlock(BlockState blockState){
return !blockState.isAir();
}

@SuppressWarnings("StringEquality")
private boolean isSameLiquid(ExtendedBlock block){
BlockState blockState = block.getBlockState();

if (this.isWaterlogged)
return blockState.isWater() || blockState.isWaterlogged() || block.getProperties().isAlwaysWaterlogged();

if (blockState.getFormatted() == this.blockState.getFormatted())
if (blockState.getId().equals(this.blockState.getId()))
return true;

return this.isWaterLike && (blockState.isWaterlogged() || block.getProperties().isAlwaysWaterlogged());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@
import de.bluecolored.bluemap.core.world.block.BlockNeighborhood;
import de.bluecolored.bluemap.core.world.block.ExtendedBlock;

import java.util.function.Function;

/**
* This model builder creates a BlockStateModel using the information from parsed resource-pack json files.
*/
@SuppressWarnings("DuplicatedCode")
public class ResourceModelRenderer implements BlockRenderer {
private static final float BLOCK_SCALE = 1f / 16f;

private final ResourcePack resourcePack;
private final Function<ResourcePath<Model>, Model> modelProvider;
private final Function<ResourcePath<Texture>, Texture> textureProvider;
private final TextureGallery textureGallery;
private final RenderSettings renderSettings;
private final BlockColorCalculatorFactory.BlockColorCalculator blockColorCalculator;
Expand All @@ -76,7 +79,8 @@ public class ResourceModelRenderer implements BlockRenderer {
private float blockColorOpacity;

public ResourceModelRenderer(ResourcePack resourcePack, TextureGallery textureGallery, RenderSettings renderSettings) {
this.resourcePack = resourcePack;
this.modelProvider = resourcePack.getModels()::get;
this.textureProvider = resourcePack.getTextures()::get;
this.textureGallery = textureGallery;
this.renderSettings = renderSettings;
this.blockColorCalculator = resourcePack.getColorCalculatorFactory().createCalculator();
Expand All @@ -91,7 +95,7 @@ public void render(BlockNeighborhood block, Variant variant, TileModelView block
this.blockColor = color;
this.blockColorOpacity = 0f;
this.variant = variant;
this.modelResource = variant.getModel().getResource(resourcePack::getModel);
this.modelResource = variant.getModel().getResource(modelProvider);

if (this.modelResource == null) return;

Expand Down Expand Up @@ -324,7 +328,7 @@ private void createElementFace(Element element, Direction faceDir, VectorM3f c0,
//if is top face set model-color
float a = faceRotationVector.y;
if (a > 0.01 && texturePath != null) {
Texture texture = texturePath.getResource(resourcePack::getTexture);
Texture texture = texturePath.getResource(textureProvider);
if (texture != null) {
mapColor.set(texture.getColorPremultiplied());
if (tintColor.a >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public EntityModelRenderer(ResourcePack resourcePack, TextureGallery textureGall
}

public void render(Entity entity, BlockNeighborhood block, TileModelView tileModel) {
EntityState stateResource = resourcePack.getEntityState(entity.getId());
EntityState stateResource = resourcePack.getEntityStates().get(entity.getId());
if (stateResource == null) return;

Part[] parts = stateResource.getParts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@
import de.bluecolored.bluemap.core.world.LightData;
import de.bluecolored.bluemap.core.world.block.BlockNeighborhood;

import java.util.function.Function;

/**
* This model builder creates a BlockStateModel using the information from parsed resource-pack json files.
*/
@SuppressWarnings("DuplicatedCode")
public class ResourceModelRenderer implements EntityRenderer {
private static final float SCALE = 1f / 16f;

final ResourcePack resourcePack;
final TextureGallery textureGallery;
final RenderSettings renderSettings;
private final Function<ResourcePath<Model>, Model> modelProvider;
private final TextureGallery textureGallery;
private final RenderSettings renderSettings;

private final VectorM3f[] corners = new VectorM3f[8];
private final VectorM2f[] rawUvs = new VectorM2f[4];
Expand All @@ -69,7 +71,7 @@ public class ResourceModelRenderer implements EntityRenderer {

@SuppressWarnings("unused")
public ResourceModelRenderer(ResourcePack resourcePack, TextureGallery textureGallery, RenderSettings renderSettings) {
this.resourcePack = resourcePack;
this.modelProvider = resourcePack.getModels()::get;
this.textureGallery = textureGallery;
this.renderSettings = renderSettings;

Expand All @@ -82,7 +84,7 @@ public void render(Entity entity, BlockNeighborhood block, Part part, TileModelV
render(
entity,
block,
part.getModel().getResource(resourcePack::getModel),
part.getModel().getResource(modelProvider),
TintColorProvider.NO_TINT,
tileModel
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import de.bluecolored.bluemap.core.storage.GridStorage;
import de.bluecolored.bluemap.core.storage.compression.CompressedInputStream;
import de.bluecolored.bluemap.core.util.Key;
import de.bluecolored.bluemap.core.util.PalettedArrayAdapter;
import de.bluecolored.bluemap.core.util.RegistryAdapter;
import de.bluecolored.bluemap.core.util.nbt.PalettedArrayAdapter;
import de.bluecolored.bluemap.core.util.nbt.RegistryAdapter;
import de.bluecolored.bluenbt.BlueNBT;
import de.bluecolored.bluenbt.TypeToken;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package de.bluecolored.bluemap.core.map.renderstate;

import de.bluecolored.bluemap.core.util.Key;
import de.bluecolored.bluemap.core.util.RegistryAdapter;
import de.bluecolored.bluemap.core.util.nbt.RegistryAdapter;
import de.bluecolored.bluenbt.*;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class BlockColorCalculator {

@SuppressWarnings("UnusedReturnValue")
public Color getBlockColor(BlockNeighborhood block, Color target) {
String blockId = block.getBlockState().getFormatted();
String blockId = block.getBlockState().getId().getFormatted();

ColorFunction colorFunction = blockColorMap.get(blockId);
if (colorFunction == null) colorFunction = blockColorMap.get("default");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package de.bluecolored.bluemap.core.resources;

import com.google.gson.stream.JsonReader;
import de.bluecolored.bluemap.core.util.Key;
import de.bluecolored.bluemap.core.world.BlockProperties;
import de.bluecolored.bluemap.core.world.BlockState;

Expand All @@ -40,7 +41,7 @@

public class BlockPropertiesConfig {

private final Map<String, List<BlockStateMapping<BlockProperties>>> mappings;
private final Map<Key, List<BlockStateMapping<BlockProperties>>> mappings;

public BlockPropertiesConfig() {
mappings = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -73,14 +74,14 @@ public void load(Path configFile) throws IOException {
BlockStateMapping<BlockProperties> mapping = new BlockStateMapping<>(bsKey, bsValueBuilder.build());

// don't overwrite already present values, higher priority resources are loaded first
mappings.computeIfAbsent(bsKey.getFormatted(), k -> new LinkedList<>()).add(mapping);
mappings.computeIfAbsent(bsKey.getId(), k -> new LinkedList<>()).add(mapping);
}
json.endObject();
}
}

public BlockProperties getBlockProperties(BlockState from){
for (BlockStateMapping<BlockProperties> bm : mappings.getOrDefault(from.getFormatted(), Collections.emptyList())){
for (BlockStateMapping<BlockProperties> bm : mappings.getOrDefault(from.getId(), Collections.emptyList())){
if (bm.fitsTo(from)){
return bm.getMapping();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public BlockStateMapping(BlockState blockState, T mapping) {
* Properties that are not defined in this Mapping are ignored on the provided BlockState.<br>
*/
public boolean fitsTo(BlockState blockState){
if (!this.blockState.getValue().equals(blockState.getValue())) return false;
if (!this.blockState.getId().equals(blockState.getId())) return false;
for (Entry<String, String> e : this.blockState.getProperties().entrySet()){
if (!e.getValue().equals(blockState.getProperties().get(e.getKey()))){
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.stream.JsonReader;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.resources.adapter.AbstractTypeAdapterFactory;
import de.bluecolored.bluemap.core.util.FileHelper;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public ResourcePath(String namespace, String value) {
super(namespace.toLowerCase(Locale.ROOT), value.toLowerCase(Locale.ROOT));
}

public ResourcePath(Key key) {
super(key.getNamespace(), key.getValue());
}

public ResourcePath(Path filePath, int namespacePos, int valuePos) {
super(parsePath(filePath, namespacePos, valuePos).toLowerCase(Locale.ROOT));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.core.resources;
package de.bluecolored.bluemap.core.resources.adapter;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
Expand Down
Loading
Loading