generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lots of rewritten garbage to enforce RL keys
- Loading branch information
Showing
78 changed files
with
925 additions
and
600 deletions.
There are no files selected for viewing
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
10 changes: 6 additions & 4 deletions
10
common/src/main/java/dev/dhyces/trimmed/api/client/ClientKeyResolver.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
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
10 changes: 0 additions & 10 deletions
10
common/src/main/java/dev/dhyces/trimmed/api/data/client/map/appenders/ClientMapAppender.java
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
...main/java/dev/dhyces/trimmed/api/data/client/map/appenders/ClientRegistryMapAppender.java
This file was deleted.
Oops, something went wrong.
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
64 changes: 31 additions & 33 deletions
64
common/src/main/java/dev/dhyces/trimmed/api/data/client/tag/ClientTagEntry.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 |
---|---|---|
@@ -1,56 +1,54 @@ | ||
package dev.dhyces.trimmed.api.data.client.tag; | ||
|
||
import com.mojang.datafixers.util.Either; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import dev.dhyces.trimmed.api.KeyResolver; | ||
import dev.dhyces.trimmed.api.client.tag.ClientTagKey; | ||
import org.jetbrains.annotations.Nullable; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.util.ExtraCodecs; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public record ClientTagEntry<T>(Either<T, ClientTagKey<T>> element, boolean isRequired) { | ||
public static <T> Codec<Either<T, ClientTagKey<T>>> elementOrTagCodec(KeyResolver<T> keyResolver) { | ||
return Codec.either(keyResolver.getCodec(), ClientTagKey.tagCodec(keyResolver)); | ||
} | ||
public static <T> Codec<ClientTagEntry<T>> fullCodec(KeyResolver<T> keyResolver) { | ||
return RecordCodecBuilder.create(instance -> | ||
instance.group( | ||
elementOrTagCodec(keyResolver).fieldOf("value").forGetter(ClientTagEntry::element), | ||
Codec.BOOL.fieldOf("required").forGetter(ClientTagEntry::isRequired) | ||
).apply(instance, ClientTagEntry::new) | ||
); | ||
} | ||
public static <T> Codec<ClientTagEntry<T>> codec(KeyResolver<T> keyResolver) { | ||
return Codec.withAlternative(elementOrTagCodec(keyResolver).xmap( | ||
either -> new ClientTagEntry<>(either, true), | ||
ClientTagEntry::element), fullCodec(keyResolver) | ||
); | ||
} | ||
public record ClientTagEntry(ExtraCodecs.TagOrElementLocation tagOrElementLocation, boolean isRequired) { | ||
public static final Codec<ClientTagEntry> FULL_CODEC = RecordCodecBuilder.create(instance -> | ||
instance.group( | ||
ExtraCodecs.TAG_OR_ELEMENT_ID.fieldOf("id").forGetter(ClientTagEntry::tagOrElementLocation), | ||
Codec.BOOL.fieldOf("required").forGetter(ClientTagEntry::isRequired) | ||
).apply(instance, ClientTagEntry::new) | ||
); | ||
|
||
public static final Codec<ClientTagEntry> CODEC = Codec.withAlternative( | ||
ExtraCodecs.TAG_OR_ELEMENT_ID.xmap( | ||
either -> new ClientTagEntry(either, true), | ||
ClientTagEntry::tagOrElementLocation | ||
), | ||
FULL_CODEC | ||
); | ||
|
||
public boolean isTag() { | ||
return element.right().isPresent(); | ||
return tagOrElementLocation.tag(); | ||
} | ||
|
||
@Nullable | ||
public T getElement() { | ||
return element.left().orElse(null); | ||
public ResourceLocation getId() { | ||
return tagOrElementLocation.id(); | ||
} | ||
|
||
@Nullable | ||
public ClientTagKey<T> getTag() { | ||
return element.right().orElse(null); | ||
public <T> ClientTagKey<T> getTag(KeyResolver<T> keyResolver) { | ||
return ClientTagKey.of(keyResolver, tagOrElementLocation.id()); | ||
} | ||
|
||
public boolean verifyExists(Predicate<T> elementPredicate, Predicate<ClientTagKey<T>> keyPredicate) { | ||
return element.map(elementPredicate::test, keyPredicate::test); | ||
public boolean verifyExists(Predicate<ResourceLocation> elementPredicate, Predicate<ResourceLocation> tagPredicate) { | ||
if (tagOrElementLocation.tag()) { | ||
return tagPredicate.test(tagOrElementLocation.id()); | ||
} | ||
return elementPredicate.test(tagOrElementLocation.id()); | ||
} | ||
|
||
public static <T> ClientTagEntry<T> element(T element, boolean isRequired) { | ||
return new ClientTagEntry<>(Either.left(element), isRequired); | ||
public static ClientTagEntry element(ResourceLocation element, boolean isRequired) { | ||
return new ClientTagEntry(new ExtraCodecs.TagOrElementLocation(element, false), isRequired); | ||
} | ||
|
||
public static <T> ClientTagEntry<T> clientTagKey(ClientTagKey<T> clientTagKey, boolean isRequired) { | ||
return new ClientTagEntry<>(Either.right(clientTagKey), isRequired); | ||
public static <T> ClientTagEntry clientTagKey(ClientTagKey<T> clientTagKey, boolean isRequired) { | ||
return new ClientTagEntry(new ExtraCodecs.TagOrElementLocation(clientTagKey.getTagId(), true), isRequired); | ||
} | ||
} |
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.