Skip to content

Commit

Permalink
Support for pushable component.
Browse files Browse the repository at this point in the history
  • Loading branch information
boybook committed Mar 17, 2024
1 parent 6b88643 commit b54394a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.easecation.bedrockloader.bedrock.entity.components

data class ComponentPushable(
val is_pushable: Boolean?,
val is_pushable_by_piston: Boolean?,
) : IEntityComponent
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ data class EntityComponents(
@SerializedName("minecraft:skin_id") val minecraftSkinId: Int?,
@SerializedName("minecraft:health") val minecraftHealth: ComponentHealth?,
@SerializedName("minecraft:rideable") val minecraftRideable: ComponentRideable?,
@SerializedName("minecraft:is_immobile") val minecraftIsImmobile: ComponentIsImmobile?
@SerializedName("minecraft:is_immobile") val minecraftIsImmobile: ComponentIsImmobile?,
@SerializedName("minecraft:pushable") val minecraftPushable: ComponentPushable?,
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package net.easecation.bedrockloader.entity

import net.easecation.bedrockloader.BedrockLoader
import net.easecation.bedrockloader.bedrock.entity.components.EntityComponents
import net.easecation.bedrockloader.loader.BedrockAddonsRegistry
import net.fabricmc.fabric.api.`object`.builder.v1.entity.FabricEntityTypeBuilder
import net.minecraft.entity.EntityDimensions
import net.minecraft.entity.EntityType
import net.minecraft.entity.EquipmentSlot
import net.minecraft.entity.SpawnGroup
import net.minecraft.entity.*
import net.minecraft.entity.attribute.DefaultAttributeContainer
import net.minecraft.entity.attribute.EntityAttributes
import net.minecraft.entity.damage.DamageSource
Expand Down Expand Up @@ -47,6 +45,22 @@ class EntityDataDriven(
}
}

override fun isPushable(): Boolean {
return components.minecraftPushable?.is_pushable ?: false
}

override fun pushAwayFrom(entity: Entity?) {
if (this.isPushable) {
super.pushAwayFrom(entity)
}
}

override fun pushAway(entity: Entity?) {
if (this.isPushable) {
super.pushAway(entity)
}
}

override fun getArmorItems(): MutableIterable<ItemStack> {
return mutableListOf()
}
Expand All @@ -63,7 +77,7 @@ class EntityDataDriven(
}

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

override fun damage(source: DamageSource?, amount: Float): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class BedrockBehaviorPackLoader(
Registry.register(Registry.ITEM, id, item)
BedrockAddonsRegistry.items[id] = item
}
BedrockLoader.logger.info("test")
// Entity
context.behavior.entities.forEach { (id, beh) ->
BedrockLoader.logger.info("Registering entity $id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,14 @@ class BedrockResourcePackLoader(
context.resource.itemTexture[spawnEggTexture]?.textures?.let {
val bedrockTexture = context.resource.textureImages[it]
if (bedrockTexture == null) {
BedrockLoader.logger.warn("[BedrockResourcePackLoader] Entity spawn egg texture not found: ${spawnEggTexture}")
return
}
val namespaceDir = this.namespaceDir(identifier.namespace)
val bedrockTextureFile = namespaceDir.resolve("textures/" + model.textures!!["layer0"]!!.path + "." + bedrockTexture.type.getExtension())
bedrockTextureFile.parentFile.mkdirs()
bedrockTexture.image.let { image ->
ImageIO.write(image, bedrockTextureFile.extension, bedrockTextureFile)
BedrockLoader.logger.warn("[BedrockResourcePackLoader] Entity spawn egg texture not found: $spawnEggTexture")
} else {
val namespaceDir = this.namespaceDir(identifier.namespace)
val bedrockTextureFile = namespaceDir.resolve("textures/" + model.textures!!["layer0"]!!.path + "." + bedrockTexture.type.getExtension())
bedrockTextureFile.parentFile.mkdirs()
bedrockTexture.image.let { image ->
ImageIO.write(image, bedrockTextureFile.extension, bedrockTextureFile)
}
}
}
} else {
Expand Down

0 comments on commit b54394a

Please sign in to comment.