Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed minor issues and implemented three entity attribute components to data-driven entity #1

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ data class TextureImage(

enum class ImageType {
PNG,
JPG;
JPG,
TGA;
fun getExtension(): String {
return name.lowercase()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import net.minecraft.util.Identifier
import java.lang.reflect.Type

data class BlockResourceDefinition(
@SerializedName("format_version") val formatVersion: String,
@SerializedName("format_version") val formatVersion: List<Int>,
val blocks: Map<Identifier, Block>
) {

Expand All @@ -28,7 +28,7 @@ data class BlockResourceDefinition(
blocks[identifier] = context.deserialize(value, Block::class.java)
}
return BlockResourceDefinition(
obj["format_version"].asString,
obj["format_version"].asJsonArray.map { it.asInt },
blocks
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package net.easecation.bedrockloader.bedrock.entity.components

data class ComponentHealth(
val value: Float?,
val max: Float?
val max: Float?,
val min: Float?
) : IEntityComponent
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import net.minecraft.entity.EntityType
import net.minecraft.entity.EquipmentSlot
import net.minecraft.entity.SpawnGroup
import net.minecraft.entity.attribute.DefaultAttributeContainer
import net.minecraft.entity.attribute.EntityAttributes
import net.minecraft.entity.damage.DamageSource
import net.minecraft.entity.mob.MobEntity
import net.minecraft.item.ItemStack
import net.minecraft.util.Arm
Expand All @@ -32,6 +34,13 @@ class EntityDataDriven(
fun buildEntityAttributes(components: EntityComponents): DefaultAttributeContainer.Builder {
val builder = MobEntity.createMobAttributes()
// TODO components
// Add HealthComponent, KnockbackResistanceComponent, MovementComponent
components.let {
it.minecraftHealth?.max?.let { value -> builder.add(EntityAttributes.GENERIC_MAX_HEALTH, value.toDouble()) } ?:
it.minecraftHealth?.value?.let { value -> builder.add(EntityAttributes.GENERIC_MAX_HEALTH, value.toDouble()) }
it.minecraftKnockbackResistance?.value?.let { value -> builder.add(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, value.toDouble()) }
it.minecraftMovement?.value?.let { value -> builder.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, value.toDouble()) }
}
return builder
}
}
Expand All @@ -51,5 +60,25 @@ class EntityDataDriven(
return Arm.RIGHT
}

override fun hasNoGravity(): Boolean {
return components.minecraftPhysics?.has_gravity == true
}

override fun damage(source: DamageSource?, amount: Float): Boolean {
return components.minecraftHealth?.min?.let {
when {
health - amount > 1 && source != DamageSource.OUT_OF_WORLD -> {
return super.damage(source, amount)
}
else -> {
if (source == DamageSource.OUT_OF_WORLD) {
return false
}
health += amount
return super.damage(source, amount)
}
}
}?: return super.damage(source, amount)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object BedrockAddonsLoader {

fun load() {
val dataFolder: File = BedrockLoader.getGameDir().resolve("config/bedrock-loader")
if (dataFolder.exists()) {
if (!dataFolder.exists()) {
dataFolder.mkdirs()
}
// 从dataFolder中读取所有的zip文件
Expand Down
Loading