-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Definitely becoming a library mod now
- Loading branch information
Showing
24 changed files
with
821 additions
and
30 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
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
222 changes: 222 additions & 0 deletions
222
src/main/java/nl/enjarai/cicada/api/cursed/CursedRegistry.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,222 @@ | ||
package nl.enjarai.cicada.api.cursed; | ||
|
||
import com.mojang.datafixers.util.Pair; | ||
import com.mojang.serialization.Lifecycle; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.RegistryWrapper; | ||
import net.minecraft.registry.entry.RegistryEntry; | ||
import net.minecraft.registry.entry.RegistryEntryList; | ||
import net.minecraft.registry.entry.RegistryEntryOwner; | ||
import net.minecraft.registry.tag.TagKey; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.random.Random; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.*; | ||
import java.util.stream.Stream; | ||
|
||
@SuppressWarnings("deprecation") | ||
public record CursedRegistry<T>(RegistryKey<? extends Registry<T>> registryKey, Identifier defaultId, T defaultValue) implements Registry<T>, RegistryEntryOwner<T> { | ||
|
||
@Override | ||
public RegistryKey<? extends Registry<T>> getKey() { | ||
return registryKey; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Identifier getId(T value) { | ||
return defaultId; | ||
} | ||
|
||
@Override | ||
public Optional<RegistryKey<T>> getKey(T entry) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public int getRawId(@Nullable T value) { | ||
return 0; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public T get(int index) { | ||
return defaultValue; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return 1; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public T get(@Nullable RegistryKey<T> key) { | ||
return defaultValue; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public T get(@Nullable Identifier id) { | ||
return defaultValue; | ||
} | ||
|
||
@Override | ||
public Lifecycle getEntryLifecycle(T entry) { | ||
return Lifecycle.experimental(); | ||
} | ||
|
||
@Override | ||
public Lifecycle getLifecycle() { | ||
return Lifecycle.experimental(); | ||
} | ||
|
||
@Override | ||
public Set<Identifier> getIds() { | ||
return Set.of(defaultId); | ||
} | ||
|
||
@Override | ||
public Set<Map.Entry<RegistryKey<T>, T>> getEntrySet() { | ||
return Set.of(); | ||
} | ||
|
||
@Override | ||
public Set<RegistryKey<T>> getKeys() { | ||
return Set.of(); | ||
} | ||
|
||
@Override | ||
public Optional<RegistryEntry.Reference<T>> getRandom(Random random) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public boolean containsId(Identifier id) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean contains(RegistryKey<T> key) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Registry<T> freeze() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public RegistryEntry.Reference<T> createEntry(T value) { | ||
return RegistryEntry.Reference.intrusive(this, value); | ||
} | ||
|
||
@Override | ||
public Optional<RegistryEntry.Reference<T>> getEntry(int rawId) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<RegistryEntry.Reference<T>> getEntry(RegistryKey<T> key) { | ||
return Optional.of(RegistryEntry.Reference.standAlone(this, key)); | ||
} | ||
|
||
@Override | ||
public RegistryEntry<T> getEntry(T value) { | ||
return RegistryEntry.of(value); | ||
} | ||
|
||
@Override | ||
public Stream<RegistryEntry.Reference<T>> streamEntries() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Optional<RegistryEntryList.Named<T>> getEntryList(TagKey<T> tag) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public RegistryEntryList.Named<T> getOrCreateEntryList(TagKey<T> tag) { | ||
return RegistryEntryList.of(this, tag); | ||
} | ||
|
||
@Override | ||
public Stream<Pair<TagKey<T>, RegistryEntryList.Named<T>>> streamTagsAndEntries() { | ||
return Stream.empty(); | ||
} | ||
|
||
@Override | ||
public Stream<TagKey<T>> streamTags() { | ||
return Stream.empty(); | ||
} | ||
|
||
@Override | ||
public void clearTags() { | ||
|
||
} | ||
|
||
@Override | ||
public void populateTags(Map<TagKey<T>, List<RegistryEntry<T>>> tagEntries) { | ||
|
||
} | ||
|
||
@Override | ||
public RegistryEntryOwner<T> getEntryOwner() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public RegistryWrapper.Impl<T> getReadOnlyWrapper() { | ||
return new RegistryWrapper.Impl<T>() { | ||
@Override | ||
public RegistryKey<? extends Registry<? extends T>> getRegistryKey() { | ||
return CursedRegistry.this.registryKey; | ||
} | ||
|
||
@Override | ||
public Lifecycle getLifecycle() { | ||
return Lifecycle.experimental(); | ||
} | ||
|
||
@Override | ||
public Stream<RegistryEntry.Reference<T>> streamEntries() { | ||
return Stream.empty(); | ||
} | ||
|
||
@Override | ||
public Stream<RegistryEntryList.Named<T>> streamTags() { | ||
return Stream.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<RegistryEntry.Reference<T>> getOptional(RegistryKey<T> key) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<RegistryEntryList.Named<T>> getOptional(TagKey<T> tag) { | ||
return Optional.empty(); | ||
} | ||
}; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Iterator<T> iterator() { | ||
return new Iterator<T>() { | ||
@Override | ||
public boolean hasNext() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public T next() { | ||
return null; | ||
} | ||
}; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/nl/enjarai/cicada/api/cursed/CursedRegistryEntry.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,71 @@ | ||
package nl.enjarai.cicada.api.cursed; | ||
|
||
import com.mojang.datafixers.util.Either; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.entry.RegistryEntry; | ||
import net.minecraft.registry.entry.RegistryEntryOwner; | ||
import net.minecraft.registry.tag.TagKey; | ||
import net.minecraft.util.Identifier; | ||
import nl.enjarai.cicada.Cicada; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Stream; | ||
|
||
public record CursedRegistryEntry<T>(T value, RegistryKey<? extends Registry<T>> key) implements RegistryEntry<T> { | ||
@Override | ||
public boolean hasKeyAndValue() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean matchesId(Identifier id) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean matchesKey(RegistryKey<T> key) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isIn(TagKey<T> tag) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean matches(Predicate<RegistryKey<T>> predicate) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Either<RegistryKey<T>, T> getKeyOrValue() { | ||
return Either.right(this.value); | ||
} | ||
|
||
@Override | ||
public Optional<RegistryKey<T>> getKey() { | ||
return Optional.of(RegistryKey.of(key, Cicada.id("dummy"))); | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.DIRECT; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CursedRegistryEntry(This is from CICADA, please report there for any issues caused){" + this.value + "}"; | ||
} | ||
|
||
@Override | ||
public boolean ownerEquals(RegistryEntryOwner<T> owner) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Stream<TagKey<T>> streamTags() { | ||
return Stream.of(); | ||
} | ||
} |
Oops, something went wrong.