Skip to content

Commit

Permalink
Merge pull request #1 from linyuzhe210/main
Browse files Browse the repository at this point in the history
Fixed minor issues and implemented three entity attribute components to data-driven entity
  • Loading branch information
boybook authored Feb 26, 2024
2 parents 7836062 + 7eb91cd commit 3305152
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
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

0 comments on commit 3305152

Please sign in to comment.