-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix static resources not getting loaded properly
- Loading branch information
Showing
22 changed files
with
300 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/main/java/com/kd8lvt/exclusionzone/datagen/enchantment/EnchantmentGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.kd8lvt.exclusionzone.datagen.enchantment; | ||
|
||
import com.kd8lvt.exclusionzone.registry.ModAttributes; | ||
import com.kd8lvt.exclusionzone.registry.ModEnchantments; | ||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; | ||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider; | ||
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceCondition; | ||
import net.minecraft.component.EnchantmentEffectComponentTypes; | ||
import net.minecraft.component.type.AttributeModifierSlot; | ||
import net.minecraft.enchantment.Enchantment; | ||
import net.minecraft.enchantment.EnchantmentLevelBasedValue; | ||
import net.minecraft.enchantment.effect.AttributeEnchantmentEffect; | ||
import net.minecraft.entity.EquipmentSlot; | ||
import net.minecraft.entity.attribute.EntityAttribute; | ||
import net.minecraft.entity.attribute.EntityAttributeModifier; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.registry.RegistryWrapper; | ||
import net.minecraft.registry.entry.RegistryEntry; | ||
import net.minecraft.registry.tag.ItemTags; | ||
import net.minecraft.registry.tag.TagKey; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static com.kd8lvt.exclusionzone.ExclusionZone.MOD_ID; | ||
|
||
public class EnchantmentGenerator extends FabricDynamicRegistryProvider { | ||
|
||
public EnchantmentGenerator(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) { | ||
super(output, registriesFuture); | ||
} | ||
|
||
@Override | ||
protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) { | ||
RegistryWrapper<Item> itemLookup = registries.getWrapperOrThrow(RegistryKeys.ITEM); | ||
|
||
register( | ||
entries, | ||
ModEnchantments.KEYS.TOXICUS_PERDITIO, | ||
createAttributeEnchantment( | ||
itemLookup, | ||
ModEnchantments.KEYS.TOXICUS_PERDITIO, | ||
ItemTags.WEAPON_ENCHANTABLE, | ||
10, | ||
5, | ||
Enchantment.leveledCost(1,10), //base cost/level | ||
Enchantment.leveledCost(1,15), //max cost/level) | ||
7, | ||
AttributeModifierSlot.forEquipmentSlot(EquipmentSlot.MAINHAND), | ||
ModAttributes.TOXIN_DAMAGE, | ||
EnchantmentLevelBasedValue.linear(20,20), | ||
EntityAttributeModifier.Operation.ADD_VALUE | ||
) | ||
); | ||
|
||
register( | ||
entries, | ||
ModEnchantments.KEYS.TOXICAE_PRAESIDIUM, | ||
createAttributeEnchantment( | ||
itemLookup, | ||
ModEnchantments.KEYS.TOXICAE_PRAESIDIUM, | ||
ItemTags.ARMOR_ENCHANTABLE, | ||
10, | ||
4, | ||
Enchantment.leveledCost(1,10), //base cost/level | ||
Enchantment.leveledCost(1,15), //max cost/level) | ||
7, | ||
AttributeModifierSlot.ARMOR, | ||
ModAttributes.TOXIN_RESISTANCE, | ||
EnchantmentLevelBasedValue.linear(0.1f,0.1f), | ||
EntityAttributeModifier.Operation.ADD_VALUE | ||
) | ||
); | ||
} | ||
|
||
private static void register(Entries entries, RegistryKey<Enchantment> key, Enchantment.Builder builder, ResourceCondition... conditions) { | ||
entries.add(key,builder.build(key.getValue()),conditions); | ||
} | ||
|
||
private static Enchantment.Builder createAttributeEnchantment(RegistryWrapper<Item> itemLookup, RegistryKey<Enchantment> registryKey, TagKey<Item> appliesToTag, int weight, int maxLevel, Enchantment.Cost baseLeveledCost, Enchantment.Cost maxLeveledCost, int anvilCost, AttributeModifierSlot modifierSlot, RegistryEntry<EntityAttribute> attrKey, EnchantmentLevelBasedValue toApplyPerLevel, EntityAttributeModifier.Operation operation) { | ||
return Enchantment.builder( | ||
Enchantment.definition( | ||
itemLookup.getOrThrow(appliesToTag), | ||
weight, | ||
maxLevel, | ||
baseLeveledCost, | ||
maxLeveledCost, | ||
anvilCost, | ||
modifierSlot | ||
) | ||
).addEffect( | ||
EnchantmentEffectComponentTypes.ATTRIBUTES, | ||
new AttributeEnchantmentEffect( | ||
registryKey.getValue(), | ||
attrKey, | ||
toApplyPerLevel, | ||
operation | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return MOD_ID+"/Enchantments"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/com/kd8lvt/exclusionzone/mixin/ArmorItemMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.kd8lvt.exclusionzone.mixin; | ||
|
||
import com.kd8lvt.exclusionzone.registry.ModAttributes; | ||
import net.minecraft.component.type.AttributeModifierSlot; | ||
import net.minecraft.component.type.AttributeModifiersComponent; | ||
import net.minecraft.entity.EquipmentSlot; | ||
import net.minecraft.entity.attribute.EntityAttributeModifier; | ||
import net.minecraft.item.ArmorItem; | ||
import net.minecraft.item.ArmorMaterial; | ||
import net.minecraft.registry.entry.RegistryEntry; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
@Mixin(ArmorItem.class) | ||
public abstract class ArmorItemMixin { | ||
//I highly doubt this actually needs to be a mixin. This is just cleaner than my original solution. | ||
@Inject(at=@At(value = "RETURN"),method="getAttributeModifiers",cancellable = true) | ||
private void getAttributeModifiers(CallbackInfoReturnable<AttributeModifiersComponent> cir) { | ||
AttributeModifiersComponent comp = cir.getReturnValue(); | ||
if (comp == AttributeModifiersComponent.DEFAULT) return; | ||
Double toxRes = getToxicResistanceForItem(); | ||
if (toxRes.isNaN()) return; | ||
cir.setReturnValue(cir.getReturnValue().with( | ||
ModAttributes.TOXIN_RESISTANCE, | ||
new EntityAttributeModifier( | ||
ModAttributes.MODIFIERS.forArmorResistance(type), | ||
toxRes, | ||
EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE | ||
), | ||
AttributeModifierSlot.forEquipmentSlot(this.getSlotType()) | ||
) | ||
); | ||
} | ||
|
||
/* | ||
Programmatically generate armor's toxin resistance values. | ||
Not guarantied to function with negative values, and outputs NaN if it doesn't like something about the input. | ||
Interactive Desmos graph for the output "curve": https://www.desmos.com/calculator/wqi6fd5poc | ||
*/ | ||
@Unique | ||
private static final Map<ArmorItem.Type,Double> baseValues = Map.of( | ||
ArmorItem.Type.HELMET, 1.0, | ||
ArmorItem.Type.CHESTPLATE, 3.0, | ||
ArmorItem.Type.LEGGINGS, 2.0, | ||
ArmorItem.Type.BOOTS, 1.0 | ||
); | ||
@Unique | ||
private static final Map<ArmorItem.Type,Double> scalingFactors = Map.of( | ||
ArmorItem.Type.HELMET, 0.15, | ||
ArmorItem.Type.CHESTPLATE, 0.5, | ||
ArmorItem.Type.LEGGINGS, 0.25, | ||
ArmorItem.Type.BOOTS, 0.1 | ||
); | ||
@Unique | ||
private Double getToxicResistanceForItem() { | ||
//Animal armor | ||
if (this.type == ArmorItem.Type.BODY) return 1.0; | ||
|
||
//Player armor | ||
Integer def = material.value().defense().get(type); | ||
Double base = baseValues.get(type); | ||
Double scale = scalingFactors.get(type); | ||
if (def == null || scale == null) return Double.NaN; | ||
return (base/def)*scale; | ||
} | ||
|
||
@Shadow @Final private Supplier<AttributeModifiersComponent> attributeModifiers; | ||
@Shadow public abstract EquipmentSlot getSlotType(); | ||
@Shadow @Final protected RegistryEntry<ArmorMaterial> material; | ||
@Shadow @Final protected ArmorItem.Type type; | ||
} | ||
|
Oops, something went wrong.