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);
}
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);
}
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);
}
}
}
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;
}
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));
}
Aggregations