diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7c48a11..024329af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,8 @@ jobs: SIGN_STOREPASS: ${{ secrets.SIGN_STOREPASS }} MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_KEY: ${{ secrets.MAVEN_KEY }} + GITHUB_USER: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: 'Test' env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} diff --git a/.gitignore b/.gitignore index 2a3fa29c..ca42da40 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ doc/info.txt /build /run +/runs # Ignore project specific files .classpath @@ -17,6 +18,7 @@ repo/* *.iws out/* keystore.jks +.idea # Ignore mac-specific file(s) .DS_Store diff --git a/build.gradle b/build.gradle index 03b23864..6f58a16c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,14 @@ plugins { - id 'net.minecraftforge.gradle' version '[6.0,6.2)' - id 'com.matthewprenger.cursegradle' version '1.4.0' + id 'net.neoforged.gradle.userdev' version '7.0.97' + id 'net.darkhax.curseforgegradle' version '1.0.8' id 'com.diffplug.spotless' version '5.14.3' id 'com.modrinth.minotaur' version '2.+' } -apply plugin: 'net.minecraftforge.gradle' apply plugin: 'idea' apply plugin: 'maven-publish' -import net.minecraftforge.gradle.common.tasks.SignJar +import net.neoforged.gradle.common.tasks.PotentiallySignJar // Determine build number String build_number = "DEV" // this will be referenced as simply build_number from now on. @@ -26,7 +25,10 @@ logger.lifecycle "BUILDING VERSION: " + build_number // Set mod details version = project.mod_version group = "org.cyclops.everlastingabilities" -archivesBaseName = "EverlastingAbilities" +archivesBaseName = "EverlastingAbilities-${project.minecraft_version}-neoforge" +base { + archivesName = archivesBaseName +} // Set Java details java.toolchain.languageVersion = JavaLanguageVersion.of(17) @@ -47,6 +49,7 @@ sourceSets { main test } +sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { mavenCentral() @@ -55,20 +58,20 @@ repositories { name "Cyclops Repo" url "https://maven.pkg.github.com/CyclopsMC/packages" credentials { - username = project.findProperty("gpr.user") ?: System.getenv("MAVEN_USERNAME") - password = project.findProperty("gpr.key") ?: System.getenv("MAVEN_KEY") + username = project.findProperty("gpr.user") ?: System.getenv("MAVEN_USERNAME") ?: System.getenv("GITHUB_USER") + password = project.findProperty("gpr.key") ?: System.getenv("MAVEN_KEY") ?: System.getenv("GITHUB_TOKEN") } } } dependencies { - minecraft "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}" + implementation "net.neoforged:neoforge:${project.neoforge_version}" // Add something like 'cyclopscore_version_local=0.1.0-DEV' to your gradle.properties if you want to use a custom local CyclopsCore version. if(secrets.cyclopscore_version_local) { - implementation "org.cyclops.cyclopscore:cyclopscore:${project.minecraft_version}-${secrets.cyclopscore_version_local}:deobf" + implementation "org.cyclops.cyclopscore:cyclopscore-${project.minecraft_version}-neoforge:${secrets.cyclopscore_version_local}:deobf" } else { - implementation "org.cyclops.cyclopscore:cyclopscore:${project.minecraft_version}-${project.cyclopscore_version}:deobf" + implementation "org.cyclops.cyclopscore:cyclopscore-${project.minecraft_version}-neoforge:${project.cyclopscore_version}:deobf" } // Project lombok @@ -78,50 +81,36 @@ dependencies { testAnnotationProcessor 'org.projectlombok:lombok:1.18.22' } -minecraft { - mappings channel: "official", version: "${project.minecraft_version}" - - accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') +runs { + configureEach { + systemProperty 'forge.logging.markers', 'REGISTRIES' + systemProperty 'forge.logging.console.level', 'debug' + systemProperty 'forge.logging.console.level', 'debug' + modSource project.sourceSets.main + } + + client { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + } - runs { - client { - workingDirectory project.file('run') - //property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP' - property 'forge.logging.console.level', 'debug' - mods { - everlastingabilities { - source sourceSets.main - } - } - } + server { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + programArgument '--nogui' + } - server { - workingDirectory project.file('run') - property 'forge.logging.console.level', 'debug' - mods { - everlastingabilities { - source sourceSets.main - } - } - } + gameTestServer { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + } - data { - workingDirectory project.file('run') - property 'forge.logging.console.level', 'debug' - args '--mod', 'everlastingabilities', '--all', '--output', file('src/generated/resources/') - mods { - everlastingabilities { - source sourceSets.main - } - } - } + data { + programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() } } if (build_number.equals("RELEASE")) - version = "${project.minecraft_version}-${project.mod_version}" + version = "${project.mod_version}" else - version = "${project.minecraft_version}-${project.mod_version}-${build_number}" + version = "${project.mod_version}-${build_number}" jar { manifest { @@ -136,7 +125,6 @@ jar { ]) } } -jar.finalizedBy('reobfJar') javadoc { source = [sourceSets.main.allJava] @@ -144,7 +132,9 @@ javadoc { options.addStringOption('Xdoclint:accessibility,html,reference,syntax', '-quiet') } -task signJar(type: SignJar, dependsOn: jar) { +task signJar(type: PotentiallySignJar, dependsOn: jar) { + dependsOn(tasks.jar) + onlyIf { System.getenv().SIGN_KEYSTORE } @@ -153,10 +143,9 @@ task signJar(type: SignJar, dependsOn: jar) { alias = System.getenv().SIGN_ALIAS storePass = System.getenv().SIGN_STOREPASS keyPass = System.getenv().SIGN_KEYPASS - inputFile = jar.archivePath - outputFile = jar.archivePath + input = jar.archivePath + output = jar.archivePath } -build.dependsOn signJar task deobfJar(type: Jar) { from sourceSets.main.output @@ -200,32 +189,28 @@ artifacts { archives javadocJar } -curseforge { - if(secrets.hasProperty("curseforge_key")) { - apiKey = secrets.curseforge_key +task publishCurseForge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) { + dependsOn(tasks.jar) + + if(secrets.hasProperty("curseforge_key") && secrets.hasProperty("changelog")) { + apiToken = secrets.curseforge_key } else if(System.getenv().GITHUB_ACTIONS && System.getenv().CURSEFORGE_KEY_SECRET) { - apiKey = System.getenv().CURSEFORGE_KEY_SECRET + apiToken = System.getenv().CURSEFORGE_KEY_SECRET + } else { + apiToken = "DUMMY" } - project { - id = "248353" // my project url is http://minecraft.curseforge.com/mc-mods/248353/ - releaseType = project.project.release_type - addGameVersion project.minecraft_version - mainArtifact(jar) { - relations { - requiredDependency 'cyclops-core' - } - } - - changelog = "" - if (new File("resources/changelog/${project.version}.txt").exists()) { - changelog = new File("resources/changelog/${project.version}.txt").text - } + def projectId = "248353" // my project url is http://minecraft.curseforge.com/mc-mods/248353/ - addArtifact deobfJar - addArtifact sourcesJar - addArtifact javadocJar + def mainFile = upload(projectId, jar) + mainFile.changelogType = "text" + if (new File("resources/changelog/${project.version}.txt").exists()) { + mainFile.changelog = file("resources/changelog/${project.version}.txt") } + mainFile.addGameVersion(project.minecraft_version) + mainFile.addModLoader("NeoForge") + + mainFile.addRequirement('cyclops-core') } modrinth { diff --git a/gradle.properties b/gradle.properties index 9f60c0be..f86e83ab 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,8 @@ +mod_id=everlastingabilities mod_version=2.0.12 -minecraft_version=1.20.1 -forge_version=47.2.1 -cyclopscore_version=1.18.4-340 +minecraft_version=1.20.4 +neoforge_version=20.4.160-beta +cyclopscore_version=1.19.0-419 release_type=release fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44 diff --git a/settings.gradle b/settings.gradle index a30364e8..b359a59d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,8 @@ pluginManagement { repositories { + mavenLocal() gradlePluginPortal() - maven { - name = 'MinecraftForge' - url = 'https://maven.minecraftforge.net/' - } + maven { url = 'https://maven.neoforged.net/releases' } } } diff --git a/src/main/java/org/cyclops/everlastingabilities/Capabilities.java b/src/main/java/org/cyclops/everlastingabilities/Capabilities.java new file mode 100644 index 00000000..4588b08e --- /dev/null +++ b/src/main/java/org/cyclops/everlastingabilities/Capabilities.java @@ -0,0 +1,28 @@ +package org.cyclops.everlastingabilities; + +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.capabilities.BlockCapability; +import net.neoforged.neoforge.capabilities.EntityCapability; +import net.neoforged.neoforge.capabilities.ItemCapability; +import org.cyclops.everlastingabilities.api.capability.IAbilityStore; +import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStore; + +/** + * @author rubensworks + */ +public class Capabilities { + + public static final class AbilityStore { + public static final BlockCapability BLOCK = BlockCapability.createSided(new ResourceLocation(Reference.MOD_ID, "ability_store"), IAbilityStore.class); + public static final ItemCapability ITEM = ItemCapability.createVoid(new ResourceLocation(Reference.MOD_ID, "ability_store"), IAbilityStore.class); + public static final EntityCapability ENTITY = EntityCapability.createVoid(new ResourceLocation(Reference.MOD_ID, "ability_store"), IAbilityStore.class); + } + + public static final class MutableAbilityStore { + public static final BlockCapability BLOCK = BlockCapability.createSided(new ResourceLocation(Reference.MOD_ID, "mutable_ability_store"), IMutableAbilityStore.class); + public static final ItemCapability ITEM = ItemCapability.createVoid(new ResourceLocation(Reference.MOD_ID, "mutable_ability_store"), IMutableAbilityStore.class); + public static final EntityCapability ENTITY = EntityCapability.createVoid(new ResourceLocation(Reference.MOD_ID, "mutable_ability_store"), IMutableAbilityStore.class); + } + +} diff --git a/src/main/java/org/cyclops/everlastingabilities/EverlastingAbilities.java b/src/main/java/org/cyclops/everlastingabilities/EverlastingAbilities.java index cc1e1d2c..d979db9f 100644 --- a/src/main/java/org/cyclops/everlastingabilities/EverlastingAbilities.java +++ b/src/main/java/org/cyclops/everlastingabilities/EverlastingAbilities.java @@ -5,37 +5,37 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.minecraft.commands.CommandSourceStack; import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; import net.minecraft.network.chat.TextColor; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.RandomSource; -import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.PathfinderMob; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobCategory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Rarity; import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.event.entity.EntityJoinLevelEvent; -import net.minecraftforge.event.entity.living.LivingDeathEvent; -import net.minecraftforge.event.entity.living.LivingEvent; -import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.capabilities.BaseCapability; +import net.neoforged.neoforge.capabilities.ICapabilityProvider; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent; +import net.neoforged.neoforge.event.entity.living.LivingDeathEvent; +import net.neoforged.neoforge.event.entity.living.LivingEvent; +import net.neoforged.neoforge.event.entity.player.PlayerEvent; import org.cyclops.cyclopscore.config.ConfigHandler; import org.cyclops.cyclopscore.helper.EntityHelpers; import org.cyclops.cyclopscore.helper.ItemStackHelpers; import org.cyclops.cyclopscore.init.ModBaseVersionable; -import org.cyclops.cyclopscore.modcompat.capabilities.SimpleCapabilityConstructor; +import org.cyclops.cyclopscore.modcompat.capabilities.ICapabilityConstructor; import org.cyclops.cyclopscore.proxy.IClientProxy; import org.cyclops.cyclopscore.proxy.ICommonProxy; import org.cyclops.everlastingabilities.ability.AbilityHelpers; @@ -49,27 +49,23 @@ import org.cyclops.everlastingabilities.api.Ability; import org.cyclops.everlastingabilities.api.AbilityTypes; import org.cyclops.everlastingabilities.api.IAbilityType; -import org.cyclops.everlastingabilities.api.capability.AbilityStoreCapabilityProvider; -import org.cyclops.everlastingabilities.api.capability.DefaultMutableAbilityStore; +import org.cyclops.everlastingabilities.api.capability.CompoundTagMutableAbilityStore; import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStore; import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStoreRegistryAccess; -import org.cyclops.everlastingabilities.capability.AbilityStoreConfig; -import org.cyclops.everlastingabilities.capability.MutableAbilityStoreConfig; import org.cyclops.everlastingabilities.command.CommandModifyAbilities; import org.cyclops.everlastingabilities.command.argument.ArgumentTypeAbilityConfig; import org.cyclops.everlastingabilities.inventory.container.ContainerAbilityContainerConfig; import org.cyclops.everlastingabilities.item.ItemAbilityBottleConfig; import org.cyclops.everlastingabilities.item.ItemAbilityTotemConfig; -import org.cyclops.everlastingabilities.loot.functions.LootFunctionSetRandomAbility; import org.cyclops.everlastingabilities.loot.modifier.LootModifierInjectAbilityTotemConfig; import org.cyclops.everlastingabilities.network.packet.RequestAbilityStorePacket; import org.cyclops.everlastingabilities.proxy.ClientProxy; import org.cyclops.everlastingabilities.proxy.CommonProxy; import org.cyclops.everlastingabilities.recipe.TotemRecycleRecipeConfig; -import javax.annotation.Nullable; import java.util.Collection; import java.util.List; +import java.util.Optional; /** * The main mod class of this mod. @@ -84,10 +80,71 @@ public class EverlastingAbilities extends ModBaseVersionable _instance = instance); + public EverlastingAbilities(IEventBus modEventBus) { + super(Reference.MOD_ID, (instance) -> _instance = instance, modEventBus); - AbilityTypes.REGISTRY.register(FMLJavaModLoadingContext.get().getModEventBus()); + AbilityTypes.REGISTRY.register(modEventBus); + + // Register capabilities + getCapabilityConstructorRegistry().registerEntity(() -> EntityType.PLAYER, new ICapabilityConstructor>() { + @Override + public BaseCapability getCapability() { + return Capabilities.MutableAbilityStore.ENTITY; + } + + @Override + public ICapabilityProvider createProvider(EntityType host) { + return (player, context) -> { + if (player.level().registryAccess().registry(AbilityTypes.REGISTRY_KEY).isEmpty()) { + return null; + } + CompoundTagMutableAbilityStore store = new CompoundTagMutableAbilityStore(player::getPersistentData); + store.setRegistryAccess(player.level().registryAccess()); + return store; + }; + } + }); + ICapabilityConstructor> capCtor = new ICapabilityConstructor<>() { + @Override + public ICapabilityProvider createProvider(EntityType key) { + return (host, context) -> { + if (host.level().registryAccess().registry(AbilityTypes.REGISTRY_KEY).isEmpty()) { + return null; + } + CompoundTagMutableAbilityStore store = new CompoundTagMutableAbilityStore(host::getPersistentData); + store.setRegistryAccess(host.level().registryAccess()); + if (!host.getCommandSenderWorld().isClientSide + && !store.isInitialized() + && GeneralConfig.mobAbilityChance > 0 + && host.getId() % GeneralConfig.mobAbilityChance == 0 + && canMobHaveAbility(host)) { + RandomSource rand = RandomSource.create(); + rand.setSeed(host.getId()); + Registry registry = AbilityHelpers.getRegistry(host.level().registryAccess()); + List abilityTypes = AbilityHelpers.getAbilityTypesMobSpawn(registry); + AbilityHelpers.getRandomRarity(abilityTypes, rand) + .flatMap(rarity -> AbilityHelpers.getRandomAbility(abilityTypes, rand, rarity)) + .ifPresent(abilityType -> store.addAbility(new Ability(abilityType, 1), true)); + } + return store; + }; + } + + @Override + public BaseCapability getCapability() { + return Capabilities.MutableAbilityStore.ENTITY; + } + }; + getCapabilityConstructorRegistry().registerMobCategoryEntity(MobCategory.MONSTER, capCtor); + getCapabilityConstructorRegistry().registerMobCategoryEntity(MobCategory.CREATURE, capCtor); + getCapabilityConstructorRegistry().registerMobCategoryEntity(MobCategory.UNDERGROUND_WATER_CREATURE, capCtor); + getCapabilityConstructorRegistry().registerMobCategoryEntity(MobCategory.WATER_CREATURE, capCtor); + + NeoForge.EVENT_BUS.addListener(this::onEntityJoinWorld); + NeoForge.EVENT_BUS.addListener(this::onPlayerLoggedIn); + NeoForge.EVENT_BUS.addListener(this::onLivingDeath); + NeoForge.EVENT_BUS.addListener(this::onPlayerClone); + NeoForge.EVENT_BUS.addListener(this::onLivingUpdate); } @Override @@ -109,66 +166,8 @@ protected ICommonProxy constructCommonProxy() { return new CommonProxy(); } - @Override - protected void setup(FMLCommonSetupEvent event) { - super.setup(event); - - // Register loot functions - LootFunctionSetRandomAbility.load(); - - // Register capabilities - getCapabilityConstructorRegistry().registerInheritableEntity(Player.class, new SimpleCapabilityConstructor() { - @Nullable - @Override - public ICapabilityProvider createProvider(Player host) { - if (host.level().registryAccess().registry(AbilityTypes.REGISTRY_KEY).isEmpty()) { - return null; - } - return new AbilityStoreCapabilityProvider<>(this, new DefaultMutableAbilityStore()); - } - - @Override - public Capability getCapability() { - return MutableAbilityStoreConfig.CAPABILITY; - } - }); - getCapabilityConstructorRegistry().registerInheritableEntity(PathfinderMob.class, new SimpleCapabilityConstructor() { // TODO: AnimalEntity was IAnimal - @Nullable - @Override - public ICapabilityProvider createProvider(PathfinderMob host) { // TODO: CreatureEntity was IAnimal - if (host.level().registryAccess().registry(AbilityTypes.REGISTRY_KEY).isEmpty()) { - return null; - } - if (host instanceof Entity) { - Entity entity = (Entity) host; - IMutableAbilityStore store = new DefaultMutableAbilityStore(); - if (!entity.getCommandSenderWorld().isClientSide && host instanceof LivingEntity) { - if (GeneralConfig.mobAbilityChance > 0 - && entity.getId() % GeneralConfig.mobAbilityChance == 0 - && canMobHaveAbility((LivingEntity) host)) { - RandomSource rand = RandomSource.create(); - rand.setSeed(entity.getId()); - Registry registry = AbilityHelpers.getRegistry(host.level().registryAccess()); - List abilityTypes = AbilityHelpers.getAbilityTypesMobSpawn(registry); - AbilityHelpers.getRandomRarity(abilityTypes, rand) - .flatMap(rarity -> AbilityHelpers.getRandomAbility(abilityTypes, rand, rarity)) - .ifPresent(abilityType -> store.addAbility(new Ability(abilityType, 1), true)); - } - } - return new AbilityStoreCapabilityProvider<>(this, store); - } - return null; - } - - @Override - public Capability getCapability() { - return MutableAbilityStoreConfig.CAPABILITY; - } - }); - } - private static boolean canMobHaveAbility(LivingEntity mob) { - ResourceLocation mobName = ForgeRegistries.ENTITY_TYPES.getKey(mob.getType()); + ResourceLocation mobName = BuiltInRegistries.ENTITY_TYPE.getKey(mob.getType()); return mobName != null && GeneralConfig.mobDropBlacklist.stream().noneMatch(mobName.toString()::matches); } @@ -186,10 +185,6 @@ protected void onConfigsRegister(ConfigHandler configHandler) { // Argument types configHandler.addConfigurable(new ArgumentTypeAbilityConfig()); - // Capabilities - configHandler.addConfigurable(new AbilityStoreConfig()); - configHandler.addConfigurable(new MutableAbilityStoreConfig()); - // Guis configHandler.addConfigurable(new ContainerAbilityContainerConfig()); @@ -230,15 +225,13 @@ public static void clog(org.apache.logging.log4j.Level level, String message) { EverlastingAbilities._instance.getLoggerHelper().log(level, message); } - @SubscribeEvent public void onEntityJoinWorld(EntityJoinLevelEvent event) { - if (event.getLevel().isClientSide && event.getEntity().getCapability(MutableAbilityStoreConfig.CAPABILITY).isPresent()) { + if (event.getLevel().isClientSide && event.getEntity().getCapability(Capabilities.MutableAbilityStore.ENTITY) != null) { getPacketHandler().sendToServer(new RequestAbilityStorePacket(event.getEntity().getUUID().toString())); } } private static final String NBT_TOTEM_SPAWNED = Reference.MOD_ID + ":totemSpawned"; - @SubscribeEvent public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { if (event.getEntity().level().registryAccess().registry(AbilityTypes.REGISTRY_KEY).isPresent() && GeneralConfig.totemMaximumSpawnRarity >= 0) { CompoundTag tag = event.getEntity().getPersistentData(); @@ -254,7 +247,7 @@ public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { Rarity rarity = Rarity.values()[GeneralConfig.totemMaximumSpawnRarity]; AbilityHelpers.getRandomAbilityUntilRarity(AbilityHelpers.getAbilityTypesPlayerSpawn(AbilityHelpers.getRegistry(world.registryAccess())), world.random, rarity, true).ifPresent(abilityType -> { ItemStack itemStack = new ItemStack(RegistryEntries.ITEM_ABILITY_BOTTLE); - itemStack.getCapability(MutableAbilityStoreConfig.CAPABILITY, null) + Optional.ofNullable(itemStack.getCapability(Capabilities.MutableAbilityStore.ITEM)) .ifPresent(mutableAbilityStore -> { ((IMutableAbilityStoreRegistryAccess) mutableAbilityStore).setRegistryAccess(world.registryAccess()); mutableAbilityStore.addAbility(new Ability(abilityType, 1), true); @@ -267,7 +260,6 @@ public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { } } - @SubscribeEvent public void onLivingDeath(LivingDeathEvent event) { boolean doMobLoot = event.getEntity().level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT); if (!event.getEntity().level().isClientSide @@ -276,7 +268,7 @@ public void onLivingDeath(LivingDeathEvent event) { && (GeneralConfig.alwaysDropAbilities || event.getSource().getEntity() instanceof Player)) : (doMobLoot && event.getSource().getEntity() instanceof Player))) { LivingEntity entity = event.getEntity(); - entity.getCapability(MutableAbilityStoreConfig.CAPABILITY, null).ifPresent(mutableAbilityStore -> { + Optional.ofNullable(entity.getCapability(Capabilities.MutableAbilityStore.ENTITY)).ifPresent(mutableAbilityStore -> { int toDrop = 1; if (event.getEntity() instanceof Player && (GeneralConfig.alwaysDropAbilities || event.getSource().getEntity() instanceof Player)) { @@ -284,7 +276,7 @@ public void onLivingDeath(LivingDeathEvent event) { } ItemStack itemStack = new ItemStack(RegistryEntries.ITEM_ABILITY_TOTEM); - IMutableAbilityStore itemStackStore = itemStack.getCapability(MutableAbilityStoreConfig.CAPABILITY, null).orElse(null); + IMutableAbilityStore itemStackStore = itemStack.getCapability(Capabilities.MutableAbilityStore.ITEM); ((IMutableAbilityStoreRegistryAccess) itemStackStore).setRegistryAccess(event.getEntity().level().registryAccess()); Collection abilities = Lists.newArrayList(mutableAbilityStore.getAbilities()); @@ -313,21 +305,18 @@ public void onLivingDeath(LivingDeathEvent event) { } } - @SubscribeEvent - public void onPlayerClone(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) { - event.getOriginal().reviveCaps(); // This is needed to enable capability retrieval - IMutableAbilityStore oldStore = event.getOriginal().getCapability(MutableAbilityStoreConfig.CAPABILITY, null).orElse(null); - IMutableAbilityStore newStore = event.getEntity().getCapability(MutableAbilityStoreConfig.CAPABILITY, null).orElse(null); + public void onPlayerClone(net.neoforged.neoforge.event.entity.player.PlayerEvent.Clone event) { + IMutableAbilityStore oldStore = event.getOriginal().getCapability(Capabilities.MutableAbilityStore.ENTITY); + IMutableAbilityStore newStore = event.getEntity().getCapability(Capabilities.MutableAbilityStore.ENTITY); if (oldStore != null && newStore != null) { newStore.setAbilities(Maps.newHashMap(oldStore.getAbilitiesRaw())); } } - @SubscribeEvent public void onLivingUpdate(LivingEvent.LivingTickEvent event) { if (GeneralConfig.tickAbilities && event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); - player.getCapability(MutableAbilityStoreConfig.CAPABILITY, null).ifPresent(abilityStore -> { + Optional.ofNullable(player.getCapability(Capabilities.MutableAbilityStore.ENTITY)).ifPresent(abilityStore -> { for (Ability ability : abilityStore.getAbilities()) { if (AbilityHelpers.PREDICATE_ABILITY_ENABLED.test(ability.getAbilityType())) { if (event.getEntity().level().getGameTime() % 20 == 0 && GeneralConfig.exhaustionPerAbilityTick > 0) { diff --git a/src/main/java/org/cyclops/everlastingabilities/GeneralConfig.java b/src/main/java/org/cyclops/everlastingabilities/GeneralConfig.java index 7e840bc4..362c05d0 100644 --- a/src/main/java/org/cyclops/everlastingabilities/GeneralConfig.java +++ b/src/main/java/org/cyclops/everlastingabilities/GeneralConfig.java @@ -1,7 +1,7 @@ package org.cyclops.everlastingabilities; import com.google.common.collect.Lists; -import net.minecraftforge.fml.config.ModConfig; +import net.neoforged.fml.config.ModConfig; import org.cyclops.cyclopscore.config.ConfigurableProperty; import org.cyclops.cyclopscore.config.extendedconfig.DummyConfig; import org.cyclops.cyclopscore.init.ModBase; diff --git a/src/main/java/org/cyclops/everlastingabilities/RegistryEntries.java b/src/main/java/org/cyclops/everlastingabilities/RegistryEntries.java index 7706c963..8762e7ce 100644 --- a/src/main/java/org/cyclops/everlastingabilities/RegistryEntries.java +++ b/src/main/java/org/cyclops/everlastingabilities/RegistryEntries.java @@ -1,10 +1,14 @@ package org.cyclops.everlastingabilities; import com.mojang.serialization.Codec; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.Item; +import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer; -import net.minecraftforge.registries.ObjectHolder; +import net.neoforged.neoforge.registries.DeferredHolder; +import org.cyclops.everlastingabilities.api.AbilityTypeSerializers; import org.cyclops.everlastingabilities.api.IAbilityType; import org.cyclops.everlastingabilities.inventory.container.ContainerAbilityContainer; import org.cyclops.everlastingabilities.recipe.TotemRecycleRecipe; @@ -15,30 +19,19 @@ */ public class RegistryEntries { - @ObjectHolder(registryName = "item", value = "everlastingabilities:ability_bottle") - public static final Item ITEM_ABILITY_BOTTLE = null; - @ObjectHolder(registryName = "item", value = "everlastingabilities:ability_totem") - public static final Item ITEM_ABILITY_TOTEM = null; + public static final DeferredHolder ITEM_ABILITY_BOTTLE = DeferredHolder.create(Registries.ITEM, new ResourceLocation("everlastingabilities:ability_bottle")); + public static final DeferredHolder ITEM_ABILITY_TOTEM = DeferredHolder.create(Registries.ITEM, new ResourceLocation("everlastingabilities:ability_totem")); - @ObjectHolder(registryName = "menu", value = "everlastingabilities:ability_container") - public static final MenuType CONTAINER_ABILITYCONTAINER = null; + public static final DeferredHolder, MenuType> CONTAINER_ABILITYCONTAINER = DeferredHolder.create(Registries.MENU, new ResourceLocation("everlastingabilities:ability_container")); - @ObjectHolder(registryName = "recipe_serializer", value = "everlastingabilities:crafting_special_totem_recycle") - public static final SimpleCraftingRecipeSerializer RECIPESERIALIZER_TOTEM_RECYCLE = null; + public static final DeferredHolder, SimpleCraftingRecipeSerializer> RECIPESERIALIZER_TOTEM_RECYCLE = DeferredHolder.create(Registries.RECIPE_SERIALIZER, new ResourceLocation("everlastingabilities:crafting_special_totem_recycle")); - @ObjectHolder(registryName = "everlastingabilities:ability_serializers", value = "everlastingabilities:effect") - public static final Codec ABILITYSERIALIZER_EFFECT = null; - @ObjectHolder(registryName = "everlastingabilities:ability_serializers", value = "everlastingabilities:special_bonemealer") - public static final Codec ABILITYSERIALIZER_SPECIAL_BONEMEALER = null; - @ObjectHolder(registryName = "everlastingabilities:ability_serializers", value = "everlastingabilities:special_fertility") - public static final Codec ABILITYSERIALIZER_SPECIAL_FERTILITY = null; - @ObjectHolder(registryName = "everlastingabilities:ability_serializers", value = "everlastingabilities:special_flight") - public static final Codec ABILITYSERIALIZER_SPECIAL_FLIGHT = null; - @ObjectHolder(registryName = "everlastingabilities:ability_serializers", value = "everlastingabilities:special_magnetize") - public static final Codec ABILITYSERIALIZER_SPECIAL_MAGNETIZE = null; - @ObjectHolder(registryName = "everlastingabilities:ability_serializers", value = "everlastingabilities:special_power_stare") - public static final Codec ABILITYSERIALIZER_SPECIAL_POWER_STARE = null; - @ObjectHolder(registryName = "everlastingabilities:ability_serializers", value = "everlastingabilities:special_step_assist") - public static final Codec ABILITYSERIALIZER_SPECIAL_STEP_ASSIST = null; + public static final DeferredHolder, Codec> ABILITYSERIALIZER_EFFECT = DeferredHolder.create(AbilityTypeSerializers.REGISTRY_KEY, new ResourceLocation("everlastingabilities:effect")); + public static final DeferredHolder, Codec> ABILITYSERIALIZER_SPECIAL_BONEMEALER = DeferredHolder.create(AbilityTypeSerializers.REGISTRY_KEY, new ResourceLocation("everlastingabilities:special_bonemealer")); + public static final DeferredHolder, Codec> ABILITYSERIALIZER_SPECIAL_FERTILITY = DeferredHolder.create(AbilityTypeSerializers.REGISTRY_KEY, new ResourceLocation("everlastingabilities:special_fertility")); + public static final DeferredHolder, Codec> ABILITYSERIALIZER_SPECIAL_FLIGHT = DeferredHolder.create(AbilityTypeSerializers.REGISTRY_KEY, new ResourceLocation("everlastingabilities:special_flight")); + public static final DeferredHolder, Codec> ABILITYSERIALIZER_SPECIAL_MAGNETIZE = DeferredHolder.create(AbilityTypeSerializers.REGISTRY_KEY, new ResourceLocation("everlastingabilities:special_magnetize")); + public static final DeferredHolder, Codec> ABILITYSERIALIZER_SPECIAL_POWER_STARE = DeferredHolder.create(AbilityTypeSerializers.REGISTRY_KEY, new ResourceLocation("everlastingabilities:special_power_stare")); + public static final DeferredHolder, Codec> ABILITYSERIALIZER_SPECIAL_STEP_ASSIST = DeferredHolder.create(AbilityTypeSerializers.REGISTRY_KEY, new ResourceLocation("everlastingabilities:special_step_assist")); } diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityHelpers.java b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityHelpers.java index 7ef4fcfb..3ee9a9a0 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityHelpers.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityHelpers.java @@ -1,26 +1,32 @@ package org.cyclops.everlastingabilities.ability; import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; import com.google.common.collect.Sets; import lombok.NonNull; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.RandomSource; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Rarity; import net.minecraft.world.level.Level; -import net.minecraftforge.common.crafting.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.ICondition; import org.apache.commons.lang3.tuple.Triple; import org.cyclops.cyclopscore.helper.Helpers; +import org.cyclops.everlastingabilities.Capabilities; +import org.cyclops.everlastingabilities.EverlastingAbilities; import org.cyclops.everlastingabilities.GeneralConfig; import org.cyclops.everlastingabilities.api.Ability; import org.cyclops.everlastingabilities.api.AbilityTypes; import org.cyclops.everlastingabilities.api.IAbilityType; import org.cyclops.everlastingabilities.api.capability.IAbilityStore; import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStore; -import org.cyclops.everlastingabilities.capability.MutableAbilityStoreConfig; import org.cyclops.everlastingabilities.core.helper.WorldHelpers; import org.cyclops.everlastingabilities.item.ItemAbilityTotem; @@ -131,7 +137,7 @@ public static int getMaxPlayerAbilities(Level world) { */ @NonNull public static Ability addPlayerAbility(Player player, Ability ability, boolean doAdd, boolean modifyXp) { - return player.getCapability(MutableAbilityStoreConfig.CAPABILITY) + return Optional.ofNullable(player.getCapability(Capabilities.MutableAbilityStore.ENTITY)) .map(abilityStore -> { int oldLevel = abilityStore.hasAbilityType(ability.getAbilityType()) ? abilityStore.getAbility(ability.getAbilityType()).getLevel() : 0; @@ -177,7 +183,7 @@ && getMaxPlayerAbilities(player.getCommandSenderWorld()) <= abilityStore.getAbil */ @NonNull public static Ability removePlayerAbility(Player player, Ability ability, boolean doRemove, boolean modifyXp) { - return player.getCapability(MutableAbilityStoreConfig.CAPABILITY, null) + return Optional.ofNullable(player.getCapability(Capabilities.MutableAbilityStore.ENTITY)) .map(abilityStore -> { int oldLevel = abilityStore.hasAbilityType(ability.getAbilityType()) ? abilityStore.getAbility(ability.getAbilityType()).getLevel() : 0; @@ -201,7 +207,7 @@ public static int getExperience(@NonNull Ability ability) { } public static void setPlayerAbilities(ServerPlayer player, Map abilityTypes) { - player.getCapability(MutableAbilityStoreConfig.CAPABILITY) + Optional.ofNullable(player.getCapability(Capabilities.MutableAbilityStore.ENTITY)) .ifPresent(abilityStore -> abilityStore.setAbilities(abilityTypes)); } @@ -316,4 +322,38 @@ public static Supplier getSafeRarity(Supplier rarityGetter) { }; } + public static Tag serialize(Registry registry, IMutableAbilityStore capability) { + ListTag list = new ListTag(); + for (Ability ability : capability.getAbilities()) { + CompoundTag tag = new CompoundTag(); + tag.putString("name", registry.getKey(ability.getAbilityType()).toString()); + tag.putInt("level", ability.getLevel()); + list.add(tag); + } + return list; + } + + public static void deserialize(Registry registry, IMutableAbilityStore capability, Tag nbt) { + Map abilityTypes = Maps.newHashMap(); + if (nbt instanceof ListTag) { + if (((ListTag) nbt).getElementType() == Tag.TAG_COMPOUND) { + ListTag list = (ListTag) nbt; + for (int i = 0; i < list.size(); i++) { + CompoundTag tag = list.getCompound(i); + String name = tag.getString("name"); + int level = tag.getInt("level"); + IAbilityType abilityType = registry.get(new ResourceLocation(name)); + if (abilityType != null) { + abilityTypes.put(abilityType, level); + } else { + EverlastingAbilities.clog(org.apache.logging.log4j.Level.WARN, "Skipped loading unknown ability by name: " + name); + } + } + } + } else { + EverlastingAbilities.clog(org.apache.logging.log4j.Level.WARN, "Resetting a corrupted ability storage."); + } + capability.setAbilities(abilityTypes); + } + } diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeEffect.java b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeEffect.java index 32a328c2..1ca4d587 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeEffect.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeEffect.java @@ -1,6 +1,7 @@ package org.cyclops.everlastingabilities.ability; import com.mojang.serialization.Codec; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; @@ -10,9 +11,8 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Rarity; import net.minecraft.world.level.Level; -import net.minecraftforge.common.crafting.conditions.FalseCondition; -import net.minecraftforge.common.crafting.conditions.ICondition; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.neoforge.common.conditions.FalseCondition; +import net.neoforged.neoforge.common.conditions.ICondition; import org.cyclops.cyclopscore.helper.MinecraftHelpers; import org.cyclops.everlastingabilities.EverlastingAbilities; import org.cyclops.everlastingabilities.GeneralConfig; @@ -48,7 +48,7 @@ public AbilityTypeEffect(ICondition condition, String name, Rarity rarity, int m this.targetsFriendlyMobs = targetsFriendlyMobs; this.radiusFactor = radiusFactor; this.effectId = effectId; - this.potion = ForgeRegistries.MOB_EFFECTS.getValue(new ResourceLocation(effectId)); + this.potion = BuiltInRegistries.MOB_EFFECT.get(new ResourceLocation(effectId)); if (this.potion == null) { EverlastingAbilities.clog(org.apache.logging.log4j.Level.INFO, "No potion effect was found with id: " + effectId + ". Marking as disabled."); this.setCondition(FalseCondition.INSTANCE); @@ -93,7 +93,7 @@ public double getDurationFactor() { @Override public Codec codec() { - return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_EFFECT); + return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_EFFECT.get()); } protected int getDuration(int tickModulus, int level) { @@ -138,7 +138,7 @@ public void onTick(Player player, int level) { public static boolean isFriendlyMob(LivingEntity mob, Player player) { ResourceLocation resourceLocation = mob instanceof Player - ? new ResourceLocation("player") : ForgeRegistries.ENTITY_TYPES.getKey(mob.getType()); + ? new ResourceLocation("player") : BuiltInRegistries.ENTITY_TYPE.getKey(mob.getType()); String mobName = resourceLocation == null ? "null" : resourceLocation.toString(); return (mob == player || player.isAlliedTo(mob) || diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialBonemealer.java b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialBonemealer.java index b2d060b0..7c567041 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialBonemealer.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialBonemealer.java @@ -9,7 +9,7 @@ import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.GrassBlock; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.crafting.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.ICondition; import org.cyclops.cyclopscore.helper.MinecraftHelpers; import org.cyclops.cyclopscore.helper.WorldHelpers; import org.cyclops.everlastingabilities.RegistryEntries; @@ -34,7 +34,7 @@ public AbilityTypeSpecialBonemealer(ICondition condition, String name, Rarity ra @Override public Codec codec() { - return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_SPECIAL_BONEMEALER); + return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_SPECIAL_BONEMEALER.get()); } protected int getDurationMultiplier() { diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialFertility.java b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialFertility.java index 532f6dab..dbff53ba 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialFertility.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialFertility.java @@ -6,7 +6,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Rarity; import net.minecraft.world.level.Level; -import net.minecraftforge.common.crafting.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.ICondition; import org.cyclops.cyclopscore.helper.MinecraftHelpers; import org.cyclops.everlastingabilities.RegistryEntries; import org.cyclops.everlastingabilities.api.AbilityTypeAdapter; @@ -30,7 +30,7 @@ public AbilityTypeSpecialFertility(ICondition condition, String name, Rarity rar @Override public Codec codec() { - return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_SPECIAL_FERTILITY); + return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_SPECIAL_FERTILITY.get()); } protected int getDurationMultiplier() { diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialFlight.java b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialFlight.java index 5465d094..a8fd36b5 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialFlight.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialFlight.java @@ -3,7 +3,7 @@ import com.mojang.serialization.Codec; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Rarity; -import net.minecraftforge.common.crafting.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.ICondition; import org.cyclops.everlastingabilities.Reference; import org.cyclops.everlastingabilities.RegistryEntries; import org.cyclops.everlastingabilities.api.AbilityTypeAdapter; @@ -26,7 +26,7 @@ public AbilityTypeSpecialFlight(ICondition condition, String name, Rarity rarity @Override public Codec codec() { - return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_SPECIAL_FLIGHT); + return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_SPECIAL_FLIGHT.get()); } @Override diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialMagnetize.java b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialMagnetize.java index bd590102..f4b9c48a 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialMagnetize.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialMagnetize.java @@ -10,7 +10,7 @@ import net.minecraft.world.item.Rarity; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; -import net.minecraftforge.common.crafting.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.ICondition; import org.cyclops.cyclopscore.helper.MinecraftHelpers; import org.cyclops.everlastingabilities.RegistryEntries; import org.cyclops.everlastingabilities.api.AbilityTypeAdapter; @@ -37,7 +37,7 @@ public AbilityTypeSpecialMagnetize(ICondition condition, String name, Rarity rar @Override public Codec codec() { - return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_SPECIAL_MAGNETIZE); + return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_SPECIAL_MAGNETIZE.get()); } public boolean isMoveXp() { diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialPowerStare.java b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialPowerStare.java index 2c4b28c9..bf076117 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialPowerStare.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialPowerStare.java @@ -9,7 +9,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.common.crafting.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.ICondition; import org.cyclops.cyclopscore.helper.MinecraftHelpers; import org.cyclops.everlastingabilities.RegistryEntries; import org.cyclops.everlastingabilities.api.AbilityTypeAdapter; @@ -37,7 +37,7 @@ public AbilityTypeSpecialPowerStare(ICondition condition, String name, Rarity ra @Override public Codec codec() { - return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_SPECIAL_POWER_STARE); + return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_SPECIAL_POWER_STARE.get()); } public boolean isRequireSneak() { @@ -62,7 +62,6 @@ public void onTick(Player player, int level) { player.getBoundingBox().expandTowards(lookVec.x * range, lookVec.y * range, lookVec.z * range) .inflate((double) range)); for (Entity e : list) { - // TODO TameableEntity was IEntityOwnable if (e.isPickable() && (!(e instanceof TamableAnimal) || ((TamableAnimal) e).getOwner() != player) && !player.isAlliedTo(e)) { Entity entity = null; float f10 = e.getPickRadius(); diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialStepAssist.java b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialStepAssist.java index 74f39f40..eda697ee 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialStepAssist.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/AbilityTypeSpecialStepAssist.java @@ -6,8 +6,8 @@ import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Rarity; -import net.minecraftforge.common.ForgeMod; -import net.minecraftforge.common.crafting.conditions.ICondition; +import net.neoforged.neoforge.common.NeoForgeMod; +import net.neoforged.neoforge.common.conditions.ICondition; import org.cyclops.everlastingabilities.Reference; import org.cyclops.everlastingabilities.RegistryEntries; import org.cyclops.everlastingabilities.api.AbilityTypeAdapter; @@ -22,15 +22,11 @@ */ public class AbilityTypeSpecialStepAssist extends AbilityTypeAdapter { - @Deprecated - private final boolean forceDefaultStepHeight; // TODO: rm in next MC version private final Map attributeModifiers; public AbilityTypeSpecialStepAssist(ICondition condition, String name, Rarity rarity, int maxLevel, int baseXpPerLevel, - boolean obtainableOnPlayerSpawn, boolean obtainableOnMobSpawn, boolean obtainableOnCraft, boolean obtainableOnLoot, - boolean forceDefaultStepHeight) { + boolean obtainableOnPlayerSpawn, boolean obtainableOnMobSpawn, boolean obtainableOnCraft, boolean obtainableOnLoot) { super(condition, name, rarity, maxLevel, baseXpPerLevel, obtainableOnPlayerSpawn, obtainableOnMobSpawn, obtainableOnCraft, obtainableOnLoot); - this.forceDefaultStepHeight = forceDefaultStepHeight; this.attributeModifiers = Maps.newHashMap(); for (int i = 1; i <= maxLevel; i++) { this.attributeModifiers.put(i, new AttributeModifier(Reference.MOD_ID + ":stepHeightModifier" + i, i, AttributeModifier.Operation.ADDITION)); @@ -39,19 +35,15 @@ public AbilityTypeSpecialStepAssist(ICondition condition, String name, Rarity ra @Override public Codec codec() { - return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_SPECIAL_STEP_ASSIST); - } - - public boolean isForceDefaultStepHeight() { - return forceDefaultStepHeight; + return Objects.requireNonNull(RegistryEntries.ABILITYSERIALIZER_SPECIAL_STEP_ASSIST.get()); } @Override public void onChangedLevel(Player player, int oldLevel, int newLevel) { - AttributeInstance attribute = player.getAttribute(ForgeMod.STEP_HEIGHT_ADDITION.get()); + AttributeInstance attribute = player.getAttribute(NeoForgeMod.STEP_HEIGHT.value()); if (attribute != null) { if (oldLevel > 0) { - attribute.removeModifier(this.attributeModifiers.get(oldLevel)); + attribute.removeModifier(this.attributeModifiers.get(oldLevel).getId()); } if (newLevel > 0) { attribute.addPermanentModifier(this.attributeModifiers.get(newLevel)); diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeEffectSerializerConfig.java b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeEffectSerializerConfig.java index 7c443f92..afe551a3 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeEffectSerializerConfig.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeEffectSerializerConfig.java @@ -2,7 +2,8 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraftforge.common.crafting.conditions.TrueCondition; +import net.neoforged.neoforge.common.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.TrueCondition; import org.cyclops.everlastingabilities.ability.AbilityTypeEffect; import org.cyclops.everlastingabilities.api.IAbilityType; import org.cyclops.everlastingabilities.core.config.extendedconfig.AbilitySerializerConfig; @@ -17,7 +18,7 @@ public class AbilityTypeEffectSerializerConfig extends AbilitySerializerConfig RecordCodecBuilder.create(builder -> ApplicativeExtended.group17( builder, - CodecHelpers.CODEC_CONDITION.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), + ICondition.CODEC.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), Codec.STRING.fieldOf("name").forGetter(AbilityTypeEffect::getTranslationKey), CodecHelpers.CODEC_RARITY.fieldOf("rarity").forGetter(AbilityTypeEffect::getRarity), Codec.INT.fieldOf("max_level").forGetter(AbilityTypeEffect::getMaxLevel), diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialBonemealerSerializerConfig.java b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialBonemealerSerializerConfig.java index 0df41eb4..9fce8a26 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialBonemealerSerializerConfig.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialBonemealerSerializerConfig.java @@ -2,7 +2,8 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraftforge.common.crafting.conditions.TrueCondition; +import net.neoforged.neoforge.common.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.TrueCondition; import org.cyclops.everlastingabilities.ability.AbilityTypeSpecialBonemealer; import org.cyclops.everlastingabilities.api.IAbilityType; import org.cyclops.everlastingabilities.core.config.extendedconfig.AbilitySerializerConfig; @@ -16,7 +17,7 @@ public class AbilityTypeSpecialBonemealerSerializerConfig extends AbilitySeriali public AbilityTypeSpecialBonemealerSerializerConfig() { super("special_bonemealer", (eConfig) -> RecordCodecBuilder.create(builder -> builder .group( - CodecHelpers.CODEC_CONDITION.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), + ICondition.CODEC.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), Codec.STRING.fieldOf("name").forGetter(IAbilityType::getTranslationKey), CodecHelpers.CODEC_RARITY.fieldOf("rarity").forGetter(IAbilityType::getRarity), Codec.INT.fieldOf("max_level").forGetter(IAbilityType::getMaxLevel), diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialFertilitySerializerConfig.java b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialFertilitySerializerConfig.java index 0324a7fd..ea0b6673 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialFertilitySerializerConfig.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialFertilitySerializerConfig.java @@ -2,7 +2,8 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraftforge.common.crafting.conditions.TrueCondition; +import net.neoforged.neoforge.common.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.TrueCondition; import org.cyclops.everlastingabilities.ability.AbilityTypeSpecialFertility; import org.cyclops.everlastingabilities.api.IAbilityType; import org.cyclops.everlastingabilities.core.config.extendedconfig.AbilitySerializerConfig; @@ -16,7 +17,7 @@ public class AbilityTypeSpecialFertilitySerializerConfig extends AbilitySerializ public AbilityTypeSpecialFertilitySerializerConfig() { super("special_fertility", (eConfig) -> RecordCodecBuilder.create(builder -> builder .group( - CodecHelpers.CODEC_CONDITION.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), + ICondition.CODEC.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), Codec.STRING.fieldOf("name").forGetter(IAbilityType::getTranslationKey), CodecHelpers.CODEC_RARITY.fieldOf("rarity").forGetter(IAbilityType::getRarity), Codec.INT.fieldOf("max_level").forGetter(IAbilityType::getMaxLevel), diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialFlightSerializerConfig.java b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialFlightSerializerConfig.java index 445fe794..6741a5c2 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialFlightSerializerConfig.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialFlightSerializerConfig.java @@ -2,7 +2,8 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraftforge.common.crafting.conditions.TrueCondition; +import net.neoforged.neoforge.common.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.TrueCondition; import org.cyclops.everlastingabilities.ability.AbilityTypeSpecialFlight; import org.cyclops.everlastingabilities.api.IAbilityType; import org.cyclops.everlastingabilities.core.config.extendedconfig.AbilitySerializerConfig; @@ -16,7 +17,7 @@ public class AbilityTypeSpecialFlightSerializerConfig extends AbilitySerializerC public AbilityTypeSpecialFlightSerializerConfig() { super("special_flight", (eConfig) -> RecordCodecBuilder.create(builder -> builder .group( - CodecHelpers.CODEC_CONDITION.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), + ICondition.CODEC.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), Codec.STRING.fieldOf("name").forGetter(IAbilityType::getTranslationKey), CodecHelpers.CODEC_RARITY.fieldOf("rarity").forGetter(IAbilityType::getRarity), Codec.INT.fieldOf("max_level").forGetter(IAbilityType::getMaxLevel), diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialMagnetizeSerializerConfig.java b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialMagnetizeSerializerConfig.java index c49e04a4..2e27684f 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialMagnetizeSerializerConfig.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialMagnetizeSerializerConfig.java @@ -2,7 +2,8 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraftforge.common.crafting.conditions.TrueCondition; +import net.neoforged.neoforge.common.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.TrueCondition; import org.cyclops.everlastingabilities.ability.AbilityTypeSpecialMagnetize; import org.cyclops.everlastingabilities.api.IAbilityType; import org.cyclops.everlastingabilities.core.config.extendedconfig.AbilitySerializerConfig; @@ -16,7 +17,7 @@ public class AbilityTypeSpecialMagnetizeSerializerConfig extends AbilitySerializ public AbilityTypeSpecialMagnetizeSerializerConfig() { super("special_magnetize", (eConfig) -> RecordCodecBuilder.create(builder -> builder .group( - CodecHelpers.CODEC_CONDITION.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), + ICondition.CODEC.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), Codec.STRING.fieldOf("name").forGetter(IAbilityType::getTranslationKey), CodecHelpers.CODEC_RARITY.fieldOf("rarity").forGetter(IAbilityType::getRarity), Codec.INT.fieldOf("max_level").forGetter(IAbilityType::getMaxLevel), diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialPowerStareSerializerConfig.java b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialPowerStareSerializerConfig.java index 9c958850..b6f37075 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialPowerStareSerializerConfig.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialPowerStareSerializerConfig.java @@ -2,7 +2,8 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraftforge.common.crafting.conditions.TrueCondition; +import net.neoforged.neoforge.common.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.TrueCondition; import org.cyclops.everlastingabilities.ability.AbilityTypeSpecialPowerStare; import org.cyclops.everlastingabilities.api.IAbilityType; import org.cyclops.everlastingabilities.core.config.extendedconfig.AbilitySerializerConfig; @@ -16,7 +17,7 @@ public class AbilityTypeSpecialPowerStareSerializerConfig extends AbilitySeriali public AbilityTypeSpecialPowerStareSerializerConfig() { super("special_power_stare", (eConfig) -> RecordCodecBuilder.create(builder -> builder .group( - CodecHelpers.CODEC_CONDITION.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), + ICondition.CODEC.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), Codec.STRING.fieldOf("name").forGetter(IAbilityType::getTranslationKey), CodecHelpers.CODEC_RARITY.fieldOf("rarity").forGetter(IAbilityType::getRarity), Codec.INT.fieldOf("max_level").forGetter(IAbilityType::getMaxLevel), diff --git a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialStepAssistSerializerConfig.java b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialStepAssistSerializerConfig.java index 4c67dc41..edb38d59 100644 --- a/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialStepAssistSerializerConfig.java +++ b/src/main/java/org/cyclops/everlastingabilities/ability/serializer/AbilityTypeSpecialStepAssistSerializerConfig.java @@ -2,7 +2,8 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraftforge.common.crafting.conditions.TrueCondition; +import net.neoforged.neoforge.common.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.TrueCondition; import org.cyclops.everlastingabilities.ability.AbilityTypeSpecialStepAssist; import org.cyclops.everlastingabilities.api.IAbilityType; import org.cyclops.everlastingabilities.core.config.extendedconfig.AbilitySerializerConfig; @@ -16,7 +17,7 @@ public class AbilityTypeSpecialStepAssistSerializerConfig extends AbilitySeriali public AbilityTypeSpecialStepAssistSerializerConfig() { super("special_step_assist", (eConfig) -> RecordCodecBuilder.create(builder -> builder .group( - CodecHelpers.CODEC_CONDITION.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), + ICondition.CODEC.optionalFieldOf("condition", TrueCondition.INSTANCE).forGetter(IAbilityType::getCondition), Codec.STRING.fieldOf("name").forGetter(IAbilityType::getTranslationKey), CodecHelpers.CODEC_RARITY.fieldOf("rarity").forGetter(IAbilityType::getRarity), Codec.INT.fieldOf("max_level").forGetter(IAbilityType::getMaxLevel), @@ -24,8 +25,7 @@ public AbilityTypeSpecialStepAssistSerializerConfig() { Codec.BOOL.optionalFieldOf("obtainable_on_player_spawn", true).forGetter(IAbilityType::isObtainableOnPlayerSpawn), Codec.BOOL.optionalFieldOf("obtainable_on_mob_spawn", true).forGetter(IAbilityType::isObtainableOnMobSpawn), Codec.BOOL.optionalFieldOf("obtainable_on_craft", true).forGetter(IAbilityType::isObtainableOnCraft), - Codec.BOOL.optionalFieldOf("obtainable_on_loot", true).forGetter(IAbilityType::isObtainableOnLoot), - Codec.BOOL.optionalFieldOf("force_default_step_height", true).forGetter(AbilityTypeSpecialStepAssist::isForceDefaultStepHeight)) + Codec.BOOL.optionalFieldOf("obtainable_on_loot", true).forGetter(IAbilityType::isObtainableOnLoot)) .apply(builder, AbilityTypeSpecialStepAssist::new)) ); } diff --git a/src/main/java/org/cyclops/everlastingabilities/api/Ability.java b/src/main/java/org/cyclops/everlastingabilities/api/Ability.java index 62c12e57..de164abf 100644 --- a/src/main/java/org/cyclops/everlastingabilities/api/Ability.java +++ b/src/main/java/org/cyclops/everlastingabilities/api/Ability.java @@ -3,7 +3,7 @@ import com.mojang.serialization.Codec; import net.minecraft.network.chat.Component; import net.minecraft.world.item.Rarity; -import net.minecraftforge.common.crafting.conditions.TrueCondition; +import net.neoforged.neoforge.common.conditions.TrueCondition; import javax.annotation.Nonnull; import java.util.Objects; diff --git a/src/main/java/org/cyclops/everlastingabilities/api/AbilityTypeAdapter.java b/src/main/java/org/cyclops/everlastingabilities/api/AbilityTypeAdapter.java index e8c913d1..4b660b98 100644 --- a/src/main/java/org/cyclops/everlastingabilities/api/AbilityTypeAdapter.java +++ b/src/main/java/org/cyclops/everlastingabilities/api/AbilityTypeAdapter.java @@ -2,7 +2,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Rarity; -import net.minecraftforge.common.crafting.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.ICondition; import org.cyclops.everlastingabilities.GeneralConfig; /** diff --git a/src/main/java/org/cyclops/everlastingabilities/api/AbilityTypeSerializers.java b/src/main/java/org/cyclops/everlastingabilities/api/AbilityTypeSerializers.java index 7e7d1b4e..f38da71b 100644 --- a/src/main/java/org/cyclops/everlastingabilities/api/AbilityTypeSerializers.java +++ b/src/main/java/org/cyclops/everlastingabilities/api/AbilityTypeSerializers.java @@ -1,13 +1,14 @@ package org.cyclops.everlastingabilities.api; import com.mojang.serialization.Codec; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.ExtraCodecs; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.registries.IForgeRegistry; -import net.minecraftforge.registries.NewRegistryEvent; -import net.minecraftforge.registries.RegistryBuilder; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.registries.NewRegistryEvent; +import net.neoforged.neoforge.registries.RegistryBuilder; import java.util.function.Function; @@ -17,22 +18,19 @@ @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class AbilityTypeSerializers { - public static IForgeRegistry> REGISTRY; + public static final ResourceKey>> REGISTRY_KEY = ResourceKey.createRegistryKey(new ResourceLocation("everlastingabilities", "ability_serializers")); + public static Registry> REGISTRY; /** * Codec for (de)serializing abilities inline. * Mods can use this for data generation. */ - public static final Codec DIRECT_CODEC = ExtraCodecs.lazyInitializedCodec(() -> REGISTRY.getCodec()) + public static final Codec DIRECT_CODEC = ExtraCodecs.lazyInitializedCodec(() -> REGISTRY.byNameCodec()) .dispatch(IAbilityType::codec, Function.identity()); @SubscribeEvent public static void onRegistriesCreate(NewRegistryEvent event) { - event.create(new RegistryBuilder>() - .setName(new ResourceLocation("everlastingabilities", "ability_serializers")) - .disableSaving() - .disableSync(), - registry -> REGISTRY = registry); + REGISTRY = event.create(new RegistryBuilder<>(REGISTRY_KEY)); } } diff --git a/src/main/java/org/cyclops/everlastingabilities/api/AbilityTypes.java b/src/main/java/org/cyclops/everlastingabilities/api/AbilityTypes.java index 5f530100..a6986274 100644 --- a/src/main/java/org/cyclops/everlastingabilities/api/AbilityTypes.java +++ b/src/main/java/org/cyclops/everlastingabilities/api/AbilityTypes.java @@ -3,14 +3,10 @@ import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.registries.DataPackRegistryEvent; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.IForgeRegistry; -import net.minecraftforge.registries.RegistryBuilder; - -import java.util.function.Supplier; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.registries.DataPackRegistryEvent; +import net.neoforged.neoforge.registries.DeferredRegister; /** @@ -24,8 +20,6 @@ public class AbilityTypes { public static final DeferredRegister REGISTRY = DeferredRegister .create(REGISTRY_KEY, "everlastingabilities"); - public static final Supplier> REGISTRY_BUILTIN = REGISTRY - .makeRegistry(() -> new RegistryBuilder().allowModification()); @SubscribeEvent public static void onDatapackRegistryCreate(DataPackRegistryEvent.NewRegistry event) { diff --git a/src/main/java/org/cyclops/everlastingabilities/api/IAbilityType.java b/src/main/java/org/cyclops/everlastingabilities/api/IAbilityType.java index 65580c57..079d8bdd 100644 --- a/src/main/java/org/cyclops/everlastingabilities/api/IAbilityType.java +++ b/src/main/java/org/cyclops/everlastingabilities/api/IAbilityType.java @@ -3,7 +3,7 @@ import com.mojang.serialization.Codec; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Rarity; -import net.minecraftforge.common.crafting.conditions.ICondition; +import net.neoforged.neoforge.common.conditions.ICondition; /** diff --git a/src/main/java/org/cyclops/everlastingabilities/api/capability/AbilityStoreCapabilityProvider.java b/src/main/java/org/cyclops/everlastingabilities/api/capability/AbilityStoreCapabilityProvider.java deleted file mode 100644 index 3dfdd6e1..00000000 --- a/src/main/java/org/cyclops/everlastingabilities/api/capability/AbilityStoreCapabilityProvider.java +++ /dev/null @@ -1,125 +0,0 @@ -package org.cyclops.everlastingabilities.api.capability; - -import com.google.common.collect.Maps; -import net.minecraft.core.Registry; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.Tag; -import net.minecraft.resources.ResourceLocation; -import org.apache.logging.log4j.Level; -import org.cyclops.cyclopscore.modcompat.capabilities.ICapabilityTypeGetter; -import org.cyclops.cyclopscore.modcompat.capabilities.SerializableCapabilityProvider; -import org.cyclops.everlastingabilities.EverlastingAbilities; -import org.cyclops.everlastingabilities.ability.AbilityHelpers; -import org.cyclops.everlastingabilities.api.Ability; -import org.cyclops.everlastingabilities.api.IAbilityType; - -import javax.annotation.Nullable; -import java.util.Map; - -/** - * NBT storage for the {@link IAbilityStore} capability. - * @author rubensworks - */ -public class AbilityStoreCapabilityProvider extends SerializableCapabilityProvider { - - // TODO: remove this in the next major MC update, this is only needed for backwards-compat in EA 1.x->2.x - public static Map BACKWARDS_COMPATIBLE_MAPPING = Maps.newHashMap(); - static { - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:absorbtion", "everlastingabilities:effect/absorption"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:bad_omen", "everlastingabilities:effect/bad_omen"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:blindness", "everlastingabilities:effect/blindness"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:conduit_power", "everlastingabilities:effect/conduit_power"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:dolphins_grace", "everlastingabilities:effect/dolphins_grace"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:fire_resistance", "everlastingabilities:effect/fire_resistance"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:glowing", "everlastingabilities:effect/glowing"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:haste", "everlastingabilities:effect/haste"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:hunger", "everlastingabilities:effect/hunger"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:invisibility", "everlastingabilities:effect/invisibility"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:jump_boost", "everlastingabilities:effect/jump_boost"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:levitation", "everlastingabilities:effect/levitation"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:luck", "everlastingabilities:effect/luck"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:mining_fatigue", "everlastingabilities:effect/mining_fatigue"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:nausea", "everlastingabilities:effect/nausea"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:night_vision", "everlastingabilities:effect/night_vision"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:poison", "everlastingabilities:effect/poison"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:regeneration", "everlastingabilities:effect/regeneration"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:resistance", "everlastingabilities:effect/resistance"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:saturation", "everlastingabilities:effect/saturation"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:slow_falling", "everlastingabilities:effect/slow_falling"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:slowness", "everlastingabilities:effect/slowness"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:speed", "everlastingabilities:effect/speed"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:strength", "everlastingabilities:effect/strength"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:unluck", "everlastingabilities:effect/unluck"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:water_breathing", "everlastingabilities:effect/water_breathing"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:weakness", "everlastingabilities:effect/weakness"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:wither", "everlastingabilities:effect/wither"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:bonemealer", "everlastingabilities:special/bonemealer"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:fertility", "everlastingabilities:special/fertility"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:flight", "everlastingabilities:special/flight"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:magnetize", "everlastingabilities:special/magnetize"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:power_stare", "everlastingabilities:special/power_stare"); - BACKWARDS_COMPATIBLE_MAPPING.put("everlastingabilities:step_assist", "everlastingabilities:special/step_assist"); - } - - public AbilityStoreCapabilityProvider(ICapabilityTypeGetter capabilityGetter, T capability) { - super(capabilityGetter, capability); - } - - @Override - protected Tag serializeNBT(IMutableAbilityStore capability) { - return serializeNBTStatic(AbilityHelpers.getRegistry(), capability); - } - - @Override - protected void deserializeNBT(IMutableAbilityStore capability, Tag nbt) { - deserializeNBTStatic(AbilityHelpers.getRegistry(), capability, nbt); - } - - public static Tag serializeNBTStatic(Registry registry, IMutableAbilityStore capability) { - ListTag list = new ListTag(); - for (Ability ability : capability.getAbilities()) { - CompoundTag tag = new CompoundTag(); - tag.putString("name", registry.getKey(ability.getAbilityType()).toString()); - tag.putInt("level", ability.getLevel()); - list.add(tag); - } - return list; - } - - public static void deserializeNBTStatic(Registry registry, IMutableAbilityStore capability, Tag nbt) { - Map abilityTypes = Maps.newHashMap(); - if (nbt instanceof ListTag) { - if (((ListTag) nbt).getElementType() == Tag.TAG_COMPOUND) { - ListTag list = (ListTag) nbt; - for (int i = 0; i < list.size(); i++) { - CompoundTag tag = list.getCompound(i); - String name = tag.getString("name"); - int level = tag.getInt("level"); - IAbilityType abilityType = getAbilityBackwardsCompatible(registry, name); - if (abilityType != null) { - abilityTypes.put(abilityType, level); - } else { - EverlastingAbilities.clog(Level.WARN, "Skipped loading unknown ability by name: " + name); - } - } - } - } else { - EverlastingAbilities.clog(Level.WARN, "Resetting a corrupted ability storage."); - } - capability.setAbilities(abilityTypes); - } - - @Nullable - public static IAbilityType getAbilityBackwardsCompatible(Registry registry, String name) { - IAbilityType abilityType = registry.get(new ResourceLocation(name)); - if (abilityType != null) { - return abilityType; - } - String backwardsCompatibleMapping = BACKWARDS_COMPATIBLE_MAPPING.get(name); - if (backwardsCompatibleMapping != null) { - return registry.get(new ResourceLocation(backwardsCompatibleMapping)); - } - return null; - } -} diff --git a/src/main/java/org/cyclops/everlastingabilities/api/capability/ItemStackMutableAbilityStore.java b/src/main/java/org/cyclops/everlastingabilities/api/capability/CompoundTagMutableAbilityStore.java similarity index 82% rename from src/main/java/org/cyclops/everlastingabilities/api/capability/ItemStackMutableAbilityStore.java rename to src/main/java/org/cyclops/everlastingabilities/api/capability/CompoundTagMutableAbilityStore.java index 8b547747..a25bfa2b 100644 --- a/src/main/java/org/cyclops/everlastingabilities/api/capability/ItemStackMutableAbilityStore.java +++ b/src/main/java/org/cyclops/everlastingabilities/api/capability/CompoundTagMutableAbilityStore.java @@ -6,7 +6,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; -import net.minecraft.world.item.ItemStack; import org.cyclops.everlastingabilities.Reference; import org.cyclops.everlastingabilities.ability.AbilityHelpers; import org.cyclops.everlastingabilities.api.Ability; @@ -16,22 +15,22 @@ import javax.annotation.Nullable; import java.util.Collection; import java.util.Map; +import java.util.function.Supplier; /** - * Wrapper for an item ability store. - * TODO: This is just to avoid a Forge bug where cap NBT is not always sent to the client. + * Wrapper for a tag-based ability store. * @author rubensworks */ -public class ItemStackMutableAbilityStore implements IMutableAbilityStoreRegistryAccess { +public class CompoundTagMutableAbilityStore implements IMutableAbilityStoreRegistryAccess { private static final String NBT_STORE = Reference.MOD_ID + ":abilityStoreStack"; - private final ItemStack itemStack; + private final Supplier tagSupplier; @Nullable private RegistryAccess registryAccess; - public ItemStackMutableAbilityStore(ItemStack itemStack) { - this.itemStack = itemStack; + public CompoundTagMutableAbilityStore(Supplier tagSupplier) { + this.tagSupplier = tagSupplier; } @Override @@ -43,20 +42,25 @@ protected Registry getRegistry() { return AbilityHelpers.getRegistry(this.registryAccess != null ? this.registryAccess : WorldHelpers.getRegistryAccess()); } + public boolean isInitialized() { + CompoundTag root = tagSupplier.get(); + return root.contains(NBT_STORE); + } + protected IMutableAbilityStore getInnerStore() { IMutableAbilityStore store = new DefaultMutableAbilityStore(); - CompoundTag root = itemStack.getOrCreateTag(); + CompoundTag root = tagSupplier.get(); if (!root.contains(NBT_STORE)) { root.put(NBT_STORE, new ListTag()); } Tag nbt = root.get(NBT_STORE); - AbilityStoreCapabilityProvider.deserializeNBTStatic(getRegistry(), store, nbt); + AbilityHelpers.deserialize(getRegistry(), store, nbt); return store; } protected IMutableAbilityStore setInnerStore(IMutableAbilityStore store) { - CompoundTag root = itemStack.getOrCreateTag(); - Tag nbt = AbilityStoreCapabilityProvider.serializeNBTStatic(getRegistry(), store); + CompoundTag root = tagSupplier.get(); + Tag nbt = AbilityHelpers.serialize(getRegistry(), store); root.put(NBT_STORE, nbt); return store; } diff --git a/src/main/java/org/cyclops/everlastingabilities/capability/AbilityStoreConfig.java b/src/main/java/org/cyclops/everlastingabilities/capability/AbilityStoreConfig.java deleted file mode 100644 index 1af3e26f..00000000 --- a/src/main/java/org/cyclops/everlastingabilities/capability/AbilityStoreConfig.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.cyclops.everlastingabilities.capability; - -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.CapabilityManager; -import net.minecraftforge.common.capabilities.CapabilityToken; -import org.cyclops.cyclopscore.config.extendedconfig.CapabilityConfig; -import org.cyclops.everlastingabilities.EverlastingAbilities; -import org.cyclops.everlastingabilities.api.capability.IAbilityStore; - -/** - * Config for the worker capability. - * @author rubensworks - * - */ -public class AbilityStoreConfig extends CapabilityConfig { - - /** - * The unique instance. - */ - public static AbilityStoreConfig _instance; - - public static Capability CAPABILITY = CapabilityManager.get(new CapabilityToken<>(){}); - - /** - * Make a new instance. - */ - public AbilityStoreConfig() { - super(EverlastingAbilities._instance, - "abilityStore", - IAbilityStore.class); - } -} diff --git a/src/main/java/org/cyclops/everlastingabilities/capability/MutableAbilityStoreConfig.java b/src/main/java/org/cyclops/everlastingabilities/capability/MutableAbilityStoreConfig.java deleted file mode 100644 index 2bce6b07..00000000 --- a/src/main/java/org/cyclops/everlastingabilities/capability/MutableAbilityStoreConfig.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.cyclops.everlastingabilities.capability; - -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.CapabilityManager; -import net.minecraftforge.common.capabilities.CapabilityToken; -import org.cyclops.cyclopscore.config.extendedconfig.CapabilityConfig; -import org.cyclops.everlastingabilities.EverlastingAbilities; -import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStore; - -/** - * Config for the worker capability. - * @author rubensworks - * - */ -public class MutableAbilityStoreConfig extends CapabilityConfig { - - /** - * The unique instance. - */ - public static MutableAbilityStoreConfig _instance; - - public static Capability CAPABILITY = CapabilityManager.get(new CapabilityToken<>(){}); - - /** - * Make a new instance. - */ - public MutableAbilityStoreConfig() { - super(EverlastingAbilities._instance, - "mutableAbilityStore", - IMutableAbilityStore.class); - } -} diff --git a/src/main/java/org/cyclops/everlastingabilities/client/gui/ContainerScreenAbilityContainer.java b/src/main/java/org/cyclops/everlastingabilities/client/gui/ContainerScreenAbilityContainer.java index bc15f1ce..57ea06fa 100644 --- a/src/main/java/org/cyclops/everlastingabilities/client/gui/ContainerScreenAbilityContainer.java +++ b/src/main/java/org/cyclops/everlastingabilities/client/gui/ContainerScreenAbilityContainer.java @@ -188,7 +188,8 @@ protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int mouseX, int i = this.leftPos; int j = this.topPos; drawFancyBackground(guiGraphics, i + 8, j + 17, 66, 61, getPlayerAbilityStore()); - InventoryScreen.renderEntityInInventoryFollowsMouse(guiGraphics, i + 41, j + 75, 30, (float)(i + 41) - mouseX, (float)(j + 76 - 50) - mouseY, this.getMinecraft().player); + // i + 41, j + 75, i + 41 + 66, j + 75 + 61 + InventoryScreen.renderEntityInInventoryFollowsMouse(guiGraphics, i + 26 - 8, j + 8 + 3, i + 75 - 8, j + 78 + 3, 30, 0.0625F, mouseX, mouseY, this.getMinecraft().player); drawXp(guiGraphics, i + 67, j + 70); RenderHelpers.drawScaledCenteredString(guiGraphics.pose(), guiGraphics.bufferSource(), font, "" + player.totalExperience, i + 62, j + 73, 0, 0.5F, Helpers.RGBToInt(40, 215, 40), false, Font.DisplayMode.NORMAL); drawFancyBackground(guiGraphics, i + 102, j + 17, 66, 61, getItemAbilityStore()); @@ -363,7 +364,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) { } @Override - public boolean mouseScrolled(double mouseX, double mouseY, double scrollAmount) { + public boolean mouseScrolled(double mouseX, double mouseY, double mouseZ, double scrollAmount) { if (isHovering(8, 83, ABILITY_BOX_WIDTH, ABILITY_BOX_HEIGHT * ABILITY_LIST_SIZE, mouseX, mouseY)) { if (scrollAmount > 0) { if (startIndexPlayer > 0) diff --git a/src/main/java/org/cyclops/everlastingabilities/command/CommandModifyAbilities.java b/src/main/java/org/cyclops/everlastingabilities/command/CommandModifyAbilities.java index 52466cab..47d57436 100644 --- a/src/main/java/org/cyclops/everlastingabilities/command/CommandModifyAbilities.java +++ b/src/main/java/org/cyclops/everlastingabilities/command/CommandModifyAbilities.java @@ -12,11 +12,11 @@ import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import org.cyclops.cyclopscore.command.argument.ArgumentTypeEnum; +import org.cyclops.everlastingabilities.Capabilities; import org.cyclops.everlastingabilities.ability.AbilityHelpers; import org.cyclops.everlastingabilities.api.Ability; import org.cyclops.everlastingabilities.api.IAbilityType; import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStore; -import org.cyclops.everlastingabilities.capability.MutableAbilityStoreConfig; import org.cyclops.everlastingabilities.command.argument.ArgumentTypeAbility; /** @@ -38,7 +38,7 @@ public int run(CommandContext context) throws CommandSyntaxE ServerPlayer sender = context.getSource().getPlayerOrException(); Action action = ArgumentTypeEnum.getValue(context, "action", Action.class); ServerPlayer player = EntityArgument.getPlayer(context, "player"); - IMutableAbilityStore abilityStore = player.getCapability(MutableAbilityStoreConfig.CAPABILITY).orElse(null); + IMutableAbilityStore abilityStore = player.getCapability(Capabilities.MutableAbilityStore.ENTITY); if (action == Action.LIST) { sender.sendSystemMessage(abilityStore.getTextComponent()); diff --git a/src/main/java/org/cyclops/everlastingabilities/core/config/extendedconfig/AbilitySerializerConfig.java b/src/main/java/org/cyclops/everlastingabilities/core/config/extendedconfig/AbilitySerializerConfig.java index 56d4850b..12a7069a 100644 --- a/src/main/java/org/cyclops/everlastingabilities/core/config/extendedconfig/AbilitySerializerConfig.java +++ b/src/main/java/org/cyclops/everlastingabilities/core/config/extendedconfig/AbilitySerializerConfig.java @@ -1,7 +1,7 @@ package org.cyclops.everlastingabilities.core.config.extendedconfig; import com.mojang.serialization.Codec; -import net.minecraftforge.registries.IForgeRegistry; +import net.minecraft.core.Registry; import org.cyclops.cyclopscore.config.ConfigurableType; import org.cyclops.cyclopscore.config.extendedconfig.ExtendedConfig; import org.cyclops.cyclopscore.config.extendedconfig.ExtendedConfigForge; @@ -34,7 +34,7 @@ public ConfigurableType getConfigurableType() { } @Override - public IForgeRegistry> getRegistry() { + public Registry> getRegistry() { return AbilityTypeSerializers.REGISTRY; } } diff --git a/src/main/java/org/cyclops/everlastingabilities/core/helper/CodecHelpers.java b/src/main/java/org/cyclops/everlastingabilities/core/helper/CodecHelpers.java index 7ddcac6c..e7a6780d 100644 --- a/src/main/java/org/cyclops/everlastingabilities/core/helper/CodecHelpers.java +++ b/src/main/java/org/cyclops/everlastingabilities/core/helper/CodecHelpers.java @@ -5,14 +5,10 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import com.mojang.serialization.Codec; -import com.mojang.serialization.DataResult; import com.mojang.serialization.DynamicOps; import com.mojang.serialization.MapLike; -import com.mojang.serialization.codecs.PrimitiveCodec; import net.minecraft.util.ExtraCodecs; import net.minecraft.world.item.Rarity; -import net.minecraftforge.common.crafting.CraftingHelper; -import net.minecraftforge.common.crafting.conditions.ICondition; import org.cyclops.everlastingabilities.ability.AbilityTypeEffect; import java.util.HashMap; @@ -47,22 +43,6 @@ public class CodecHelpers { ) ); - public static final Codec CODEC_CONDITION = new PrimitiveCodec() { - @Override - public DataResult read(DynamicOps ops, T input) { - try { - return DataResult.success(CraftingHelper.getCondition((JsonObject) opsToJson(ops, input))); - } catch (RuntimeException error) { - return DataResult.error(error::getMessage); - } - } - - @Override - public T write(DynamicOps ops, ICondition value) { - return jsonToOps(ops, CraftingHelper.serialize(value)); - } - }; - public static JsonElement opsToJson(DynamicOps ops, T input) { if (input instanceof JsonElement jsonElement) { return jsonElement; diff --git a/src/main/java/org/cyclops/everlastingabilities/core/helper/WorldHelpers.java b/src/main/java/org/cyclops/everlastingabilities/core/helper/WorldHelpers.java index d35d8bc1..4596bd49 100644 --- a/src/main/java/org/cyclops/everlastingabilities/core/helper/WorldHelpers.java +++ b/src/main/java/org/cyclops/everlastingabilities/core/helper/WorldHelpers.java @@ -1,8 +1,8 @@ package org.cyclops.everlastingabilities.core.helper; import net.minecraft.core.RegistryAccess; -import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.fml.DistExecutor; +import net.neoforged.neoforge.server.ServerLifecycleHooks; /** * Helpers for world related logic. diff --git a/src/main/java/org/cyclops/everlastingabilities/core/helper/WorldHelpersClient.java b/src/main/java/org/cyclops/everlastingabilities/core/helper/WorldHelpersClient.java index e0aed7e5..16841694 100644 --- a/src/main/java/org/cyclops/everlastingabilities/core/helper/WorldHelpersClient.java +++ b/src/main/java/org/cyclops/everlastingabilities/core/helper/WorldHelpersClient.java @@ -2,8 +2,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.core.RegistryAccess; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; /** * @author rubensworks diff --git a/src/main/java/org/cyclops/everlastingabilities/core/helper/WorldHelpersServer.java b/src/main/java/org/cyclops/everlastingabilities/core/helper/WorldHelpersServer.java index 80b3e21f..5a3ebb44 100644 --- a/src/main/java/org/cyclops/everlastingabilities/core/helper/WorldHelpersServer.java +++ b/src/main/java/org/cyclops/everlastingabilities/core/helper/WorldHelpersServer.java @@ -1,7 +1,7 @@ package org.cyclops.everlastingabilities.core.helper; import net.minecraft.core.RegistryAccess; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.neoforge.server.ServerLifecycleHooks; /** * @author rubensworks diff --git a/src/main/java/org/cyclops/everlastingabilities/inventory/container/ContainerAbilityContainer.java b/src/main/java/org/cyclops/everlastingabilities/inventory/container/ContainerAbilityContainer.java index 51d36044..70e9b49f 100644 --- a/src/main/java/org/cyclops/everlastingabilities/inventory/container/ContainerAbilityContainer.java +++ b/src/main/java/org/cyclops/everlastingabilities/inventory/container/ContainerAbilityContainer.java @@ -5,22 +5,22 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.util.LazyOptional; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.cyclopscore.inventory.ItemLocation; import org.cyclops.cyclopscore.inventory.container.ItemInventoryContainer; +import org.cyclops.everlastingabilities.Capabilities; import org.cyclops.everlastingabilities.RegistryEntries; import org.cyclops.everlastingabilities.ability.AbilityHelpers; import org.cyclops.everlastingabilities.api.Ability; import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStore; import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStoreRegistryAccess; -import org.cyclops.everlastingabilities.capability.MutableAbilityStoreConfig; import org.cyclops.everlastingabilities.client.gui.ContainerScreenAbilityContainer; import org.cyclops.everlastingabilities.item.ItemGuiAbilityContainer; import java.util.Collections; import java.util.List; +import java.util.Optional; /** * Container for the labeller. @@ -36,7 +36,7 @@ public ContainerAbilityContainer(int id, Inventory inventory, FriendlyByteBuf pa } public ContainerAbilityContainer(int id, Inventory inventory, ItemLocation itemLocation) { - super(RegistryEntries.CONTAINER_ABILITYCONTAINER, id, inventory, itemLocation); + super(RegistryEntries.CONTAINER_ABILITYCONTAINER.get(), id, inventory, itemLocation); addInventory(inventory, 0, 8, 195, 1, 9); // If level is not consistent with total experience count, fix it. @@ -63,17 +63,17 @@ protected int getSizeInventory() { return 0; } - public LazyOptional getPlayerAbilityStore() { - return player.getCapability(MutableAbilityStoreConfig.CAPABILITY); + public Optional getPlayerAbilityStore() { + return Optional.ofNullable(player.getCapability(Capabilities.MutableAbilityStore.ENTITY)); } - public LazyOptional getItemAbilityStore() { + public Optional getItemAbilityStore() { ItemStack itemStack = getItemStack(player); if (itemStack.isEmpty()) { - return LazyOptional.empty(); + return Optional.empty(); } - return itemStack.getCapability(MutableAbilityStoreConfig.CAPABILITY) - .lazyMap(store -> { + return Optional.ofNullable(itemStack.getCapability(Capabilities.MutableAbilityStore.ITEM)) + .map(store -> { ((IMutableAbilityStoreRegistryAccess) store).setRegistryAccess(this.player.level().registryAccess()); return store; }); diff --git a/src/main/java/org/cyclops/everlastingabilities/inventory/container/ContainerAbilityContainerConfig.java b/src/main/java/org/cyclops/everlastingabilities/inventory/container/ContainerAbilityContainerConfig.java index fda8df1d..81a21317 100644 --- a/src/main/java/org/cyclops/everlastingabilities/inventory/container/ContainerAbilityContainerConfig.java +++ b/src/main/java/org/cyclops/everlastingabilities/inventory/container/ContainerAbilityContainerConfig.java @@ -4,8 +4,8 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.MenuAccess; import net.minecraft.world.flag.FeatureFlags; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.cyclopscore.client.gui.ScreenFactorySafe; import org.cyclops.cyclopscore.config.extendedconfig.GuiConfig; import org.cyclops.cyclopscore.inventory.container.ContainerTypeData; diff --git a/src/main/java/org/cyclops/everlastingabilities/item/ItemAbilityBottleConfig.java b/src/main/java/org/cyclops/everlastingabilities/item/ItemAbilityBottleConfig.java index 585deda5..15f94c2f 100644 --- a/src/main/java/org/cyclops/everlastingabilities/item/ItemAbilityBottleConfig.java +++ b/src/main/java/org/cyclops/everlastingabilities/item/ItemAbilityBottleConfig.java @@ -1,8 +1,11 @@ package org.cyclops.everlastingabilities.item; import net.minecraft.world.item.Item; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; import org.cyclops.cyclopscore.config.extendedconfig.ItemConfig; +import org.cyclops.everlastingabilities.Capabilities; import org.cyclops.everlastingabilities.EverlastingAbilities; +import org.cyclops.everlastingabilities.api.capability.CompoundTagMutableAbilityStore; /** * Config for the ability bottle. @@ -15,6 +18,11 @@ public ItemAbilityBottleConfig() { "ability_bottle", (eConfig) -> new ItemAbilityBottle(new Item.Properties() .stacksTo(1))); + EverlastingAbilities._instance.getModEventBus().addListener(this::registerCapability); + } + + protected void registerCapability(RegisterCapabilitiesEvent event) { + event.registerItem(Capabilities.MutableAbilityStore.ITEM, (stack, context) -> new CompoundTagMutableAbilityStore(stack::getOrCreateTag), getInstance()); } } diff --git a/src/main/java/org/cyclops/everlastingabilities/item/ItemAbilityTotem.java b/src/main/java/org/cyclops/everlastingabilities/item/ItemAbilityTotem.java index 68790d9d..58d4c536 100644 --- a/src/main/java/org/cyclops/everlastingabilities/item/ItemAbilityTotem.java +++ b/src/main/java/org/cyclops/everlastingabilities/item/ItemAbilityTotem.java @@ -2,9 +2,11 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Rarity; +import org.cyclops.everlastingabilities.Capabilities; import org.cyclops.everlastingabilities.RegistryEntries; import org.cyclops.everlastingabilities.api.Ability; -import org.cyclops.everlastingabilities.capability.MutableAbilityStoreConfig; + +import java.util.Optional; /** * A totem with abilities. @@ -23,7 +25,7 @@ public boolean canMoveFromPlayer() { @Override public Rarity getRarity(ItemStack itemStack) { - return itemStack.getCapability(MutableAbilityStoreConfig.CAPABILITY, null) + return Optional.ofNullable(itemStack.getCapability(Capabilities.MutableAbilityStore.ITEM)) .map(abilityStore -> { int maxRarity = 0; for (Ability ability : abilityStore.getAbilities()) { @@ -36,7 +38,7 @@ public Rarity getRarity(ItemStack itemStack) { public static ItemStack getTotem(Ability ability) { ItemStack itemStack = new ItemStack(RegistryEntries.ITEM_ABILITY_TOTEM); - itemStack.getCapability(MutableAbilityStoreConfig.CAPABILITY, null) + Optional.ofNullable(itemStack.getCapability(Capabilities.MutableAbilityStore.ITEM)) .ifPresent(mutableAbilityStore -> mutableAbilityStore.addAbility(ability, true)); return itemStack; } diff --git a/src/main/java/org/cyclops/everlastingabilities/item/ItemAbilityTotemConfig.java b/src/main/java/org/cyclops/everlastingabilities/item/ItemAbilityTotemConfig.java index 3c091bd6..1ec1d221 100644 --- a/src/main/java/org/cyclops/everlastingabilities/item/ItemAbilityTotemConfig.java +++ b/src/main/java/org/cyclops/everlastingabilities/item/ItemAbilityTotemConfig.java @@ -5,15 +5,17 @@ import net.minecraft.core.RegistryAccess; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.event.BuildCreativeModeTabContentsEvent; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; import org.cyclops.cyclopscore.config.ConfigurableProperty; import org.cyclops.cyclopscore.config.extendedconfig.ItemConfig; +import org.cyclops.everlastingabilities.Capabilities; import org.cyclops.everlastingabilities.EverlastingAbilities; import org.cyclops.everlastingabilities.ability.AbilityHelpers; import org.cyclops.everlastingabilities.api.Ability; import org.cyclops.everlastingabilities.api.IAbilityType; +import org.cyclops.everlastingabilities.api.capability.CompoundTagMutableAbilityStore; import org.cyclops.everlastingabilities.core.helper.WorldHelpers; import java.util.Collection; @@ -35,7 +37,8 @@ public ItemAbilityTotemConfig() { "ability_totem", (eConfig) -> new ItemAbilityTotem(new Item.Properties() .stacksTo(1))); - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onCreativeModeTabBuildContents); + EverlastingAbilities._instance.getModEventBus().addListener(this::onCreativeModeTabBuildContents); + EverlastingAbilities._instance.getModEventBus().addListener(this::registerCapability); } @Override @@ -57,4 +60,8 @@ protected void onCreativeModeTabBuildContents(BuildCreativeModeTabContentsEvent }); } } + + protected void registerCapability(RegisterCapabilitiesEvent event) { + event.registerItem(Capabilities.MutableAbilityStore.ITEM, (stack, context) -> new CompoundTagMutableAbilityStore(stack::getOrCreateTag), getInstance()); + } } diff --git a/src/main/java/org/cyclops/everlastingabilities/item/ItemGuiAbilityContainer.java b/src/main/java/org/cyclops/everlastingabilities/item/ItemGuiAbilityContainer.java index 92ca6814..8b02363c 100644 --- a/src/main/java/org/cyclops/everlastingabilities/item/ItemGuiAbilityContainer.java +++ b/src/main/java/org/cyclops/everlastingabilities/item/ItemGuiAbilityContainer.java @@ -1,7 +1,6 @@ package org.cyclops.everlastingabilities.item; import net.minecraft.ChatFormatting; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; import net.minecraft.network.chat.TextColor; @@ -11,21 +10,19 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; -import net.minecraftforge.common.capabilities.ICapabilityProvider; import org.cyclops.cyclopscore.inventory.ItemLocation; import org.cyclops.cyclopscore.inventory.container.NamedContainerProviderItem; import org.cyclops.cyclopscore.item.ItemGui; -import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityProvider; +import org.cyclops.everlastingabilities.Capabilities; import org.cyclops.everlastingabilities.api.Ability; import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStoreRegistryAccess; -import org.cyclops.everlastingabilities.api.capability.ItemStackMutableAbilityStore; -import org.cyclops.everlastingabilities.capability.MutableAbilityStoreConfig; import org.cyclops.everlastingabilities.inventory.container.ContainerAbilityContainer; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; /** * Base class for items with abilities. @@ -52,7 +49,7 @@ public MenuProvider getContainer(Level world, Player playerEntity, ItemLocation public void appendHoverText(ItemStack itemStack, @Nullable Level worldIn, List tooltip, TooltipFlag flagIn) { super.appendHoverText(itemStack, worldIn, tooltip, flagIn); - itemStack.getCapability(MutableAbilityStoreConfig.CAPABILITY, null).ifPresent(abilityStore -> { + Optional.ofNullable(itemStack.getCapability(Capabilities.MutableAbilityStore.ITEM, null)).ifPresent(abilityStore -> { if (worldIn != null) { ((IMutableAbilityStoreRegistryAccess) abilityStore).setRegistryAccess(worldIn.registryAccess()); } @@ -78,15 +75,6 @@ public void appendHoverText(ItemStack itemStack, @Nullable Level worldIn, List(MutableAbilityStoreConfig.CAPABILITY, - // new DefaultMutableAbilityStore()); - return new DefaultCapabilityProvider<>(() -> MutableAbilityStoreConfig.CAPABILITY, - new ItemStackMutableAbilityStore(stack)); - } - public abstract boolean canMoveFromPlayer(); @Override diff --git a/src/main/java/org/cyclops/everlastingabilities/loot/functions/LootFunctionSetRandomAbility.java b/src/main/java/org/cyclops/everlastingabilities/loot/functions/LootFunctionSetRandomAbility.java deleted file mode 100644 index 6e13c494..00000000 --- a/src/main/java/org/cyclops/everlastingabilities/loot/functions/LootFunctionSetRandomAbility.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.cyclops.everlastingabilities.loot.functions; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializationContext; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.functions.LootItemConditionalFunction; -import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType; -import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; -import org.cyclops.cyclopscore.helper.LootHelpers; -import org.cyclops.everlastingabilities.Reference; -import org.cyclops.everlastingabilities.ability.AbilityHelpers; -import org.cyclops.everlastingabilities.api.Ability; -import org.cyclops.everlastingabilities.api.IAbilityType; -import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStoreRegistryAccess; -import org.cyclops.everlastingabilities.capability.MutableAbilityStoreConfig; - -import java.util.List; - -/** - * A loot function that sets a random into an item. - * @author rubensworks - */ -@Deprecated // Deprecated in favor of LootModifierInjectAbilityTotem -public class LootFunctionSetRandomAbility extends LootItemConditionalFunction { - public static final LootItemFunctionType TYPE = LootHelpers.registerFunction(new ResourceLocation(Reference.MOD_ID, "set_random_ability"), new LootFunctionSetRandomAbility.Serializer()); - - public LootFunctionSetRandomAbility(LootItemCondition[] conditionsIn) { - super(conditionsIn); - } - - @Override - public ItemStack run(ItemStack stack, LootContext context) { - try { - List abilityTypes = AbilityHelpers.getAbilityTypesLoot(AbilityHelpers.getRegistry(context.getLevel().registryAccess())); - AbilityHelpers.getRandomRarity(abilityTypes, context.getRandom()) - .ifPresent(rarity -> { - IAbilityType abilityType = AbilityHelpers.getRandomAbility(abilityTypes, context.getRandom(), rarity).get(); // Should always be present, as the method above guarantees that - - stack.getCapability(MutableAbilityStoreConfig.CAPABILITY, null) - .ifPresent(mutableAbilityStore -> { - ((IMutableAbilityStoreRegistryAccess) mutableAbilityStore).setRegistryAccess(context.getLevel().registryAccess()); - mutableAbilityStore.addAbility(new Ability(abilityType, 1), true); - }); - }); - return stack; - } catch (IllegalStateException e) { - return ItemStack.EMPTY; - } - } - - @Override - public LootItemFunctionType getType() { - return TYPE; - } - - public static void load() { - // Dummy call, to enforce class loading - } - - public static class Serializer extends LootItemConditionalFunction.Serializer { - @Override - public void serialize(JsonObject object, LootFunctionSetRandomAbility functionClazz, JsonSerializationContext serializationContext) { - - } - - @Override - public LootFunctionSetRandomAbility deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootItemCondition[] conditionsIn) { - return new LootFunctionSetRandomAbility(conditionsIn); - } - } - -} diff --git a/src/main/java/org/cyclops/everlastingabilities/loot/modifier/LootModifierInjectAbilityTotem.java b/src/main/java/org/cyclops/everlastingabilities/loot/modifier/LootModifierInjectAbilityTotem.java index 00776e21..335e1e0c 100644 --- a/src/main/java/org/cyclops/everlastingabilities/loot/modifier/LootModifierInjectAbilityTotem.java +++ b/src/main/java/org/cyclops/everlastingabilities/loot/modifier/LootModifierInjectAbilityTotem.java @@ -7,17 +7,18 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; -import net.minecraftforge.common.loot.IGlobalLootModifier; -import net.minecraftforge.common.loot.LootModifier; +import net.neoforged.neoforge.common.loot.IGlobalLootModifier; +import net.neoforged.neoforge.common.loot.LootModifier; +import org.cyclops.everlastingabilities.Capabilities; import org.cyclops.everlastingabilities.RegistryEntries; import org.cyclops.everlastingabilities.ability.AbilityHelpers; import org.cyclops.everlastingabilities.api.Ability; import org.cyclops.everlastingabilities.api.IAbilityType; import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStoreRegistryAccess; -import org.cyclops.everlastingabilities.capability.MutableAbilityStoreConfig; import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Optional; import java.util.function.Supplier; /** @@ -48,7 +49,7 @@ public List getLootTables() { IAbilityType abilityType = AbilityHelpers.getRandomAbility(abilityTypes, context.getRandom(), rarity).get(); // Should always be present, as the method above guarantees that ItemStack stack = new ItemStack(RegistryEntries.ITEM_ABILITY_TOTEM); - stack.getCapability(MutableAbilityStoreConfig.CAPABILITY, null) + Optional.ofNullable(stack.getCapability(Capabilities.MutableAbilityStore.ITEM)) .ifPresent(mutableAbilityStore -> { ((IMutableAbilityStoreRegistryAccess) mutableAbilityStore).setRegistryAccess(context.getLevel().registryAccess()); mutableAbilityStore.addAbility(new Ability(abilityType, 1), true); diff --git a/src/main/java/org/cyclops/everlastingabilities/network/packet/MoveAbilityPacket.java b/src/main/java/org/cyclops/everlastingabilities/network/packet/MoveAbilityPacket.java index dca7b68e..7424a6d8 100644 --- a/src/main/java/org/cyclops/everlastingabilities/network/packet/MoveAbilityPacket.java +++ b/src/main/java/org/cyclops/everlastingabilities/network/packet/MoveAbilityPacket.java @@ -5,10 +5,11 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.cyclopscore.network.CodecField; import org.cyclops.cyclopscore.network.PacketCodec; +import org.cyclops.everlastingabilities.Reference; import org.cyclops.everlastingabilities.ability.AbilityHelpers; import org.cyclops.everlastingabilities.api.Ability; import org.cyclops.everlastingabilities.api.IAbilityType; @@ -21,6 +22,8 @@ */ public class MoveAbilityPacket extends PacketCodec { + public static final ResourceLocation ID = new ResourceLocation(Reference.MOD_ID, "move_ability"); + @CodecField private String abilityName; @CodecField @@ -29,10 +32,11 @@ public class MoveAbilityPacket extends PacketCodec { private int movement; public MoveAbilityPacket() { - + super(ID); } public MoveAbilityPacket(Registry registry, Ability ability, Movement movement) { + this(); this.abilityName = registry.getKey(ability.getAbilityType()).toString(); this.abilityLevel = ability.getLevel(); this.movement = movement.ordinal(); diff --git a/src/main/java/org/cyclops/everlastingabilities/network/packet/RequestAbilityStorePacket.java b/src/main/java/org/cyclops/everlastingabilities/network/packet/RequestAbilityStorePacket.java index 30acf0f0..a8828b22 100644 --- a/src/main/java/org/cyclops/everlastingabilities/network/packet/RequestAbilityStorePacket.java +++ b/src/main/java/org/cyclops/everlastingabilities/network/packet/RequestAbilityStorePacket.java @@ -2,20 +2,22 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.cyclopscore.network.CodecField; import org.cyclops.cyclopscore.network.PacketCodec; +import org.cyclops.everlastingabilities.Capabilities; import org.cyclops.everlastingabilities.EverlastingAbilities; +import org.cyclops.everlastingabilities.Reference; import org.cyclops.everlastingabilities.ability.AbilityHelpers; -import org.cyclops.everlastingabilities.api.capability.AbilityStoreCapabilityProvider; -import org.cyclops.everlastingabilities.capability.MutableAbilityStoreConfig; +import java.util.Optional; import java.util.UUID; /** @@ -25,14 +27,17 @@ */ public class RequestAbilityStorePacket extends PacketCodec { + public static final ResourceLocation ID = new ResourceLocation(Reference.MOD_ID, "request_ability_store"); + @CodecField private String entityUuid; public RequestAbilityStorePacket() { - + super(ID); } public RequestAbilityStorePacket(String entityUuid) { + this(); this.entityUuid = entityUuid; } @@ -53,8 +58,8 @@ public void actionServer(Level world, ServerPlayer player) { UUID uuid = UUID.fromString(entityUuid); Entity entity = ((ServerLevel) world).getEntity(uuid); if (entity != null) { - entity.getCapability(MutableAbilityStoreConfig.CAPABILITY, null).ifPresent(abilityStore -> { - Tag contents = AbilityStoreCapabilityProvider.serializeNBTStatic(AbilityHelpers.getRegistry(world.registryAccess()), abilityStore); + Optional.ofNullable(entity.getCapability(Capabilities.MutableAbilityStore.ENTITY)).ifPresent(abilityStore -> { + Tag contents = AbilityHelpers.serialize(AbilityHelpers.getRegistry(world.registryAccess()), abilityStore); CompoundTag tag = new CompoundTag(); tag.put("contents", contents); EverlastingAbilities._instance.getPacketHandler().sendToPlayer(new SendAbilityStorePacket(entity.getId(), tag), player); diff --git a/src/main/java/org/cyclops/everlastingabilities/network/packet/SendAbilityStorePacket.java b/src/main/java/org/cyclops/everlastingabilities/network/packet/SendAbilityStorePacket.java index 6d000194..c6b1c4b2 100644 --- a/src/main/java/org/cyclops/everlastingabilities/network/packet/SendAbilityStorePacket.java +++ b/src/main/java/org/cyclops/everlastingabilities/network/packet/SendAbilityStorePacket.java @@ -1,19 +1,22 @@ package org.cyclops.everlastingabilities.network.packet; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import org.cyclops.cyclopscore.network.CodecField; import org.cyclops.cyclopscore.network.PacketCodec; +import org.cyclops.everlastingabilities.Capabilities; import org.cyclops.everlastingabilities.EverlastingAbilities; import org.cyclops.everlastingabilities.GeneralConfig; +import org.cyclops.everlastingabilities.Reference; import org.cyclops.everlastingabilities.ability.AbilityHelpers; -import org.cyclops.everlastingabilities.api.capability.AbilityStoreCapabilityProvider; -import org.cyclops.everlastingabilities.capability.MutableAbilityStoreConfig; + +import java.util.Optional; /** * Packet from client to server to request an entity's ability store. @@ -23,6 +26,8 @@ */ public class SendAbilityStorePacket extends PacketCodec { + public static final ResourceLocation ID = new ResourceLocation(Reference.MOD_ID, "send_ability_store"); + @CodecField private int entityId; @CodecField @@ -31,10 +36,11 @@ public class SendAbilityStorePacket extends PacketCodec { private int maxPlayerAbilities; public SendAbilityStorePacket() { - + super(ID); } public SendAbilityStorePacket(int entityId, CompoundTag tag) { + this(); this.entityId = entityId; this.tag = tag; this.maxPlayerAbilities = GeneralConfig.maxPlayerAbilities; @@ -53,8 +59,8 @@ public void actionClient(Level world, Player player) { Entity entity = world.getEntity(entityId); if (entity != null) { // Sync ability store - entity.getCapability(MutableAbilityStoreConfig.CAPABILITY, null).ifPresent(abilityStore -> { - AbilityStoreCapabilityProvider.deserializeNBTStatic(AbilityHelpers.getRegistry(world.registryAccess()), abilityStore, tag.get("contents")); + Optional.ofNullable(entity.getCapability(Capabilities.MutableAbilityStore.ENTITY)).ifPresent(abilityStore -> { + AbilityHelpers.deserialize(AbilityHelpers.getRegistry(world.registryAccess()), abilityStore, tag.get("contents")); }); // Sync max abilities value diff --git a/src/main/java/org/cyclops/everlastingabilities/proxy/ClientProxy.java b/src/main/java/org/cyclops/everlastingabilities/proxy/ClientProxy.java index fa7076bf..55f948c4 100644 --- a/src/main/java/org/cyclops/everlastingabilities/proxy/ClientProxy.java +++ b/src/main/java/org/cyclops/everlastingabilities/proxy/ClientProxy.java @@ -5,17 +5,18 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.PathfinderMob; import net.minecraft.world.entity.player.Player; -import net.minecraftforge.client.event.RenderLivingEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.client.event.RenderLivingEvent; +import net.neoforged.neoforge.common.NeoForge; import org.apache.commons.lang3.tuple.Triple; import org.cyclops.cyclopscore.client.particle.ParticleBlurData; import org.cyclops.cyclopscore.init.ModBase; import org.cyclops.cyclopscore.proxy.ClientProxyComponent; +import org.cyclops.everlastingabilities.Capabilities; import org.cyclops.everlastingabilities.EverlastingAbilities; import org.cyclops.everlastingabilities.GeneralConfig; import org.cyclops.everlastingabilities.ability.AbilityHelpers; -import org.cyclops.everlastingabilities.capability.MutableAbilityStoreConfig; +import org.cyclops.everlastingabilities.api.capability.IMutableAbilityStore; /** * Proxy for the client side. @@ -27,7 +28,7 @@ public class ClientProxy extends ClientProxyComponent { public ClientProxy() { super(new CommonProxy()); - MinecraftForge.EVENT_BUS.register(this); + NeoForge.EVENT_BUS.register(this); } @Override @@ -38,11 +39,12 @@ public ModBase getMod() { @SubscribeEvent public void onRenderLiving(RenderLivingEvent.Post event) { LivingEntity entity = event.getEntity(); - if (((GeneralConfig.showEntityParticles && entity instanceof PathfinderMob) // TODO CreatureEntity was IAnimal + if (((GeneralConfig.showEntityParticles && entity instanceof PathfinderMob) || (GeneralConfig.showPlayerParticles && entity instanceof Player)) && !Minecraft.getInstance().isPaused() && entity.level().getGameTime() % 10 == 0) { - entity.getCapability(MutableAbilityStoreConfig.CAPABILITY, null).ifPresent((abilityStore) -> { + IMutableAbilityStore abilityStore = entity.getCapability(Capabilities.MutableAbilityStore.ENTITY); + if (abilityStore != null) { if (!abilityStore.getAbilities().isEmpty()) { Triple abilityColors = AbilityHelpers.getAverageRarityColor(abilityStore); float r = abilityColors.getLeft() / 255F; @@ -69,7 +71,7 @@ public void onRenderLiving(RenderLivingEvent.Post event) { x, y, z, motionX, motionY, motionZ); } - }); + } } } diff --git a/src/main/java/org/cyclops/everlastingabilities/proxy/CommonProxy.java b/src/main/java/org/cyclops/everlastingabilities/proxy/CommonProxy.java index 28f12180..bd273e37 100644 --- a/src/main/java/org/cyclops/everlastingabilities/proxy/CommonProxy.java +++ b/src/main/java/org/cyclops/everlastingabilities/proxy/CommonProxy.java @@ -24,8 +24,8 @@ public ModBase getMod() { public void registerPacketHandlers(PacketHandler packetHandler) { super.registerPacketHandlers(packetHandler); - packetHandler.register(MoveAbilityPacket.class); - packetHandler.register(RequestAbilityStorePacket.class); - packetHandler.register(SendAbilityStorePacket.class); + packetHandler.register(MoveAbilityPacket.ID, MoveAbilityPacket::new); + packetHandler.register(RequestAbilityStorePacket.ID, RequestAbilityStorePacket::new); + packetHandler.register(SendAbilityStorePacket.ID, SendAbilityStorePacket::new); } } diff --git a/src/main/java/org/cyclops/everlastingabilities/recipe/TotemRecycleRecipe.java b/src/main/java/org/cyclops/everlastingabilities/recipe/TotemRecycleRecipe.java index f1a3fdb4..fea2ae07 100644 --- a/src/main/java/org/cyclops/everlastingabilities/recipe/TotemRecycleRecipe.java +++ b/src/main/java/org/cyclops/everlastingabilities/recipe/TotemRecycleRecipe.java @@ -2,7 +2,6 @@ import net.minecraft.core.NonNullList; import net.minecraft.core.RegistryAccess; -import net.minecraft.resources.ResourceLocation; import net.minecraft.util.RandomSource; import net.minecraft.world.inventory.CraftingContainer; import net.minecraft.world.item.ItemStack; @@ -26,8 +25,8 @@ public class TotemRecycleRecipe extends CustomRecipe { private final RandomSource rand = RandomSource.create(); private long seed = rand.nextLong(); - public TotemRecycleRecipe(ResourceLocation id, CraftingBookCategory craftingBookCategory) { - super(id, craftingBookCategory); + public TotemRecycleRecipe(CraftingBookCategory craftingBookCategory) { + super(craftingBookCategory); } @Override @@ -81,7 +80,7 @@ public ItemStack assemble(CraftingContainer invCrafting, RegistryAccess registry // Should not be able to happen, unless some mod is doing funky stuff. return ItemStack.EMPTY; } - Rarity rarity = RegistryEntries.ITEM_ABILITY_TOTEM.getRarity(sortedStacks.get(inputTargetIndex)); + Rarity rarity = RegistryEntries.ITEM_ABILITY_TOTEM.get().getRarity(sortedStacks.get(inputTargetIndex)); // A chance of a bump List abilityTypes = AbilityHelpers.getAbilityTypesCrafting(AbilityHelpers.getRegistry(registryAccess)); @@ -137,6 +136,6 @@ public NonNullList getRemainingItems(CraftingContainer inv) { @Override public RecipeSerializer getSerializer() { - return RegistryEntries.RECIPESERIALIZER_TOTEM_RECYCLE; + return RegistryEntries.RECIPESERIALIZER_TOTEM_RECYCLE.get(); } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 173134ab..9924c53b 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[47,)" +loaderVersion="[2,)" issueTrackerURL="https://github.com/CyclopsMC/EverlastingAbilities/issues" displayURL="https://www.curseforge.com/minecraft/mc-mods/everlastingabilities" license="MIT" @@ -15,19 +15,19 @@ Discover, share and conquer abilities that stick. ''' [[dependencies.everlastingabilities]] modId="cyclopscore" - mandatory=true - versionRange="[1.18.4,)" + type="required" + versionRange="[1.19.0,)" ordering="NONE" side="BOTH" [[dependencies.everlastingabilities]] - modId="forge" - mandatory=true - versionRange="[47.0.1,)" + modId="neoforge" + type="required" + versionRange="[20.4,)" ordering="NONE" side="BOTH" [[dependencies.everlastingabilities]] modId="minecraft" - mandatory=true - versionRange="[1.20.1,]" + type="required" + versionRange="[1.20.4,]" ordering="NONE" side="BOTH" diff --git a/src/main/resources/data/everlastingabilities/everlastingabilities/abilities/special/step_assist.json b/src/main/resources/data/everlastingabilities/everlastingabilities/abilities/special/step_assist.json index f8447c3c..1b49bf4d 100644 --- a/src/main/resources/data/everlastingabilities/everlastingabilities/abilities/special/step_assist.json +++ b/src/main/resources/data/everlastingabilities/everlastingabilities/abilities/special/step_assist.json @@ -3,6 +3,5 @@ "name": "ability.everlastingabilities.step_assist", "rarity": "common", "max_level": 3, - "xp_per_level": 25, - "force_default_step_height": true + "xp_per_level": 25 } \ No newline at end of file