-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Custom class for ID and modifier
- Loading branch information
Showing
8 changed files
with
154 additions
and
45 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/main/java/io/github/null2264/cobblegen/data/CGIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.github.null2264.cobblegen.data; | ||
|
||
import lombok.val; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import static io.github.null2264.cobblegen.CobbleGen.MOD_ID; | ||
|
||
/** | ||
* Replaces MC's ResourceLocation, in case MC's ResourceLocation changed | ||
* @param modid | ||
* @param name | ||
*/ | ||
public record CGIdentifier(String modid, String name) { | ||
public static CGIdentifier of(String id) { | ||
if (id.equals("*")) return wildcard(); | ||
|
||
val split = id.split(":", 2); | ||
if (split.length < 1) | ||
throw new RuntimeException("Invalid ID"); | ||
if (split.length == 1) | ||
return new CGIdentifier(MOD_ID, split[0]); | ||
|
||
return new CGIdentifier(split[0], split[1]); | ||
} | ||
|
||
public static CGIdentifier wildcard() { | ||
return new CGIdentifier(MOD_ID, "*"); | ||
} | ||
|
||
public boolean isWildcard() { | ||
return name.equals("*"); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (isWildcard()) return "*"; | ||
return String.format("%s:%s", modid, name); | ||
} | ||
|
||
public static CGIdentifier fromMC(ResourceLocation location) { | ||
return new CGIdentifier(location.getNamespace(), location.getPath()); | ||
} | ||
|
||
public ResourceLocation toMC() { | ||
if (isWildcard()) throw new RuntimeException("Wildcard is not a valid MC ID"); | ||
return new ResourceLocation(modid, name); | ||
} | ||
|
||
public void writeToBuf(FriendlyByteBuf buf) { | ||
buf.writeUtf(this.toString()); | ||
} | ||
|
||
public static CGIdentifier readFromBuf(FriendlyByteBuf buf) { | ||
return of(buf.readUtf()); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/io/github/null2264/cobblegen/data/Modifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.null2264.cobblegen.data; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Class to holds modifier as Map key | ||
*/ | ||
public class Modifier { | ||
List<CGIdentifier> modifiers; | ||
|
||
public Modifier(List<CGIdentifier> modifiers) { | ||
this.modifiers = modifiers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.