mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 03:43:30 +01:00
parent
7ac1c3d66d
commit
b3701fbada
7 changed files with 27 additions and 27 deletions
|
@ -285,7 +285,7 @@ public final class Helper {
|
|||
}
|
||||
|
||||
// This is how @ObjectHolder SHOULD work...
|
||||
public static <T> void populateObjectHolders(Class<?> clazz, Registry<T> registry) {
|
||||
public static <T> void populateObjectHolders(Class<?> clazz, Registry<T> registry, boolean useHolders) {
|
||||
for (var entry : clazz.getFields()) {
|
||||
if (!Modifier.isStatic(entry.getModifiers()))
|
||||
continue;
|
||||
|
@ -295,7 +295,7 @@ public final class Helper {
|
|||
continue;
|
||||
}
|
||||
try {
|
||||
entry.set(null, registry.get(location));
|
||||
entry.set(null, useHolders ? registry.getHolder(location).orElseThrow() : registry.get(location));
|
||||
} catch (IllegalAccessException e) {
|
||||
NaturesAura.LOGGER.error(e);
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public class BreathlessEffect implements IDrainSpotEffect {
|
|||
return;
|
||||
var entities = level.getEntitiesOfClass(LivingEntity.class, this.bb);
|
||||
for (var entity : entities)
|
||||
entity.addEffect(new MobEffectInstance(Holder.direct(ModPotions.BREATHLESS), 300, this.amp));
|
||||
entity.addEffect(new MobEffectInstance(ModPotions.BREATHLESS, 300, this.amp));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,21 +1,11 @@
|
|||
package de.ellpeck.naturesaura.enchant;
|
||||
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EquipmentSlotGroup;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.server.ReloadableServerRegistries;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
|
||||
public final class ModEnchantments {
|
||||
|
||||
public static final Enchantment AURA_MENDING = Enchantment.enchantment(
|
||||
Enchantment.definition(
|
||||
HolderSet.direct(BuiltInRegistries.ITEM.holders().filter(i -> new ItemStack(i).getCapability(NaturesAuraAPI.AURA_RECHARGE_CAPABILITY) == null).toList()),
|
||||
// same values as unbreaking, except for the max level
|
||||
5, 1, Enchantment.dynamicCost(5, 8), Enchantment.dynamicCost(55, 8), 2, EquipmentSlotGroup.ANY)
|
||||
).build(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "aura_mending"));
|
||||
public static Holder<Enchantment> AURA_MENDING;
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem, ICustomCrea
|
|||
if (recharge != null) {
|
||||
if (recharge.rechargeFromContainer(container, itemSlot, i, player.getInventory().selected == i))
|
||||
break;
|
||||
} else if (stack.getEnchantmentLevel(Holder.direct(ModEnchantments.AURA_MENDING)) > 0) {
|
||||
} else if (stack.getEnchantmentLevel(ModEnchantments.AURA_MENDING) > 0) {
|
||||
var mainSize = player.getInventory().items.size();
|
||||
var isArmor = i >= mainSize && i < mainSize + player.getInventory().armor.size();
|
||||
if ((isArmor || player.getInventory().selected == i) && Helper.rechargeAuraItem(stack, container, 1000))
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package de.ellpeck.naturesaura.potion;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
|
||||
@SuppressWarnings("NonConstantFieldWithUpperCaseName")
|
||||
public final class ModPotions {
|
||||
|
||||
public static MobEffect BREATHLESS;
|
||||
public static Holder<MobEffect> BREATHLESS;
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class PotionBreathless extends PotionImpl {
|
|||
|
||||
@SubscribeEvent
|
||||
public void onHeal(LivingHealEvent event) {
|
||||
var effect = event.getEntity().getEffect(Holder.direct(this));
|
||||
var effect = event.getEntity().getEffect(ModPotions.BREATHLESS);
|
||||
if (effect == null)
|
||||
return;
|
||||
var chance = (effect.getAmplifier() + 1) / 15F;
|
||||
|
|
|
@ -29,13 +29,16 @@ import de.ellpeck.naturesaura.recipes.ModRecipes;
|
|||
import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets;
|
||||
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
|
||||
import net.minecraft.client.resources.PlayerSkin;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.EquipmentSlotGroup;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
@ -150,7 +153,7 @@ public final class ModRegistry {
|
|||
new BlockImpl("sky_ingot_block", Block.Properties.of().sound(SoundType.METAL).strength(4F)),
|
||||
new BlockImpl("depth_ingot_block", Block.Properties.of().sound(SoundType.METAL).strength(6F))
|
||||
);
|
||||
Helper.populateObjectHolders(ModBlocks.class, BuiltInRegistries.BLOCK);
|
||||
Helper.populateObjectHolders(ModBlocks.class, event.getRegistry(), false);
|
||||
});
|
||||
|
||||
event.register(Registries.ITEM, h -> {
|
||||
|
@ -235,7 +238,7 @@ public final class ModRegistry {
|
|||
new ItemArmor("depth_pants", ModArmorMaterial.DEPTH, ArmorItem.Type.LEGGINGS),
|
||||
new ItemArmor("depth_shoes", ModArmorMaterial.DEPTH, ArmorItem.Type.BOOTS)
|
||||
);
|
||||
Helper.populateObjectHolders(ModItems.class, BuiltInRegistries.ITEM);
|
||||
Helper.populateObjectHolders(ModItems.class, event.getRegistry(), false);
|
||||
});
|
||||
|
||||
event.register(Registries.BLOCK_ENTITY_TYPE, h -> {
|
||||
|
@ -246,12 +249,12 @@ public final class ModRegistry {
|
|||
if (item instanceof ModTileType<?> type)
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, type.getBaseName()), type.type);
|
||||
}
|
||||
Helper.populateObjectHolders(ModBlockEntities.class, BuiltInRegistries.BLOCK_ENTITY_TYPE);
|
||||
Helper.populateObjectHolders(ModBlockEntities.class, event.getRegistry(), false);
|
||||
});
|
||||
|
||||
event.register(Registries.MOB_EFFECT, h -> {
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "breathless"), new PotionBreathless());
|
||||
Helper.populateObjectHolders(ModPotions.class, BuiltInRegistries.MOB_EFFECT);
|
||||
Helper.populateObjectHolders(ModPotions.class, event.getRegistry(), true);
|
||||
});
|
||||
|
||||
event.register(Registries.MENU, h -> {
|
||||
|
@ -267,11 +270,17 @@ public final class ModRegistry {
|
|||
IItemHandler handler = ILevelData.getOverworldData(inv.player.level()).getEnderStorage(data.readUtf());
|
||||
return new ContainerEnderCrate(ModContainers.ENDER_ACCESS, windowId, inv.player, handler);
|
||||
}));
|
||||
Helper.populateObjectHolders(ModContainers.class, BuiltInRegistries.MENU);
|
||||
Helper.populateObjectHolders(ModContainers.class, event.getRegistry(), false);
|
||||
});
|
||||
|
||||
event.register(Registries.ENCHANTMENT, h -> {
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "aura_mending"), ModEnchantments.AURA_MENDING);
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "aura_mending"), Enchantment.enchantment(
|
||||
Enchantment.definition(
|
||||
HolderSet.direct(BuiltInRegistries.ITEM.holders().filter(i -> new ItemStack(i).getCapability(NaturesAuraAPI.AURA_RECHARGE_CAPABILITY) == null).toList()),
|
||||
// same values as unbreaking, except for the max level
|
||||
5, 1, Enchantment.dynamicCost(5, 8), Enchantment.dynamicCost(55, 8), 2, EquipmentSlotGroup.ANY)
|
||||
).build(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "aura_mending")));
|
||||
Helper.populateObjectHolders(ModEnchantments.class, event.getRegistry(), true);
|
||||
});
|
||||
|
||||
event.register(Registries.ENTITY_TYPE, h -> {
|
||||
|
@ -291,7 +300,7 @@ public final class ModRegistry {
|
|||
.of(EntityStructureFinder::new, MobCategory.MISC)
|
||||
.sized(0.5F, 0.5F).setShouldReceiveVelocityUpdates(true)
|
||||
.setTrackingRange(64).setUpdateInterval(2).fireImmune().build(NaturesAura.MOD_ID + ":structure_finder"));
|
||||
Helper.populateObjectHolders(ModEntities.class, BuiltInRegistries.ENTITY_TYPE);
|
||||
Helper.populateObjectHolders(ModEntities.class, event.getRegistry(), false);
|
||||
});
|
||||
|
||||
event.register(Registries.FEATURE, h -> {
|
||||
|
@ -302,7 +311,7 @@ public final class ModRegistry {
|
|||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "aura_mushroom"), new LevelGenAuraBloom(ModBlocks.AURA_MUSHROOM, 20, false));
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "ancient_tree"), new LevelGenAncientTree());
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "nether_wart_mushroom"), new LevelGenNetherWartMushroom());
|
||||
Helper.populateObjectHolders(ModFeatures.class, BuiltInRegistries.FEATURE);
|
||||
Helper.populateObjectHolders(ModFeatures.class, event.getRegistry(), false);
|
||||
});
|
||||
|
||||
event.register(Registries.RECIPE_TYPE, h -> {
|
||||
|
|
Loading…
Reference in a new issue