aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/mc/TolerantRegistriesOps.kt
blob: ce596a0bb723583af25a9a37f218146cb9c97838 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package moe.nea.firmament.util.mc

import com.mojang.serialization.DynamicOps
import java.util.Optional
import net.minecraft.registry.Registry
import net.minecraft.registry.RegistryKey
import net.minecraft.registry.RegistryOps
import net.minecraft.registry.RegistryWrapper
import net.minecraft.registry.entry.RegistryEntryOwner

class TolerantRegistriesOps<T>(
	delegate: DynamicOps<T>,
	registryInfoGetter: RegistryInfoGetter
) : RegistryOps<T>(delegate, registryInfoGetter) {
	constructor(delegate: DynamicOps<T>, registry: RegistryWrapper.WrapperLookup) :
		this(delegate, CachedRegistryInfoGetter(registry))

	class TolerantOwner<E> : RegistryEntryOwner<E> {
		override fun ownerEquals(other: RegistryEntryOwner<E>?): Boolean {
			return true
		}
	}

	override fun <E : Any?> getOwner(registryRef: RegistryKey<out Registry<out E>>?): Optional<RegistryEntryOwner<E>> {
		return super.getOwner(registryRef).map {
			TolerantOwner()
		}
	}
}