Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.21.x' into 1.21.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatGravyBoat committed Oct 8, 2024
2 parents 7d8077c + 51308fe commit b9a979b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ You can then add our mod as a dependency:
```gradle
dependencies {
<--- Other dependencies here --->
implementation fg.deobf("com.teamresourceful.resourcefullib:resourcefullib-forge-1.21:3.0.9")
implementation fg.deobf("com.teamresourceful.resourcefullib:resourcefullib-forge-1.21:3.0.10")
}
```

### Fabric:
```gradle
dependencies {
<--- Other dependencies here --->
implementation "com.teamresourceful.resourcefullib:resourcefullib-fabric-1.21:3.0.9"
implementation "com.teamresourceful.resourcefullib:resourcefullib-fabric-1.21:3.0.10"
}
```

Expand All @@ -50,23 +50,23 @@ dependencies {
```gradle
dependencies {
<--- Other dependencies here --->
modImplementation "com.teamresourceful.resourcefullib:resourcefullib-common-1.21:3.0.9"
modImplementation "com.teamresourceful.resourcefullib:resourcefullib-common-1.21:3.0.10"
}
```

#### Fabric `build.gradle`
```gradle
dependencies {
<--- Other dependencies here --->
modImplementation "com.teamresourceful.resourcefullib:resourcefullib-fabric-1.21:3.0.9"
modImplementation "com.teamresourceful.resourcefullib:resourcefullib-fabric-1.21:3.0.10"
}
```

#### Forge `build.gradle`
```gradle
dependencies {
<--- Other dependencies here --->
modImplementation "com.teamresourceful.resourcefullib:resourcefullib-forge-1.21:3.0.9"
modImplementation "com.teamresourceful.resourcefullib:resourcefullib-forge-1.21:3.0.10"
}
```

Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# -----{ 3.0.10 }-----



# -----{ 3.0.9 }-----


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.teamresourceful.resourcefullib.common.utils.Scheduling;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Locale;
Expand All @@ -24,16 +26,16 @@ public class Color {

protected static final Map<String, Color> colorsWithNames = new HashMap<>();

public static final Codec<Color> CODEC = Codec.PASSTHROUGH.comapFlatMap(Color::decodeColor, color -> new Dynamic<>(JsonOps.INSTANCE, new JsonPrimitive(color.value)));
public static final Codec<Color> CODEC = Codec.PASSTHROUGH.comapFlatMap(Color::decodeColor, color -> new Dynamic<>(JsonOps.INSTANCE, new JsonPrimitive(color.toString())));
public static final Color DEFAULT = defaultColor();
public static final Color RAINBOW = createRainbowColor();
public static final ByteCodec<Color> BYTE_CODEC = ByteCodec.BYTE.dispatch(aByte -> switch (aByte) {
case 0 -> ByteCodec.unit(DEFAULT);
case 1 -> ByteCodec.unit(RAINBOW);
case 1 -> ByteCodec.STRING.map(Color::parse, Color::toString);
default -> ByteCodec.INT.map(Color::new, Color::getValue);
}, color -> {
if (color.isDefault()) return (byte) 0;
if (color.isRainbow()) return (byte) 1;
if (color.isSpecial()) return (byte) 1;
return (byte) 2;
});

Expand All @@ -48,7 +50,9 @@ public class Color {
private int value;

private boolean defaultValue;
private boolean isRainbow;

@Nullable
private String specialName;

private float[] rgbaValue;

Expand Down Expand Up @@ -86,30 +90,39 @@ private static Color defaultColor() {

private static Color createRainbowColor() {
Color color = new Color(0xff0000);
color.isRainbow = true;
color.specialName = "rainbow";
colorsWithNames.put("rainbow", color);
return color;
}

public static Color createNamedColor(String name, int value) {
Color color = new Color(value);
colorsWithNames.putIfAbsent(name.toLowerCase(Locale.ENGLISH), color);
color.specialName = name.toLowerCase(Locale.ENGLISH);
colorsWithNames.putIfAbsent(color.specialName, color);
return color;
}

//endregion

//region Parsers

public static Color parse(String color) {
if (colorsWithNames.containsKey(color.toLowerCase()))
@Nullable
public static Color tryParse(String color) {
if (color.startsWith("0x") || color.startsWith("#") || color.startsWith("0X"))
return new Color(Long.decode(color).intValue());
else if (colorsWithNames.containsKey(color.toLowerCase()))
return colorsWithNames.get(color.toLowerCase());
return new Color(parseColor(color));
return null;
}

public static Color parse(String color) {
Color parsedColor = tryParse(color);
return parsedColor == null ? DEFAULT : parsedColor;
}

public static int parseColor(String color) {
Objects.requireNonNull(color);
if (color.startsWith("0x") || color.startsWith("#"))
if (color.startsWith("0x") || color.startsWith("#") || color.startsWith("0X"))
return Long.decode(color).intValue();
else if (colorsWithNames.containsKey(color.toLowerCase()))
return colorsWithNames.get(color.toLowerCase()).getValue();
Expand Down Expand Up @@ -188,26 +201,35 @@ public boolean isDefault() {
return defaultValue;
}

/**
* @deprecated Use {@link #isSpecial()} instead.
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "1.21.2")
public boolean isRainbow() {
return isRainbow;
return "rainbow".equals(specialName);
}

public boolean isSpecial() {
return specialName != null;
}

@Override
public String toString() {
if (this.isRainbow) return "rainbow";
if (specialName != null) return specialName;
return String.format("#%x", this.value);
}

@Override
public int hashCode() {
return Objects.hash(defaultValue, isRainbow, value);
return Objects.hash(defaultValue, specialName, value);
}

@Override
public boolean equals(Object obj) {
return obj instanceof Color color &&
color.value == this.value &&
color.isRainbow == this.isRainbow &&
color.specialName == this.specialName &&
color.defaultValue == this.defaultValue;
}

Expand Down
4 changes: 2 additions & 2 deletions version.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
patch=9
patch=10
buildTime=0
build=0
releaseType=release
currentMCVersion=1.21
initialMCVersion=1.19.1
version=3.0.9
version=3.0.10

0 comments on commit b9a979b

Please sign in to comment.