diff --git a/build.gradle.kts b/build.gradle.kts index d3f20e6..b66a650 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,10 @@ subprojects { dependencies { "minecraft"("com.mojang:minecraft:${project.property("minecraft_version")}") - "mappings"(loom.officialMojangMappings()) + "mappings"(loom.layered { + officialMojangMappings() + parchment("org.parchmentmc.data:parchment-${project.property("minecraft_version")}:${project.property("parchment_version")}@zip") + }) } } @@ -35,6 +38,13 @@ allprojects { version = "1.0.0" group = "quaedam" + repositories { + maven { + name = "ParchmentMC" + setUrl("https://maven.parchmentmc.org") + } + } + dependencies { compileOnly("org.jetbrains.kotlin:kotlin-stdlib") } diff --git a/common/src/main/kotlin/quaedam/Quaedam.kt b/common/src/main/kotlin/quaedam/Quaedam.kt index 62ee12e..392a45c 100644 --- a/common/src/main/kotlin/quaedam/Quaedam.kt +++ b/common/src/main/kotlin/quaedam/Quaedam.kt @@ -11,6 +11,7 @@ import net.minecraft.world.item.ItemStack import org.slf4j.LoggerFactory import quaedam.projection.ProjectionCommand import quaedam.projection.ProjectionEffectType +import quaedam.projection.SimpleProjectionUpdate import quaedam.projection.misc.NoiseProjection import quaedam.projection.misc.SkylightProjection import quaedam.projection.misc.SoundProjection @@ -48,6 +49,7 @@ object Quaedam { SoundProjection NoiseProjection ProjectionCommand + SimpleProjectionUpdate creativeModeTabs.register() items.register() diff --git a/common/src/main/kotlin/quaedam/projection/EntityProjectionBlock.kt b/common/src/main/kotlin/quaedam/projection/EntityProjectionBlock.kt index 93c5208..208f9d6 100644 --- a/common/src/main/kotlin/quaedam/projection/EntityProjectionBlock.kt +++ b/common/src/main/kotlin/quaedam/projection/EntityProjectionBlock.kt @@ -1,12 +1,14 @@ package quaedam.projection import dev.architectury.registry.registries.DeferredSupplier +import net.minecraft.client.Minecraft import net.minecraft.core.BlockPos import net.minecraft.server.level.ServerLevel import net.minecraft.world.level.Level import net.minecraft.world.level.block.EntityBlock import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.state.BlockState +import quaedam.utils.sendBlockUpdated abstract class EntityProjectionBlock
(properties: Properties = createProperties()) : ProjectionBlock
(properties), EntityBlock { @@ -17,16 +19,25 @@ abstract class EntityProjectionBlock
(properties: Propertie
abstract val blockEntity: DeferredSupplier ).projection
+ fun getBlockEntity(level: Level, pos: BlockPos) = (level.getBlockEntity(pos) as SimpleProjectionEntity )
- override fun applyProjectionEffect(level: ServerLevel, state: BlockState, pos: BlockPos) = getProjection(level, pos)
+ override fun applyProjectionEffect(level: ServerLevel, state: BlockState, pos: BlockPos) =
+ getBlockEntity(level, pos).cloneProjection()
- inline fun applyChange(level: Level, pos: BlockPos, func: P.() -> Unit) {
- getProjection(level, pos).apply(func)
- sendUpdateToProjectors(level, pos)
+ fun applyChange(level: Level, pos: BlockPos, func: P.() -> Unit) {
+ val entity = getBlockEntity(level, pos)
+ val projection = entity.projection
+ projection.apply(func)
+ if (level.isClientSide) {
+ check(level == Minecraft.getInstance().player!!.level())
+ SimpleProjectionUpdate.send(pos, projection.toNbt())
+ } else {
+ getBlockEntity(level, pos).sendBlockUpdated()
+ sendUpdateToProjectors(level, pos)
+ }
}
}
diff --git a/common/src/main/kotlin/quaedam/projection/ProjectionBlock.kt b/common/src/main/kotlin/quaedam/projection/ProjectionBlock.kt
index a3af4e4..340171c 100644
--- a/common/src/main/kotlin/quaedam/projection/ProjectionBlock.kt
+++ b/common/src/main/kotlin/quaedam/projection/ProjectionBlock.kt
@@ -29,6 +29,13 @@ abstract class ProjectionBlock (properties: Properties = cr
}
.toSet()
+ fun sendUpdateToProjectors(level: Level, pos: BlockPos) {
+ if (!level.isClientSide) {
+ findNearbyProjectors(level, pos)
+ .forEach { (level.getBlockEntity(it) as ProjectorBlockEntity).checkUpdate() }
+ }
+ }
+
}
@Suppress("OVERRIDE_DEPRECATION")
@@ -52,11 +59,4 @@ abstract class ProjectionBlock (properties: Properties = cr
}
}
- fun sendUpdateToProjectors(level: Level, pos: BlockPos) {
- if (!level.isClientSide) {
- findNearbyProjectors(level, pos)
- .forEach { (level.getBlockEntity(it) as ProjectorBlockEntity).checkUpdate() }
- }
- }
-
}
diff --git a/common/src/main/kotlin/quaedam/projection/ProjectionEffect.kt b/common/src/main/kotlin/quaedam/projection/ProjectionEffect.kt
index e786252..ad3420c 100644
--- a/common/src/main/kotlin/quaedam/projection/ProjectionEffect.kt
+++ b/common/src/main/kotlin/quaedam/projection/ProjectionEffect.kt
@@ -10,17 +10,17 @@ import net.minecraft.server.level.ServerLevel
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.state.BlockState
-abstract class ProjectionEffect {
+abstract class ProjectionEffect : Cloneable {
abstract val type: ProjectionEffectType<*>
abstract fun toNbt(tag: CompoundTag)
- abstract fun fromNbt(tag: CompoundTag, trusted: Boolean)
+ abstract fun fromNbt(tag: CompoundTag, trusted: Boolean = true)
fun toNbt() = CompoundTag().apply { toNbt(this) }
- override fun equals(other: Any?) = other === this
+ override fun equals(other: Any?): Boolean = other === this
override fun hashCode() = type.hashCode()
diff --git a/common/src/main/kotlin/quaedam/projection/SimpleProjectionEntity.kt b/common/src/main/kotlin/quaedam/projection/SimpleProjectionEntity.kt
index 14c09ae..edd9876 100644
--- a/common/src/main/kotlin/quaedam/projection/SimpleProjectionEntity.kt
+++ b/common/src/main/kotlin/quaedam/projection/SimpleProjectionEntity.kt
@@ -14,19 +14,20 @@ class SimpleProjectionEntity (
type: BlockEntityType > createBlockEntityType(
+ fun > createBlockEntityType(
block: RegistrySupplier,
default: () -> P,
): BlockEntityType (
override fun load(tag: CompoundTag) {
super.load(tag)
- projection.fromNbt(tag.getCompound(TAG_PROJECTION_EFFECT), true)
+ if (TAG_PROJECTION_EFFECT in tag) {
+ projection.fromNbt(tag.getCompound(TAG_PROJECTION_EFFECT))
+ }
}
override fun getUpdateTag(): CompoundTag = saveWithoutMetadata()
override fun getUpdatePacket(): Packet