Skip to content

Commit

Permalink
Naming fixes and backport misc. changes from 1.21
Browse files Browse the repository at this point in the history
- Rename variables, fields, and methods to use "pack id" instead of "pack name"
- Fix overlay CtmProperties naming variables and fields with "id" instead of "resourceId"
- Use Identifier.withPath whenever possible
- Add missing nullable annotations in BaseProcessingPredicate
  • Loading branch information
PepperCode1 committed Jul 5, 2024
1 parent 24781a2 commit 3dab2d1
Show file tree
Hide file tree
Showing 21 changed files with 92 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract class AtlasLoaderMixin {
Map<Identifier, Identifier> emissiveIdMap = new Object2ObjectOpenHashMap<>();
suppliers.forEach((id, supplier) -> {
if (!id.getPath().endsWith(emissiveSuffix)) {
Identifier emissiveId = new Identifier(id.getNamespace(), id.getPath() + emissiveSuffix);
Identifier emissiveId = id.withPath(id.getPath() + emissiveSuffix);
if (!suppliers.containsKey(emissiveId)) {
Identifier emissiveLocation = emissiveId.withPath("textures/" + emissiveId.getPath() + ".png");
Optional<Resource> optionalResource = resourceManager.getResource(emissiveLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public QuadProcessor createProcessor(T properties, Function<SpriteIdentifier, Sp
int max = provided;

if (provided > textureAmount) {
ContinuityClient.LOGGER.warn("Method '" + properties.getMethod() + "' requires " + textureAmount + " tiles but " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackName() + "'");
ContinuityClient.LOGGER.warn("Method '" + properties.getMethod() + "' requires " + textureAmount + " tiles but " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackId() + "'");
max = textureAmount;
}

Expand All @@ -40,7 +40,7 @@ public QuadProcessor createProcessor(T properties, Function<SpriteIdentifier, Sp
}

if (provided < textureAmount) {
ContinuityClient.LOGGER.error("Method '" + properties.getMethod() + "' requires " + textureAmount + " tiles but only " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackName() + "'");
ContinuityClient.LOGGER.error("Method '" + properties.getMethod() + "' requires " + textureAmount + " tiles but only " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackId() + "'");
for (int i = provided; i < textureAmount; i++) {
sprites[i] = missingSprite;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static BaseProcessingPredicate fromProperties(BaseCtmProperties propertie
}

public static class BiomeCache {
@Nullable
protected Biome biome;
protected boolean invalid = true;

Expand All @@ -96,6 +97,7 @@ public void reset() {
}

public static class BlockEntityNameCache {
@Nullable
protected String blockEntityName;
protected boolean invalid = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,17 +634,17 @@ public QuadProcessor createProcessor(CompactConnectingCtmProperties properties,
if (value < provided) {
replacementSprites[key] = textureGetter.apply(spriteIds.get(value));
} else {
ContinuityClient.LOGGER.warn("Cannot replace tile " + key + " with tile " + value + " as only " + provided + " tiles were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackName() + "'");
ContinuityClient.LOGGER.warn("Cannot replace tile " + key + " with tile " + value + " as only " + provided + " tiles were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackId() + "'");
}
} else {
ContinuityClient.LOGGER.warn("Cannot replace tile " + key + " as method '" + properties.getMethod() + "' only supports " + replacementTextureAmount + " replacement tiles in file '" + properties.getResourceId() + "' in pack '" + properties.getPackName() + "'");
ContinuityClient.LOGGER.warn("Cannot replace tile " + key + " as method '" + properties.getMethod() + "' only supports " + replacementTextureAmount + " replacement tiles in file '" + properties.getResourceId() + "' in pack '" + properties.getPackId() + "'");
}
}
}

if (provided > textureAmount) {
if (replacementSprites == null) {
ContinuityClient.LOGGER.warn("Method '" + properties.getMethod() + "' requires " + textureAmount + " tiles but " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackName() + "'");
ContinuityClient.LOGGER.warn("Method '" + properties.getMethod() + "' requires " + textureAmount + " tiles but " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackId() + "'");
}
max = textureAmount;
}
Expand All @@ -666,7 +666,7 @@ public QuadProcessor createProcessor(CompactConnectingCtmProperties properties,
}

if (provided < textureAmount) {
ContinuityClient.LOGGER.error("Method '" + properties.getMethod() + "' requires at least " + textureAmount + " tiles but only " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackName() + "'");
ContinuityClient.LOGGER.error("Method '" + properties.getMethod() + "' requires at least " + textureAmount + " tiles but only " + provided + " were provided in file '" + properties.getResourceId() + "' in pack '" + properties.getPackId() + "'");
for (int i = provided; i < textureAmount; i++) {
sprites[i] = missingSprite;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class BaseCtmProperties implements CtmProperties {

protected Properties properties;
protected Identifier resourceId;
protected String packName;
protected String packId;
protected int packPriority;
protected ResourceManager resourceManager;
protected String method;
Expand Down Expand Up @@ -81,7 +81,7 @@ public class BaseCtmProperties implements CtmProperties {
public BaseCtmProperties(Properties properties, Identifier resourceId, ResourcePack pack, int packPriority, ResourceManager resourceManager, String method) {
this.properties = properties;
this.resourceId = resourceId;
this.packName = pack.getName();
this.packId = pack.getName();
this.packPriority = packPriority;
this.resourceManager = resourceManager;
this.method = method;
Expand Down Expand Up @@ -135,14 +135,14 @@ public void init() {
}

protected void parseMatchTiles() {
matchTilesSet = PropertiesParsingHelper.parseMatchTiles(properties, "matchTiles", resourceId, packName, ResourceRedirectHandler.get(resourceManager));
matchTilesSet = PropertiesParsingHelper.parseMatchTiles(properties, "matchTiles", resourceId, packId, ResourceRedirectHandler.get(resourceManager));
if (matchTilesSet != null && matchTilesSet.isEmpty()) {
valid = false;
}
}

protected void parseMatchBlocks() {
matchBlocksPredicate = PropertiesParsingHelper.parseBlockStates(properties, "matchBlocks", resourceId, packName);
matchBlocksPredicate = PropertiesParsingHelper.parseBlockStates(properties, "matchBlocks", resourceId, packId);
if (matchBlocksPredicate == PropertiesParsingHelper.EMPTY_BLOCK_STATE_PREDICATE) {
valid = false;
}
Expand All @@ -167,15 +167,15 @@ protected void detectMatches() {

protected void validateMatches() {
if (matchTilesSet == null && matchBlocksPredicate == null) {
ContinuityClient.LOGGER.error("No tile or block matches provided in file '" + resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.error("No tile or block matches provided in file '" + resourceId + "' in pack '" + packId + "'");
valid = false;
}
}

protected void parseTiles() {
String tilesStr = properties.getProperty("tiles");
if (tilesStr == null) {
ContinuityClient.LOGGER.error("No 'tiles' value provided in file '" + resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.error("No 'tiles' value provided in file '" + resourceId + "' in pack '" + packId + "'");
valid = false;
return;
}
Expand Down Expand Up @@ -208,13 +208,13 @@ protected void parseTiles() {
if (min <= max) {
try {
for (int tile = min; tile <= max; tile++) {
listBuilder.add(new Identifier(resourceId.getNamespace(), basePath + tile + ".png"));
listBuilder.add(resourceId.withPath(basePath + tile + ".png"));
}
} catch (InvalidIdentifierException e) {
ContinuityClient.LOGGER.warn("Invalid 'tiles' element '" + tileStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packName + "'", e);
ContinuityClient.LOGGER.warn("Invalid 'tiles' element '" + tileStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packId + "'", e);
}
} else {
ContinuityClient.LOGGER.warn("Invalid 'tiles' element '" + tileStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.warn("Invalid 'tiles' element '" + tileStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packId + "'");
}
continue;
} catch (NumberFormatException e) {
Expand Down Expand Up @@ -271,11 +271,11 @@ protected void parseTiles() {
try {
listBuilder.add(new Identifier(namespace, path));
} catch (InvalidIdentifierException e) {
ContinuityClient.LOGGER.warn("Invalid 'tiles' element '" + tileStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packName + "'", e);
ContinuityClient.LOGGER.warn("Invalid 'tiles' element '" + tileStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packId + "'", e);
}
}
} else {
ContinuityClient.LOGGER.warn("Invalid 'tiles' element '" + tileStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.warn("Invalid 'tiles' element '" + tileStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packId + "'");
}
}

Expand Down Expand Up @@ -313,7 +313,7 @@ protected void parseFaces() {
try {
faces.add(Direction.valueOf(faceStr1));
} catch (IllegalArgumentException e) {
ContinuityClient.LOGGER.warn("Unknown 'faces' element '" + faceStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.warn("Unknown 'faces' element '" + faceStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packId + "'");
}
}
}
Expand Down Expand Up @@ -356,7 +356,7 @@ protected void parseBiomes() {
Identifier biomeId = new Identifier(biomeStr.toLowerCase(Locale.ROOT));
biomeHolderSet.add(BiomeHolderManager.getOrCreateHolder(biomeId));
} catch (InvalidIdentifierException e) {
ContinuityClient.LOGGER.warn("Invalid 'biomes' element '" + biomeStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packName + "'", e);
ContinuityClient.LOGGER.warn("Invalid 'biomes' element '" + biomeStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packId + "'", e);
}
}

Expand Down Expand Up @@ -446,7 +446,7 @@ protected void parseHeights() {
}
}
}
ContinuityClient.LOGGER.warn("Invalid 'heights' element '" + heightStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.warn("Invalid 'heights' element '" + heightStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packId + "'");
}

if (!predicateList.isEmpty()) {
Expand Down Expand Up @@ -480,15 +480,15 @@ protected void parseLegacyHeights() {
try {
min = Integer.parseInt(minHeightStr.trim());
} catch (NumberFormatException e) {
ContinuityClient.LOGGER.warn("Invalid 'minHeight' value '" + minHeightStr + "' in file '" + resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.warn("Invalid 'minHeight' value '" + minHeightStr + "' in file '" + resourceId + "' in pack '" + packId + "'");
hasMinHeight = false;
}
}
if (hasMaxHeight) {
try {
max = Integer.parseInt(maxHeightStr.trim());
} catch (NumberFormatException e) {
ContinuityClient.LOGGER.warn("Invalid 'maxHeight' value '" + minHeightStr + "' in file '" + resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.warn("Invalid 'maxHeight' value '" + minHeightStr + "' in file '" + resourceId + "' in pack '" + packId + "'");
hasMaxHeight = false;
}
}
Expand Down Expand Up @@ -586,7 +586,7 @@ protected void parseResourceCondition() {
try {
resourceId = new Identifier(resourceStr);
} catch (InvalidIdentifierException e) {
ContinuityClient.LOGGER.warn("Invalid resource '" + resourceStr + "' in 'resourceCondition' element '" + conditionStr + "' at index " + i + " in file '" + this.resourceId + "' in pack '" + packName + "'", e);
ContinuityClient.LOGGER.warn("Invalid resource '" + resourceStr + "' in 'resourceCondition' element '" + conditionStr + "' at index " + i + " in file '" + this.resourceId + "' in pack '" + packId + "'", e);
continue;
}

Expand All @@ -610,10 +610,10 @@ protected void parseResourceCondition() {
break;
}
} else {
ContinuityClient.LOGGER.warn("Unknown pack '" + packStr + "' in 'resourceCondition' element '" + conditionStr + "' at index " + i + " in file '" + this.resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.warn("Unknown pack '" + packStr + "' in 'resourceCondition' element '" + conditionStr + "' at index " + i + " in file '" + this.resourceId + "' in pack '" + packId + "'");
}
} else {
ContinuityClient.LOGGER.warn("Invalid 'resourceCondition' element '" + conditionStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.warn("Invalid 'resourceCondition' element '" + conditionStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packId + "'");
}
}
}
Expand Down Expand Up @@ -666,8 +666,8 @@ public Identifier getResourceId() {
return resourceId;
}

public String getPackName() {
return packName;
public String getPackId() {
return packId;
}

public int getPackPriority() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected void detectConnect() {

protected void validateConnect() {
if (connectionPredicate == null) {
ContinuityClient.LOGGER.error("No valid connection type provided in file '" + resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.error("No valid connection type provided in file '" + resourceId + "' in pack '" + packId + "'");
valid = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ protected void parseTileReplacements() {
try {
value = Integer.parseInt(valueStr);
} catch (NumberFormatException e) {
ContinuityClient.LOGGER.warn("Invalid '" + key + "' value '" + valueStr + "' in file '" + resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.warn("Invalid '" + key + "' value '" + valueStr + "' in file '" + resourceId + "' in pack '" + packId + "'");
continue;
}
// TODO: deduplicate code
if (value < 0) {
ContinuityClient.LOGGER.warn("Invalid '" + key + "' value '" + valueStr + "' in file '" + resourceId + "' in pack '" + packName + "'");
ContinuityClient.LOGGER.warn("Invalid '" + key + "' value '" + valueStr + "' in file '" + resourceId + "' in pack '" + packId + "'");
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void init() {
}

protected void parseOrient() {
OrientationMode orientationMode = PropertiesParsingHelper.parseOrientationMode(properties, "orient", resourceId, packName);
OrientationMode orientationMode = PropertiesParsingHelper.parseOrientationMode(properties, "orient", resourceId, packId);
if (orientationMode != null) {
this.orientationMode = orientationMode;
}
Expand Down
Loading

0 comments on commit 3dab2d1

Please sign in to comment.