Feat: Добавлены новые теги
This commit is contained in:
@@ -7,6 +7,8 @@ import cn.nukkit.level.Position;
|
||||
import com.reider745.behavior.entities.formats.tags.DescriptionsFactory;
|
||||
import com.reider745.behavior.entities.formats.tags.components.CollisionComponent;
|
||||
import com.reider745.behavior.entities.formats.tags.components.HealthComponent;
|
||||
import com.reider745.behavior.entities.formats.tags.components.attack.MeleeAttackComponent;
|
||||
import com.reider745.behavior.entities.formats.tags.components.attack.NearestAttackableTarget;
|
||||
import com.reider745.behavior.entities.formats.tags.components.navigation.NavigationComponentsTag;
|
||||
import com.reider745.behavior.entities.formats.tags.components.navigation.NavigationRandomStroll;
|
||||
import com.reider745.behavior.entities.formats.tags.components.navigation.NavigationWalkComponent;
|
||||
@@ -27,6 +29,9 @@ public class EntityContentFactory {
|
||||
public ArrayList<NavigationComponentsTag> navigations_compononets = new ArrayList<>();
|
||||
public NavigationWalkComponent navigationWalkComponent = new NavigationWalkComponent();
|
||||
|
||||
public NearestAttackableTarget nearestAttackableTarget = new NearestAttackableTarget();
|
||||
public MeleeAttackComponent meleeAttackComponent = new MeleeAttackComponent();
|
||||
|
||||
public List<String> family = new ArrayList<>();
|
||||
|
||||
public boolean isFireImmune = false;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.reider745.behavior.entities.ComponentsTag;
|
||||
import com.reider745.behavior.entities.EntityContentFactory;
|
||||
import com.reider745.behavior.entities.TagContentFactory;
|
||||
import com.reider745.behavior.entities.formats.tags.components.*;
|
||||
import com.reider745.behavior.entities.formats.tags.components.attack.MeleeAttackComponent;
|
||||
import com.reider745.behavior.entities.formats.tags.components.attack.NearestAttackableTarget;
|
||||
import com.reider745.behavior.entities.formats.tags.components.navigation.NavigationRandomStroll;
|
||||
import com.reider745.behavior.entities.formats.tags.components.navigation.NavigationWalkComponent;
|
||||
@@ -37,6 +38,7 @@ public class ComponentsFactory extends TagContentFactory {
|
||||
|
||||
add(new AttackComponent());
|
||||
add(new NearestAttackableTarget());
|
||||
add(new MeleeAttackComponent());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,7 +53,7 @@ public class ComponentsFactory extends TagContentFactory {
|
||||
final String key = it.next();
|
||||
final ComponentsTag tag = tags.get(key);
|
||||
if(tag == null){
|
||||
//Logger.warning("Not support ComponentsFactory "+key);
|
||||
Logger.warning("Not support ComponentsFactory "+key);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.reider745.behavior.entities.formats.tags.components.attack;
|
||||
|
||||
import com.reider745.behavior.entities.ComponentsTag;
|
||||
import com.reider745.behavior.entities.EntityContentFactory;
|
||||
import com.zhekasmirnov.horizon.runtime.logger.Logger;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class MeleeAttackComponent extends ComponentsTag {
|
||||
public int priority;
|
||||
public float speed_multiplier;
|
||||
public boolean track_target;
|
||||
|
||||
@Override
|
||||
public String getNameTag() {
|
||||
return "minecraft:behavior.melee_attack";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(EntityContentFactory factory, Object json) {
|
||||
if(json instanceof JSONObject object){
|
||||
MeleeAttackComponent component = new MeleeAttackComponent();
|
||||
|
||||
component.priority = object.optInt("priority", priority);
|
||||
component.speed_multiplier = object.optFloat("speed_multiplier", speed_multiplier);
|
||||
component.track_target = object.optBoolean("track_target", track_target);
|
||||
|
||||
factory.meleeAttackComponent = component;
|
||||
}else
|
||||
Logger.warning("Not support MeleeAttackComponent "+json.getClass());
|
||||
}
|
||||
}
|
||||
+65
-4
@@ -1,21 +1,82 @@
|
||||
package com.reider745.behavior.entities.formats.tags.components.attack;
|
||||
|
||||
import cn.nukkit.entity.Entity;
|
||||
import com.reider745.behavior.api.VanillaMobsFamily;
|
||||
import com.reider745.behavior.entities.ComponentsTag;
|
||||
import com.reider745.behavior.entities.EntityContentFactory;
|
||||
import com.zhekasmirnov.horizon.runtime.logger.Logger;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class NearestAttackableTarget extends ComponentsTag {
|
||||
public interface Condition {
|
||||
boolean test(Entity entity);
|
||||
}
|
||||
|
||||
private static class IsFamilyCondition implements Condition {
|
||||
private final String other, value;
|
||||
|
||||
public IsFamilyCondition(JSONObject obj){
|
||||
other = obj.getString("subject");
|
||||
value = obj.getString("value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Entity entity) {
|
||||
switch (other){
|
||||
case "other" -> {
|
||||
return VanillaMobsFamily.getFor(entity.getNetworkId()).contains(this.value);
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("not support NearestAttackableTarget.IsFamilyCondition");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Filters {
|
||||
public int max_dist;
|
||||
public int attack_interval ;
|
||||
public ArrayList<Condition> filters = new ArrayList<>();
|
||||
|
||||
public Filters(JSONObject json){
|
||||
max_dist = json.getInt("max_dist");
|
||||
attack_interval = json.getInt("attack_interval");
|
||||
|
||||
final JSONArray any_of = json.getJSONObject("filters").getJSONArray("any_of");
|
||||
for(int i = 0;i < any_of.length();i++){
|
||||
JSONObject condition = any_of.getJSONObject(i);
|
||||
|
||||
switch (condition.getString("test")){
|
||||
case "is_family" ->
|
||||
filters.add(new IsFamilyCondition(condition));
|
||||
default ->
|
||||
throw new RuntimeException("Not support NearestAttackableTarget.Filters");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int priority = 1;
|
||||
public ArrayList<Filters> list = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public String getNameTag() {
|
||||
return "minecraft:behavior.nearest_attackable_target";
|
||||
}
|
||||
|
||||
private interface Condition {
|
||||
boolean test(Entity entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(EntityContentFactory factory, Object json) {
|
||||
if(json instanceof JSONObject object){
|
||||
NearestAttackableTarget self = new NearestAttackableTarget();
|
||||
|
||||
self.priority = object.getInt("priority");
|
||||
final JSONArray entity_types = object.getJSONArray("entity_types");
|
||||
for(int i = 0;i < entity_types.length();i++)
|
||||
self.list.add(new Filters(entity_types.getJSONObject(i)));
|
||||
|
||||
factory.nearestAttackableTarget = self;
|
||||
}else
|
||||
Logger.warning("Not support NearestAttackableTarget "+json.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user