-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More ray stuff, still needs a lot of work
- Loading branch information
1 parent
e3ae6d8
commit 132f947
Showing
14 changed files
with
592 additions
and
101 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...ent/kotlin/dev/hybridlabs/aquatic/client/model/entity/fish/HybridAquaticRayEntityModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package dev.hybridlabs.aquatic.client.model.entity.fish | ||
|
||
import dev.hybridlabs.aquatic.HybridAquatic | ||
import dev.hybridlabs.aquatic.entity.fish.ray.HybridAquaticRayEntity | ||
import dev.hybridlabs.aquatic.entity.fish.ray.HybridAquaticRayEntity.RayVariant.Ignore.* | ||
import net.minecraft.client.MinecraftClient | ||
import net.minecraft.client.render.entity.model.EntityModelPartNames | ||
import net.minecraft.util.Identifier | ||
import net.minecraft.util.math.MathHelper | ||
import software.bernie.geckolib.core.animation.AnimationState | ||
import software.bernie.geckolib.model.GeoModel | ||
|
||
abstract class HybridAquaticRayEntityModel<T: HybridAquaticRayEntity> (private val id: String) : GeoModel<T>() { | ||
override fun getModelResource(animatable: T?): Identifier { | ||
val variant = animatable?.variant | ||
if (variant != null && !variant.ignore.contains(MODEL)) | ||
return Identifier(HybridAquatic.MOD_ID, "geo/${id}_${variant.getProvidedVariant(animatable)}.geo.json") | ||
return Identifier(HybridAquatic.MOD_ID, "geo/$id.geo.json") | ||
} | ||
|
||
override fun getTextureResource(animatable: T?): Identifier { | ||
val variant = animatable?.variant | ||
if (variant != null && !variant.ignore.contains(TEXTURE)) | ||
return Identifier(HybridAquatic.MOD_ID, "textures/entity/${id}_${variant.getProvidedVariant(animatable)}.png") | ||
return Identifier(HybridAquatic.MOD_ID, "textures/entity/$id.png") | ||
} | ||
|
||
override fun getAnimationResource(animatable: T?): Identifier { | ||
val variant = animatable?.variant | ||
if (variant != null && !variant.ignore.contains(ANIMATION)) | ||
return Identifier(HybridAquatic.MOD_ID, "animations/${id}_${variant.getProvidedVariant(animatable)}.animation.json") | ||
return Identifier(HybridAquatic.MOD_ID, "animations/$id.animation.json") | ||
} | ||
|
||
override fun setCustomAnimations( | ||
animatable: T, | ||
instanceId: Long, | ||
animationState: AnimationState<T> | ||
) { | ||
super.setCustomAnimations(animatable, instanceId, animationState) | ||
val deltaTime: Float = MinecraftClient.getInstance().tickDelta | ||
|
||
val body = animationProcessor.getBone(EntityModelPartNames.BODY) | ||
body.rotX = MathHelper.lerp(deltaTime, animatable.prevPitch, animatable.pitch) * -MathHelper.RADIANS_PER_DEGREE | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/client/kotlin/dev/hybridlabs/aquatic/client/model/entity/fish/MantaRayEntityModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package dev.hybridlabs.aquatic.client.model.entity.fish | ||
|
||
import dev.hybridlabs.aquatic.entity.fish.HybridAquaticFishEntity | ||
import dev.hybridlabs.aquatic.entity.fish.ray.HybridAquaticRayEntity | ||
|
||
class MantaRayEntityModel : HybridAquaticFishEntityModel<HybridAquaticFishEntity>("manta_ray") | ||
class MantaRayEntityModel : HybridAquaticRayEntityModel<HybridAquaticRayEntity>("manta_ray") |
4 changes: 2 additions & 2 deletions
4
src/client/kotlin/dev/hybridlabs/aquatic/client/model/entity/fish/StingrayEntityModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package dev.hybridlabs.aquatic.client.model.entity.fish | ||
|
||
import dev.hybridlabs.aquatic.entity.fish.HybridAquaticFishEntity | ||
import dev.hybridlabs.aquatic.entity.fish.ray.HybridAquaticRayEntity | ||
|
||
class StingrayEntityModel : HybridAquaticFishEntityModel<HybridAquaticFishEntity>("stingray") | ||
class StingrayEntityModel : HybridAquaticRayEntityModel<HybridAquaticRayEntity>("stingray") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...kotlin/dev/hybridlabs/aquatic/client/render/entity/fish/HybridAquaticRayEntityRenderer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package dev.hybridlabs.aquatic.client.render.entity.fish | ||
|
||
import dev.hybridlabs.aquatic.entity.fish.ray.HybridAquaticRayEntity | ||
import net.minecraft.client.render.VertexConsumerProvider | ||
import net.minecraft.client.render.entity.EntityRendererFactory | ||
import net.minecraft.client.util.math.MatrixStack | ||
import software.bernie.geckolib.model.GeoModel | ||
import software.bernie.geckolib.renderer.GeoEntityRenderer | ||
import software.bernie.geckolib.renderer.layer.AutoGlowingGeoLayer | ||
|
||
@Suppress("LeakingThis") | ||
open class HybridAquaticRayEntityRenderer<T: HybridAquaticRayEntity>(context: EntityRendererFactory.Context, model: GeoModel<T>, private var variableSize: Boolean = false, canGlow: Boolean = false): GeoEntityRenderer<T>(context, model) { | ||
|
||
init { | ||
if(canGlow) addRenderLayer(AutoGlowingGeoLayer(this)) | ||
} | ||
|
||
override fun render( | ||
entity: T, | ||
entityYaw: Float, | ||
partialTick: Float, | ||
poseStack: MatrixStack, | ||
bufferSource: VertexConsumerProvider, | ||
packedLight: Int | ||
) { | ||
if(variableSize) { | ||
val size = HybridAquaticRayEntity.getScaleAdjustment(entity, 0.05f) | ||
poseStack.scale(size, size, size) | ||
} | ||
super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/kotlin/dev/hybridlabs/aquatic/entity/ai/goal/StayNearSurfaceGoal.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package dev.hybridlabs.aquatic.entity.ai.goal | ||
|
||
import net.minecraft.block.Blocks | ||
import net.minecraft.entity.ai.goal.Goal | ||
import net.minecraft.entity.mob.MobEntity | ||
import net.minecraft.util.math.BlockPos | ||
import net.minecraft.util.math.Vec3d | ||
|
||
@Suppress("DEPRECATION") | ||
class StayNearSurfaceGoal(private val mob: MobEntity) : Goal() { | ||
|
||
override fun canStart(): Boolean { | ||
return true | ||
} | ||
|
||
override fun tick() { | ||
val blockPos = mob.blockPos | ||
val blockAbove = mob.entityWorld.getBlockState(blockPos.up(17)) | ||
val ceilingAbove = isSolidBlockAbove(blockPos) | ||
val waterBelow = isWaterBelow(blockPos) | ||
|
||
if (blockAbove.isOf(Blocks.WATER) && !ceilingAbove && waterBelow) { | ||
setUpwardVelocity() | ||
} | ||
} | ||
|
||
private fun isSolidBlockAbove(pos: BlockPos): Boolean { | ||
for (i in 1..16) { | ||
val state = mob.entityWorld.getBlockState(pos.up(i)) | ||
if (state.isSolid) { | ||
val airGapBelow = mob.entityWorld.getBlockState(pos.up(i - 1)).isOf(Blocks.AIR) | ||
if (!airGapBelow) { | ||
return true | ||
} | ||
} | ||
} | ||
return false | ||
} | ||
|
||
private fun isWaterBelow(pos: BlockPos): Boolean { | ||
for (i in 1..8) { | ||
val state = mob.entityWorld.getBlockState(pos.down(i)) | ||
if (state.isOf(Blocks.WATER)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
private fun setUpwardVelocity() { | ||
val upwardVelocity = 0.25 | ||
val currentVelocity = mob.velocity | ||
mob.velocity = Vec3d(currentVelocity.x, upwardVelocity, currentVelocity.z) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.