Skip to content

Commit

Permalink
Liches
Browse files Browse the repository at this point in the history
  • Loading branch information
Darthsae committed Jul 6, 2024
1 parent e583c2f commit 359addf
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/sockmit2007/omniaetnihil/OmniaEtNihil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.mojang.serialization.Codec;
import com.sockmit2007.omniaetnihil.block.HurtBlock;
import com.sockmit2007.omniaetnihil.client.renderer.entity.ExampleEntityRenderer;
import com.sockmit2007.omniaetnihil.client.renderer.entity.LichEntityRenderer;
import com.sockmit2007.omniaetnihil.entity.ExampleEntity;
import com.sockmit2007.omniaetnihil.entity.LichEntity;
import com.sockmit2007.omniaetnihil.item.GrabberJar;

import net.minecraft.core.component.DataComponentType;
Expand Down Expand Up @@ -76,9 +78,15 @@ public class OmniaEtNihil {
.register("example_entity",
() -> EntityType.Builder.of(ExampleEntity::new, MobCategory.MONSTER).sized(0.9F, 0.9F)
.clientTrackingRange(10).build("example_entity"));
public static final DeferredHolder<EntityType<?>, EntityType<LichEntity>> LICH = ENTITY_TYPES
.register("lich",
() -> EntityType.Builder.of(LichEntity::new, MobCategory.MONSTER).sized(0.9F, 0.9F)
.clientTrackingRange(10).build("lich"));

public static final DeferredItem<SpawnEggItem> EXAMPLE_ENTITY_SPAWN_EGG = ITEMS.register("example_entity_spawn_egg",
() -> new DeferredSpawnEggItem(EXAMPLE_ENTITY, 0xDFDFDF, 0x99CFE8, new Item.Properties()));
public static final DeferredItem<SpawnEggItem> LICH_ENTITY_SPAWN_EGG = ITEMS.register("lich_entity_spawn_egg",
() -> new DeferredSpawnEggItem(LICH, 0xDFDFDF, 0x99CFE8, new Item.Properties()));

public static final DeferredItem<Item> EXAMPLE_ITEM = ITEMS.registerSimpleItem("example_item",
new Item.Properties().food(new FoodProperties.Builder()
Expand All @@ -105,6 +113,7 @@ public class OmniaEtNihil {
output.accept(GRABBER_JAR.get());
output.accept(HURT_BLOCK_ITEM.get());
output.accept(EXAMPLE_ENTITY_SPAWN_EGG.get());
output.accept(LICH_ENTITY_SPAWN_EGG.get());
}).build());

public OmniaEtNihil(IEventBus modEventBus, ModContainer modContainer, Dist dist) {
Expand Down Expand Up @@ -133,6 +142,7 @@ public OmniaEtNihil(IEventBus modEventBus, ModContainer modContainer, Dist dist)

public void registerEntityRenderers(EntityRenderersEvent.RegisterRenderers event) {
event.registerEntityRenderer(EXAMPLE_ENTITY.get(), ExampleEntityRenderer::new);
event.registerEntityRenderer(LICH.get(), LichEntityRenderer::new);
}

private void commonSetup(final FMLCommonSetupEvent event) {
Expand All @@ -149,6 +159,7 @@ private void registerCapabilities(RegisterCapabilitiesEvent event) {

public void registerEntityAttributes(EntityAttributeCreationEvent event) {
event.put(EXAMPLE_ENTITY.get(), ExampleEntity.createMobAttributes().build());
event.put(LICH.get(), LichEntity.createMobAttributes().build());
}

@SubscribeEvent
Expand Down
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());
}
}
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 src/main/java/com/sockmit2007/omniaetnihil/entity/LichEntity.java
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
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/omniaetnihil/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"item.omniaetnihil.grabber_jar": "Grabber Jar",
"item.omniaetnihil.hurt_block": "Hurt Block",
"item.omniaetnihil.example_entity_spawn_egg": "Example Entity",
"item.omniaetnihil.lich": "Lich",
"entity.omniaetnihil.lich": "Lich",
"entity.omniaetnihil.example_entity": "Example Entity",
"block.omniaetnihil.hurt_block": "Hurt Block",
"block.omniaetnihil.example_block": "Example Block",
Expand Down

0 comments on commit 359addf

Please sign in to comment.