Skip to content

Commit

Permalink
Add gazelles (preliminary AI)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeow committed Jan 9, 2023
1 parent b27730c commit 1b06638
Show file tree
Hide file tree
Showing 12 changed files with 541 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ public static void registerEntityRenders() {
}
// s.translate(0.0F, -1.2F, 0.0F);
}));
R.addRender(ModEntities.GAZELLE::getEntityType, 0.8F, r -> r.tVariant().childScale(0.6F).mMapped(e -> {
String v = e.getVariantNameOrEmpty();
if(v.equals("blackbuck_2")) {
return "blackbuck_gazelle";
}
return v.isEmpty() ? "blackbuck_gazelle" : v + "_gazelle";
}, ModelGazelle::new, "blackbuck_gazelle")
.mEntry(ModelGazelle::new, "chinkara_gazelle")
.mEntry(ModelGazelle::new, "erlanger_gazelle")
.mEntry(ModelGazelle::new, "springbok_gazelle"));
RenderFactory.addRender(ModEntities.PROJECTILE_BADGER_DIRT::get, RenderFactory.nothing());
}

Expand Down Expand Up @@ -264,6 +274,11 @@ public static void layerDefinitions(ImmutableMap.Builder<ModelLayerLocation, Lay
r.accept("blue_whale", ModelWhaleBlue.createBodyLayer());
r.accept("right_whale", ModelWhaleRight.createBodyLayer());

r.accept("blackbuck_gazelle", ModelGazelle.createBlackbuck());
r.accept("chinkara_gazelle", ModelGazelle.createChinkara());
r.accept("erlanger_gazelle", ModelGazelle.createErlanger());
r.accept("springbok_gazelle", ModelGazelle.createSpringbok());

r.accept("bear_cape", ModelBearCape.createBodyLayer());
r.accept("wolf_cape", ModelWolfCape.createBodyLayer());

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package dev.itsmeow.betteranimalsplus.common.entity;

import dev.itsmeow.betteranimalsplus.common.entity.util.EntityUtil;
import dev.itsmeow.betteranimalsplus.common.entity.util.IDropHead;
import dev.itsmeow.betteranimalsplus.common.entity.util.abstracts.EntityAnimalEatsGrassWithTypes;
import dev.itsmeow.betteranimalsplus.common.entity.util.abstracts.EntityAnimalWithTypes;
import dev.itsmeow.betteranimalsplus.init.ModEntities;
import dev.itsmeow.imdlib.entity.EntityTypeContainer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.ai.goal.*;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.state.BlockState;

public class EntityGazelle extends EntityAnimalEatsGrassWithTypes implements IDropHead<EntityAnimalWithTypes> {

public EntityGazelle(EntityType<? extends EntityGazelle> entityType, Level level) {
super(entityType, level, 6);
}

@Override
public int getEatTime() {
return eatTimer;
}

@Environment(EnvType.CLIENT)
@Override
public void handleEntityEvent(byte id) {
if (id == 10) {
this.eatTimer = 40;
} else {
super.handleEntityEvent(id);
}
}

@Override
public void baseTick() {
super.baseTick();
if (this.level.isClientSide) {
this.eatTimer = Math.max(0, this.eatTimer - 1);
}
}

@Override
public boolean isFood(ItemStack stack) {
Item i = stack.getItem();
return i == Items.WHEAT || i == Items.CARROT || i == Items.GOLDEN_CARROT || i == Items.APPLE || i == Items.GOLDEN_APPLE;
}

@Override
public int getMaxSpawnClusterSize() {
return 4;
}

@Override
protected void playStepSound(BlockPos pos, BlockState state) {
this.playSound(SoundEvents.SHEEP_STEP, 0.15F, 1.0F);
}

@Override
protected void registerGoals() {
super.registerGoals();
this.goalSelector.addGoal(0, new FloatGoal(this));
this.goalSelector.addGoal(1, new BreedGoal(this, 0.45D));
this.goalSelector.addGoal(2, new PanicGoal(this, 0.65D));
ItemLike[] temptItems = new ItemLike[]{Items.APPLE, Items.GOLDEN_APPLE, Items.CARROT, Items.CARROT_ON_A_STICK, Items.GOLDEN_CARROT, Items.WHEAT};
this.goalSelector.addGoal(3, new TemptGoal(this, 0.45D, Ingredient.of(temptItems), false));
this.goalSelector.addGoal(4, new AvoidEntityGoal<>(this, Player.class, 20, 0.55D, 0.7D));
this.goalSelector.addGoal(5, new FollowParentGoal(this, 1D));
// Eat Grass at Priority 6
this.goalSelector.addGoal(6, new RandomStrollGoal(this, 0.45D));
this.goalSelector.addGoal(7, new RandomLookAroundGoal(this));
}

@Override
public void ate() {
super.ate();
this.ageUp(60);
}

@Override
public void die(DamageSource cause) {
super.die(cause);
this.doHeadDrop();
}

@Override
protected EntityGazelle getBaseChild() {
return getContainer().getEntityType().create(level);
}

@Override
public SpawnGroupData finalizeSpawn(ServerLevelAccessor world, DifficultyInstance difficulty, MobSpawnType reason, SpawnGroupData livingdata, CompoundTag compound) {
return EntityUtil.childChance(this, reason, super.finalizeSpawn(world, difficulty, reason, livingdata, compound), 0.25F);
}

@Override
public EntityTypeContainer<EntityGazelle> getContainer() {
return ModEntities.GAZELLE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,16 @@ public class ModEntities {
.despawn()
.biomesOverworld(BiomeTypes.JUNGLE)
.containers("%s_bucket", ItemModFishBucket.waterBucket(G), "", c -> Items.WATER_BUCKET));
public static final EntityTypeContainer<EntityGazelle> GAZELLE = H.add(EntityGazelle.class, EntityGazelle::new, "gazelle", () -> Mob.createMobAttributes()
.add(Attributes.MAX_HEALTH, 15.0D)
.add(Attributes.MOVEMENT_SPEED, 0.45D), b -> b
.spawn(MobCategory.CREATURE, 14, 1, 4)
.defaultPlacement(Mob::checkMobSpawnRules)
.egg(0x593306, 0xedc391)
.size(1F, 1.5F)
.biomesOverworld(BiomeTypes.SAVANNA)
.variants("blackbuck", "blackbuck_2", "chinkara", "erlanger", "springbok")
/*.head().itemGroup(G).mapToNames().setModel(() -> ModelGazelleHead::new, "gazelle_head").done()*/);

public static LinkedHashMap<String, EntityTypeContainer<? extends Mob>> getEntities() {
return H.ENTITIES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"entity.betteranimalsplus.squid_colossal": "Colossal Squid",
"entity.betteranimalsplus.piranha": "Piranha",
"entity.betteranimalsplus.octopus": "Octopus",
"entity.betteranimalsplus.gazelle": "Gazelle",

"entity.betteranimalsplus.eel_saltwater.type.conger": "Conger",
"entity.betteranimalsplus.eel_saltwater.type.dragon": "Dragon",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "item/template_spawn_egg"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"type": "minecraft:entity",
"pools": [
{
"name": "gazelle-venison",
"rolls": 1,
"entries": [
{
"type": "item",
"name": "betteranimalsplus:venisonraw",
"weight": 2,
"functions": [
{
"function": "set_count",
"count": {
"min": 1,
"max": 3
}
},
{
"function": "furnace_smelt",
"conditions": [
{
"condition": "entity_properties",
"entity": "this",
"predicate": {
"flags": {
"is_on_fire": true
}
}
}
]
},
{
"function": "looting_enchant",
"count": {
"min": 0,
"max": 1
}
}
]
}
]
}
]
}

0 comments on commit 1b06638

Please sign in to comment.