generated from NeoForgeMDKs/MDK-1.21-ModDevGradle
-
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.
skills are now capped manually; creeper armor
- Loading branch information
1 parent
2691308
commit 5b2ad31
Showing
45 changed files
with
594 additions
and
110 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/main/java/com/nateplays/my_neoforge_mod/enchantment/ModEnchantmentHelper.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,53 @@ | ||
package com.nateplays.my_neoforge_mod.enchantment; | ||
|
||
import com.nateplays.my_neoforge_mod.MyNeoForgeMod; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.core.HolderLookup; | ||
import net.minecraft.core.RegistryAccess; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.entity.EquipmentSlot; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.enchantment.Enchantment; | ||
import net.minecraft.world.level.Level; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ModEnchantmentHelper { | ||
|
||
public static ResourceLocation getRL(String id) { | ||
return ResourceLocation.fromNamespaceAndPath(MyNeoForgeMod.MODID, id); | ||
} | ||
|
||
@Nullable | ||
public static Holder<Enchantment> getEnchantmentFromLocation(ResourceLocation location, Level level) { | ||
HolderLookup.RegistryLookup<Enchantment> registryLookup = level.registryAccess().lookupOrThrow(Registries.ENCHANTMENT); | ||
return getEnchantmentFromLocationAndLookup(location, registryLookup); | ||
} | ||
|
||
@Nullable public static Holder<Enchantment> getEnchantmentFromLocationAndLookup(ResourceLocation location, HolderLookup.RegistryLookup<Enchantment> lookup) { | ||
return lookup.getOrThrow(ResourceKey.create(Registries.ENCHANTMENT, location)).getDelegate(); | ||
} | ||
|
||
public static int getTotalEnchantmentLevel(LivingEntity livingEntity, Holder<Enchantment> enchantment) { | ||
int totalLevel = 0; | ||
for (EquipmentSlot slot : EquipmentSlot.values()) { | ||
ItemStack itemStack = livingEntity.getItemBySlot(slot); | ||
if (enchantment.value().matchingSlot(slot)) { | ||
int level = itemStack.getEnchantmentLevel(enchantment); | ||
totalLevel += level; | ||
} | ||
} | ||
if (enchantment.is(ModEnchantments.TAG_SKILL_ENCHANTMENTS)) { | ||
totalLevel = Mth.floor(Math.min(totalLevel, enchantment.value().getMaxLevel())); | ||
} | ||
return totalLevel; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/nateplays/my_neoforge_mod/enchantment/ModEnchantments.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,18 @@ | ||
package com.nateplays.my_neoforge_mod.enchantment; | ||
|
||
import com.nateplays.my_neoforge_mod.MyNeoForgeMod; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.tags.TagKey; | ||
import net.minecraft.world.item.enchantment.Enchantment; | ||
|
||
public class ModEnchantments { | ||
|
||
public static final TagKey<Enchantment> TAG_SKILL_ENCHANTMENTS = TagKey.create( | ||
Registries.ENCHANTMENT, | ||
// ResourceLocation.fromNamespaceAndPath(MyNeoForgeMod.MODID, "skill_enchantments" | ||
ResourceLocation.fromNamespaceAndPath(MyNeoForgeMod.MODID, "skill_enchantments" | ||
)); | ||
|
||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/nateplays/my_neoforge_mod/enchantment/event/BombardierEventHandler.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,17 @@ | ||
package com.nateplays.my_neoforge_mod.enchantment.event; | ||
|
||
import com.nateplays.my_neoforge_mod.MyNeoForgeMod; | ||
import net.minecraft.world.level.Explosion; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.EventBusSubscriber; | ||
import net.neoforged.neoforge.event.level.ExplosionEvent; | ||
|
||
@EventBusSubscriber(modid = MyNeoForgeMod.MODID) | ||
public class BombardierEventHandler { | ||
|
||
|
||
@SubscribeEvent | ||
public static void onExplosionDetonate(ExplosionEvent.Detonate event) { | ||
Explosion explosion = event.getExplosion(); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...main/java/com/nateplays/my_neoforge_mod/enchantment/event/SkillAttributeEventHandler.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,74 @@ | ||
package com.nateplays.my_neoforge_mod.enchantment.event; | ||
|
||
import com.mojang.logging.LogUtils; | ||
import com.nateplays.my_neoforge_mod.MyNeoForgeMod; | ||
import com.nateplays.my_neoforge_mod.attribute.ModAttributes; | ||
import com.nateplays.my_neoforge_mod.enchantment.ModEnchantmentHelper; | ||
import com.nateplays.my_neoforge_mod.enchantment.ModEnchantments; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.ai.attributes.Attribute; | ||
import net.minecraft.world.entity.ai.attributes.AttributeInstance; | ||
import net.minecraft.world.entity.ai.attributes.AttributeModifier; | ||
import net.minecraft.world.entity.ai.attributes.Attributes; | ||
import net.minecraft.world.item.enchantment.Enchantment; | ||
import net.minecraft.world.level.Explosion; | ||
import net.minecraft.world.level.Level; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.EventBusSubscriber; | ||
import net.neoforged.neoforge.event.entity.living.LivingEquipmentChangeEvent; | ||
import net.neoforged.neoforge.event.level.ExplosionEvent; | ||
import org.slf4j.Logger; | ||
|
||
import java.util.function.Supplier; | ||
|
||
@EventBusSubscriber(modid = MyNeoForgeMod.MODID) | ||
public class SkillAttributeEventHandler { | ||
|
||
private static final Logger LOGGER = LogUtils.getLogger(); | ||
|
||
@SubscribeEvent | ||
public static void onLivingEquipmentChange(LivingEquipmentChangeEvent event) { | ||
LivingEntity livingEntity = event.getEntity(); | ||
Level level = livingEntity.level(); | ||
if (!level.isClientSide) { | ||
updateQuickEatingModifier(livingEntity); | ||
updateMuckResistanceModifier(livingEntity); | ||
} | ||
} | ||
|
||
|
||
|
||
public static void updateQuickEatingModifier(LivingEntity livingEntity) { | ||
String enchantName = "quick_eating"; | ||
AttributeInstance attributeInstance = livingEntity.getAttribute(ModAttributes.EATING_SPEED); | ||
if (attributeInstance == null) return; | ||
ResourceLocation modifierId = ResourceLocation.fromNamespaceAndPath(MyNeoForgeMod.MODID, "skill."+enchantName); | ||
Holder<Enchantment> enchantment = ModEnchantmentHelper.getEnchantmentFromLocation(ModEnchantmentHelper.getRL(enchantName), livingEntity.level()); | ||
int enchantLevel = ModEnchantmentHelper.getTotalEnchantmentLevel(livingEntity, enchantment); | ||
if (enchantLevel > 0) { | ||
AttributeModifier modifier = new AttributeModifier(modifierId, enchantLevel * 1.0d, AttributeModifier.Operation.ADD_VALUE); | ||
attributeInstance.addOrUpdateTransientModifier(modifier); | ||
} else { | ||
attributeInstance.removeModifier(modifierId); | ||
} | ||
} | ||
|
||
public static void updateMuckResistanceModifier(LivingEntity livingEntity) { | ||
String enchantName = "muck_resistance"; | ||
AttributeInstance attributeInstance = livingEntity.getAttribute(Attributes.MOVEMENT_EFFICIENCY); | ||
if (attributeInstance == null) return; | ||
ResourceLocation modifierId = ResourceLocation.fromNamespaceAndPath(MyNeoForgeMod.MODID, "skill."+enchantName); | ||
Holder<Enchantment> enchantment = ModEnchantmentHelper.getEnchantmentFromLocation(ModEnchantmentHelper.getRL(enchantName), livingEntity.level()); | ||
int enchantLevel = ModEnchantmentHelper.getTotalEnchantmentLevel(livingEntity, enchantment); | ||
if (enchantLevel > 0) { | ||
AttributeModifier modifier = new AttributeModifier(modifierId, enchantLevel * 0.5d, AttributeModifier.Operation.ADD_VALUE); | ||
attributeInstance.addOrUpdateTransientModifier(modifier); | ||
} else { | ||
attributeInstance.removeModifier(modifierId); | ||
} | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.