Skip to content

Commit

Permalink
1.20.6 Update II
Browse files Browse the repository at this point in the history
 - Started working on Enchantment Configuration
  • Loading branch information
chronosacaria committed May 25, 2024
1 parent 04a20d0 commit 1f45dd5
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 84 deletions.
69 changes: 36 additions & 33 deletions src/main/java/dev/timefall/mcdw/api/util/AOEHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.util.math.Box;

import java.util.List;
Expand All @@ -18,36 +21,36 @@
public class AOEHelper {

// Owner is center
//public static List<LivingEntity> getEntitiesByConfig(LivingEntity center, float distance) {
// int permissionLevel = Mcdw.CONFIG.mcdwEnchantmentSettingsConfig.aoePermission;
// //noinspection DuplicatedCode
// Predicate<? super LivingEntity> predicate = livingEntity -> AbilityHelper.isAoeTarget(center, livingEntity) &&
// switch (permissionLevel) {
// case 1 -> !AbilityHelper.isTrueAlly(center, livingEntity);
// case 2 -> !AbilityHelper.isTrueAlly(center, livingEntity) && !(livingEntity instanceof AnimalEntity);
// case 3 -> !AbilityHelper.isPotentialAlly(livingEntity);
// case 4 -> livingEntity instanceof HostileEntity;
// // case 0 has no further restrictions
// default -> true;
// };
// return getEntitiesByPredicate(center, distance, predicate);
//}
public static List<LivingEntity> getEntitiesByConfig(LivingEntity center, float distance) {
int permissionLevel = Mcdw.CONFIG.mcdwEnchantmentSettingsConfig.aoePermission;
//noinspection DuplicatedCode
Predicate<? super LivingEntity> predicate = livingEntity -> AbilityHelper.isAoeTarget(center, livingEntity) &&
switch (permissionLevel) {
case 1 -> !AbilityHelper.isTrueAlly(center, livingEntity);
case 2 -> !AbilityHelper.isTrueAlly(center, livingEntity) && !(livingEntity instanceof AnimalEntity);
case 3 -> !AbilityHelper.isPotentialAlly(livingEntity);
case 4 -> livingEntity instanceof HostileEntity;
// case 0 has no further restrictions
default -> true;
};
return getEntitiesByPredicate(center, distance, predicate);
}

// Owner and center are different
//public static List<LivingEntity> getEntitiesByConfig(LivingEntity center, LivingEntity owner, float distance) {
// int permissionLevel = Mcdw.CONFIG.mcdwEnchantmentSettingsConfig.aoePermission;
// //noinspection DuplicatedCode
// Predicate<? super LivingEntity> predicate = livingEntity -> AbilityHelper.isAoeTarget(center, owner, livingEntity) &&
// switch (permissionLevel) {
// case 1 -> !AbilityHelper.isTrueAlly(owner, livingEntity);
// case 2 -> !AbilityHelper.isTrueAlly(owner, livingEntity) && !(livingEntity instanceof AnimalEntity);
// case 3 -> !AbilityHelper.isPotentialAlly(livingEntity);
// case 4 -> livingEntity instanceof HostileEntity;
// // case 0 has no further restrictions
// default -> true;
// };
// return getEntitiesByPredicate(center, distance, predicate);
//}
public static List<LivingEntity> getEntitiesByConfig(LivingEntity center, LivingEntity owner, float distance) {
int permissionLevel = Mcdw.CONFIG.mcdwEnchantmentSettingsConfig.aoePermission;
//noinspection DuplicatedCode
Predicate<? super LivingEntity> predicate = livingEntity -> AbilityHelper.isAoeTarget(center, owner, livingEntity) &&
switch (permissionLevel) {
case 1 -> !AbilityHelper.isTrueAlly(owner, livingEntity);
case 2 -> !AbilityHelper.isTrueAlly(owner, livingEntity) && !(livingEntity instanceof AnimalEntity);
case 3 -> !AbilityHelper.isPotentialAlly(livingEntity);
case 4 -> livingEntity instanceof HostileEntity;
// case 0 has no further restrictions
default -> true;
};
return getEntitiesByPredicate(center, distance, predicate);
}

/** Returns targets of an AOE effect from 'attacker' around 'center'. This includes 'center'. */
public static List<LivingEntity> getEntitiesByPredicate(LivingEntity center, float distance, Predicate<? super LivingEntity> predicate) {
Expand All @@ -64,11 +67,11 @@ public static List<? extends LivingEntity> getEntitiesByPredicate(Class<? extend
}

//public static void afflictNearbyEntities(LivingEntity user, float distance, StatusEffectInstance... statusEffectInstances) {
// for (LivingEntity nearbyEntity : getEntitiesByConfig(user, distance)) {
// for (StatusEffectInstance instance : statusEffectInstances)
// nearbyEntity.addStatusEffect(instance);
// }
//}
for (LivingEntity nearbyEntity : getEntitiesByConfig(user, distance)) {
for (StatusEffectInstance instance : statusEffectInstances)
nearbyEntity.addStatusEffect(instance);
}
}

public static boolean satisfySweepConditions(LivingEntity attackingEntity, Entity targetEntity, LivingEntity collateralEntity, float distanceToCollateral) {
return collateralEntity != attackingEntity && collateralEntity != targetEntity && !attackingEntity.isTeammate(collateralEntity)
Expand Down
39 changes: 20 additions & 19 deletions src/main/java/dev/timefall/mcdw/api/util/AbilityHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package dev.timefall.mcdw.api.util;

import dev.timefall.mcdw.enchants.goals.GoalUtils;
import dev.timefall.mcdw.enums.SettingsID;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
Expand Down Expand Up @@ -67,27 +68,27 @@ private static boolean isVillagerTyped(LivingEntity nearbyEntity) {
return (nearbyEntity instanceof VillagerEntity) || (nearbyEntity instanceof IronGolemEntity);
}

//public static boolean isAoeTarget(LivingEntity self, LivingEntity foreignEntity) {
// return foreignEntity != self
// && foreignEntity.isAlive()
// && isAffectedByAoe(foreignEntity)
// && self.canSee(foreignEntity);
//}
public static boolean isAoeTarget(LivingEntity self, LivingEntity foreignEntity) {
return foreignEntity != self
&& foreignEntity.isAlive()
&& isAffectedByAoe(foreignEntity)
&& self.canSee(foreignEntity);
}

//public static boolean isAoeTarget(LivingEntity center, LivingEntity owner, LivingEntity foreignEntity) {
// return foreignEntity != owner
// && foreignEntity.isAlive()
// && isAffectedByAoe(foreignEntity)
// && center.canSee(foreignEntity);
//}
public static boolean isAoeTarget(LivingEntity center, LivingEntity owner, LivingEntity foreignEntity) {
return foreignEntity != owner
&& foreignEntity.isAlive()
&& isAffectedByAoe(foreignEntity)
&& center.canSee(foreignEntity);
}

//private static boolean isAffectedByAoe(LivingEntity entity) {
// if (entity instanceof PlayerEntity player) {
// if (player.isCreative()) return false;
// return !Mcdw.CONFIG.mcdwEnchantmentSettingsConfig.ENABLE_ENCHANTMENT_SETTINGS.get(SettingsID.AREA_OF_EFFECT_ENCHANTS_DONT_AFFECT_PLAYERS);
// }
// return true;
//}
private static boolean isAffectedByAoe(LivingEntity entity) {
if (entity instanceof PlayerEntity player) {
if (player.isCreative()) return false;
return !Mcdw.CONFIG.mcdwEnchantmentSettingsConfig.ENABLE_ENCHANTMENT_SETTINGS.get(SettingsID.AREA_OF_EFFECT_ENCHANTS_DONT_AFFECT_PLAYERS);
}
return true;
}

public static float getAnimaRepairAmount(float experience, int level) {
experience *= (float) (0.2 * level);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,23 @@
/*
* Timefall Development License 1.2
* Copyright (c) 2020-2024. Chronosacaria, Kluzzio, Timefall Development. All Rights Reserved.
* Copyright (c) 2024. Chronosacaria, Kluzzio, Timefall Development. All Rights Reserved.
*
* This software's content is licensed under the Timefall Development License 1.2. You can find this license information here: https://github.com/Timefall-Development/Timefall-Development-Licence/blob/main/TimefallDevelopmentLicense1.2.txt
*/
package dev.timefall.mcdw.configs;
/*
import dev.timefall.mcdw.enums.SettingsID;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Comment;

import java.util.LinkedHashMap;
package dev.timefall.mcdw.configs;

@Config(name = "mcdw_enchantment_settings_config")
public class McdwEnchantmentSettingsConfig implements ConfigData {
import dev.timefall.mcdw.Mcdw;
import me.fzzyhmstrs.fzzy_config.api.ConfigApi;
import me.fzzyhmstrs.fzzy_config.config.Config;

@Comment("""
Default (0): Everything other than self
Next Permission (1): Not self and not teammates or pets of self
Next Permission (2): Not self and not teammates or pets of self or AnimalEntities (not hitting farm animals is not present in permission 3)
Next Permission (3): Not self and not Potential allies (pets of any player, iron golems, villagers, players)
Final Permission (4): Only hostile mobs
WARNING: LOOKS AT HOSTILE ENTITY CLASS WHICH DOES NOT INCLUDE ENDER DRAGON AND OTHERS.
If anything else is put, it will be treated as default""")
public int aoePermission = 0;
import java.util.function.Supplier;

// Enchantment Settings
public final LinkedHashMap<SettingsID, Boolean> ENABLE_ENCHANTMENT_SETTINGS = new LinkedHashMap<>();
public class McdwEnchantmentSettingsConfig extends Config {
public static final McdwEnchantmentSettingsConfig CONFIG = ConfigApi.registerAndLoadConfig((Supplier<McdwEnchantmentSettingsConfig>) McdwEnchantmentSettingsConfig::new);

public McdwEnchantmentSettingsConfig(){
ENABLE_ENCHANTMENT_SETTINGS.put(SettingsID.ENABLE_OP_ENCHANTMENT_MIXING, false);
ENABLE_ENCHANTMENT_SETTINGS.put(SettingsID.LEECHING_CAN_BE_MIXED_WITH_HEALING, false);
ENABLE_ENCHANTMENT_SETTINGS.put(SettingsID.EXTRA_XP_HEALING, false);
ENABLE_ENCHANTMENT_SETTINGS.put(SettingsID.SHARED_PAIN_CAN_DAMAGE_USER, false);
ENABLE_ENCHANTMENT_SETTINGS.put(SettingsID.AREA_OF_EFFECT_ENCHANTS_DONT_AFFECT_PLAYERS, true);
ENABLE_ENCHANTMENT_SETTINGS.put(SettingsID.ENABLE_INNATE_ENCHANTMENTS, true);
public McdwEnchantmentSettingsConfig() {
super(Mcdw.ID("mcdw_enchantment_settings_config"));
}
}

*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Timefall Development License 1.2
* Copyright (c) 2020-2024. Chronosacaria, Kluzzio, Timefall Development. All Rights Reserved.
*
* This software's content is licensed under the Timefall Development License 1.2. You can find this license information here: https://github.com/Timefall-Development/Timefall-Development-Licence/blob/main/TimefallDevelopmentLicense1.2.txt
*/
package dev.timefall.mcdw.configs;

import dev.timefall.mcdw.enums.SettingsID;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Comment;

import java.util.LinkedHashMap;

@Config(name = "mcdw_enchantment_settings_config")
public class McdwEnchantmentSettingsConfigOld implements ConfigData {

@Comment("""
Default (0): Everything other than self
Next Permission (1): Not self and not teammates or pets of self
Next Permission (2): Not self and not teammates or pets of self or AnimalEntities (not hitting farm animals is not present in permission 3)
Next Permission (3): Not self and not Potential allies (pets of any player, iron golems, villagers, players)
Final Permission (4): Only hostile mobs
WARNING: LOOKS AT HOSTILE ENTITY CLASS WHICH DOES NOT INCLUDE ENDER DRAGON AND OTHERS.
If anything else is put, it will be treated as default""")
public int aoePermission = 0;

// Enchantment Settings
public final LinkedHashMap<SettingsID, Boolean> ENABLE_ENCHANTMENT_SETTINGS = new LinkedHashMap<>();

public McdwEnchantmentSettingsConfigOld(){
ENABLE_ENCHANTMENT_SETTINGS.put(SettingsID.ENABLE_OP_ENCHANTMENT_MIXING, false);
ENABLE_ENCHANTMENT_SETTINGS.put(SettingsID.LEECHING_CAN_BE_MIXED_WITH_HEALING, false);
ENABLE_ENCHANTMENT_SETTINGS.put(SettingsID.EXTRA_XP_HEALING, false);
ENABLE_ENCHANTMENT_SETTINGS.put(SettingsID.SHARED_PAIN_CAN_DAMAGE_USER, false);
ENABLE_ENCHANTMENT_SETTINGS.put(SettingsID.AREA_OF_EFFECT_ENCHANTS_DONT_AFFECT_PLAYERS, true);
ENABLE_ENCHANTMENT_SETTINGS.put(SettingsID.ENABLE_INNATE_ENCHANTMENTS, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class McdwEnchantmentStatsConfig extends Config {
public static final McdwEnchantmentStatsConfig CONFIG = ConfigApi.registerAndLoadConfig((Supplier<McdwEnchantmentStatsConfig>) McdwEnchantmentStatsConfig::new);

public McdwEnchantmentStatsConfig() {
super(Mcdw.ID("mcdw_stats_config"));
super(Mcdw.ID("mcdw_enchantment_stats_config"));
}

private McdwEnchantmentStats mcdwEnchantmentStats = new McdwEnchantmentStats();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class McdwWeaponStatsConfig extends Config {
public static final McdwWeaponStatsConfig CONFIG = ConfigApi.registerAndLoadConfig((Supplier<McdwWeaponStatsConfig>) McdwWeaponStatsConfig::new);

public McdwWeaponStatsConfig() {
super(Mcdw.ID("mcdw_stats_config"));
super(Mcdw.ID("mcdw_weapon_stats_config"));
}

private McdwAxeItemStats mcdwAxeItemStats = new McdwAxeItemStats();
Expand Down

0 comments on commit 1f45dd5

Please sign in to comment.