diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ItemStackBuilder.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ItemStackBuilder.java new file mode 100644 index 0000000..753c233 --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ItemStackBuilder.java @@ -0,0 +1,203 @@ +package org.imesense.dynamicspawncontrol.technical.customlibrary; + +/** + * + */ +public class ItemStackBuilder +{ + /** + * + * @param name + * @return + */ + public static Pair parseStackWithFactor(String name) + { + int i = 0; + + while (i < name.length() && (Character.isDigit(name.charAt(i)) || name.charAt(i) == '.')) + { + i++; + } + + if (i < name.length() && name.charAt(i) == '=') + { + String f = name.substring(0, i); + float v; + + try + { + v = Float.parseFloat(f); + } + catch (NumberFormatException e) + { + v = 1.0f; + } + + return Pair.of(v, parseStack(name.substring(i+1))); + } + + return Pair.of(1.0f, parseStack(name)); + } + + /** + * + * @param jsonObject + * @return + */ + public static Pair parseStackWithFactor(JsonObject jsonObject) + { + float factor = 1.0f; + + if (jsonObject.has("factor")) + { + factor = jsonObject.get("factor").getAsFloat(); + } + + ItemStack stack = parseStack(jsonObject); + + if (stack == null) + { + return null; + } + + return Pair.of(factor, stack); + } + + /** + * + * @param name + * @return + */ + @Nonnull + public static ItemStack parseStack(String name) + { + if (name.contains("/")) + { + String[] split = StringUtils.split(name, "/"); + ItemStack stack = parseStackNoNBT(split[0]); + + if (stack.isEmpty()) + { + return stack; + } + + NBTTagCompound nbt; + + try + { + nbt = JsonToNBT.getTagFromJson(split[1]); + } + catch (NBTException e) + { + Log.writeDataToLogFile(Log._typeLog[2], "Error parsing NBT in '" + name + "'!"); + return ItemStack.EMPTY; + } + + stack.setTagCompound(nbt); + return stack; + } + else + { + return parseStackNoNBT(name); + } + } + + /** + * + * @param jsonObject + * @return + */ + @Nullable + public static ItemStack parseStack(JsonObject jsonObject) + { + if (jsonObject.has("empty")) + { + return ItemStack.EMPTY; + } + + String name = jsonObject.get("item").getAsString(); + Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(name)); + + if (item == null) + { + Log.writeDataToLogFile(Log._typeLog[2], "Unknown item '" + name + "'!"); + return null; + } + + ItemStack stack = new ItemStack(item); + + if (jsonObject.has("damage")) + { + stack.setItemDamage(jsonObject.get("damage").getAsInt()); + } + + if (jsonObject.has("count")) + { + stack.setCount(jsonObject.get("count").getAsInt()); + } + + if (jsonObject.has("nbt")) + { + String nbt = jsonObject.get("nbt").toString(); + NBTTagCompound tag; + + try + { + tag = JsonToNBT.getTagFromJson(nbt); + } + catch (NBTException e) + { + Log.writeDataToLogFile(Log._typeLog[2], "Error parsing json '" + nbt + "'!"); + return ItemStack.EMPTY; + } + + stack.setTagCompound(tag); + } + + return stack; + } + + /** + * + * @param name + * @return + */ + private static ItemStack parseStackNoNBT(String name) + { + if (name.contains("@")) + { + String[] split = StringUtils.split(name, "@"); + Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(split[0])); + + if (item == null) + { + return ItemStack.EMPTY; + } + + int meta; + + try + { + meta = Integer.parseInt(split[1]); + } + catch (NumberFormatException e) + { + Log.writeDataToLogFile(Log._typeLog[2], "Unknown item '" + name + "'!"); + return ItemStack.EMPTY; + } + + return new ItemStack(item, 1, meta); + } + else + { + Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(name)); + + if (item == null) + { + return ItemStack.EMPTY; + } + + return new ItemStack(item); + } + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsBinary.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsBinary.java new file mode 100644 index 0000000..33eba1b --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsBinary.java @@ -0,0 +1,1337 @@ +package org.imesense.dynamicspawncontrol.technical.customlibrary; + +/** + * + * @param + */ +public class ListActionsBinary +{ + /** + * + */ + public final List> _arrayList = new ArrayList<>(); + + /** + * + * @param map + * @param nameClass + */ + public ListActionsBinary(AttributeMap map, String nameClass) + { + Log.writeDataToLogFile(Log._typeLog[0], nameClass); + this.CreateListActions(map); + } + + /** + * + * @param event + * @param query + * @return + */ + public boolean match(Event event, SignalDataAccessor query) + { + for (BiFunction rule : _arrayList) + { + if (!rule.apply(event, query)) + { + return false; + } + } + + return true; + } + + /** + * + * @param map + */ + public void CreateListActions(AttributeMap map) + { + if (map.has(KeyWordsGeneral.CommonKeyWorlds.SEE_SKY)) + { + this.addSeeSkyCheck(map); + } + + if (map.has(KeyWordsGeneral.SpawnCondition.CAN_SPAWN_HERE)) + { + this.addCanSpawnHereCheck(map); + } + + if (map.has(KeyWordsGeneral.SpawnCondition.NOT_COLLIDING)) + { + this.addNotCollidingCheck(map); + } + + if (map.has(KeyWordsGeneral.SpawnCondition.SPAWNER)) + { + this.addSpawnerCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.WEATHER)) + { + this.addWeatherCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.BIOMES)) + { + addBiomesCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.BIOMES_TYPE)) + { + this.addBiomesTypesCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.STRUCTURE)) + { + this.addStructureCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.DIMENSION)) + { + this.addDimensionCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.HELMET)) + { + this.addHelmetCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.CHEST_PLATE)) + { + this.addChestPlateCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.LEGGINGS)) + { + this.addLeggingsCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.BOOTS)) + { + this.addBootsCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MIN_TIME)) + { + this.addMinTimeCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MAX_TIME)) + { + this.addMaxTimeCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MIN_LIGHT)) + { + this.addMinLightCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MAX_LIGHT)) + { + this.addMaxLightCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MIN_HEIGHT)) + { + this.addMinHeightCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MAX_HEIGHT)) + { + this.addMaxHeightCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.DIFFICULTY)) + { + this.addDifficultyCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MIN_DIFFICULTY)) + { + this.addMinAdditionalDifficultyCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MAX_DIFFICULTY)) + { + this.addMaxAdditionalDifficultyCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MIN_SPAWN_DIST)) + { + this.addMinSpawnDistCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MAX_SPAWN_DIST)) + { + this.addMaxSpawnDistCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.BLOCK)) + { + this.addBlocksCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.GET_MOON_PHASE)) + { + this.addCheckMoonPhase(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MOB)) + { + this.addMobsCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.ANIMALS)) + { + this.addInterfaceAnimalsCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MONSTERS)) + { + this.addInterfaceMonstersCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.PLAYER)) + { + this.addPlayerCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.FAKE_PLAYER)) + { + this.addFakePlayerCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.REAL_PLAYER)) + { + this.addRealPlayerCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.HELD_ITEM)) + { + this.addHeldItemCheck(map, KeyWordsGeneral.CommonKeyWorlds.HELD_ITEM); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.PLAYER_HELD_ITEM)) + { + this.addHeldItemCheck(map, KeyWordsGeneral.CommonKeyWorlds.PLAYER_HELD_ITEM); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.OFF_HAND_ITEM)) + { + this.addOffHandItemCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.BOTH_HANDS_ITEM)) + { + this.addBothHandsItemCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.EXPLOSION)) + { + this.addExplosionCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.PROJECTILE)) + { + this.addProjectileCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.FIRE)) + { + this.addFireCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.MAGIC)) + { + this.addMagicCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.SOURCE)) + { + this.addSourceCheck(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.RANDOM_KEY_0)) + { + this.addRandomCheck_0(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.RANDOM_KEY_1)) + { + this.addRandomCheck_1(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.RANDOM_KEY_2)) + { + this.addRandomCheck_2(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.RANDOM_KEY_3)) + { + this.addRandomCheck_3(map); + } + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.RANDOM_KEY_4)) + { + this.addRandomCheck_4(map); + } + } + + /** + * + * @param map + */ + private void addSeeSkyCheck(AttributeMap map) + { + Object seeSky = map.get(KeyWordsGeneral.CommonKeyWorlds.SEE_SKY); + + if ((Boolean)seeSky) + { + _arrayList.add((event,query) -> + query.getWorld(event).canBlockSeeSky(query.getPos(event))); + } + else + { + _arrayList.add((event,query) -> + !query.getWorld(event).canBlockSeeSky(query.getPos(event))); + } + } + + /** + * + * @param map + */ + private void addCanSpawnHereCheck(AttributeMap map) + { + Object canSpawn = map.get(KeyWordsGeneral.SpawnCondition.CAN_SPAWN_HERE); + + if ((Boolean)canSpawn) + { + _arrayList.add((event, query) -> + { + Entity entity = query.getEntity(event); + + if (entity instanceof EntityLiving) + { + return ((EntityLiving) entity).getCanSpawnHere(); + } + else + { + return false; + } + }); + } + else + { + _arrayList.add((event, query) -> + { + Entity entity = query.getEntity(event); + + if (entity instanceof EntityLiving) + { + return !((EntityLiving) entity).getCanSpawnHere(); + } + else + { + return true; + } + }); + } + } + + /** + * + * @param map + */ + private void addNotCollidingCheck(AttributeMap map) + { + Object notCollidingCheck = map.get(KeyWordsGeneral.SpawnCondition.NOT_COLLIDING); + + if ((Boolean)notCollidingCheck) + { + _arrayList.add((event, query) -> + { + Entity entity = query.getEntity(event); + + if (entity instanceof EntityLiving) + { + return ((EntityLiving) entity).isNotColliding(); + } + else + { + return false; + } + }); + } + else + { + _arrayList.add((event, query) -> + { + Entity entity = query.getEntity(event); + + if (entity instanceof EntityLiving) + { + return !((EntityLiving) entity).isNotColliding(); + } + else + { + return true; + } + }); + } + } + + /** + * + * @param map + */ + private void addSpawnerCheck(AttributeMap map) + { + Object spawner = map.get(KeyWordsGeneral.SpawnCondition.SPAWNER); + + if ((Boolean)spawner) + { + _arrayList.add((event, query) -> + { + if (event instanceof LivingSpawnEvent.CheckSpawn) + { + LivingSpawnEvent.CheckSpawn checkSpawn = (LivingSpawnEvent.CheckSpawn) event; + return checkSpawn.isSpawner(); + } + else + { + return false; + } + }); + } + else + { + _arrayList.add((event, query) -> + { + if (event instanceof LivingSpawnEvent.CheckSpawn) + { + LivingSpawnEvent.CheckSpawn checkSpawn = (LivingSpawnEvent.CheckSpawn) event; + return !checkSpawn.isSpawner(); + } + else + { + return false; + } + }); + } + } + + /** + * + * @param map + */ + private void addBiomesCheck(AttributeMap map) + { + List biomes = map.getList(KeyWordsGeneral.CommonKeyWorlds.BIOMES); + + if (biomes.size() == 1) + { + String biomesName = biomes.get(0); + + _arrayList.add((event,query) -> + { + Biome biome = query.getWorld(event).getBiome(query.getPos(event)); + return biomesName.equals(biome.getBiomeName()); + }); + } + else + { + Set biomesName = new HashSet<>(biomes); + + _arrayList.add((event,query) -> + { + Biome biome = query.getWorld(event).getBiome(query.getPos(event)); + return biomesName.contains(biome.getBiomeName()); + }); + } + } + + /** + * + * @param map + */ + private void addBiomesTypesCheck(AttributeMap map) + { + List biomesTypes = map.getList(KeyWordsGeneral.CommonKeyWorlds.BIOMES_TYPE); + + if (biomesTypes.size() == 1) + { + String biomesType = biomesTypes.get(0); + + BiomeDictionary.Type type = BiomeDictionary.Type.getType(biomesType); + + _arrayList.add((event,query) -> + { + Biome biome = query.getWorld(event).getBiome(query.getPos(event)); + return BiomeDictionary.getTypes(biome).contains(type); + }); + } + else + { + Set types = new HashSet<>(); + + for (String s : biomesTypes) + { + types.add(BiomeDictionary.Type.getType(s)); + } + + _arrayList.add((event,query) -> + { + Biome biome = query.getWorld(event).getBiome(query.getPos(event)); + return BiomeDictionary.getTypes(biome).stream().anyMatch(s -> types.contains(s)); + }); + } + } + + /** + * + * @param map + */ + private void addWeatherCheck(AttributeMap map) + { + Object weatherObject = map.get(KeyWordsGeneral.CommonKeyWorlds.WEATHER); + + if (weatherObject instanceof String) + { + String weather = (String) weatherObject; + + boolean raining = weather.toLowerCase().startsWith("rain"); + boolean thunder = weather.toLowerCase().startsWith("thunder"); + + if (raining) + { + _arrayList.add((event, query) -> + query.getWorld(event).isRaining()); + } + else if (thunder) + { + _arrayList.add((event, query) -> + query.getWorld(event).isThundering()); + } + else + { + Log.writeDataToLogFile(Log._typeLog[2], "Unknown weather '" + weather + "'! Use 'rain' or 'thunder'"); + } + } + else + { + Log.writeDataToLogFile(Log._typeLog[2], "Weather is not a string object!"); + } + } + + /** + * + * @param map + */ + private void addStructureCheck(AttributeMap map) + { + Object structure = map.get(KeyWordsGeneral.CommonKeyWorlds.STRUCTURE); + + _arrayList.add((event,query) -> + Structures._structuresCache.isInStructure(query.getWorld(event), (String) structure, query.getPos(event))); + } + + /** + * + * @param map + */ + private void addDimensionCheck(AttributeMap map) + { + List dimensions = map.getListI(KeyWordsGeneral.CommonKeyWorlds.DIMENSION); + + if (dimensions.size() == 1) + { + Integer dim = dimensions.get(0); + + _arrayList.add((event, query) -> + query.getWorld(event).provider.getDimension() == dim); + } + else + { + Set dims = new HashSet<>(dimensions); + + _arrayList.add((event, query) -> + dims.contains(query.getWorld(event).provider.getDimension())); + } + } + + /** + * + * @param map + */ + public void addHelmetCheck(AttributeMap map) + { + List> items = AuxFunctions.getItems(map.getList(KeyWordsGeneral.CommonKeyWorlds.HELMET)); + + _arrayList.add((event, query) -> + { + EntityPlayer player = query.getPlayer(event); + + if (player != null) + { + ItemStack armorItem = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD); + if (!armorItem.isEmpty()) + { + return items.stream().anyMatch(item -> item.test(armorItem)); + } + } + + return false; + }); + } + + /** + * + * @param map + */ + public void addChestPlateCheck(AttributeMap map) + { + List> items = AuxFunctions.getItems(map.getList(KeyWordsGeneral.CommonKeyWorlds.CHEST_PLATE)); + + _arrayList.add((event, query) -> + { + EntityPlayer player = query.getPlayer(event); + + if (player != null) + { + ItemStack armorItem = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST); + if (!armorItem.isEmpty()) + { + return items.stream().anyMatch(item -> item.test(armorItem)); + } + } + + return false; + }); + } + + /** + * + * @param map + */ + public void addLeggingsCheck(AttributeMap map) + { + List> items = AuxFunctions.getItems(map.getList(KeyWordsGeneral.CommonKeyWorlds.LEGGINGS)); + + _arrayList.add((event, query) -> + { + EntityPlayer player = query.getPlayer(event); + + if (player != null) + { + ItemStack armorItem = player.getItemStackFromSlot(EntityEquipmentSlot.LEGS); + if (!armorItem.isEmpty()) + { + return items.stream().anyMatch(item -> item.test(armorItem)); + } + } + + return false; + }); + } + + /** + * + * @param map + */ + public void addBootsCheck(AttributeMap map) + { + List> items = AuxFunctions.getItems(map.getList(KeyWordsGeneral.CommonKeyWorlds.BOOTS)); + + _arrayList.add((event, query) -> + { + EntityPlayer player = query.getPlayer(event); + + if (player != null) + { + ItemStack armorItem = player.getItemStackFromSlot(EntityEquipmentSlot.FEET); + if (!armorItem.isEmpty()) + { + return items.stream().anyMatch(item -> item.test(armorItem)); + } + } + + return false; + }); + } + + /** + * + * @param map + */ + private void addMinTimeCheck(AttributeMap map) + { + Object minTime = map.get(KeyWordsGeneral.CommonKeyWorlds.MIN_TIME); + + _arrayList.add((event, query) -> + { + long time = query.getWorld(event).getWorldTime(); + return (time % 24000) >= (Integer) minTime; + }); + } + + /** + * + * @param map + */ + private void addMaxTimeCheck(AttributeMap map) + { + Object maxTime = map.get(KeyWordsGeneral.CommonKeyWorlds.MAX_TIME); + + _arrayList.add((event, query) -> + { + long time = query.getWorld(event).getWorldTime(); + return (time % 24000) <= (Integer) maxTime; + }); + } + + /** + * + * @param map + */ + private void addMinLightCheck(AttributeMap map) + { + Object minLight = map.get(KeyWordsGeneral.CommonKeyWorlds.MIN_LIGHT); + + _arrayList.add((event,query) -> + { + BlockPos pos = query.getPos(event); + return query.getWorld(event).getLight(pos, true) >= (Integer) minLight; + }); + } + + /** + * + * @param map + */ + private void addMaxLightCheck(AttributeMap map) + { + Object maxLight = map.get(KeyWordsGeneral.CommonKeyWorlds.MAX_LIGHT); + + _arrayList.add((event,query) -> + { + BlockPos pos = query.getPos(event); + return query.getWorld(event).getLight(pos, true) <= (Integer) maxLight; + }); + } + + /** + * + * @param map + */ + private void addMinHeightCheck(AttributeMap map) + { + Object minHeight = map.get(KeyWordsGeneral.CommonKeyWorlds.MIN_HEIGHT); + + _arrayList.add((event,query) -> + query.getY(event) >= (Integer) minHeight); + } + + /** + * + * @param map + */ + private void addMaxHeightCheck(AttributeMap map) + { + Object maxHeight = map.get(KeyWordsGeneral.CommonKeyWorlds.MAX_HEIGHT); + + _arrayList.add((event,query) -> + query.getY(event) <= (Integer) maxHeight); + } + + /** + * + * @param map + */ + private void addMinAdditionalDifficultyCheck(AttributeMap map) + { + Object minDifficulty = map.get(KeyWordsGeneral.CommonKeyWorlds.MIN_DIFFICULTY); + + _arrayList.add((event,query) -> + query.getWorld(event).getDifficultyForLocation(query.getPos(event)).getAdditionalDifficulty() >= (Float) minDifficulty); + } + + /** + * + * @param map + */ + private void addDifficultyCheck(AttributeMap map) + { + EnumDifficulty enumDifficulty = null; + + Object difficulty = map.get(KeyWordsGeneral.CommonKeyWorlds.DIFFICULTY); + + for (EnumDifficulty _difficulty : EnumDifficulty.values()) + { + if (_difficulty.getDifficultyResourceKey().endsWith("." + difficulty)) + { + enumDifficulty = _difficulty; + break; + } + } + + if (enumDifficulty != null) + { + EnumDifficulty finalDiff = enumDifficulty; + + _arrayList.add((event,query) -> + query.getWorld(event).getDifficulty() == finalDiff); + } + else + { + Log.writeDataToLogFile(Log._typeLog[2], "Unknown difficulty '" + difficulty + "'! Use one of 'easy', 'normal', 'hard', or 'peaceful'"); + throw new RuntimeException(); + } + } + + /** + * + * @param map + */ + private void addMaxAdditionalDifficultyCheck(AttributeMap map) + { + Object maxDifficulty = map.get(KeyWordsGeneral.CommonKeyWorlds.MAX_DIFFICULTY); + + _arrayList.add((event,query) -> + query.getWorld(event).getDifficultyForLocation(query.getPos(event)).getAdditionalDifficulty() <= (Float) maxDifficulty); + } + + /** + * + * @param map + */ + private void addMinSpawnDistCheck(AttributeMap map) + { + Object degree = map.get(KeyWordsGeneral.CommonKeyWorlds.MIN_SPAWN_DIST); + + _arrayList.add((event,query) -> + { + BlockPos pos = query.getPos(event); + double sqDist = pos.distanceSq(query.getWorld(event).getSpawnPoint()); + + return sqDist >= (Float) degree * (Float) degree; + }); + } + + /** + * + * @param map + */ + private void addMaxSpawnDistCheck(AttributeMap map) + { + Object degree = map.get(KeyWordsGeneral.CommonKeyWorlds.MAX_SPAWN_DIST); + + _arrayList.add((event, query) -> + { + BlockPos pos = query.getPos(event); + double sqDist = pos.distanceSq(query.getWorld(event).getSpawnPoint()); + + return sqDist <= (Float) degree * (Float) degree; + }); + } + + /** + * + * @param map + */ + private void addBlocksCheck(AttributeMap map) + { + BiFunction posFunction; + + if (map.has(KeyWordsGeneral.CommonKeyWorlds.BLOCK_OFFSET)) + { + posFunction = AuxFunctions.parseOffset((String)map.get(KeyWordsGeneral.CommonKeyWorlds.BLOCK_OFFSET)); + } + else + { + posFunction = (event, query) -> + query.getPos(event); + } + + List blocks = map.getList(KeyWordsGeneral.CommonKeyWorlds.BLOCK); + + if (blocks.size() == 1) + { + String json = blocks.get(0); + BiPredicate blockMatcher = AuxFunctions.parseBlock(json); + + if (blockMatcher != null) + { + _arrayList.add((event, query) -> + { + BlockPos pos = posFunction.apply(event, query); + + return pos != null && blockMatcher.test(query.getWorld(event), pos); + }); + } + } + else + { + List> blockMatchers = new ArrayList<>(); + + for (String block : blocks) + { + BiPredicate blockMatcher = AuxFunctions.parseBlock(block); + + if (blockMatcher == null) + { + return; + } + + blockMatchers.add(blockMatcher); + } + + _arrayList.add((event,query) -> + { + BlockPos pos = posFunction.apply(event, query); + + if (pos != null) + { + World world = query.getWorld(event); + + for (BiPredicate matcher : blockMatchers) + { + if (matcher.test(world, pos)) + { + return true; + } + } + } + + return false; + }); + } + } + + /** + * + * @param _map + */ + private void addCheckMoonPhase(AttributeMap _map) + { + Object moon = _map.get(KeyWordsGeneral.CommonKeyWorlds.GET_MOON_PHASE); + + _arrayList.add((event,query) -> + query.getWorld(event).getMoonPhase() == (Integer)moon); + } + + /** + * + * @param map + */ + private void addMobsCheck(AttributeMap map) + { + List listMobs = map.getList(KeyWordsGeneral.CommonKeyWorlds.MOB); + + if (listMobs.size() == 1) + { + String name = listMobs.get(0); + String id = GenericOverrideSpawn.fixEntityId(name); + EntityEntry _forgeRegEntity0 = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(id)); + Class typeClass = _forgeRegEntity0 == null ? null : _forgeRegEntity0.getEntityClass(); + + if (typeClass != null) + { + _arrayList.add((event, query) -> + typeClass.equals(query.getEntity(event).getClass())); + } + else + { + Log.writeDataToLogFile(Log._typeLog[2], "Unknown mob '" + name + "'!"); + throw new RuntimeException(); + } + } + else + { + Set> classes = new HashSet<>(); + + for (String name : listMobs) + { + String id = GenericOverrideSpawn.fixEntityId(name); + EntityEntry _forgeRegEntity1 = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(id)); + Class typeClass = _forgeRegEntity1 == null ? null : _forgeRegEntity1.getEntityClass(); + + if (typeClass != null) + { + classes.add(typeClass); + } + else + { + Log.writeDataToLogFile(Log._typeLog[2], "Unknown mob '" + name + "'!"); + throw new RuntimeException(); + } + } + + if (!classes.isEmpty()) + { + _arrayList.add((event, query) -> + classes.contains(query.getEntity(event).getClass())); + } + } + } + + /** + * + * @param map + */ + private void addInterfaceAnimalsCheck(AttributeMap map) + { + Object animalsObj = map.get(KeyWordsGeneral.CommonKeyWorlds.ANIMALS); + + if ((Boolean)animalsObj) + { + _arrayList.add((event, query) -> + (query.getEntity(event) instanceof IAnimals + && !(query.getEntity(event) instanceof IMob))); + } + else + { + _arrayList.add((event, query) -> + !(query.getEntity(event) instanceof IAnimals + && !(query.getEntity(event) instanceof IMob))); + } + } + + /** + * + * @param map + */ + private void addInterfaceMonstersCheck(AttributeMap map) + { + Object monstersObj = map.get(KeyWordsGeneral.CommonKeyWorlds.MONSTERS); + + if ((Boolean)monstersObj) + { + _arrayList.add((event, query) -> + query.getEntity(event) instanceof IMob); + } + else + { + _arrayList.add((event, query) -> + !(query.getEntity(event) instanceof IMob)); + } + } + + /** + * + * @param map + */ + private void addPlayerCheck(AttributeMap map) + { + Object asPlayer = map.get(KeyWordsGeneral.CommonKeyWorlds.PLAYER); + + if ((Boolean)asPlayer) + { + _arrayList.add((event, query) -> + query.getAttacker(event) instanceof EntityPlayer); + } + //else + //{ + // _arrayList.add((event, query) -> query.getAttacker(event) instanceof EntityPlayer); + //} + } + + /** + * + * @param _map + */ + private void addFakePlayerCheck(AttributeMap _map) + { + Object asPlayer = _map.get(KeyWordsGeneral.CommonKeyWorlds.FAKE_PLAYER); + + if ((Boolean)asPlayer) + { + _arrayList.add((event, query) -> query.getAttacker(event) == null ? false : AuxFunctions.isFakePlayer(query.getAttacker(event))); + } + else + { + _arrayList.add((event, query) -> query.getAttacker(event) == null ? true : !AuxFunctions.isFakePlayer(query.getAttacker(event))); + } + } + + /** + * + * @param map + */ + private void addRealPlayerCheck(AttributeMap map) + { + Object asPlayer = map.get(KeyWordsGeneral.CommonKeyWorlds.REAL_PLAYER); + + if ((Boolean)asPlayer) + { + _arrayList.add((event, query) -> query.getAttacker(event) == null ? false : AuxFunctions.isRealPlayer(query.getAttacker(event))); + } + else + { + _arrayList.add((event, query) -> query.getAttacker(event) == null ? true : !AuxFunctions.isRealPlayer(query.getAttacker(event))); + } + } + + /** + * + * @param map + * @param key + */ + public void addHeldItemCheck(AttributeMap map, AttributeKey key) + { + List> items = AuxFunctions.getItems(map.getList(key)); + + _arrayList.add((event,query) -> + { + EntityPlayer player = query.getPlayer(event); + + if (player != null) + { + ItemStack main_hand = player.getHeldItemMainhand(); + + if (!main_hand.isEmpty()) + { + for (Predicate item : items) + { + if (item.test(main_hand)) + { + return true; + } + } + } + } + + return false; + }); + } + + /** + * + * @param map + */ + public void addOffHandItemCheck(AttributeMap map) + { + List> items = AuxFunctions.getItems(map.getList(KeyWordsGeneral.CommonKeyWorlds.OFF_HAND_ITEM)); + + _arrayList.add((event,query) -> + { + EntityPlayer player = query.getPlayer(event); + + if (player != null) + { + ItemStack offhand = player.getHeldItemOffhand(); + + if (!offhand.isEmpty()) + { + for (Predicate item : items) + { + if (item.test(offhand)) + { + return true; + } + } + } + } + + return false; + }); + } + + /** + * + * @param map + */ + private void addExplosionCheck(AttributeMap map) + { + Object explosion = map.get(KeyWordsGeneral.CommonKeyWorlds.EXPLOSION); + + if ((Boolean)explosion) + { + _arrayList.add((event, query) -> query.getSource(event) == null ? false : query.getSource(event).isExplosion()); + } + else + { + _arrayList.add((event, query) -> query.getSource(event) == null ? true : !query.getSource(event).isExplosion()); + } + } + + /** + * + * @param map + */ + private void addProjectileCheck(AttributeMap map) + { + Object projectile = map.get(KeyWordsGeneral.CommonKeyWorlds.PROJECTILE); + + if ((Boolean)projectile) + { + _arrayList.add((event, query) -> query.getSource(event) == null ? false : query.getSource(event).isProjectile()); + } + else + { + _arrayList.add((event, query) -> query.getSource(event) == null ? true : !query.getSource(event).isProjectile()); + } + } + + /** + * + * @param map + */ + private void addFireCheck(AttributeMap map) + { + Object fire = map.get(KeyWordsGeneral.CommonKeyWorlds.FIRE); + + if ((Boolean)fire) + { + _arrayList.add((event, query) -> query.getSource(event) == null ? false : query.getSource(event).isFireDamage()); + } + else + { + _arrayList.add((event, query) -> query.getSource(event) == null ? true : !query.getSource(event).isFireDamage()); + } + } + + /** + * + * @param map + */ + private void addMagicCheck(AttributeMap map) + { + Object magic = map.get(KeyWordsGeneral.CommonKeyWorlds.MAGIC); + + if ((Boolean)magic) + { + _arrayList.add((event, query) -> query.getSource(event) == null ? false : query.getSource(event).isMagicDamage()); + } + else + { + _arrayList.add((event, query) -> query.getSource(event) == null ? true : !query.getSource(event).isMagicDamage()); + } + } + + /** + * + * @param map + */ + private void addSourceCheck(AttributeMap map) + { + List sources = map.getList(KeyWordsGeneral.CommonKeyWorlds.SOURCE); + Set sourceSet = new HashSet<>(sources); + + _arrayList.add((event, query) -> + { + if (query.getSource(event) == null) + { + return false; + } + + return sourceSet.contains(query.getSource(event).getDamageType()); + }); + } + + /** + * + * @param map + */ + public void addBothHandsItemCheck(AttributeMap map) + { + List> items = AuxFunctions.getItems(map.getList(KeyWordsGeneral.CommonKeyWorlds.BOTH_HANDS_ITEM)); + + _arrayList.add((event,query) -> + { + EntityPlayer player = query.getPlayer(event); + + if (player != null) + { + ItemStack offhand = player.getHeldItemOffhand(); + + if (!offhand.isEmpty()) + { + for (Predicate item : items) + { + if (item.test(offhand)) + { + return true; + } + } + } + + ItemStack mainHand = player.getHeldItemMainhand(); + + if (!mainHand.isEmpty()) + { + for (Predicate item : items) + { + if (item.test(mainHand)) + { + return true; + } + } + } + } + + return false; + }); + } + + /** + * + * @param map + */ + private void addRandomCheck_0(AttributeMap map) + { + Object _random = map.get(KeyWordsGeneral.CommonKeyWorlds.RANDOM_KEY_0); + + _arrayList.add((event, query) -> + new Random().nextFloat() < (Float)_random); + } + + /** + * + * @param map + */ + private void addRandomCheck_1(AttributeMap map) + { + Object _random = map.get(KeyWordsGeneral.CommonKeyWorlds.RANDOM_KEY_1); + + _arrayList.add((event, query) -> + new Random().nextFloat() < (Float)_random); + } + + /** + * + * @param map + */ + private void addRandomCheck_2(AttributeMap map) + { + Object _random = map.get(KeyWordsGeneral.CommonKeyWorlds.RANDOM_KEY_2); + + _arrayList.add((event, query) -> + new Random().nextFloat() < (Float)_random); + } + + /** + * + * @param map + */ + private void addRandomCheck_3(AttributeMap map) + { + Object _random = map.get(KeyWordsGeneral.CommonKeyWorlds.RANDOM_KEY_3); + + _arrayList.add((event, query) -> + new Random().nextFloat() < (Float)_random); + } + + /** + * + * @param map + */ + private void addRandomCheck_4(AttributeMap map) + { + Object _random = map.get(KeyWordsGeneral.CommonKeyWorlds.RANDOM_KEY_4); + + _arrayList.add((event, query) -> + new Random().nextFloat() < (Float)_random); + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsSingleEvent.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsSingleEvent.java new file mode 100644 index 0000000..71ce82b --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsSingleEvent.java @@ -0,0 +1,1646 @@ +package org.imesense.dynamicspawncontrol.technical.customlibrary; + +/** + * + * @param + */ +public abstract class ListActionsSingleEvent +{ + /** + * + */ + protected final List> _actions = new ArrayList<>(); + + /** + * + * @param nameClass + */ + public ListActionsSingleEvent(String nameClass) + { + Log.writeDataToLogFile(Log._typeLog[0], String.format("Call .super[%s]", nameClass)); + } + + /** + * + * @param map + */ + protected void addActions(AttributeMap map) + { + { + if (map.has(ENEMIES_TO) && map.has(TO_THEM)) + { + this.addEnemy(map, INFConfigDebugSingleEvents._debugActionAddEnemyToLog); + } + + if (map.has(ENEMIES_TO) && map.has(ENEMY_ID)) + { + this.addEnemyId(map, INFConfigDebugSingleEvents._debugActionAddEnemyToLog); + } + + if (map.has(PANIC_TO) && map.has(PANIC_ID)) + { + this.addPanicToId(map, INFConfigDebugSingleEvents._debugActionPanicToIdLog); + } + + if (map.has(ENEMY_ID) && map.has(THEM_ID)) + { + this.addEnemyToIdThemToId(map, INFConfigDebugSingleEvents._debugActionAddEnemyToLog); + } + } + + if (map.has(ACTION_MESSAGE)) + { + this.addDoMessageAction(map); + } + + if (map.has(ACTION_ANGRY)) + { + this.addAngryAction(map); + } + + if (map.has(ACTION_HELD_ITEM)) + { + this.addHeldItem(map); + } + + if (map.has(ACTION_ARMOR_BOOTS)) + { + this.addArmorItem(map, ACTION_ARMOR_BOOTS, EntityEquipmentSlot.FEET); + } + + if (map.has(ACTION_ARMOR_LEGS)) + { + this.addArmorItem(map, ACTION_ARMOR_LEGS, EntityEquipmentSlot.LEGS); + } + + if (map.has(ACTION_ARMOR_HELMET)) + { + this.addArmorItem(map, ACTION_ARMOR_HELMET, EntityEquipmentSlot.HEAD); + } + + if (map.has(ACTION_ARMOR_CHEST)) + { + this.addArmorItem(map, ACTION_ARMOR_CHEST, EntityEquipmentSlot.CHEST); + } + + if (map.has(ACTION_SET_NBT)) + { + this.addMobNBT(map); + } + + if (map.has(ACTION_HEALTH_MULTIPLY) && map.has(ACTION_HEALTH_ADD)) + { + this.addHealthAction(map); + } + + if (map.has(ACTION_SPEED_MULTIPLY) && map.has(ACTION_SPEED_ADD)) + { + this.addSpeedAction(map); + } + + if (map.has(ACTION_DAMAGE_MULTIPLY) && map.has(ACTION_DAMAGE_ADD)) + { + this.addDamageAction(map); + } + + if (map.has(ACTION_CUSTOM_NAME)) + { + this.addCustomName(map); + } + + if (map.has(ACTION_POTION)) + { + this.addPotionsAction(map); + } + + if (map.has(ACTION_GIVE)) + { + this.addGiveAction(map); + } + + if (map.has(ACTION_DROP)) + { + this.addDropAction(map); + } + + if (map.has(ACTION_COMMAND)) + { + this.addCommandAction(map); + } + + if (map.has(ACTION_FIRE)) + { + this.addFireAction(map); + } + + if (map.has(ACTION_EXPLOSION)) + { + this.addExplosionAction(map); + } + + if (map.has(ACTION_CLEAR)) + { + this.addClearAction(map); + } + + if (map.has(ACTION_DAMAGE)) + { + this.addDoDamageAction(map); + } + + if (map.has(ACTION_SET_BLOCK)) + { + this.addSetBlockAction(map); + } + + if (map.has(ACTION_SET_HELD_ITEM)) + { + this.addSetHeldItemAction(map); + } + + if (map.has(ACTION_SET_HELD_AMOUNT)) + { + this.addSetHeldAmountAction(map); + } + } + + /** + * + * @param map + * @param localDebug + */ + private void addEnemy(AttributeMap map, boolean localDebug) + { + List enemiesTo = map.getList(KeyWordsGeneral.MobsTaskManager.ENEMIES_TO); + List toThem = map.getList(KeyWordsGeneral.MobsTaskManager.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(Log._typeLog[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(Log._typeLog[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(Log._typeLog[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(Log._typeLog[0], String.format("Step 4: %s, %s", typeClassEnemiesTo, typeClassToThem)); + } + + if (typeClassEnemiesTo != null && localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Added entity: " + typeClassEnemiesTo.getName()); + } + + if (typeClassToThem != null && localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Added entity: " + typeClassToThem.getName()); + } + + if (typeClassEnemiesTo != null && typeClassToThem != null) + { + _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(Log._typeLog[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(Log._typeLog[0], "Added attack target task for entity: " + typeClassToThem.getName() + " targeting " + typeClassEnemiesTo.getName()); + } + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Entity type mismatch, cannot add attack target task."); + } + } + }); + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[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(Log._typeLog[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(Log._typeLog[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(Log._typeLog[0], String.format("Step 3.1: %s", typeClassEnemiesTo)); + } + + if (typeClassEnemiesTo != null) + { + classesEnemiesTo.add((Class) typeClassEnemiesTo); + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[2], "Unknown mob '" + enemiesTo + "'!"); + } + } + } + + for (String fToThem : toThem) + { + String toThem_s_id = GenericOverrideSpawn.fixEntityId(fToThem); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[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(Log._typeLog[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(Log._typeLog[0], String.format("Step 3.2: %s", typeClassToThem)); + } + + if (typeClassToThem != null) + { + classesToThem.add((Class) typeClassToThem); + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[2], "Unknown mob '" + toThem + "'!"); + } + } + } + + if (!classesEnemiesTo.isEmpty() && !classesToThem.isEmpty()) + { + _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(Log._typeLog[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(Log._typeLog[0], "Added attack target task for entity: " + entityClass.getName() + " targeting " + targetClass.getName()); + } + } + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Entity type mismatch, cannot add attack target task."); + } + } + }); + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[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(KeyWordsGeneral.MobsTaskManager.ENEMIES_TO); + List enemyIdPrefixes = map.getList(KeyWordsGeneral.MobsTaskManager.ENEMY_ID); + + Set> classesEnemiesTo = new HashSet<>(); + Set> classesEnemyId = new HashSet<>(); + + try + { + // Extract enemy classes from _enemiesTo + for (String fEnemiesTo : enemiesTo) + { + String enemiesTo_s_id = GenericOverrideSpawn.fixEntityId(fEnemiesTo); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[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(Log._typeLog[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(Log._typeLog[0], String.format("Step 3.1: %s", typeClassEnemiesTo)); + } + + if (typeClassEnemiesTo != null && EntityLiving.class.isAssignableFrom(typeClassEnemiesTo)) + { + classesEnemiesTo.add((Class) typeClassEnemiesTo); + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[2], "Unknown or incompatible mob '" + enemiesTo + "'!"); + } + } + } + + // Extract enemy classes from _enemyId that start with the given prefix + for (String enemyIdPrefix : enemyIdPrefixes) + { + for (EntityEntry entityEntry : ForgeRegistries.ENTITIES) + { + if (entityEntry.getRegistryName().toString().startsWith(enemyIdPrefix)) + { + Class typeClassEnemyId = entityEntry.getEntityClass(); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[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(Log._typeLog[2], "Unknown or incompatible mob with prefix '" + enemyIdPrefix + "'!"); + } + } + } + } + } + + if (!classesEnemiesTo.isEmpty() && !classesEnemyId.isEmpty()) + { + _actions.add(event -> + { + try + { + EntityLiving entity = (EntityLiving) event.getEntityLiving(); + Class entityClass = entity.getClass(); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Event entity: " + entityClass.getName()); + } + + if (classesEnemiesTo.contains(entityClass)) + { + for (Class targetClass : classesEnemyId) + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Adding attack task for: " + entityClass.getName() + " targeting " + targetClass.getName()); + } + + entity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) entity, targetClass, true)); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[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(Log._typeLog[0], "Adding attack task for: " + entityClass.getName() + " targeting " + targetClass.getName()); + } + + entity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) entity, targetClass, true)); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Added attack target task for entity: " + entityClass.getName() + " targeting " + targetClass.getName()); + } + } + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Entity type mismatch, cannot add attack target task."); + } + } + } + catch (Exception e) + { + Log.writeDataToLogFile(Log._typeLog[2], "Error in event action: " + e.getMessage()); + if (localDebug) + { + e.printStackTrace(); + } + } + }); + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Failed to add attack target task: No valid entity classes found."); + } + } + } + catch (Exception e) + { + Log.writeDataToLogFile(Log._typeLog[2], "Error in addEnemyId method: " + e.getMessage()); + + if (localDebug) + { + e.printStackTrace(); + } + } + } + + /** + * + * @param map + * @param localDebug + */ + private void addPanicToId(AttributeMap map, boolean localDebug) + { + List panicTo = map.getList(KeyWordsGeneral.MobsTaskManager.PANIC_TO); + List panicIdPrefixes = map.getList(KeyWordsGeneral.MobsTaskManager.PANIC_ID); + + Set> classesPanicTo = new HashSet<>(); + Set> classesPanicId = new HashSet<>(); + + try + { + // Extract panic classes from _PanicTo + for (String fPanicTo : panicTo) + { + String panicTo_s_id = GenericOverrideSpawn.fixEntityId(fPanicTo); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[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(Log._typeLog[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(Log._typeLog[0], String.format("Step 3.1: %s", typeClassPanicTo)); + } + + if (typeClassPanicTo != null && EntityLiving.class.isAssignableFrom(typeClassPanicTo)) + { + classesPanicTo.add((Class) typeClassPanicTo); + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[2], "Unknown or incompatible mob '" + panicTo + "'!"); + } + } + } + + // Extract panic classes from _panicId that start with the given prefix + for (String fPanicIdPrefix : panicIdPrefixes) + { + for (EntityEntry entityEntry : ForgeRegistries.ENTITIES) + { + if (entityEntry.getRegistryName().toString().startsWith(fPanicIdPrefix)) + { + Class typeClassPanicId = entityEntry.getEntityClass(); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[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(Log._typeLog[2], "Unknown or incompatible mob with prefix '" + fPanicIdPrefix + "'!"); + } + } + } + } + } + + if (!classesPanicTo.isEmpty() && !classesPanicId.isEmpty()) + { + _actions.add(event -> + { + try + { + EntityLiving entity = (EntityLiving) event.getEntityLiving(); + Class entityClass = entity.getClass(); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Event entity: " + entityClass.getName()); + } + + if (classesPanicTo.contains(entityClass)) + { + for (Class panicClass : classesPanicId) + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[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(Log._typeLog[0], "Added panic task for entity: " + entityClass.getName() + " avoiding " + panicClass.getName()); + } + } + } + } + catch (Exception e) + { + Log.writeDataToLogFile(Log._typeLog[2], "Error in event action: " + e.getMessage()); + if (localDebug) + { + e.printStackTrace(); + } + } + }); + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Failed to add panic task: No valid entity classes found."); + } + } + } + catch (Exception e) + { + Log.writeDataToLogFile(Log._typeLog[2], "Error in addPanicToId method: " + e.getMessage()); + + if (localDebug) + { + e.printStackTrace(); + } + } + } + + /** + * + * @param map + * @param localDebug + */ + private void addEnemyToIdThemToId(AttributeMap map, boolean localDebug) + { + List listEnemyId = map.getList(KeyWordsGeneral.MobsTaskManager.ENEMY_ID); + List listThemId = map.getList(KeyWordsGeneral.MobsTaskManager.THEM_ID); + + Set> classesEnemyId = new HashSet<>(); + Set> classesThemId = new HashSet<>(); + + try + { + // Extract enemy classes from _listEnemyId that start with the given prefix + for (String enemyIdPrefix : listEnemyId) + { + for (EntityEntry entityEntry : ForgeRegistries.ENTITIES) + { + if (entityEntry.getRegistryName().toString().startsWith(enemyIdPrefix)) + { + Class typeClassEnemyId = entityEntry.getEntityClass(); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[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(Log._typeLog[2], "Unknown or incompatible mob with prefix '" + enemyIdPrefix + "'!"); + } + } + } + } + } + + // Extract them classes from _listThemId that start with the given prefix + for (String themIdPrefix : listThemId) + { + for (EntityEntry entityEntry : ForgeRegistries.ENTITIES) + { + if (entityEntry.getRegistryName().toString().startsWith(themIdPrefix)) + { + Class typeClassThemId = entityEntry.getEntityClass(); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[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(Log._typeLog[2], "Unknown or incompatible mob with prefix '" + themIdPrefix + "'!"); + } + } + } + } + } + + if (!classesEnemyId.isEmpty() && !classesThemId.isEmpty()) + { + _actions.add(event -> + { + try + { + EntityLiving entity = (EntityLiving) event.getEntityLiving(); + Class entityClass = entity.getClass(); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Event entity: " + entityClass.getName()); + } + + if (classesEnemyId.contains(entityClass)) + { + for (Class targetClass : classesThemId) + { + if (localDebug) { + Log.writeDataToLogFile(Log._typeLog[0], "Adding attack task for: " + entityClass.getName() + " targeting " + targetClass.getName()); + } + + entity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) entity, targetClass, true)); + + if (localDebug) { + Log.writeDataToLogFile(Log._typeLog[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(Log._typeLog[0], "Adding attack task for: " + entityClass.getName() + " targeting " + targetClass.getName()); + } + + entity.targetTasks.addTask(5, new EntityAINearestAttackableTarget<>((EntityCreature) entity, targetClass, true)); + + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Added attack target task for entity: " + entityClass.getName() + " targeting " + targetClass.getName()); + } + } + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Entity type mismatch, cannot add attack target task."); + } + } + } + catch (Exception e) + { + Log.writeDataToLogFile(Log._typeLog[2], "Error in event action: " + e.getMessage()); + if (localDebug) + { + e.printStackTrace(); + } + } + }); + } + else + { + if (localDebug) + { + Log.writeDataToLogFile(Log._typeLog[0], "Failed to add attack target task: No valid entity classes found."); + } + } + } + catch (Exception e) + { + Log.writeDataToLogFile(Log._typeLog[2], "Error in addEnemyToIdThemToId method: " + e.getMessage()); + + if (localDebug) + { + e.printStackTrace(); + } + } + } + + /** + * + * @param map + */ + private void addDoMessageAction(AttributeMap map) + { + Object message = map.get(KeyWordsGeneral.CommonKeyWorlds.ACTION_MESSAGE); + + _actions.add(event -> + { + EntityPlayer player = event.getPlayer(); + + if (player == null) + { + player = event.getWorld().getClosestPlayerToEntity(event.getEntityLiving(), 100); + } + + if (player != null) + { + player.sendStatusMessage(new TextComponentString((String)message), false); + } + }); + } + + /** + * + * @param map + */ + public void addAngryAction(AttributeMap map) + { + Object actionAngry = map.get(KeyWordsGeneral.CommonKeyWorlds.ACTION_ANGRY); + + if ((Boolean)actionAngry) + { + _actions.add(event -> + { + EntityLivingBase entityLiving = event.getEntityLiving(); + + if (entityLiving instanceof EntityPigZombie) + { + EntityPigZombie pigZombie = (EntityPigZombie) entityLiving; + EntityPlayer player = event.getWorld().getClosestPlayerToEntity(entityLiving, 50); + + if (player != null) + { + pigZombie.setRevengeTarget(player); + } + } + else if (entityLiving instanceof EntityLiving) + { + EntityPlayer player = event.getWorld().getClosestPlayerToEntity(entityLiving, 50); + + if (player != null) + { + ((EntityLiving) entityLiving).setAttackTarget(player); + } + } + }); + } + } + + /** + * + * @param map + */ + private void addHeldItem(AttributeMap map) + { + List> items = AuxFunctions.getItemsWeighted(map.getList(KeyWordsGeneral.CommonKeyWorlds.ACTION_HELD_ITEM)); + + if (items.isEmpty()) + { + return; + } + + if (items.size() == 1) + { + ItemStack item = items.get(0).getRight(); + + _actions.add(event -> + { + EntityLivingBase entityLiving = event.getEntityLiving(); + + if (entityLiving != null) + { + if (entityLiving instanceof EntityEnderman) + { + if (item.getItem() instanceof ItemBlock) + { + ItemBlock b = (ItemBlock) item.getItem(); + ((EntityEnderman) entityLiving).setHeldBlockState(b.getBlock().getStateFromMeta(b.getMetadata(item.getItemDamage()))); + } + } + else + { + entityLiving.setHeldItem(EnumHand.MAIN_HAND, item.copy()); + } + } + }); + } + else + { + float total = AuxFunctions.getTotal(items); + + _actions.add(event -> + { + EntityLivingBase entityLiving = event.getEntityLiving(); + + if (entityLiving != null) + { + ItemStack item = AuxFunctions.getRandomItem(items, total); + + if (entityLiving instanceof EntityEnderman) + { + if (item.getItem() instanceof ItemBlock) + { + ItemBlock b = (ItemBlock) item.getItem(); + ((EntityEnderman) entityLiving).setHeldBlockState(b.getBlock().getStateFromMeta(b.getMetadata(item.getItemDamage()))); + } + } + else + { + entityLiving.setHeldItem(EnumHand.MAIN_HAND, item.copy()); + } + } + }); + } + } + + /** + * + * @param map + * @param itemKey + * @param slot + */ + private void addArmorItem(AttributeMap map, AttributeKey itemKey, EntityEquipmentSlot slot) + { + List> items = AuxFunctions.getItemsWeighted(map.getList(itemKey)); + + if (items.isEmpty()) + { + return; + } + + if (items.size() == 1) + { + ItemStack item = items.get(0).getRight(); + + _actions.add(event -> + { + EntityLivingBase entityLiving = event.getEntityLiving(); + + if (entityLiving != null) + { + entityLiving.setItemStackToSlot(slot, item.copy()); + } + }); + } + else + { + float total = AuxFunctions.getTotal(items); + + _actions.add(event -> + { + EntityLivingBase entityLiving = event.getEntityLiving(); + + if (entityLiving != null) + { + entityLiving.setItemStackToSlot(slot, AuxFunctions.getRandomItem(items, total)); + } + }); + } + } + + /** + * + * @param map + */ + private void addMobNBT(AttributeMap map) + { + String mobNbt = (String)map.get(ACTION_SET_NBT); + + if (mobNbt != null) + { + NBTTagCompound tagCompound; + + try + { + tagCompound = JsonToNBT.getTagFromJson(mobNbt); + } + catch (NBTException e) + { + Log.writeDataToLogFile(Log._typeLog[2], "Bad NBT for mob!"); + return; + } + + _actions.add(event -> + { + EntityLivingBase entityLiving = event.getEntityLiving(); + entityLiving.readEntityFromNBT(tagCompound); + }); + } + } + + /** + * + * @param map + */ + private void addHealthAction(AttributeMap map) + { + Object multiple = map.has(ACTION_HEALTH_MULTIPLY) ? map.get(ACTION_HEALTH_MULTIPLY) : 1.f; + Object added = map.has(ACTION_HEALTH_ADD) ? map.get(ACTION_HEALTH_ADD) : 0.f; + + _actions.add(event -> + { + EntityLivingBase entityLiving = event.getEntityLiving(); + + if (entityLiving != null) + { + if (!entityLiving.getTags().contains("ctrlHealth")) + { + IAttributeInstance entityAttribute = entityLiving.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH); + + double newMax = entityAttribute.getBaseValue() * (Float)multiple + (Float)added; + entityAttribute.setBaseValue(newMax); + entityLiving.setHealth((float)newMax); + entityLiving.addTag("ctrlHealth"); + } + } + }); + } + + /** + * + * @param map + */ + private void addSpeedAction(AttributeMap map) + { + Object multiple = map.has(ACTION_SPEED_MULTIPLY) ? map.get(ACTION_SPEED_MULTIPLY) : 1.f; + Object added = map.has(ACTION_SPEED_ADD) ? map.get(ACTION_SPEED_ADD) : 0.f; + + _actions.add(event -> + { + EntityLivingBase entityLiving = event.getEntityLiving(); + + if (entityLiving != null) + { + if (!entityLiving.getTags().contains("ctrlSpeed")) + { + IAttributeInstance entityAttribute = entityLiving.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); + + double newMax = entityAttribute.getBaseValue() * (Float)multiple + (Float)added; + entityAttribute.setBaseValue(newMax); + entityLiving.addTag("ctrlSpeed"); + } + } + }); + } + + /** + * + * @param map + */ + private void addDamageAction(AttributeMap map) + { + Object multiple = map.has(ACTION_DAMAGE_MULTIPLY) ? map.get(ACTION_DAMAGE_MULTIPLY) : 1.f; + Object added = map.has(ACTION_DAMAGE_ADD) ? map.get(ACTION_DAMAGE_ADD) : 0.f; + + _actions.add(event -> + { + EntityLivingBase entityLiving = event.getEntityLiving(); + + if (entityLiving != null) + { + if (!entityLiving.getTags().contains("ctrlDamage")) + { + IAttributeInstance entityAttribute = entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE); + + double newMax = entityAttribute.getBaseValue() * (Float)multiple + (Float)added; + entityAttribute.setBaseValue(newMax); + entityLiving.addTag("ctrlDamage"); + } + } + }); + } + + /** + * + * @param map + */ + private void addCustomName(AttributeMap map) + { + Object customName = map.get(ACTION_CUSTOM_NAME); + + if (customName != null) + { + _actions.add(event -> + { + EntityLivingBase entityLiving = event.getEntityLiving(); + entityLiving.setCustomNameTag((String)customName); + }); + } + } + + /** + * + * @param map + */ + private void addPotionsAction(AttributeMap map) + { + List effects = new ArrayList<>(); + + for (String actionPotion : map.getList(ACTION_POTION)) + { + String[] split = Arrays.stream(StringUtils.split(actionPotion, ',')) + .map(String::trim) + .toArray(String[]::new); + + if (split.length < 3 || split.length > 4) + { + Log.writeDataToLogFile(Log._typeLog[2], "Bad potion specifier '" + actionPotion + "'! Use ,,[,]"); + continue; + } + + Potion potion = ForgeRegistries.POTIONS.getValue(new ResourceLocation(split[0])); + + if (potion == null) + { + Log.writeDataToLogFile(Log._typeLog[2], "Can't find potion '" + actionPotion + "'!"); + continue; + } + + int duration; + int amplifier; + double chance = 1.0D; // Default to 100% chance + + try + { + duration = Integer.parseInt(split[1]); + amplifier = Integer.parseInt(split[2]); + + if (split.length == 4) + { + chance = Double.parseDouble(split[3]); + } + } + catch (NumberFormatException e) + { + Log.writeDataToLogFile(Log._typeLog[2], "Bad duration, amplifier or chance integer for '" + actionPotion + "'!"); + continue; + } + + effects.add(new AuxFunctions.PotionEffectWithChance(new PotionEffect(potion, duration, amplifier), chance)); + } + + if (!effects.isEmpty()) + { + _actions.add(event -> + { + EntityLivingBase living = event.getEntityLiving(); + + if (living != null) + { + for (AuxFunctions.PotionEffectWithChance effectWithChance : effects) + { + if (Math.random() <= effectWithChance._chance) + { + PotionEffect effect = effectWithChance._effect; + PotionEffect newEffect = new PotionEffect(effect.getPotion(), effect.getDuration(), effect.getAmplifier()); + living.addPotionEffect(newEffect); + } + } + } + }); + } + } + + /** + * + * @param map + */ + private void addGiveAction(AttributeMap map) + { + List> items = AuxFunctions.getItemsWeighted(map.getList(ACTION_GIVE)); + + if (items.isEmpty()) + { + return; + } + + if (items.size() == 1) + { + ItemStack item = items.get(0).getRight(); + + _actions.add(event -> + { + EntityPlayer player = event.getPlayer(); + + if (player != null) + { + if (!player.inventory.addItemStackToInventory(item.copy())) + { + player.entityDropItem(item.copy(), 1.05f); + } + } + }); + } + else + { + float total = AuxFunctions.getTotal(items); + + _actions.add(event -> + { + EntityPlayer player = event.getPlayer(); + + if (player != null) + { + ItemStack item = AuxFunctions.getRandomItem(items, total); + + if (!player.inventory.addItemStackToInventory(item.copy())) + { + player.entityDropItem(item.copy(), 1.05f); + } + } + }); + } + } + + /** + * + * @param map + */ + private void addDropAction(AttributeMap map) + { + List> items = AuxFunctions.getItemsWeighted(map.getList(ACTION_DROP)); + + if (items.isEmpty()) + { + return; + } + + if (items.size() == 1) + { + ItemStack item = items.get(0).getRight(); + + _actions.add(event -> + { + BlockPos pos = event.getPosition(); + EntityItem entityItem = new EntityItem(event.getWorld(), pos.getX(), pos.getY(), pos.getZ(), item.copy()); + event.getWorld().spawnEntity(entityItem); + }); + } + else + { + float total = AuxFunctions.getTotal(items); + + _actions.add(event -> + { + BlockPos pos = event.getPosition(); + ItemStack item = AuxFunctions.getRandomItem(items, total); + EntityItem entityItem = new EntityItem(event.getWorld(), pos.getX(), pos.getY(), pos.getZ(), item.copy()); + event.getWorld().spawnEntity(entityItem); + }); + } + } + + /** + * + * @param map + */ + private void addCommandAction(AttributeMap map) + { + Object command = map.get(ACTION_COMMAND); + + _actions.add(event -> + { + EntityPlayer player = event.getPlayer(); + MinecraftServer server = event.getWorld().getMinecraftServer(); + + assert server != null; + + server.commandManager.executeCommand(player != null ? player : new Sender(event.getWorld(), null), (String)command); + }); + } + + /** + * + * @param map + */ + private void addFireAction(AttributeMap map) + { + Object fireAction = map.get(ACTION_FIRE); + + _actions.add(event -> + { + EntityLivingBase living = event.getEntityLiving(); + + if (living != null) + { + living.attackEntityFrom(DamageSource.ON_FIRE, 0.1f); + living.setFire((Integer)fireAction); + } + }); + } + + /** + * + * @param map + */ + private void addExplosionAction(AttributeMap map) + { + String fireAction = (String)map.get(ACTION_EXPLOSION); + String[] split = StringUtils.split(fireAction, ","); + + float strength = 1.0f; + + boolean flaming = false; + boolean smoking = false; + + try + { + strength = Float.parseFloat(split[0]); + flaming = "1".equalsIgnoreCase(split[1]) || "true".equals(split[1].toLowerCase()) || "yes".equals(split[1].toLowerCase()); + smoking = "1".equalsIgnoreCase(split[2]) || "true".equals(split[2].toLowerCase()) || "yes".equals(split[2].toLowerCase()); + } + catch (Exception ignore) + { + + } + + float finalStrength = strength; + boolean finalFlaming = flaming; + boolean finalSmoking = smoking; + + _actions.add(event -> + { + BlockPos pos = event.getPosition(); + + if (pos != null) + { + event.getWorld().newExplosion(null, pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5, finalStrength, finalFlaming, finalSmoking); + } + }); + } + + /** + * + * @param map + */ + private void addClearAction(AttributeMap map) + { + Object clear = map.get(ACTION_CLEAR); + + if ((Boolean)clear) + { + _actions.add(event -> + { + EntityLivingBase living = event.getEntityLiving(); + + if (living != null) + { + living.clearActivePotions(); + } + }); + } + } + + /** + * + * @param map + */ + private void addDoDamageAction(AttributeMap map) + { + String damage = (String) map.get(ACTION_DAMAGE); + String[] split = StringUtils.split(damage, "="); + DamageSource source = AuxFunctions._damageMap.get(split[0]); + + if (source == null) + { + Log.writeDataToLogFile(Log._typeLog[2], "Can't find damage source '" + split[0] + "'!"); + return; + } + + float amount = split.length > 1 ? Float.parseFloat(split[1]) : 1.0f; + + _actions.add(event -> + { + EntityLivingBase living = event.getEntityLiving(); + + if (living != null) + { + living.attackEntityFrom(source, amount); + } + }); + } + + /** + * + * @param map + */ + private void addSetBlockAction(AttributeMap map) + { + Function posFunction; + + if (map.has(BLOCK_OFFSET)) + { + posFunction = (Function) + AuxFunctions.parseOffset((String)map.get(BLOCK_OFFSET)); + } + else + { + posFunction = event -> event.getPosition(); + } + + Object json = map.get(ACTION_SET_BLOCK); + JsonParser parser = new JsonParser(); + JsonElement element = parser.parse((String)json); + + if (element.isJsonPrimitive()) + { + String blockName = element.getAsString(); + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + + if (block == null) + { + Log.writeDataToLogFile(Log._typeLog[2], "Block '" + blockName + "' is not valid!"); + return; + } + + IBlockState state = block.getDefaultState(); + + _actions.add(event -> + { + BlockPos pos = posFunction.apply(event); + + if (pos != null) + { + event.getWorld().setBlockState(pos, state, 3); + } + }); + } + else + { + JsonObject obj = element.getAsJsonObject(); + + if (!obj.has("block")) + { + Log.writeDataToLogFile(Log._typeLog[2], "Block is not valid!"); + return; + } + + String blockName = obj.get("block").getAsString(); + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + + if (block == null) + { + Log.writeDataToLogFile(Log._typeLog[2], "Block '" + blockName + "' is not valid!"); + return; + } + + IBlockState state = block.getDefaultState(); + + if (obj.has("properties")) + { + JsonArray propArray = obj.get("properties").getAsJsonArray(); + + for (JsonElement el : propArray) + { + JsonObject propObj = el.getAsJsonObject(); + String name = propObj.get("name").getAsString(); + String value = propObj.get("value").getAsString(); + + for (IProperty key : state.getPropertyKeys()) + { + if (name.equals(key.getName())) + { + state = AuxFunctions.set(state, key, value); + } + } + } + } + + IBlockState finalState = state; + + _actions.add(event -> + { + BlockPos pos = posFunction.apply(event); + + if (pos != null) + { + event.getWorld().setBlockState(pos, finalState, 3); + } + }); + } + } + + /** + * + * @param map + */ + private void addSetHeldItemAction(AttributeMap map) + { + Object json = map.get(ACTION_SET_HELD_ITEM); + JsonParser parser = new JsonParser(); + JsonElement element = parser.parse((String)json); + ItemStack stack; + + if (element.isJsonPrimitive()) + { + String name = element.getAsString(); + stack = ItemStackBuilder.parseStack(name); + } + else if (element.isJsonObject()) + { + JsonObject obj = element.getAsJsonObject(); + stack = ItemStackBuilder.parseStack(obj); + + if (stack == null) + { + return; + } + } + else + { + Log.writeDataToLogFile(Log._typeLog[2], "Item description '" + json + "' is not valid!"); + return; + } + + _actions.add(event -> event.getPlayer().setHeldItem(EnumHand.MAIN_HAND, stack.copy())); + } + + /** + * + * @param map + */ + private void addSetHeldAmountAction(AttributeMap map) + { + String amount = (String)map.get(ACTION_SET_HELD_AMOUNT); + + int add = 0; + int set = -1; + + if (amount.startsWith("+")) + { + add = Integer.parseInt(amount.substring(1)); + } + else if (amount.startsWith("-")) + { + add = -Integer.parseInt(amount.substring(1)); + } + else if (amount.startsWith("=")) + { + set = Integer.parseInt(amount.substring(1)); + } + else + { + set = Integer.parseInt(amount); + } + + int finalSet = set; + + if (finalSet >= 0) + { + _actions.add(event -> + { + ItemStack item = event.getPlayer().getHeldItemMainhand(); + item.setCount(finalSet); + event.getPlayer().setHeldItem(EnumHand.MAIN_HAND, item.copy()); + }); + } + else + { + int finalAdd = add; + + _actions.add(event -> + { + ItemStack item = event.getPlayer().getHeldItemMainhand(); + + int newCount = item.getCount() + finalAdd; + + if (newCount < 0) + { + newCount = 0; + } + else if (newCount >= item.getMaxStackSize()) + { + newCount = item.getMaxStackSize()-1; + } + + item.setCount(newCount); + event.getPlayer().setHeldItem(EnumHand.MAIN_HAND, item.copy()); + }); + } + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsStaticFactoryBlocks.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsStaticFactoryBlocks.java new file mode 100644 index 0000000..f9fe025 --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsStaticFactoryBlocks.java @@ -0,0 +1,74 @@ +package org.imesense.dynamicspawncontrol.technical.customlibrary; + +/** + * + */ +public class ListActionsStaticFactoryBlocks +{ + public static final AttributeMapFactory FACTORY = new AttributeMapFactory<>(); + + static + { + FACTORY + .attribute(Attribute.create(ID_RULE)) + .attribute(Attribute.create(SEE_SKY)) + .attribute(Attribute.create(WEATHER)) + .attribute(Attribute.create(STRUCTURE)) + .attribute(Attribute.createMulti(BIOMES)) + .attribute(Attribute.createMulti(BIOMES_TYPE)) + .attribute(Attribute.createMulti(DIMENSION)) + + .attribute(Attribute.createMulti(HELMET)) + .attribute(Attribute.createMulti(CHEST_PLATE)) + .attribute(Attribute.createMulti(LEGGINGS)) + .attribute(Attribute.createMulti(BOOTS)) + + .attribute(Attribute.create(MIN_TIME)) + .attribute(Attribute.create(MAX_TIME)) + + .attribute(Attribute.create(MIN_LIGHT)) + .attribute(Attribute.create(MAX_LIGHT)) + + .attribute(Attribute.create(MIN_HEIGHT)) + .attribute(Attribute.create(MAX_HEIGHT)) + + .attribute(Attribute.create(DIFFICULTY)) + .attribute(Attribute.create(MIN_DIFFICULTY)) + .attribute(Attribute.create(MAX_DIFFICULTY)) + + .attribute(Attribute.create(MIN_SPAWN_DIST)) + .attribute(Attribute.create(MAX_SPAWN_DIST)) + + .attribute(Attribute.createMulti(BLOCK)) + .attribute(Attribute.create(BLOCK_OFFSET)) + + .attribute(Attribute.create(GET_MOON_PHASE)) + + .attribute(Attribute.createMulti(HELD_ITEM)) + .attribute(Attribute.createMulti(PLAYER_HELD_ITEM)) + .attribute(Attribute.createMulti(OFF_HAND_ITEM)) + .attribute(Attribute.createMulti(BOTH_HANDS_ITEM)) + + .attribute(Attribute.create(RANDOM_KEY_0)) + .attribute(Attribute.create(RANDOM_KEY_1)) + .attribute(Attribute.create(RANDOM_KEY_2)) + .attribute(Attribute.create(RANDOM_KEY_3)) + .attribute(Attribute.create(RANDOM_KEY_4)) + + .attribute(Attribute.create(ACTION_RESULT)) + + .attribute(Attribute.create(ACTION_MESSAGE)) + .attribute(Attribute.createMulti(ACTION_POTION)) + .attribute(Attribute.createMulti(ACTION_GIVE)) + .attribute(Attribute.createMulti(ACTION_DROP)) + .attribute(Attribute.create(ACTION_COMMAND)) + .attribute(Attribute.create(ACTION_FIRE)) + .attribute(Attribute.create(ACTION_EXPLOSION)) + .attribute(Attribute.create(ACTION_CLEAR)) + .attribute(Attribute.create(ACTION_DAMAGE)) + .attribute(Attribute.create(ACTION_SET_BLOCK)) + .attribute(Attribute.create(ACTION_SET_HELD_ITEM)) + .attribute(Attribute.create(ACTION_SET_HELD_AMOUNT)) + ; + } +} diff --git a/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsStaticFactoryMouse.java b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsStaticFactoryMouse.java new file mode 100644 index 0000000..92e99a6 --- /dev/null +++ b/dynamicspawncontrol-1.12.2/src/main/java/org/imesense/dynamicspawncontrol/technical/customlibrary/ListActionsStaticFactoryMouse.java @@ -0,0 +1,74 @@ +package org.imesense.dynamicspawncontrol.technical.customlibrary; + +/** + * + */ +public class ListActionsStaticFactoryMouse +{ + public static final AttributeMapFactory FACTORY = new AttributeMapFactory<>(); + + static + { + FACTORY + .attribute(Attribute.create(ID_RULE)) + .attribute(Attribute.create(SEE_SKY)) + .attribute(Attribute.create(WEATHER)) + .attribute(Attribute.create(STRUCTURE)) + .attribute(Attribute.createMulti(BIOMES)) + .attribute(Attribute.createMulti(BIOMES_TYPE)) + .attribute(Attribute.createMulti(DIMENSION)) + + .attribute(Attribute.createMulti(HELMET)) + .attribute(Attribute.createMulti(CHEST_PLATE)) + .attribute(Attribute.createMulti(LEGGINGS)) + .attribute(Attribute.createMulti(BOOTS)) + + .attribute(Attribute.create(MIN_TIME)) + .attribute(Attribute.create(MAX_TIME)) + + .attribute(Attribute.create(MIN_LIGHT)) + .attribute(Attribute.create(MAX_LIGHT)) + + .attribute(Attribute.create(MIN_HEIGHT)) + .attribute(Attribute.create(MAX_HEIGHT)) + + .attribute(Attribute.create(DIFFICULTY)) + .attribute(Attribute.create(MIN_DIFFICULTY)) + .attribute(Attribute.create(MAX_DIFFICULTY)) + + .attribute(Attribute.create(MIN_SPAWN_DIST)) + .attribute(Attribute.create(MAX_SPAWN_DIST)) + + .attribute(Attribute.createMulti(BLOCK)) + .attribute(Attribute.create(BLOCK_OFFSET)) + + .attribute(Attribute.create(GET_MOON_PHASE)) + + .attribute(Attribute.createMulti(HELD_ITEM)) + .attribute(Attribute.createMulti(PLAYER_HELD_ITEM)) + .attribute(Attribute.createMulti(OFF_HAND_ITEM)) + .attribute(Attribute.createMulti(BOTH_HANDS_ITEM)) + + .attribute(Attribute.create(RANDOM_KEY_0)) + .attribute(Attribute.create(RANDOM_KEY_1)) + .attribute(Attribute.create(RANDOM_KEY_2)) + .attribute(Attribute.create(RANDOM_KEY_3)) + .attribute(Attribute.create(RANDOM_KEY_4)) + + .attribute(Attribute.create(ACTION_RESULT)) + + .attribute(Attribute.create(ACTION_MESSAGE)) + .attribute(Attribute.createMulti(ACTION_POTION)) + .attribute(Attribute.createMulti(ACTION_GIVE)) + .attribute(Attribute.createMulti(ACTION_DROP)) + .attribute(Attribute.create(ACTION_COMMAND)) + .attribute(Attribute.create(ACTION_FIRE)) + .attribute(Attribute.create(ACTION_EXPLOSION)) + .attribute(Attribute.create(ACTION_CLEAR)) + .attribute(Attribute.create(ACTION_DAMAGE)) + .attribute(Attribute.create(ACTION_SET_BLOCK)) + .attribute(Attribute.create(ACTION_SET_HELD_ITEM)) + .attribute(Attribute.create(ACTION_SET_HELD_AMOUNT)) + ; + } +}