-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/sockmit2007/omniaetnihil/client/renderer/entity/LichEntityRenderer.java
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,13 @@ | ||
package com.sockmit2007.omniaetnihil.client.renderer.entity; | ||
|
||
import com.sockmit2007.omniaetnihil.client.renderer.entity.model.LichEntityModel; | ||
import com.sockmit2007.omniaetnihil.entity.LichEntity; | ||
|
||
import mod.azure.azurelib.common.api.client.renderer.GeoEntityRenderer; | ||
import net.minecraft.client.renderer.entity.EntityRendererProvider; | ||
|
||
public class LichEntityRenderer extends GeoEntityRenderer<LichEntity> { | ||
public LichEntityRenderer(EntityRendererProvider.Context context) { | ||
super(context, new LichEntityModel()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/sockmit2007/omniaetnihil/client/renderer/entity/model/LichEntityModel.java
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,37 @@ | ||
package com.sockmit2007.omniaetnihil.client.renderer.entity.model; | ||
|
||
import com.sockmit2007.omniaetnihil.OmniaEtNihil; | ||
import com.sockmit2007.omniaetnihil.entity.LichEntity; | ||
|
||
import mod.azure.azurelib.common.api.client.model.GeoModel; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public class LichEntityModel extends GeoModel<LichEntity> { | ||
// Models must be stored in assets/<modid>/geo with subfolders supported inside | ||
// the geo folder | ||
private static final ResourceLocation model = ResourceLocation.fromNamespaceAndPath(OmniaEtNihil.MODID, | ||
"geo/lich.geo.json"); | ||
// Textures must be stored in assets/<modid>/geo with subfolders supported | ||
// inside the textures folder | ||
private static final ResourceLocation texture = ResourceLocation.fromNamespaceAndPath(OmniaEtNihil.MODID, | ||
"textures/entity/lich.png"); | ||
// Animations must be stored in assets/<modid>/animations with subfolders | ||
// supported inside the animations folder | ||
private static final ResourceLocation animation = ResourceLocation.fromNamespaceAndPath(OmniaEtNihil.MODID, | ||
"animations/lich.animation.json"); | ||
|
||
@Override | ||
public ResourceLocation getModelResource(LichEntity object) { | ||
return LichEntityModel.model; | ||
} | ||
|
||
@Override | ||
public ResourceLocation getTextureResource(LichEntity object) { | ||
return LichEntityModel.texture; | ||
} | ||
|
||
@Override | ||
public ResourceLocation getAnimationResource(LichEntity object) { | ||
return LichEntityModel.animation; | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/main/java/com/sockmit2007/omniaetnihil/entity/LichEntity.java
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,115 @@ | ||
package com.sockmit2007.omniaetnihil.entity; | ||
|
||
import java.util.List; | ||
|
||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
import mod.azure.azurelib.common.api.common.animatable.GeoEntity; | ||
import mod.azure.azurelib.common.internal.common.util.AzureLibUtil; | ||
import mod.azure.azurelib.core.animatable.instance.AnimatableInstanceCache; | ||
import mod.azure.azurelib.core.animation.AnimatableManager.ControllerRegistrar; | ||
import mod.azure.azurelib.core.animation.AnimationController; | ||
import mod.azure.azurelib.core.animation.RawAnimation; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.Mob; | ||
import net.minecraft.world.entity.ai.Brain; | ||
import net.minecraft.world.entity.ai.attributes.AttributeSupplier; | ||
import net.minecraft.world.entity.ai.attributes.Attributes; | ||
import net.minecraft.world.entity.monster.Enemy; | ||
import net.minecraft.world.level.Level; | ||
import net.tslat.smartbrainlib.api.SmartBrainOwner; | ||
import net.tslat.smartbrainlib.api.core.BrainActivityGroup; | ||
import net.tslat.smartbrainlib.api.core.SmartBrainProvider; | ||
import net.tslat.smartbrainlib.api.core.behaviour.FirstApplicableBehaviour; | ||
import net.tslat.smartbrainlib.api.core.behaviour.OneRandomBehaviour; | ||
import net.tslat.smartbrainlib.api.core.behaviour.custom.attack.AnimatableMeleeAttack; | ||
import net.tslat.smartbrainlib.api.core.behaviour.custom.look.LookAtTarget; | ||
import net.tslat.smartbrainlib.api.core.behaviour.custom.misc.Idle; | ||
import net.tslat.smartbrainlib.api.core.behaviour.custom.move.MoveToWalkTarget; | ||
import net.tslat.smartbrainlib.api.core.behaviour.custom.path.SetRandomWalkTarget; | ||
import net.tslat.smartbrainlib.api.core.behaviour.custom.path.SetWalkTargetToAttackTarget; | ||
import net.tslat.smartbrainlib.api.core.behaviour.custom.target.InvalidateAttackTarget; | ||
import net.tslat.smartbrainlib.api.core.behaviour.custom.target.SetPlayerLookTarget; | ||
import net.tslat.smartbrainlib.api.core.behaviour.custom.target.SetRandomLookTarget; | ||
import net.tslat.smartbrainlib.api.core.behaviour.custom.target.TargetOrRetaliate; | ||
import net.tslat.smartbrainlib.api.core.sensor.ExtendedSensor; | ||
import net.tslat.smartbrainlib.api.core.sensor.vanilla.HurtBySensor; | ||
import net.tslat.smartbrainlib.api.core.sensor.vanilla.NearbyLivingEntitySensor; | ||
|
||
public class LichEntity extends Mob implements Enemy, GeoEntity, SmartBrainOwner<LichEntity> { | ||
public LichEntity(EntityType<? extends LichEntity> pEntityType, Level pLevel) { | ||
super(pEntityType, pLevel); | ||
} | ||
|
||
private final AnimatableInstanceCache cache = AzureLibUtil.createInstanceCache(this); | ||
|
||
@Override | ||
public AnimatableInstanceCache getAnimatableInstanceCache() { | ||
return cache; | ||
} | ||
|
||
@Override | ||
public void registerControllers(ControllerRegistrar controllers) { | ||
controllers.add(new AnimationController<>(this, "controllerName", 0, event -> { | ||
return event.setAndContinue( | ||
event.isMoving() ? RawAnimation.begin().thenLoop("walking") | ||
: RawAnimation.begin().thenLoop("idle")); | ||
})); | ||
} | ||
|
||
public static AttributeSupplier.Builder createMobAttributes() { | ||
return Mob.createMobAttributes() | ||
.add(Attributes.MAX_HEALTH, 25.0) | ||
.add(Attributes.FOLLOW_RANGE, 50.0); | ||
} | ||
|
||
@Override | ||
protected Brain.Provider<?> brainProvider() { | ||
return new SmartBrainProvider<>(this); | ||
} | ||
|
||
@Override | ||
protected void customServerAiStep() { | ||
tickBrain(this); | ||
} | ||
|
||
@Override | ||
public List<ExtendedSensor<LichEntity>> getSensors() { | ||
return ObjectArrayList.of( | ||
new NearbyLivingEntitySensor<>(), // This tracks nearby entities | ||
new HurtBySensor<>() // This tracks the last damage source and attacker | ||
); | ||
} | ||
|
||
@Override | ||
public BrainActivityGroup<LichEntity> getCoreTasks() { // These are the tasks that run all the time (usually) | ||
return BrainActivityGroup.coreTasks( | ||
new LookAtTarget<>(), // Have the entity turn to face and look at its current look target | ||
new MoveToWalkTarget<>()); // Walk towards the current walk target | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public BrainActivityGroup<LichEntity> getIdleTasks() { // These are the tasks that run when the mob isn't doing | ||
// anything | ||
// else (usually) | ||
return BrainActivityGroup.idleTasks( | ||
new FirstApplicableBehaviour<LichEntity>( // Run only one of the below behaviours, trying each one in | ||
// order. | ||
// Include the generic type because JavaC is silly | ||
new TargetOrRetaliate<>(), // Set the attack target and walk target based on nearby entities | ||
new SetPlayerLookTarget<>(), // Set the look target for the nearest player | ||
new SetRandomLookTarget<>()), // Set a random look target | ||
new OneRandomBehaviour<>( // Run a random task from the below options | ||
new SetRandomWalkTarget<>(), // Set a random walk target to a nearby position | ||
new Idle<>().runFor(entity -> entity.getRandom().nextInt(30, 60)))); // Do nothing for 1.5->3 | ||
// seconds | ||
} | ||
|
||
@Override | ||
public BrainActivityGroup<LichEntity> getFightTasks() { // These are the tasks that handle fighting | ||
return BrainActivityGroup.fightTasks( | ||
new InvalidateAttackTarget<>(), // Cancel fighting if the target is no longer valid | ||
new SetWalkTargetToAttackTarget<>(), // Set the walk target to the attack target | ||
new AnimatableMeleeAttack<>(0)); // Melee attack the target if close enough | ||
} | ||
} |
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