Skip to content

Commit

Permalink
Merge pull request #280 from fzzyhmstrs/1.20.6
Browse files Browse the repository at this point in the history
Fzzy Update 1 - Start work on Enchantment Datagen, Enchantment Tags, …
  • Loading branch information
chronosacaria committed May 28, 2024
2 parents 1abf045 + 64921ad commit 092ad88
Show file tree
Hide file tree
Showing 65 changed files with 2,050 additions and 440 deletions.
7 changes: 7 additions & 0 deletions src/main/java/dev/timefall/mcdw/Mcdw.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
package dev.timefall.mcdw;

import dev.timefall.mcdw.configs.CompatibilityFlags;
import dev.timefall.mcdw.data.ConfigEnchantmentEnabledCondition;
import dev.timefall.mcdw.data.ConfigItemEnabledCondition;
import dev.timefall.mcdw.enchants.EnchantmentIds;
import dev.timefall.mcdw.registries.*;
import dev.timefall.mcdw.registries.items.*;
import net.fabricmc.api.ModInitializer;
Expand All @@ -25,6 +28,7 @@ public static Identifier ID(String path) {

@Override
public void onInitialize() {
McdwRegistries.register();
// Register Weapons
// TODO CHECK ORDER AND MAKE SURE CALLED WHERE NEEDS TO BE CALLED
McdwAxeItemRegistry.register();
Expand All @@ -47,6 +51,9 @@ public void onInitialize() {
McdwSwordItemRegistry.register();
McdwWhipItemRegistry.register();

EnchantmentIds.init();
ConfigEnchantmentEnabledCondition.register();
ConfigItemEnabledCondition.register();
CompatibilityFlags.init();
CompatRegistry.register();
EntityAttributesRegistry.register();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/timefall/mcdw/api/util/AOEHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static List<LivingEntity> getEntitiesByConfig(LivingEntity center, Living
return getEntitiesByPredicate(center, distance, predicate);
}

/** Returns targets of an AOE effect from 'attacker' around 'center'. This includes 'center'. */
/** Returns targets of an AOE statusEffect from 'attacker' around 'center'. This includes 'center'. */
public static List<LivingEntity> getEntitiesByPredicate(LivingEntity center, float distance, Predicate<? super LivingEntity> predicate) {
return center.getEntityWorld().getEntitiesByClass(LivingEntity.class,
new Box(center.getBlockPos()).expand(distance), predicate
Expand All @@ -78,4 +78,4 @@ public static boolean satisfySweepConditions(LivingEntity attackingEntity, Entit
&& !(collateralEntity instanceof ArmorStandEntity armorStand && armorStand.isMarker())
&& attackingEntity.distanceTo(collateralEntity) < distanceToCollateral;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class ProjectileEffectHelper {
}
}

//public static List<LivingEntity> mcdw$getSecondaryTargets(LivingEntity source, double distance) {
//public static List<LivingEntity> mcdw$getSecondaryTargets(LivingEntity source, double radius) {
// List<LivingEntity> nearbyEntities = AOEHelper.getEntitiesByConfig(source, (float) distance);
// if (nearbyEntities.size() < 2) return Collections.emptyList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
package dev.timefall.mcdw.component;

import dev.timefall.mcdw.Mcdw;
import dev.timefall.mcdw.enchants.effect.EntityAwareValueEffectType;
import net.minecraft.component.ComponentType;
import net.minecraft.enchantment.effect.EnchantmentEffectEntry;
import net.minecraft.enchantment.effect.EnchantmentEntityEffectType;
import net.minecraft.enchantment.effect.EnchantmentValueEffectType;
import net.minecraft.enchantment.effect.TargetedEnchantmentEffectType;
import net.minecraft.loot.context.LootContextTypes;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;

Expand All @@ -19,10 +23,14 @@

public class McdwEffectComponentTypes {

public static final ComponentType<List<EnchantmentEffectEntry<EnchantmentValueEffectType>>> ACCELERATE_CHARGE_TIME = register("accelerate_charge_time", builder -> builder);
public static final ComponentType<EntityAwareValueEffectType> ACCELERATE_CHARGE_TIME = register("accelerate_charge_time", builder -> builder.codec(EntityAwareValueEffectType.CODEC));
public static final ComponentType<List<EnchantmentEffectEntry<EntityAwareValueEffectType>>> ENTITY_AWARE_DAMAGE = register("entity_aware_damage", builder -> builder.codec(EnchantmentEffectEntry.createCodec(EntityAwareValueEffectType.CODEC, LootContextTypes.ENCHANTED_DAMAGE).listOf()));
public static final ComponentType<List<EnchantmentEffectEntry<EnchantmentEntityEffectType>>> ON_JUMP = register("on_jump", builder -> builder.codec(EnchantmentEffectEntry.createCodec(EnchantmentEntityEffectType.CODEC, LootContextTypes.ENCHANTED_ENTITY).listOf()));
public static final ComponentType<List<TargetedEnchantmentEffectType<EnchantmentEntityEffectType>>> POST_DEATH = register("post_death", builder -> builder.codec(TargetedEnchantmentEffectType.createPostAttackCodec(EnchantmentEntityEffectType.CODEC, LootContextTypes.ENCHANTED_DAMAGE).listOf()));
public static final ComponentType<List<EnchantmentEffectEntry<EnchantmentValueEffectType>>> XP_REPAIR_PLAYER = register("xp_repair_player", builder -> builder.codec(EnchantmentEffectEntry.createCodec(EnchantmentValueEffectType.CODEC, LootContextTypes.ENCHANTED_ENTITY).listOf()));


private static <T> ComponentType<T> register(String id, UnaryOperator<ComponentType.Builder<T>> builderOperator) {
return Registry.register(Registries.ENCHANTMENT_EFFECT_COMPONENT_TYPE, Mcdw.ID(id), (builderOperator.apply(ComponentType.builder())).build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,27 @@
package dev.timefall.mcdw.configs;

import dev.timefall.mcdw.Mcdw;
import dev.timefall.mcdw.enchants.EnchantmentIds;
import me.fzzyhmstrs.fzzy_config.annotations.IgnoreVisibility;
import me.fzzyhmstrs.fzzy_config.api.ConfigApi;
import me.fzzyhmstrs.fzzy_config.config.Config;
import me.fzzyhmstrs.fzzy_config.validation.collection.ValidatedList;
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedIdentifier;
import net.minecraft.util.Identifier;

import java.util.function.Supplier;

@SuppressWarnings("FieldMayBeFinal")
@IgnoreVisibility
public class McdwEnchantmentSettingsConfig extends Config {
public static final McdwEnchantmentSettingsConfig CONFIG = ConfigApi.registerAndLoadConfig((Supplier<McdwEnchantmentSettingsConfig>) McdwEnchantmentSettingsConfig::new);
public static final McdwEnchantmentSettingsConfig CONFIG = ConfigApi.registerAndLoadConfig(McdwEnchantmentSettingsConfig::new);

public McdwEnchantmentSettingsConfig() {
super(Mcdw.ID("mcdw_enchantment_settings_config"));
}

}
private ValidatedList<Identifier> disabledEnchantments = ValidatedIdentifier.ofSuppliedList(() -> EnchantmentIds.ENCHANTMENT_IDS).toList();

public boolean isEnchantmentEnabled(Identifier id){
return !disabledEnchantments.contains(id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
import me.fzzyhmstrs.fzzy_config.annotations.IgnoreVisibility;
import me.fzzyhmstrs.fzzy_config.api.ConfigApi;
import me.fzzyhmstrs.fzzy_config.config.Config;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;

import java.beans.Transient;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.function.Supplier;

@SuppressWarnings("FieldMayBeFinal")
@IgnoreVisibility
Expand All @@ -24,6 +31,18 @@ public McdwWeaponStatsConfig() {
super(Mcdw.ID("mcdw_weapon_stats_config"));
}

transient private LinkedHashMap<Identifier, Supplier<Boolean>> itemEnabledMap = new LinkedHashMap<>();

@ApiStatus.Internal
public void registerItemEnableCheck(Identifier id, Supplier<Boolean> checker){
itemEnabledMap.put(id,checker);
}

public boolean isItemEnabled(Identifier id) {
//supplier returns isEnabled, we negate that for disabled check
return itemEnabledMap.getOrDefault(id, () -> false).get();
}

private McdwAxeItemStats mcdwAxeItemStats = new McdwAxeItemStats();
private McdwBowItemStats mcdwBowItemStats = new McdwBowItemStats();
private McdwCrossbowItemStats mcdwCrossbowItemStats = new McdwCrossbowItemStats();
Expand Down Expand Up @@ -120,4 +139,4 @@ public McdwSwordItemStats getSwordItemStats() {
public McdwWhipItemStats getWhipItemStats() {
return mcdwWhipItemStats;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.data;


import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.timefall.mcdw.Mcdw;
import dev.timefall.mcdw.configs.McdwEnchantmentSettingsConfig;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceCondition;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditionType;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditions;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

public record ConfigEnchantmentEnabledCondition(Identifier enchant) implements ResourceCondition {

private static final MapCodec<ConfigEnchantmentEnabledCondition> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
Identifier.CODEC.fieldOf("enchant").forGetter(ConfigEnchantmentEnabledCondition::enchant)
).apply(instance, ConfigEnchantmentEnabledCondition::new)
);

private static final ResourceConditionType<ConfigEnchantmentEnabledCondition> TYPE = ResourceConditionType.create(Mcdw.ID("enchant_enabled"), CODEC);

public static void register(){
ResourceConditions.register(TYPE);
}

@Override
public ResourceConditionType<?> getType() {
return TYPE;
}

@Override
public boolean test(@Nullable RegistryWrapper.WrapperLookup registryLookup) {
return McdwEnchantmentSettingsConfig.CONFIG.isEnchantmentEnabled(enchant);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,41 @@
*/
package dev.timefall.mcdw.data;

/*
public class ConfigItemEnabledCondition {

public static void register() {
// Register a resource condition for checking if multiple config values are all true
ResourceConditions.register(Identifier.of(Mcdw.MOD_ID, "config_enabled"), jsonObject -> {
JsonArray values = JsonHelper.getArray(jsonObject, "values");
List<Boolean> booleanList = new ArrayList<>();
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.timefall.mcdw.Mcdw;
import dev.timefall.mcdw.configs.McdwEnchantmentSettingsConfig;
import dev.timefall.mcdw.configs.stats.McdwWeaponStatsConfig;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceCondition;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditionType;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditions;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

public record ConfigItemEnabledCondition(Identifier item) implements ResourceCondition {

private static final MapCodec<ConfigItemEnabledCondition> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
Identifier.CODEC.fieldOf("item").forGetter(ConfigItemEnabledCondition::item)
).apply(instance, ConfigItemEnabledCondition::new)
);

for (JsonElement element : values) {
if (element.isJsonPrimitive()) {
String elementString = element.getAsString();
List<String> configClasses = Arrays.asList(elementString.split("\\."));
try {
if (configClasses.size() > 1) {
// Retrieve the config value and add it to the boolean list
booleanList.add(
Mcdw.CONFIG
.getClass().getField(configClasses.get(0))
.get(Mcdw.CONFIG).getClass().getField(configClasses.get(1))
.getBoolean(Mcdw.CONFIG.getClass().getField(configClasses.get(0))
.get(Mcdw.CONFIG)));
} else {
// Retrieve the config value and add it to the boolean list
booleanList.add(Mcdw.CONFIG.getClass().getField(elementString).getBoolean(Mcdw.CONFIG));
}
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
// Check if all config values are true
return booleanList.stream().allMatch(Boolean::booleanValue);
});
private static final ResourceConditionType<ConfigItemEnabledCondition> TYPE = ResourceConditionType.create(Mcdw.ID("item_enabled"), CODEC);

// Register a resource condition for checking if an item is enabled
ResourceConditions.register(Identifier.of(Mcdw.MOD_ID, "item_enabled"), jsonObject -> {
JsonArray values = JsonHelper.getArray(jsonObject, "values");
public static void register(){
ResourceConditions.register(TYPE);
}

@Override
public ResourceConditionType<?> getType() {
return TYPE;
}

for (JsonElement element : values) {
if (element.isJsonPrimitive()) {
try {
// Check if the item exists in the item registry
return Registries.ITEM.get(Identifier.of(element.getAsString())) != Items.AIR;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
// If no item is specified, default to true
return true;
});
@Override
public boolean test(@Nullable RegistryWrapper.WrapperLookup registryLookup) {
return McdwWeaponStatsConfig.CONFIG.isItemEnabled(item);
}
}

*/
}
5 changes: 3 additions & 2 deletions src/main/java/dev/timefall/mcdw/data/McdwDataGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class McdwDataGenerator implements DataGeneratorEntrypoint {
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
FabricDataGenerator.Pack pack = fabricDataGenerator.createPack();

pack.addProvider(McdwTagGenerator::new);
pack.addProvider(McdwItemTagGenerator::new);
pack.addProvider(McdwEnchantmentTagGenerator::new);
}
}
}
Loading

0 comments on commit 092ad88

Please sign in to comment.