diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/configs/ConfigDebugSingleEvents.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/configs/ConfigDebugSingleEvents.java index b5378d8..3095e78 100644 --- a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/configs/ConfigDebugSingleEvents.java +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/configs/ConfigDebugSingleEvents.java @@ -17,16 +17,6 @@ public final class ConfigDebugSingleEvents implements IConfig */ private static boolean instanceExists = false; - /** - * - */ - public static boolean DebugActionAddEnemyToLog = false; - - /** - * - */ - public static boolean DebugActionPanicToIdLog = false; - /** * */ @@ -58,19 +48,7 @@ public void init(FMLPreInitializationEvent event) @Override public void readProperties(Configuration configuration) { - DebugActionAddEnemyToLog = this.getConfigValueB( - configuration, - "Debug Action 'AddEnemy'", - "actions_single_events", - DebugActionAddEnemyToLog, - "Tracks the logical action of 'addEnemy'"); - DebugActionPanicToIdLog = this.getConfigValueB( - configuration, - "Debug Action 'AddPanicToId'", - "actions_single_events", - DebugActionPanicToIdLog, - "Tracks the logical action of 'addPanicToId'"); } /** diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsConsumer.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsConsumer.java index bce7e06..419a85e 100644 --- a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsConsumer.java +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsConsumer.java @@ -44,7 +44,7 @@ import java.util.function.Function; import static org.imesense.dynamicspawncontrol.technical.customlibrary.MultipleKeyWords.CommonKeyWorlds.*; -import static org.imesense.dynamicspawncontrol.technical.customlibrary.MultipleKeyWords.MobsTaskManager.*; +import static org.imesense.dynamicspawncontrol.technical.customlibrary.MultipleKeyWords.MobTaskManager.*; /** * @@ -71,26 +71,6 @@ public ListActionsConsumer() */ protected void addActions(AttributeMap map) { - if (map.has(ENEMIES_TO) && map.has(TO_THEM)) - { - this.addEnemy(map, ConfigDebugSingleEvents.DebugActionAddEnemyToLog); - } - - if (map.has(ENEMIES_TO) && map.has(ENEMY_ID)) - { - this.addEnemyId(map, ConfigDebugSingleEvents.DebugActionAddEnemyToLog); - } - - if (map.has(PANIC_TO) && map.has(PANIC_ID)) - { - this.addPanicToId(map, ConfigDebugSingleEvents.DebugActionPanicToIdLog); - } - - if (map.has(ENEMY_ID) && map.has(THEM_ID)) - { - this.addEnemyToIdThemToId(map, ConfigDebugSingleEvents.DebugActionAddEnemyToLog); - } - if (map.has(ACTION_MESSAGE)) { this.addDoMessageAction(map); @@ -207,659 +187,6 @@ protected void addActions(AttributeMap map) } } - /** - * - * @param map - * @param localDebug - */ - private void addEnemy(AttributeMap map, boolean localDebug) - { - List enemiesTo = map.getList(ENEMIES_TO); - List toThem = map.getList(TO_THEM); - - if (enemiesTo.size() == 1 && toThem.size() == 1) - { - String enemiesTo_s = enemiesTo.get(0); - String toThem_s = toThem.get(0); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 1: %s, %s", enemiesTo_s, toThem_s)); - } - - String enemiesTo_s_id = GenericOverrideSpawn.fixEntityId(enemiesTo_s); - String toThem_s_id = GenericOverrideSpawn.fixEntityId(toThem_s); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 2: %s, %s", enemiesTo_s_id, toThem_s_id)); - } - - EntityEntry e_enemiesTo_forgeRegEntity = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(enemiesTo_s_id)); - EntityEntry e_toThem_forgeRegEntity = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(toThem_s_id)); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 3: %s, %s", e_enemiesTo_forgeRegEntity, e_toThem_forgeRegEntity)); - } - - Class typeClassEnemiesTo = e_enemiesTo_forgeRegEntity == null ? null : e_enemiesTo_forgeRegEntity.getEntityClass(); - Class typeClassToThem = e_toThem_forgeRegEntity == null ? null : e_toThem_forgeRegEntity.getEntityClass(); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 4: %s, %s", typeClassEnemiesTo, typeClassToThem)); - } - - if (typeClassEnemiesTo != null && localDebug) - { - Log.writeDataToLogFile(0, "Added entity: " + typeClassEnemiesTo.getName()); - } - - if (typeClassToThem != null && localDebug) - { - Log.writeDataToLogFile(0, "Added entity: " + typeClassToThem.getName()); - } - - if (typeClassEnemiesTo != null && typeClassToThem != null) - { - this.ACTIONS.add(event -> - { - EntityLiving entity = (EntityLiving) event.getEntityLiving(); - - if (typeClassEnemiesTo.isInstance(entity)) - { - entity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) entity, typeClassToThem.asSubclass(EntityLiving.class), true)); - - if (localDebug) - { - Log.writeDataToLogFile(0, "Added attack target task for entity: " + typeClassEnemiesTo.getName() + " targeting " + typeClassToThem.getName()); - } - } - else if (typeClassToThem.isInstance(entity)) - { - entity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) entity, typeClassEnemiesTo.asSubclass(EntityLiving.class), true)); - - if (localDebug) - { - Log.writeDataToLogFile(0, "Added attack target task for entity: " + typeClassToThem.getName() + " targeting " + typeClassEnemiesTo.getName()); - } - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Entity type mismatch, cannot add attack target task."); - } - } - }); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Failed to add attack target task: Entity class not found for one or both entities."); - } - } - } - else - { - Set> classesEnemiesTo = new HashSet<>(); - Set> classesToThem = new HashSet<>(); - - for (String fEnemiesTo : enemiesTo) - { - String enemiesTo_s_id = GenericOverrideSpawn.fixEntityId(fEnemiesTo); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 1.1: %s", enemiesTo_s_id)); - } - - EntityEntry e_enemiesTo_forgeRegEntity = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(enemiesTo_s_id)); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 2.1: %s", e_enemiesTo_forgeRegEntity)); - } - - Class typeClassEnemiesTo = e_enemiesTo_forgeRegEntity == null ? null : e_enemiesTo_forgeRegEntity.getEntityClass(); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 3.1: %s", typeClassEnemiesTo)); - } - - if (typeClassEnemiesTo != null) - { - classesEnemiesTo.add((Class) typeClassEnemiesTo); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(2, "Unknown mob '" + enemiesTo + "'!"); - } - } - } - - for (String fToThem : toThem) - { - String toThem_s_id = GenericOverrideSpawn.fixEntityId(fToThem); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 1.2: %s", toThem_s_id)); - } - - EntityEntry e_toThem_forgeRegEntity = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(toThem_s_id)); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 2.2: %s", e_toThem_forgeRegEntity)); - } - - Class typeClassToThem = e_toThem_forgeRegEntity == null ? null : e_toThem_forgeRegEntity.getEntityClass(); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 3.2: %s", typeClassToThem)); - } - - if (typeClassToThem != null) - { - classesToThem.add((Class) typeClassToThem); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(2, "Unknown mob '" + toThem + "'!"); - } - } - } - - if (!classesEnemiesTo.isEmpty() && !classesToThem.isEmpty()) - { - this.ACTIONS.add(event -> - { - EntityLiving entity = (EntityLiving) event.getEntityLiving(); - Class entityClass = entity.getClass(); - - if (classesEnemiesTo.contains(entityClass)) - { - for (Class targetClass : classesToThem) - { - entity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) entity, targetClass, true)); - - if (localDebug) - { - Log.writeDataToLogFile(0, "Added attack target task for entity: " + entityClass.getName() + " targeting " + targetClass.getName()); - } - } - } - else if (classesToThem.contains(entityClass)) - { - for (Class targetClass : classesEnemiesTo) - { - entity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) entity, targetClass, true)); - - if (localDebug) - { - Log.writeDataToLogFile(0, "Added attack target task for entity: " + entityClass.getName() + " targeting " + targetClass.getName()); - } - } - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Entity type mismatch, cannot add attack target task."); - } - } - }); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Failed to add attack target task: No valid entity classes found."); - } - } - } - } - - /** - * - * @param map - * @param localDebug - */ - private void addEnemyId(AttributeMap map, boolean localDebug) - { - List enemiesTo = map.getList(ENEMIES_TO); - List enemyIdPrefixes = map.getList(ENEMY_ID); - - Set> classesEnemiesTo = new HashSet<>(); - Set> classesEnemyId = new HashSet<>(); - - try - { - for (String fEnemiesTo : enemiesTo) - { - String enemiesTo_s_id = GenericOverrideSpawn.fixEntityId(fEnemiesTo); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 1.1: %s", enemiesTo_s_id)); - } - - EntityEntry e_enemiesTo_forgeRegEntity = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(enemiesTo_s_id)); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 2.1: %s", e_enemiesTo_forgeRegEntity)); - } - - Class typeClassEnemiesTo = e_enemiesTo_forgeRegEntity == null ? null : e_enemiesTo_forgeRegEntity.getEntityClass(); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 3.1: %s", typeClassEnemiesTo)); - } - - if (typeClassEnemiesTo != null && EntityLiving.class.isAssignableFrom(typeClassEnemiesTo)) - { - classesEnemiesTo.add((Class) typeClassEnemiesTo); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(2, "Unknown or incompatible mob '" + enemiesTo + "'!"); - } - } - } - - for (String enemyIdPrefix : enemyIdPrefixes) - { - for (EntityEntry entityEntry : ForgeRegistries.ENTITIES) - { - if (entityEntry.getRegistryName().toString().startsWith(enemyIdPrefix)) - { - Class typeClassEnemyId = entityEntry.getEntityClass(); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 1.2: %s", entityEntry.getRegistryName().toString())); - } - - if (typeClassEnemyId != null && EntityLiving.class.isAssignableFrom(typeClassEnemyId)) - { - classesEnemyId.add((Class) typeClassEnemyId); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(2, "Unknown or incompatible mob with prefix '" + enemyIdPrefix + "'!"); - } - } - } - } - } - - if (!classesEnemiesTo.isEmpty() && !classesEnemyId.isEmpty()) - { - this.ACTIONS.add(event -> - { - try - { - EntityLiving entity = (EntityLiving) event.getEntityLiving(); - Class entityClass = entity.getClass(); - - if (localDebug) - { - Log.writeDataToLogFile(0, "Event entity: " + entityClass.getName()); - } - - if (classesEnemiesTo.contains(entityClass)) - { - for (Class targetClass : classesEnemyId) - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Adding attack task for: " + entityClass.getName() + " targeting " + targetClass.getName()); - } - - entity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) entity, targetClass, true)); - - if (localDebug) - { - Log.writeDataToLogFile(0, "Added attack target task for entity: " + entityClass.getName() + " targeting " + targetClass.getName()); - } - } - } - else if (classesEnemyId.contains(entityClass)) - { - for (Class targetClass : classesEnemiesTo) - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Adding attack task for: " + entityClass.getName() + " targeting " + targetClass.getName()); - } - - entity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) entity, targetClass, true)); - - if (localDebug) - { - Log.writeDataToLogFile(0, "Added attack target task for entity: " + entityClass.getName() + " targeting " + targetClass.getName()); - } - } - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Entity type mismatch, cannot add attack target task."); - } - } - } - catch (Exception exception) - { - Log.writeDataToLogFile(2, "Error in event action: " + exception.getMessage()); - } - }); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Failed to add attack target task: No valid entity classes found."); - } - } - } - catch (Exception exception) - { - Log.writeDataToLogFile(2, "Error in addEnemyId method: " + exception.getMessage()); - } - } - - /** - * - * @param map - * @param localDebug - */ - private void addPanicToId(AttributeMap map, boolean localDebug) - { - List panicTo = map.getList(PANIC_TO); - List panicIdPrefixes = map.getList(PANIC_ID); - - Set> classesPanicTo = new HashSet<>(); - Set> classesPanicId = new HashSet<>(); - - try - { - for (String fPanicTo : panicTo) - { - String panicTo_s_id = GenericOverrideSpawn.fixEntityId(fPanicTo); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 1.1: %s", panicTo_s_id)); - } - - EntityEntry e_panicTo_forgeRegEntity = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(panicTo_s_id)); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 2.1: %s", e_panicTo_forgeRegEntity)); - } - - Class typeClassPanicTo = e_panicTo_forgeRegEntity == null ? null : e_panicTo_forgeRegEntity.getEntityClass(); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 3.1: %s", typeClassPanicTo)); - } - - if (typeClassPanicTo != null && EntityLiving.class.isAssignableFrom(typeClassPanicTo)) - { - classesPanicTo.add((Class) typeClassPanicTo); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(2, "Unknown or incompatible mob '" + panicTo + "'!"); - } - } - } - - for (String fPanicIdPrefix : panicIdPrefixes) - { - for (EntityEntry entityEntry : ForgeRegistries.ENTITIES) - { - if (entityEntry.getRegistryName().toString().startsWith(fPanicIdPrefix)) - { - Class typeClassPanicId = entityEntry.getEntityClass(); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 1.2: %s", entityEntry.getRegistryName().toString())); - } - - if (typeClassPanicId != null && EntityLiving.class.isAssignableFrom(typeClassPanicId)) - { - classesPanicId.add((Class) typeClassPanicId); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(2, "Unknown or incompatible mob with prefix '" + fPanicIdPrefix + "'!"); - } - } - } - } - } - - if (!classesPanicTo.isEmpty() && !classesPanicId.isEmpty()) - { - this.ACTIONS.add(event -> - { - try - { - EntityLiving entity = (EntityLiving) event.getEntityLiving(); - Class entityClass = entity.getClass(); - - if (localDebug) - { - Log.writeDataToLogFile(0, "Event entity: " + entityClass.getName()); - } - - if (classesPanicTo.contains(entityClass)) - { - for (Class panicClass : classesPanicId) - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Adding panic task for: " + entityClass.getName() + " avoiding " + panicClass.getName()); - } - - entity.tasks.addTask(1, new EntityAIAvoidEntity<>((EntityCreature) entity, panicClass, 16.0F, 1.5D, 2.0D)); - - if (localDebug) - { - Log.writeDataToLogFile(0, "Added panic task for entity: " + entityClass.getName() + " avoiding " + panicClass.getName()); - } - } - } - } - catch (Exception exception) - { - Log.writeDataToLogFile(2, "Error in event action: " + exception.getMessage()); - } - }); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Failed to add panic task: No valid entity classes found."); - } - } - } - catch (Exception exception) - { - Log.writeDataToLogFile(2, "Error in addPanicToId method: " + exception.getMessage()); - } - } - - /** - * - * @param map - * @param localDebug - */ - private void addEnemyToIdThemToId(AttributeMap map, boolean localDebug) - { - List listEnemyId = map.getList(ENEMY_ID); - List listThemId = map.getList(THEM_ID); - - Set> classesEnemyId = new HashSet<>(); - Set> classesThemId = new HashSet<>(); - - try - { - for (String enemyIdPrefix : listEnemyId) - { - for (EntityEntry entityEntry : ForgeRegistries.ENTITIES) - { - if (entityEntry.getRegistryName().toString().startsWith(enemyIdPrefix)) - { - Class typeClassEnemyId = entityEntry.getEntityClass(); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 1.1: %s", entityEntry.getRegistryName().toString())); - } - - if (typeClassEnemyId != null && EntityLiving.class.isAssignableFrom(typeClassEnemyId)) - { - classesEnemyId.add((Class) typeClassEnemyId); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(2, "Unknown or incompatible mob with prefix '" + enemyIdPrefix + "'!"); - } - } - } - } - } - - for (String themIdPrefix : listThemId) - { - for (EntityEntry entityEntry : ForgeRegistries.ENTITIES) - { - if (entityEntry.getRegistryName().toString().startsWith(themIdPrefix)) - { - Class typeClassThemId = entityEntry.getEntityClass(); - - if (localDebug) - { - Log.writeDataToLogFile(0, String.format("Step 1.2: %s", entityEntry.getRegistryName().toString())); - } - - if (typeClassThemId != null && EntityLiving.class.isAssignableFrom(typeClassThemId)) - { - classesThemId.add((Class) typeClassThemId); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(2, "Unknown or incompatible mob with prefix '" + themIdPrefix + "'!"); - } - } - } - } - } - - if (!classesEnemyId.isEmpty() && !classesThemId.isEmpty()) - { - this.ACTIONS.add(event -> - { - try - { - EntityLiving entity = (EntityLiving) event.getEntityLiving(); - Class entityClass = entity.getClass(); - - if (localDebug) - { - Log.writeDataToLogFile(0, "Event entity: " + entityClass.getName()); - } - - if (classesEnemyId.contains(entityClass)) - { - for (Class targetClass : classesThemId) - { - if (localDebug) { - Log.writeDataToLogFile(0, "Adding attack task for: " + entityClass.getName() + " targeting " + targetClass.getName()); - } - - entity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) entity, targetClass, true)); - - if (localDebug) { - Log.writeDataToLogFile(0, "Added attack target task for entity: " + entityClass.getName() + " targeting " + targetClass.getName()); - } - } - } - else if (classesThemId.contains(entityClass)) - { - for (Class targetClass : classesEnemyId) - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Adding attack task for: " + entityClass.getName() + " targeting " + targetClass.getName()); - } - - entity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) entity, targetClass, true)); - - if (localDebug) - { - Log.writeDataToLogFile(0, "Added attack target task for entity: " + entityClass.getName() + " targeting " + targetClass.getName()); - } - } - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Entity type mismatch, cannot add attack target task."); - } - } - } - catch (Exception exception) - { - Log.writeDataToLogFile(2, "Error in event action: " + exception.getMessage()); - } - }); - } - else - { - if (localDebug) - { - Log.writeDataToLogFile(0, "Failed to add attack target task: No valid entity classes found."); - } - } - } - catch (Exception exception) - { - Log.writeDataToLogFile(2, "Error in addEnemyToIdThemToId method: " + exception.getMessage()); - } - } - /** * * @param map diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsConsumerMobTaskManager.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsConsumerMobTaskManager.java new file mode 100644 index 0000000..42f98dd --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsConsumerMobTaskManager.java @@ -0,0 +1,387 @@ +package org.imesense.dynamicspawncontrol.technical.customlibrary; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityCreature; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.ai.EntityAIAvoidEntity; +import net.minecraft.entity.ai.EntityAINearestAttackableTarget; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.registry.EntityEntry; +import net.minecraftforge.fml.common.registry.ForgeRegistries; +import org.imesense.dynamicspawncontrol.technical.attributefactory.AttributeMap; +import org.imesense.dynamicspawncontrol.technical.eventprocessor.generic.GenericOverrideSpawn; +import org.imesense.dynamicspawncontrol.technical.eventprocessor.signal.SignalDataGetter; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.function.Consumer; + +import static org.imesense.dynamicspawncontrol.technical.customlibrary.MultipleKeyWords.MobTaskManager.*; + +/** + * + * @param + */ +public abstract class ListActionsConsumerMobTaskManager +{ + /** + * + */ + protected final List> ACTIONS = new ArrayList<>(); + + /** + * + */ + public ListActionsConsumerMobTaskManager() + { + + } + + /** + * + * @param map + */ + protected void addActions(AttributeMap map) + { + /** + * + */ + final boolean hasEnemiesTo = map.has(ENEMIES_TO); + final boolean hasToThem = map.has(TO_THEM); + + /** + * + */ + final boolean hasEnemyId = map.has(ENEMY_ID); + final boolean hasThemId = map.has(THEM_ID); + + /** + * + */ + final boolean hasPanicTo = map.has(PANIC_TO); + final boolean hasPanicId = map.has(PANIC_ID); + + try + { + if (hasEnemiesTo && hasToThem) + { + this.addEnemy(map); + } + else if (hasEnemiesTo && hasEnemyId) + { + this.addEnemyId(map); + } + else if (hasPanicTo && hasPanicId) + { + this.addPanicToId(map); + } + else if (hasEnemyId && hasThemId) + { + this.addEnemyToIdThemToId(map); + } + else + { + Log.writeDataToLogFile(2, "None of the required conditions were met in addActions."); + throw new IllegalArgumentException("Error: Invalid attribute map configuration in addActions. Required conditions not met."); + } + } + catch (Exception exception) + { + Log.writeDataToLogFile(2, "Exception: " + exception.getMessage()); + throw exception; + } + } + + /** + * + * @param map + */ + private void addEnemy(AttributeMap map) + { + List enemiesToList = map.getList(ENEMIES_TO); + List targetList = map.getList(TO_THEM); + + if (enemiesToList.size() == 1 && targetList.size() == 1) + { + String enemyToId = enemiesToList.get(0); + String targetId = targetList.get(0); + + String fixedEnemyToId = GenericOverrideSpawn.fixEntityId(enemyToId); + String fixedTargetId = GenericOverrideSpawn.fixEntityId(targetId); + + EntityEntry enemyToEntityEntry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(fixedEnemyToId)); + EntityEntry targetEntityEntry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(fixedTargetId)); + + Class enemyToEntityClass = enemyToEntityEntry == null ? null : enemyToEntityEntry.getEntityClass(); + Class targetEntityClass = targetEntityEntry == null ? null : targetEntityEntry.getEntityClass(); + + if (enemyToEntityClass != null && targetEntityClass != null) + { + this.ACTIONS.add(event -> + { + EntityLiving currentEntity = (EntityLiving) event.getEntityLiving(); + + if (enemyToEntityClass.isInstance(currentEntity)) + { + currentEntity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) currentEntity, targetEntityClass.asSubclass(EntityLiving.class), true)); + } + else if (targetEntityClass.isInstance(currentEntity)) + { + currentEntity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) currentEntity, enemyToEntityClass.asSubclass(EntityLiving.class), true)); + } + }); + } + } + else + { + Set> enemyClassesSet = new HashSet<>(); + Set> targetClassesSet = new HashSet<>(); + + for (String enemyToId : enemiesToList) + { + String fixedEnemyToId = GenericOverrideSpawn.fixEntityId(enemyToId); + + EntityEntry enemyToEntityEntry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(fixedEnemyToId)); + Class enemyToEntityClass = enemyToEntityEntry == null ? null : enemyToEntityEntry.getEntityClass(); + + if (enemyToEntityClass != null) + { + enemyClassesSet.add((Class) enemyToEntityClass); + } + } + + for (String targetId : targetList) + { + String fixedTargetId = GenericOverrideSpawn.fixEntityId(targetId); + + EntityEntry targetEntityEntry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(fixedTargetId)); + Class targetEntityClass = targetEntityEntry == null ? null : targetEntityEntry.getEntityClass(); + + if (targetEntityClass != null) + { + targetClassesSet.add((Class) targetEntityClass); + } + } + + if (!enemyClassesSet.isEmpty() && !targetClassesSet.isEmpty()) + { + this.ACTIONS.add(event -> + { + EntityLiving currentEntity = (EntityLiving) event.getEntityLiving(); + Class entityClass = currentEntity.getClass(); + + if (enemyClassesSet.contains(entityClass)) + { + for (Class targetClass : targetClassesSet) + { + currentEntity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) currentEntity, targetClass, true)); + } + } + else if (targetClassesSet.contains(entityClass)) + { + for (Class enemyClass : enemyClassesSet) + { + currentEntity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) currentEntity, enemyClass, true)); + } + } + }); + } + } + } + + /** + * + * @param map + */ + private void addEnemyId(AttributeMap map) + { + List enemiesToList = map.getList(ENEMIES_TO); + List enemyIdPrefixList = map.getList(ENEMY_ID); + + Set> enemyClassesSet = new HashSet<>(); + Set> enemyIdClassesSet = new HashSet<>(); + + for (String enemyToId : enemiesToList) + { + String fixedEnemyToId = GenericOverrideSpawn.fixEntityId(enemyToId); + EntityEntry enemyToEntityEntry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(fixedEnemyToId)); + Class enemyToEntityClass = enemyToEntityEntry == null ? null : enemyToEntityEntry.getEntityClass(); + + if (enemyToEntityClass != null && EntityLiving.class.isAssignableFrom(enemyToEntityClass)) + { + enemyClassesSet.add((Class) enemyToEntityClass); + } + } + + for (String enemyIdPrefix : enemyIdPrefixList) + { + for (EntityEntry entityEntry : ForgeRegistries.ENTITIES) + { + if (entityEntry.getRegistryName().toString().startsWith(enemyIdPrefix)) + { + Class entityClassFromRegistry = entityEntry.getEntityClass(); + + if (entityClassFromRegistry != null && EntityLiving.class.isAssignableFrom(entityClassFromRegistry)) + { + enemyIdClassesSet.add((Class) entityClassFromRegistry); + } + } + } + } + + if (!enemyClassesSet.isEmpty() && !enemyIdClassesSet.isEmpty()) + { + this.ACTIONS.add(event -> + { + EntityLiving currentEntity = (EntityLiving) event.getEntityLiving(); + Class currentEntityClass = currentEntity.getClass(); + + if (enemyClassesSet.contains(currentEntityClass)) + { + for (Class targetClass : enemyIdClassesSet) + { + currentEntity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) currentEntity, targetClass, true)); + } + } + else if (enemyIdClassesSet.contains(currentEntityClass)) + { + for (Class targetClass : enemyClassesSet) + { + currentEntity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) currentEntity, targetClass, true)); + } + } + }); + } + } + + /** + * + * @param map + */ + private void addPanicToId(AttributeMap map) + { + List panicToList = map.getList(PANIC_TO); + List panicIdPrefixList = map.getList(PANIC_ID); + + Set> panicToClassesSet = new HashSet<>(); + Set> panicIdClassesSet = new HashSet<>(); + + for (String panicToId : panicToList) + { + String fixedPanicToId = GenericOverrideSpawn.fixEntityId(panicToId); + + EntityEntry panicToEntityEntry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(fixedPanicToId)); + + Class panicToEntityClass = panicToEntityEntry == null ? null : panicToEntityEntry.getEntityClass(); + + if (panicToEntityClass != null && EntityLiving.class.isAssignableFrom(panicToEntityClass)) + { + panicToClassesSet.add((Class) panicToEntityClass); + } + } + + for (String panicIdPrefix : panicIdPrefixList) + { + for (EntityEntry entityEntry : ForgeRegistries.ENTITIES) + { + if (entityEntry.getRegistryName().toString().startsWith(panicIdPrefix)) + { + Class panicIdEntityClass = entityEntry.getEntityClass(); + + if (panicIdEntityClass != null && EntityLiving.class.isAssignableFrom(panicIdEntityClass)) + { + panicIdClassesSet.add((Class) panicIdEntityClass); + } + } + } + } + + if (!panicToClassesSet.isEmpty() && !panicIdClassesSet.isEmpty()) + { + this.ACTIONS.add(event -> + { + EntityLiving currentEntity = (EntityLiving) event.getEntityLiving(); + Class currentEntityClass = currentEntity.getClass(); + + if (panicToClassesSet.contains(currentEntityClass)) + { + for (Class panicClass : panicIdClassesSet) + { + currentEntity.tasks.addTask(1, new EntityAIAvoidEntity<>((EntityCreature) currentEntity, panicClass, 16.0F, 1.5D, 2.0D)); + } + } + }); + } + } + + /** + * + * @param map + */ + private void addEnemyToIdThemToId(AttributeMap map) + { + List enemyIdList = map.getList(ENEMY_ID); + List themIdList = map.getList(THEM_ID); + + Set> enemyIdClassesSet = new HashSet<>(); + Set> themIdClassesSet = new HashSet<>(); + + for (String enemyIdPrefix : enemyIdList) + { + for (EntityEntry entityEntry : ForgeRegistries.ENTITIES) + { + if (entityEntry.getRegistryName().toString().startsWith(enemyIdPrefix)) + { + Class enemyEntityClass = entityEntry.getEntityClass(); + + if (enemyEntityClass != null && EntityLiving.class.isAssignableFrom(enemyEntityClass)) + { + enemyIdClassesSet.add((Class) enemyEntityClass); + } + } + } + } + + for (String themIdPrefix : themIdList) + { + for (EntityEntry entityEntry : ForgeRegistries.ENTITIES) + { + if (entityEntry.getRegistryName().toString().startsWith(themIdPrefix)) + { + Class themEntityClass = entityEntry.getEntityClass(); + + if (themEntityClass != null && EntityLiving.class.isAssignableFrom(themEntityClass)) + { + themIdClassesSet.add((Class) themEntityClass); + } + } + } + } + + if (!enemyIdClassesSet.isEmpty() && !themIdClassesSet.isEmpty()) + { + this.ACTIONS.add(event -> + { + EntityLiving currentEntity = (EntityLiving) event.getEntityLiving(); + Class currentEntityClass = currentEntity.getClass(); + + if (enemyIdClassesSet.contains(currentEntityClass)) + { + for (Class targetClass : themIdClassesSet) + { + currentEntity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) currentEntity, targetClass, true)); + } + } + else if (themIdClassesSet.contains(currentEntityClass)) + { + for (Class targetClass : enemyIdClassesSet) + { + currentEntity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) currentEntity, targetClass, true)); + } + } + }); + } + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/MultipleKeyWords.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/MultipleKeyWords.java index 880448f..0a86a5c 100644 --- a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/MultipleKeyWords.java +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/MultipleKeyWords.java @@ -183,10 +183,10 @@ public static class PotentialSpawn /* * ********************************************************************************************************************* - * Индивидуальные ключевые слова (MobsTaskManager.json) + * Индивидуальные ключевые слова (MobTaskManager.json) * ********************************************************************************************************************* */ - public static class MobsTaskManager + public static class MobTaskManager { public static final AttributeKey ENEMIES_TO = AttributeKey.create(AttributeType.STRING, "enemies_to"); public static final AttributeKey ENEMY_ID = AttributeKey.create(AttributeType.STRING, "enemy_id"); diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/eventprocessor/generic/GenericMobsTaskManager.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/eventprocessor/generic/GenericMobTaskManager.java similarity index 94% rename from dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/eventprocessor/generic/GenericMobsTaskManager.java rename to dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/eventprocessor/generic/GenericMobTaskManager.java index 2a4fcea..aeef684 100644 --- a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/eventprocessor/generic/GenericMobsTaskManager.java +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/eventprocessor/generic/GenericMobTaskManager.java @@ -13,7 +13,7 @@ import org.imesense.dynamicspawncontrol.technical.attributefactory.AttributeMap; import org.imesense.dynamicspawncontrol.technical.attributefactory.AttributeMapFactory; import org.imesense.dynamicspawncontrol.technical.customlibrary.ListActionsBinary; -import org.imesense.dynamicspawncontrol.technical.customlibrary.ListActionsConsumer; +import org.imesense.dynamicspawncontrol.technical.customlibrary.ListActionsConsumerMobTaskManager; import org.imesense.dynamicspawncontrol.technical.customlibrary.Log; import org.imesense.dynamicspawncontrol.technical.eventprocessor.signal.SignalDataAccessor; import org.imesense.dynamicspawncontrol.technical.eventprocessor.signal.SignalDataGetter; @@ -21,12 +21,12 @@ import java.util.function.Consumer; import static org.imesense.dynamicspawncontrol.technical.customlibrary.MultipleKeyWords.CommonKeyWorlds.*; -import static org.imesense.dynamicspawncontrol.technical.customlibrary.MultipleKeyWords.MobsTaskManager.*; +import static org.imesense.dynamicspawncontrol.technical.customlibrary.MultipleKeyWords.MobTaskManager.*; /** * */ -public final class GenericMobsTaskManager extends ListActionsConsumer +public final class GenericMobTaskManager extends ListActionsConsumerMobTaskManager { /** * @@ -54,11 +54,11 @@ public final class GenericMobsTaskManager extends ListActionsConsumer map) + private GenericMobTaskManager(AttributeMap map) { super(); - Log.writeDataToLogFile(0, String.format("Iterator for [%s] number [%d]", GenericMobsTaskManager.class.getName(), countCreatedMaps++)); + Log.writeDataToLogFile(0, String.format("Iterator for [%s] number [%d]", GenericMobTaskManager.class.getName(), countCreatedMaps++)); this.RULE_EVALUATOR = new ListActionsBinary<>(map); @@ -70,7 +70,7 @@ private GenericMobsTaskManager(AttributeMap map) * @param element * @return */ - public static GenericMobsTaskManager parse(JsonElement element) + public static GenericMobTaskManager parse(JsonElement element) { if (element == null) { @@ -80,7 +80,7 @@ public static GenericMobsTaskManager parse(JsonElement element) { AttributeMap map = FACTORY.parse(element); - return new GenericMobsTaskManager(map); + return new GenericMobTaskManager(map); } } diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/eventprocessor/script/multiple/OnMobsTaskManager.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/eventprocessor/script/multiple/OnMobTaskManager.java similarity index 85% rename from dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/eventprocessor/script/multiple/OnMobsTaskManager.java rename to dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/eventprocessor/script/multiple/OnMobTaskManager.java index 6a809c8..da09010 100644 --- a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/eventprocessor/script/multiple/OnMobsTaskManager.java +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/eventprocessor/script/multiple/OnMobTaskManager.java @@ -9,14 +9,14 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.imesense.dynamicspawncontrol.debug.CodeGenericUtils; import org.imesense.dynamicspawncontrol.technical.customlibrary.Log; -import org.imesense.dynamicspawncontrol.technical.eventprocessor.generic.GenericMobsTaskManager; +import org.imesense.dynamicspawncontrol.technical.eventprocessor.generic.GenericMobTaskManager; import org.imesense.dynamicspawncontrol.technical.parsers.ParserGenericJsonScripts; /** * */ @Mod.EventBusSubscriber -public final class OnMobsTaskManager +public final class OnMobTaskManager { /** * @@ -26,7 +26,7 @@ public final class OnMobsTaskManager /** * */ - public OnMobsTaskManager() + public OnMobTaskManager() { if (instanceExists) { @@ -36,7 +36,7 @@ public OnMobsTaskManager() instanceExists = true; - CodeGenericUtils.printInitClassToLog(OnMobsTaskManager.class); + CodeGenericUtils.printInitClassToLog(OnMobTaskManager.class); } /** @@ -53,7 +53,7 @@ public synchronized void onUpdateEntityJoinWorld_0(EntityJoinWorldEvent event) AtomicInteger i = new AtomicInteger(); - for (GenericMobsTaskManager rule : ParserGenericJsonScripts.GENERIC_MOBS_TASK_MANAGER_LIST) + for (GenericMobTaskManager rule : ParserGenericJsonScripts.GENERIC_MOBS_TASK_MANAGER_LIST) { if (rule.match(event)) { diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/initializer/RegisterTechnicalClasses.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/initializer/RegisterTechnicalClasses.java index 503831e..1d0a31c 100644 --- a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/initializer/RegisterTechnicalClasses.java +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/initializer/RegisterTechnicalClasses.java @@ -29,7 +29,7 @@ public final class RegisterTechnicalClasses OnLeftClickEvent.class, OnLivingDrops.class, OnLivingExperienceDrop.class, - OnMobsTaskManager.class, + OnMobTaskManager.class, OnPlayerEvents.class, OnPotentialSpawns.class, OnRightClickEvent.class, diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/parsers/ParserGenericJsonScripts.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/parsers/ParserGenericJsonScripts.java index d3c149a..b887257 100644 --- a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/parsers/ParserGenericJsonScripts.java +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/parsers/ParserGenericJsonScripts.java @@ -51,7 +51,7 @@ public final class ParserGenericJsonScripts /** * */ - public final static List GENERIC_MOBS_TASK_MANAGER_LIST = new ArrayList<>(); + public final static List GENERIC_MOBS_TASK_MANAGER_LIST = new ArrayList<>(); /** * @@ -137,8 +137,8 @@ private static void readAllRules() GenericSpawnConditions::parse, GENERIC_SPAWN_CONDITIONS_LIST, ARRAY_TYPE_SCRIPT[4]); // - CodeGenericUtils.readAndLogRules(path, "MobsTaskManager" + DynamicSpawnControl.STRUCT_FILES_EXTENSION.SCRIPT_FILE_EXTENSION, - GenericMobsTaskManager::parse, GENERIC_MOBS_TASK_MANAGER_LIST, ARRAY_TYPE_SCRIPT[4]); + CodeGenericUtils.readAndLogRules(path, "MobTaskManager" + DynamicSpawnControl.STRUCT_FILES_EXTENSION.SCRIPT_FILE_EXTENSION, + GenericMobTaskManager::parse, GENERIC_MOBS_TASK_MANAGER_LIST, ARRAY_TYPE_SCRIPT[4]); // CodeGenericUtils.readAndLogRules(path, "EventEffects" + DynamicSpawnControl.STRUCT_FILES_EXTENSION.SCRIPT_FILE_EXTENSION,