Skip to content

Commit

Permalink
fix: wrong name pattern returned from cem rename
Browse files Browse the repository at this point in the history
  • Loading branch information
HiWord9 committed Sep 23, 2024
1 parent 8225e66 commit 156328e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ private static void propertiesToRenameMob(Properties p, String packName, String
for (String s : p.stringPropertyNames()) {
if (!s.startsWith("name.")) continue;

String skin = p.getProperty("skins." + s.substring(5));
String nameIndex = s.substring(5);

String skin = p.getProperty("skins." + nameIndex);
if (skins.contains(skin)) continue;
skins.add(skin);

Expand All @@ -220,15 +222,17 @@ private static void propertiesToRenameMob(Properties p, String packName, String

ArrayList<AbstractRename> alreadyExist = RenamesManager.getRenames(CEMRename.DEFAULT_MOB_ITEM);

AbstractRename rename;
AbstractRename renameNameOnly = new CITRename(name, CEMRename.DEFAULT_MOB_ITEM);
CEMRename.Mob mob = new CEMRename.Mob(
entityType,
p,
path.replaceAll("\\\\", "/"),
packName
packName,
nameIndex
);

AbstractRename rename;
AbstractRename renameNameOnly = new CITRename(name, CEMRename.DEFAULT_MOB_ITEM);

String citPackName = null;
String citPath = null;
Properties citProperties = null;
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/com/HiWord9/RPRenames/util/rename/type/CEMRename.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void setMob(Mob mob) {
public String getNamePattern() {
Mob mob = getMob();
if (mob == null) return null;
return mob.propName;
return mob.getNamePattern();
}

public ItemStack toSpawnEgg() {
Expand Down Expand Up @@ -104,22 +104,24 @@ public static final class Mob {
private final Properties properties;
private final String path;
private final String packName;
private final String propName;
private final String namePattern;
private final String nameIndex;

public Mob(EntityType<?> entity) {
this(entity, null);
}

public Mob(EntityType<?> entity, String packName) {
this(entity, null, null, packName);
this(entity, null, null, packName, null);
}

public Mob(EntityType<?> entity, Properties properties, String path, String packName) {
public Mob(EntityType<?> entity, Properties properties, String path, String packName, String nameIndex) {
this.entity = entity;
this.properties = properties;
this.path = path;
this.packName = packName;
this.propName = properties == null ? null : findPropName(properties);
this.nameIndex = nameIndex;
this.namePattern = findPropName();
}

public EntityType<?> getEntity() {
Expand All @@ -138,18 +140,20 @@ public String getPackName() {
return packName;
}

public String getPropName() {
return propName;
public String getNamePattern() {
return namePattern;
}

public static String findPropName(Properties properties) {
if (properties == null) return null;
public String findPropName() {
return findPropName(properties, nameIndex);
}

public static String findPropName(Properties properties, String nameIndex) {
if (properties == null || nameIndex == null) return null;
Set<String> propertyNames = properties.stringPropertyNames();
for (String s : propertyNames) {
if (s.startsWith("name.")) {
if (propertyNames.contains("skins." + s.substring(5))) {
return properties.getProperty(s);
}
if (s.startsWith("name." + nameIndex)) {
return properties.getProperty(s);
}
}
return null;
Expand Down Expand Up @@ -180,7 +184,7 @@ && paramsEquals(this.path, obj.path, ignoreNull)
public boolean same(Mob obj, boolean ignoreNull) {
if (obj == null) return ignoreNull;
return paramsEquals(this.entity, obj.entity, ignoreNull)
&& paramsEquals(this.propName, obj.propName, ignoreNull);
&& paramsEquals(this.namePattern, obj.namePattern, ignoreNull);
}
}

Expand Down

0 comments on commit 156328e

Please sign in to comment.