feat: add untrusted projection
This commit is contained in:
parent
c80859d643
commit
7308a478b8
@ -16,7 +16,7 @@ abstract class ProjectionEffect {
|
|||||||
|
|
||||||
abstract fun toNbt(tag: CompoundTag)
|
abstract fun toNbt(tag: CompoundTag)
|
||||||
|
|
||||||
abstract fun fromNbt(tag: CompoundTag)
|
abstract fun fromNbt(tag: CompoundTag, trusted: Boolean)
|
||||||
|
|
||||||
fun toNbt() = CompoundTag().apply { toNbt(this) }
|
fun toNbt() = CompoundTag().apply { toNbt(this) }
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ data class ProjectionEffectType<T : ProjectionEffect>(val constructor: () -> T)
|
|||||||
object NopEffect : ProjectionEffect() {
|
object NopEffect : ProjectionEffect() {
|
||||||
override val type get() = nopEffect
|
override val type get() = nopEffect
|
||||||
override fun toNbt(tag: CompoundTag) {}
|
override fun toNbt(tag: CompoundTag) {}
|
||||||
override fun fromNbt(tag: CompoundTag) {}
|
override fun fromNbt(tag: CompoundTag, trusted: Boolean) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class SimpleProjectionEntity<P : ProjectionEffect>(
|
|||||||
|
|
||||||
override fun load(tag: CompoundTag) {
|
override fun load(tag: CompoundTag) {
|
||||||
super.load(tag)
|
super.load(tag)
|
||||||
projection.fromNbt(tag.getCompound(TAG_PROJECTION_EFFECT))
|
projection.fromNbt(tag.getCompound(TAG_PROJECTION_EFFECT), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getUpdateTag(): CompoundTag = saveWithoutMetadata()
|
override fun getUpdateTag(): CompoundTag = saveWithoutMetadata()
|
||||||
|
@ -8,6 +8,7 @@ import quaedam.projection.EntityProjectionBlock
|
|||||||
import quaedam.projection.ProjectionEffect
|
import quaedam.projection.ProjectionEffect
|
||||||
import quaedam.projection.ProjectionEffectType
|
import quaedam.projection.ProjectionEffectType
|
||||||
import quaedam.projection.SimpleProjectionEntity
|
import quaedam.projection.SimpleProjectionEntity
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
object NoiseProjection {
|
object NoiseProjection {
|
||||||
|
|
||||||
@ -52,8 +53,11 @@ data class NoiseProjectionEffect(var amount: Int = 5) : ProjectionEffect() {
|
|||||||
tag.putInt(TAG_AMOUNT, amount)
|
tag.putInt(TAG_AMOUNT, amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromNbt(tag: CompoundTag) {
|
override fun fromNbt(tag: CompoundTag, trusted: Boolean) {
|
||||||
amount = tag.getInt(TAG_AMOUNT)
|
amount = tag.getInt(TAG_AMOUNT)
|
||||||
|
if (!trusted) {
|
||||||
|
amount = min(amount, 8)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import quaedam.projection.EntityProjectionBlock
|
|||||||
import quaedam.projection.ProjectionEffect
|
import quaedam.projection.ProjectionEffect
|
||||||
import quaedam.projection.ProjectionEffectType
|
import quaedam.projection.ProjectionEffectType
|
||||||
import quaedam.projection.SimpleProjectionEntity
|
import quaedam.projection.SimpleProjectionEntity
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
object SkylightProjection {
|
object SkylightProjection {
|
||||||
|
|
||||||
@ -52,8 +53,11 @@ data class SkylightProjectionEffect(var factor: Double = 2.0) : ProjectionEffect
|
|||||||
tag.putDouble(TAG_FACTOR, factor)
|
tag.putDouble(TAG_FACTOR, factor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromNbt(tag: CompoundTag) {
|
override fun fromNbt(tag: CompoundTag, trusted: Boolean) {
|
||||||
factor = tag.getDouble(TAG_FACTOR)
|
factor = tag.getDouble(TAG_FACTOR)
|
||||||
|
if (!trusted) {
|
||||||
|
factor = min(factor, 5.0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ object SoundProjectionEffect : ProjectionEffect() {
|
|||||||
override fun toNbt(tag: CompoundTag) {
|
override fun toNbt(tag: CompoundTag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromNbt(tag: CompoundTag) {
|
override fun fromNbt(tag: CompoundTag, trusted: Boolean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,11 @@ data class SwarmProjectionEffect(
|
|||||||
tag.putInt(TAG_MAX_COUNT, maxCount)
|
tag.putInt(TAG_MAX_COUNT, maxCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromNbt(tag: CompoundTag) {
|
override fun fromNbt(tag: CompoundTag, trusted: Boolean) {
|
||||||
maxCount = tag.getInt(TAG_MAX_COUNT)
|
maxCount = tag.getInt(TAG_MAX_COUNT)
|
||||||
|
if (!trusted){
|
||||||
|
maxCount = min(maxCount, 250)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun randomTick(level: ServerLevel, pos: BlockPos) {
|
override fun randomTick(level: ServerLevel, pos: BlockPos) {
|
||||||
|
@ -68,7 +68,7 @@ class ProjectorBlockEntity(pos: BlockPos, state: BlockState) :
|
|||||||
effectsTag.allKeys.forEach { id ->
|
effectsTag.allKeys.forEach { id ->
|
||||||
val type = ProjectionEffectType.registry[ResourceLocation(id)]
|
val type = ProjectionEffectType.registry[ResourceLocation(id)]
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
val effect = type.constructor().apply { fromNbt(effectsTag[id] as CompoundTag) }
|
val effect = type.constructor().apply { fromNbt(effectsTag[id] as CompoundTag, true) }
|
||||||
effects[type] = effect
|
effects[type] = effect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user