Skip to content

Commit

Permalink
Added 1.16.4 living entity element support (#590)
Browse files Browse the repository at this point in the history
* Added 1.16.4 mob element support (#4)

Signed-off-by: KlemenDEV <klemen.pylo@gmail.com>

* Made unit tests ignore AI tasks if not defined

Signed-off-by: KlemenDEV <klemen.pylo@gmail.com>

* Added AI Tasks (#591)

* Fixed AI tasks

Signed-off-by: KlemenDEV <klemen.pylo@gmail.com>

Co-authored-by: Max094Reikeb <49318596+Max094Reikeb@users.noreply.github.com>
  • Loading branch information
KlemenDEV and Max094Reikeb committed Dec 2, 2020
1 parent 9a1fb2c commit e6bb0c0
Show file tree
Hide file tree
Showing 32 changed files with 1,102 additions and 6 deletions.
@@ -0,0 +1,3 @@
<#include "aiconditions.java.ftl">
this.targetSelector.addGoal(${customBlockIndex+1}, new HurtByTargetGoal(this)<@conditionCode field$condition/>
<#if field$callhelp?lower_case == "true">.setCallsForHelp(this.getClass())</#if>);
@@ -0,0 +1,4 @@
<#include "aiconditions.java.ftl">
this.targetSelector.addGoal(${customBlockIndex+1},
new NearestAttackableTargetGoal(this, ${generator.map(field$entity, "entities")}.class, ${field$insight?lower_case},
${field$nearby?lower_case})<@conditionCode field$condition/>);
57 changes: 57 additions & 0 deletions plugins/generator-1.16.4/forge-1.16.4/aitasks/attack_fly.java.ftl
@@ -0,0 +1,57 @@
<#-- @formatter:off -->
<#include "procedures.java.ftl">
<#if field$condition?has_content>
<#assign conditions = generator.procedureNamesToObjects(field$condition)>
<#else>
<#assign conditions = ["", ""]>
</#if>
this.goalSelector.addGoal(${customBlockIndex+1}, new Goal() {
{
this.setMutexFlags(EnumSet.of(Goal.Flag.MOVE));
}

public boolean shouldExecute() {
if (CustomEntity.this.getAttackTarget() != null && !CustomEntity.this.getMoveHelper().isUpdating()) {
<#if hasCondition(conditions[0])>
double x = CustomEntity.this.getPosX();
double y = CustomEntity.this.getPosY();
double z = CustomEntity.this.getPosZ();
Entity entity = CustomEntity.this;
</#if>
return <#if hasCondition(conditions[0])><@procedureOBJToConditionCode conditions[0]/><#else>true</#if>;
} else {
return false;
}
}

@Override public boolean shouldContinueExecuting() {
<#if hasCondition(conditions[1])>
double x = CustomEntity.this.getPosX();
double y = CustomEntity.this.getPosY();
double z = CustomEntity.this.getPosZ();
Entity entity = CustomEntity.this;
</#if>
return <#if hasCondition(conditions[1])><@procedureOBJToConditionCode conditions[1]/> &&</#if>
CustomEntity.this.getMoveHelper().isUpdating() && CustomEntity.this.getAttackTarget() != null && CustomEntity.this.getAttackTarget().isAlive();
}

@Override public void startExecuting() {
LivingEntity livingentity = CustomEntity.this.getAttackTarget();
Vector3d vec3d = livingentity.getEyePosition(1);
CustomEntity.this.moveController.setMoveTo(vec3d.x, vec3d.y, vec3d.z, ${field$speed});
}

@Override public void tick() {
LivingEntity livingentity = CustomEntity.this.getAttackTarget();
if (CustomEntity.this.getBoundingBox().intersects(livingentity.getBoundingBox())) {
CustomEntity.this.attackEntityAsMob(livingentity);
} else {
double d0 = CustomEntity.this.getDistanceSq(livingentity);
if (d0 < ${field$radius}) {
Vector3d vec3d = livingentity.getEyePosition(1);
CustomEntity.this.moveController.setMoveTo(vec3d.x, vec3d.y, vec3d.z, ${field$speed});
}
}
}
});
<#-- @formatter:on -->
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new MeleeAttackGoal(this, ${field$speed}, ${field$longmemory?lower_case})<@conditionCode field$condition/>);
@@ -0,0 +1,3 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1},
new AvoidEntityGoal(this, ${generator.map(field$entity, "entities")}.class, (float)${field$radius}, ${field$farspeed}, ${field$nearspeed})<@conditionCode field$condition/>);
@@ -0,0 +1,4 @@
<#include "mcitems.ftl">
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new BreakBlockGoal(${mappedBlockToBlockStateCode(input$block)}.getBlock(),
this, ${field$speed}, (int) ${field$y_max})<@conditionCode field$condition/>);
4 changes: 4 additions & 0 deletions plugins/generator-1.16.4/forge-1.16.4/aitasks/breed.java.ftl
@@ -0,0 +1,4 @@
<#if data.breedable>
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new BreedGoal(this, ${field$speed})<@conditionCode field$condition/>);
</#if>
@@ -0,0 +1,4 @@
<#if !data.flyingMob>
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new BreakDoorGoal(this, e -> true)<@conditionCode field$condition/>);
</#if>
@@ -0,0 +1,4 @@
<#if !data.flyingMob>
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new OpenDoorGoal(this, false)<@conditionCode field$condition/>);
</#if>
@@ -0,0 +1,4 @@
<#if !data.flyingMob>
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new OpenDoorGoal(this, true)<@conditionCode field$condition/>);
</#if>
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new EatGrassGoal(this)<@conditionCode field$condition/>);
@@ -0,0 +1,4 @@
<#if data.tameable>
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new OwnerHurtTargetGoal(this)<@conditionCode field$condition/>);
</#if>
16 changes: 16 additions & 0 deletions plugins/generator-1.16.4/forge-1.16.4/aitasks/fly.java.ftl
@@ -0,0 +1,16 @@
<#-- @formatter:off -->
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new RandomWalkingGoal(this, ${field$speed}, 20) {

@Override protected Vector3d getPosition() {
Random random = CustomEntity.this.getRNG();
double dir_x = CustomEntity.this.getPosX() + ((random.nextFloat() * 2 - 1) * 16);
double dir_y = CustomEntity.this.getPosY() + ((random.nextFloat() * 2 - 1) * 16);
double dir_z = CustomEntity.this.getPosZ() + ((random.nextFloat() * 2 - 1) * 16);
return new Vector3d(dir_x, dir_y, dir_z);
}

<@conditionCode field$condition false/>

});
<#-- @formatter:on -->
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new FollowMobGoal(this, (float)${field$speed}, ${field$maxrange}, ${field$followarea})<@conditionCode field$condition/>);
@@ -0,0 +1,3 @@
<#include "mcitems.ftl">
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new TemptGoal(this, ${field$speed}, Ingredient.fromItems(${mappedMCItemToItem(input$item)}), ${field$scared?lower_case})<@conditionCode field$condition/>);
@@ -0,0 +1,4 @@
<#if data.tameable>
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new FollowOwnerGoal(this, ${field$speed}, (float) ${field$min_distance}, (float) ${field$max_distance}, false)<@conditionCode field$condition/>);
</#if>
@@ -0,0 +1,4 @@
<#if data.breedable>
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new FollowParentGoal(this, ${field$speed})<@conditionCode field$condition/>);
</#if>
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new LeapAtTargetGoal(this, (float)${field$speed})<@conditionCode field$condition/>);
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new LookRandomlyGoal(this)<@conditionCode field$condition/>);
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new ReturnToVillageGoal(this, 0.6, false)<@conditionCode field$condition/>);
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1},new PanicGoal(this, ${field$speed})<@conditionCode field$condition/>);
@@ -0,0 +1,4 @@
<#if data.tameable>
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new OwnerHurtByTargetGoal(this)<@conditionCode field$condition/>);
</#if>
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new RestrictSunGoal(this)<@conditionCode field$condition/>);
2 changes: 2 additions & 0 deletions plugins/generator-1.16.4/forge-1.16.4/aitasks/swim.java.ftl
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new RandomSwimmingGoal(this, ${field$speed}, 40)<@conditionCode field$condition/>);
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new SwimGoal(this)<@conditionCode field$condition/>);
2 changes: 2 additions & 0 deletions plugins/generator-1.16.4/forge-1.16.4/aitasks/wander.java.ftl
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new RandomWalkingGoal(this, ${field$speed})<@conditionCode field$condition/>);
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new WaterAvoidingRandomWalkingGoal(this, ${field$speed})<@conditionCode field$condition/>);
@@ -0,0 +1,2 @@
<#include "aiconditions.java.ftl">
this.goalSelector.addGoal(${customBlockIndex+1}, new LookAtGoal(this, ${generator.map(field$entity, "entities")}.class,(float)${field$radius})<@conditionCode field$condition/>);
15 changes: 15 additions & 0 deletions plugins/generator-1.16.4/forge-1.16.4/mob.definition.yaml
@@ -0,0 +1,15 @@
templates:
- template: mob.java.ftl
name: "@SRCROOT/@BASEPACKAGEPATH/entity/@NAMEEntity.java"
- template: json/spawn_egg.json.ftl
writer: json
name: "@MODASSETSROOT/models/item/@registryname_spawn_egg.json"
condition: hasSpawnEgg
deleteWhenConditionFalse: true

localizationkeys:
- key: item.@modid.@registryname_spawn_egg
mapto: mobName
suffix: " Spawn Egg"
- key: entity.@modid.@registryname
mapto: mobName
@@ -0,0 +1,3 @@
{
"parent": "item/template_spawn_egg"
}

0 comments on commit e6bb0c0

Please sign in to comment.