Search in sources :

Example 1 with NamespacedId

use of net.coderbot.iris.shaderpack.materialmap.NamespacedId in project Iris by IrisShaders.

the class IdMap method parseIdMap.

/**
 * Parses a NamespacedId map in OptiFine format
 */
private static Object2IntMap<NamespacedId> parseIdMap(Properties properties, String keyPrefix, String fileName) {
    Object2IntMap<NamespacedId> idMap = new Object2IntOpenHashMap<>();
    idMap.defaultReturnValue(-1);
    properties.forEach((keyObject, valueObject) -> {
        String key = (String) keyObject;
        String value = (String) valueObject;
        if (!key.startsWith(keyPrefix)) {
            // Not a valid line, ignore it
            return;
        }
        int intId;
        try {
            intId = Integer.parseInt(key.substring(keyPrefix.length()));
        } catch (NumberFormatException e) {
            // Not a valid property line
            Iris.logger.warn("Failed to parse line in " + fileName + ": invalid key " + key);
            return;
        }
        // Split on any whitespace
        for (String part : value.split("\\s+")) {
            if (part.contains("=")) {
                // Avoid tons of logspam for now
                Iris.logger.warn("Failed to parse an ResourceLocation in " + fileName + " for the key " + key + ": state properties are currently not supported: " + part);
                continue;
            }
            // Note: NamespacedId performs no validation on the content. That will need to be done by whatever is
            // converting these things to ResourceLocations.
            idMap.put(new NamespacedId(part), intId);
        }
    });
    return Object2IntMaps.unmodifiable(idMap);
}
Also used : NamespacedId(net.coderbot.iris.shaderpack.materialmap.NamespacedId) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)

Example 2 with NamespacedId

use of net.coderbot.iris.shaderpack.materialmap.NamespacedId in project Iris by IrisShaders.

the class IdMapTest method testLoadIdMaps.

@Test
void testLoadIdMaps() {
    ShaderPack shaderPack;
    // ensure that we can actually load the shader pack
    try {
        shaderPack = new ShaderPack(IrisTests.getTestShaderPackPath("id_maps"));
    } catch (Exception e) {
        Assertions.fail("Couldn't load test shader pack id_maps", e);
        return;
    }
    Map<NamespacedId, BlockRenderType> overrides = shaderPack.getIdMap().getBlockRenderTypeMap();
    Int2ObjectMap<List<BlockEntry>> blocks = shaderPack.getIdMap().getBlockProperties();
    Assertions.assertEquals(EXPECTED_LAYERS, overrides);
    Assertions.assertEquals(EXPECTED_BLOCKS, blocks);
}
Also used : NamespacedId(net.coderbot.iris.shaderpack.materialmap.NamespacedId) BlockRenderType(net.coderbot.iris.shaderpack.materialmap.BlockRenderType) List(java.util.List) ShaderPack(net.coderbot.iris.shaderpack.ShaderPack) Test(org.junit.jupiter.api.Test)

Example 3 with NamespacedId

use of net.coderbot.iris.shaderpack.materialmap.NamespacedId in project Iris by IrisShaders.

the class BlockMaterialMapping method addBlockStates.

private static void addBlockStates(BlockEntry entry, Object2IntMap<BlockState> idMap, int intId) {
    NamespacedId id = entry.getId();
    ResourceLocation resourceLocation = new ResourceLocation(id.getNamespace(), id.getName());
    Block block = Registry.BLOCK.get(resourceLocation);
    // TODO: Assuming that Registry.BLOCK.getDefaultId() == "minecraft:air" here
    if (block == Blocks.AIR) {
        return;
    }
    Map<String, String> propertyPredicates = entry.getPropertyPredicates();
    if (propertyPredicates.isEmpty()) {
        // Just add all the states if there aren't any predicates
        for (BlockState state : block.getStateDefinition().getPossibleStates()) {
            idMap.put(state, intId);
        }
        return;
    }
    // As a result, we first collect each key=value pair in order to determine what properties we need to filter on.
    // We already get this from BlockEntry, but we convert the keys to `Property`s to ensure they exist and to avoid
    // string comparisons later.
    Map<Property<?>, String> properties = new HashMap<>();
    StateDefinition<Block, BlockState> stateManager = block.getStateDefinition();
    propertyPredicates.forEach((key, value) -> {
        Property<?> property = stateManager.getProperty(key);
        if (property == null) {
            Iris.logger.warn("Error while parsing the block ID map entry for \"" + "block." + intId + "\":");
            Iris.logger.warn("- The block " + resourceLocation + " has no property with the name " + key + ", ignoring!");
            return;
        }
        properties.put(property, value);
    });
    // block and check for ones that match the filters. This isn't particularly efficient, but it works!
    for (BlockState state : stateManager.getPossibleStates()) {
        if (checkState(state, properties)) {
            idMap.put(state, intId);
        }
    }
}
Also used : NamespacedId(net.coderbot.iris.shaderpack.materialmap.NamespacedId) BlockState(net.minecraft.world.level.block.state.BlockState) HashMap(java.util.HashMap) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) ResourceLocation(net.minecraft.resources.ResourceLocation) Block(net.minecraft.world.level.block.Block) Property(net.minecraft.world.level.block.state.properties.Property)

Example 4 with NamespacedId

use of net.coderbot.iris.shaderpack.materialmap.NamespacedId in project Iris by IrisShaders.

the class IdMap method parseRenderTypeMap.

/**
 * Parses a render layer map.
 *
 * This feature is used by Chocapic v9 and Wisdom Shaders. Otherwise, it is a rarely-used feature.
 */
private static Map<NamespacedId, BlockRenderType> parseRenderTypeMap(Properties properties, String keyPrefix, String fileName) {
    Map<NamespacedId, BlockRenderType> overrides = new HashMap<>();
    properties.forEach((keyObject, valueObject) -> {
        String key = (String) keyObject;
        String value = (String) valueObject;
        if (!key.startsWith(keyPrefix)) {
            // Not a valid line, ignore it
            return;
        }
        // Note: We have to remove the prefix "layer." because fromString expects "cutout", not "layer.cutout".
        String keyWithoutPrefix = key.substring(keyPrefix.length());
        BlockRenderType renderType = BlockRenderType.fromString(keyWithoutPrefix).orElse(null);
        if (renderType == null) {
            Iris.logger.warn("Failed to parse line in " + fileName + ": invalid block render type: " + key);
            return;
        }
        for (String part : value.split("\\s+")) {
            // Note: NamespacedId performs no validation on the content. That will need to be done by whatever is
            // converting these things to ResourceLocations.
            overrides.put(new NamespacedId(part), renderType);
        }
    });
    return overrides;
}
Also used : NamespacedId(net.coderbot.iris.shaderpack.materialmap.NamespacedId) HashMap(java.util.HashMap) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) BlockRenderType(net.coderbot.iris.shaderpack.materialmap.BlockRenderType)

Example 5 with NamespacedId

use of net.coderbot.iris.shaderpack.materialmap.NamespacedId in project Iris by IrisShaders.

the class MixinEntityRenderDispatcher method iris$beginEntityRender.

// Inject after MatrixStack#push to increase the chances that we won't be caught out by a poorly-positioned
// cancellation in an inject.
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V", shift = At.Shift.AFTER))
private void iris$beginEntityRender(Entity entity, double x, double y, double z, float yaw, float tickDelta, PoseStack poseStack, MultiBufferSource bufferSource, int light, CallbackInfo ci) {
    if (!(bufferSource instanceof WrappingMultiBufferSource)) {
        return;
    }
    ResourceLocation entityId = Registry.ENTITY_TYPE.getKey(entity.getType());
    Object2IntFunction<NamespacedId> entityIds = BlockRenderingSettings.INSTANCE.getEntityIds();
    if (entityIds == null) {
        return;
    }
    int intId = entityIds.applyAsInt(new NamespacedId(entityId.getNamespace(), entityId.getPath()));
    RenderStateShard phase = EntityRenderStateShard.forId(intId);
    ((WrappingMultiBufferSource) bufferSource).pushWrappingFunction(layer -> new OuterWrappedRenderType("iris:is_entity", layer, phase));
}
Also used : WrappingMultiBufferSource(net.coderbot.iris.fantastic.WrappingMultiBufferSource) NamespacedId(net.coderbot.iris.shaderpack.materialmap.NamespacedId) OuterWrappedRenderType(net.coderbot.iris.layer.OuterWrappedRenderType) RenderStateShard(net.minecraft.client.renderer.RenderStateShard) EntityRenderStateShard(net.coderbot.iris.layer.EntityRenderStateShard) ResourceLocation(net.minecraft.resources.ResourceLocation) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

NamespacedId (net.coderbot.iris.shaderpack.materialmap.NamespacedId)5 Object2IntOpenHashMap (it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)3 HashMap (java.util.HashMap)2 BlockRenderType (net.coderbot.iris.shaderpack.materialmap.BlockRenderType)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 List (java.util.List)1 WrappingMultiBufferSource (net.coderbot.iris.fantastic.WrappingMultiBufferSource)1 EntityRenderStateShard (net.coderbot.iris.layer.EntityRenderStateShard)1 OuterWrappedRenderType (net.coderbot.iris.layer.OuterWrappedRenderType)1 ShaderPack (net.coderbot.iris.shaderpack.ShaderPack)1 RenderStateShard (net.minecraft.client.renderer.RenderStateShard)1 Block (net.minecraft.world.level.block.Block)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 Property (net.minecraft.world.level.block.state.properties.Property)1 Test (org.junit.jupiter.api.Test)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1