Skip to content

Commit

Permalink
Update Fabric api version and added API features
Browse files Browse the repository at this point in the history
  • Loading branch information
Akinesis committed Nov 5, 2024
1 parent 31b69b2 commit 9ef96c3
Show file tree
Hide file tree
Showing 70 changed files with 1,923 additions and 473 deletions.
20 changes: 16 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'fabric-loom' version '1.8-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -19,6 +19,7 @@ repositories {

maven { url = "https://maven.resourcefulbees.com/repository/maven-public/" }


exclusiveContent {
forRepository {
maven {
Expand Down Expand Up @@ -50,11 +51,22 @@ dependencies {

//Incantatonionem
modCompileOnly "maven.modrinth:incantationem:ivGrgU5k"

//The Bumblezone
//Horseshoes
modCompileOnly "maven.modrinth:tyg1IZwj:${project.horseshoes_version_id}"
//The Bumblezone
modCompileOnly "maven.modrinth:eA8SXqWL:${project.bublezone_version_id}"
modCompileOnly "com.teamresourceful.resourcefullib:resourcefullib-fabric-1.21:3.0.10"
modCompileOnly "com.teamresourceful.resourcefullib:resourcefullib-fabric-1.21:3.0.11"

//Spell engine
modCompileOnly("maven.modrinth:spell-engine:${project.spell_engine_version}")
//Spell power
modCompileOnly("maven.modrinth:8ooWzSQP:Yr88WIqG")
//Cloth config
modCompileOnly("maven.modrinth:9s6osm5g:HpMb5wGb")
//player animator
modCompileOnly("maven.modrinth:gedNE4y2:c6DQKGQp")
//trinkets
modCompileOnly("maven.modrinth:5aaWibi9:JagCscwi")

}

Expand Down
9 changes: 5 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ org.gradle.parallel=true
# check these on https://fabricmc.net/develop
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.16.5
loader_version=0.16.9

# Mod Properties
mod_version=0.7.4
mod_version=0.7.5
maven_group=cutefox.betterenchanting
archives_base_name=betterenchanting

# Dependencies
fabric_version=0.104.0+1.21.1
fabric_version=0.107.0+1.21.1
bublezone_version_id=oNmsCcuk
horseshoes_version_id=tN59Jh0l
horseshoes_version_id=tN59Jh0l
spell_engine_version=1.1.2+1.21.1
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
104 changes: 86 additions & 18 deletions remappedSrc/cutefox/betterenchanting/BetterEnchanting.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package cutefox.betterenchanting;

import cutefox.betterenchanting.Util.BetterEnchantingApi;
import cutefox.betterenchanting.Util.EnchantingIngredientMapPayload;
import cutefox.betterenchanting.Util.Utils;
import cutefox.betterenchanting.conditions.ModConfigConditions;
import cutefox.betterenchanting.datagen.ModEnchantIngredientMap;
import cutefox.betterenchanting.registry.*;
import net.fabricmc.api.ModInitializer;
Expand All @@ -11,25 +15,35 @@
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;


public class BetterEnchanting implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.

public static final Logger LOGGER = LoggerFactory.getLogger("better-enchanting");
public static final String MOD_ID = "BetterEnchanting";
public static boolean NEO_ENCHANT_PRESENT = false;
public static boolean BUMBLEZONE_PRESENT = false;
public static boolean REPLANTMENT_PRESENT = false;
public static boolean DUNGEONS_AND_TAVERNS_PRESENT = false;
public static boolean HORSESHOES_PRESENT = false;
public static boolean DIVERSITY_PRESENT = false;

@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.


ModConfigConditions.registerConditions();

checkForCompat();

ModItems.registerModItems();
ModScreenHandlerType.registerModScreenHandlers();
Expand All @@ -39,16 +53,13 @@ public void onInitialize() {
ModItemTags.registerModTags();
ModLootTables.registerLootTables();

Registry.register(Registries.ITEM_GROUP, Utils.id("item_group"), ITEM_GROUP);
//Registry.register(Registries.ITEM_GROUP, Utils.id("item_group"), ITEM_GROUP);
Registry.register(Registries.ITEM_GROUP, Utils.id("item_group"), generateItemGroup());
PayloadTypeRegistry.playS2C().register(EnchantingIngredientMapPayload.ID, EnchantingIngredientMapPayload.CODEC);

ModLootTableModifiers.modifyLootTables();

addEventListner();
if(FabricLoader.getInstance().isModLoaded("incantationem")){
LOGGER.info("Mod incantationem is loded ! ");
}


}

Expand All @@ -60,15 +71,72 @@ private void addEventListner(){
});
});
ServerLifecycleEvents.SERVER_STARTED.register(e -> {

if(e.getResourceManager().getAllNamespaces().contains("enchantplus")){
NEO_ENCHANT_PRESENT = true;
ModEnchantIngredientMap.loadNeoEnchantConfig();
}

if(e.getResourceManager().getAllNamespaces().contains("replantment")){
REPLANTMENT_PRESENT = true;
ModEnchantIngredientMap.loadReplantmentConfig();
}

if(e.getResourceManager().getAllNamespaces().contains("nova_structures")){
DUNGEONS_AND_TAVERNS_PRESENT = true;
LOGGER.info("Mod nova_structures (Dungeon and Taverns) is loaded ! ");
ModEnchantIngredientMap.loadDungeonsAndTavernsConfig();
}

ModEnchantIngredientMap.genMapFromJson(e.getWorld(ServerWorld.OVERWORLD));
BetterEnchantingApi.addEnchantmentIngredient(Utils.id("random_enchant"), List.of(Items.TURTLE_SCUTE, Items.BAMBOO_FENCE));
});

ServerLifecycleEvents.SERVER_STARTING.register(e -> {
Utils.setRegistryManager(e.getRegistryManager());
});

}

private static final ItemGroup ITEM_GROUP = FabricItemGroup.builder()
.icon(() -> new ItemStack(ModItems.ESSENCE_OF_PROTECTION))
.displayName(Text.translatable("itemGroup.better-enchanting.item_group"))
.entries((context, entries) -> {
entries.addAll(ModItems.MOD_ITEM_LIST.stream().map(i -> i.getDefaultStack()).toList());
})
.build();
private ItemGroup generateItemGroup(){
ItemGroup itemGroup = FabricItemGroup.builder()
.icon(() -> new ItemStack(ModItems.ESSENCE_OF_PROTECTION))
.displayName(Text.translatable("itemGroup.betterenchanting.item_group"))
.entries((context, entries) -> {
entries.addAll(ModItems.MOD_ITEM_LIST.stream().map(i -> i.getDefaultStack()).toList());

if(BetterEnchanting.BUMBLEZONE_PRESENT)
entries.addAll(ModItems.MOD_ITEM_LIST_BUMBLEZONE_COMPAT.stream().map(i -> i.getDefaultStack()).toList());
})
.build();

return itemGroup;
}

private void checkForCompat(){
if(FabricLoader.getInstance().isModLoaded("the_bumblezone")){
LOGGER.info("Mod Bumblezone is loded ! ");
BUMBLEZONE_PRESENT = true;
ModEnchantIngredientMap.loadBumblezoneConfig();
}

if(FabricLoader.getInstance().isModLoaded("incantationem")){
LOGGER.info("Mod incantationem is loded ! ");
}

if(FabricLoader.getInstance().isModLoaded("horseshoes")){
LOGGER.info("Mod horseshoes is loded ! ");
HORSESHOES_PRESENT = true;
}

if(FabricLoader.getInstance().isModLoaded("mr_dungeons_andtaverns")){
LOGGER.info("Mod nova_structures (Dungeon and Taverns) is loaded ! ");
DUNGEONS_AND_TAVERNS_PRESENT = true;
}

if(FabricLoader.getInstance().isModLoaded("diversity")){
LOGGER.info("Mod Diversity is loaded ! ");
DIVERSITY_PRESENT = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.*;

import cutefox.betterenchanting.Util.EnchantingIngredientMapPayload;
import cutefox.betterenchanting.datagen.ModEnchantIngredientMap;
import cutefox.betterenchanting.registry.ModHandledScreens;
import net.fabricmc.api.ClientModInitializer;
Expand Down
57 changes: 57 additions & 0 deletions remappedSrc/cutefox/betterenchanting/Util/BetterEnchantingApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cutefox.betterenchanting.Util;

import cutefox.betterenchanting.datagen.ModEnchantIngredientMap;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.item.Item;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;

import java.util.List;

public class BetterEnchantingApi {

/**
* Add the ingredients for the enchantment of the identifier in parameters
* If possible, prefer the {@link #addEnchantmentIngredient(Enchantment, List)} of this call.
* @param enchantmentId The Identifier of the enchantment
* @param ingredients A list of the ingredients for the enchantment, ordered by level. (so first entry is for Enchantment I, then Enchantment II etc.)
* @return True if enchantment is found and successfully added to the map. False otherwise.
*/
public static boolean addEnchantmentIngredient(Identifier enchantmentId, List<Item> ingredients){
Registry<Enchantment> enchantRegistry = Utils.getRegistryManager().get(RegistryKeys.ENCHANTMENT);
Enchantment enchantment = enchantRegistry.get(enchantmentId);

return addEnchantmentIngredient(enchantment, ingredients);

}

/**
* Add ingredients for enchantment of the enchantments of "enchantmentId".
* If possible, prefer the {@link #addEnchantmentIngredient(Enchantment, List)} of this call.
* @param enchantmentId The enchantment identifier as a String (includind namespace. Ex : "minecraft:smite")
* @param ingredients
* @return
*/
public static boolean addEnchantmentIngredient(String enchantmentId, List<Item> ingredients){

Identifier enchantId = Identifier.of(enchantmentId);
return addEnchantmentIngredient(enchantId, ingredients);
}

/**
* Add the ingredients for the enchantment of the identifier in parameters.
* This is the preferred method as it's the more robust and error-free one.
* @param enchantment The Enchantment to be added
* @param ingredients A list of the ingredients for the enchantment, ordered by level. (so first entry is for Enchantment I, then Enchantment II etc.)
* @return True if enchantment is found and successfully added to the map. False otherwise.
*/
public static boolean addEnchantmentIngredient(Enchantment enchantment, List<Item> ingredients){

if(enchantment == null)
return false;

return ModEnchantIngredientMap.addEnchantmentIngredient(enchantment,ingredients);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cutefox.betterenchanting;
package cutefox.betterenchanting.Util;

import net.minecraft.util.Identifier;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cutefox.betterenchanting;
package cutefox.betterenchanting.Util;

import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cutefox.betterenchanting;
package cutefox.betterenchanting.Util;

import com.google.common.collect.Lists;
import cutefox.betterenchanting.BetterEnchanting;
import cutefox.betterenchanting.datagen.ModEnchantIngredientMap;
import cutefox.betterenchanting.registry.ModEnchantmentTags;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
Expand Down Expand Up @@ -62,12 +63,12 @@ public static int getBookshelfCountRequierment(Enchantment enchantment, int ench
return tempReq<=3?0:tempReq;
}

public static Item getEnchantIngredient(RegistryKey<Enchantment> enchantment, int enchantLevel){
if(ModEnchantIngredientMap.map.containsKey(enchantment))
if(ModEnchantIngredientMap.map.get(enchantment).size()>enchantLevel)
return ModEnchantIngredientMap.map.get(enchantment).get(enchantLevel);
public static Item getEnchantIngredient(Enchantment enchantment, int enchantLevel){
return ModEnchantIngredientMap.getIngredientOfLevel(enchantment,enchantLevel);
}

return null;
public static List<Item> getIngredientsOfEnchantment(Enchantment enchantment){
return ModEnchantIngredientMap.getIngredientsOfEnchantment(enchantment);
}

public static int getEnchantmentIngredientCost(Enchantment value, int displayedEnchantLevel, Item ingredient) {
Expand Down
26 changes: 26 additions & 0 deletions remappedSrc/cutefox/betterenchanting/Util/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cutefox.betterenchanting.Util;

import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.util.Identifier;

public class Utils {

private static DynamicRegistryManager registryManager;

public static Identifier id(String path) {
return Identifier.of("betterenchanting", path);
}

public static Identifier id() {
return Identifier.of("betterenchanting");
}


public static DynamicRegistryManager getRegistryManager() {
return registryManager;
}

public static void setRegistryManager(DynamicRegistryManager registryManager) {
Utils.registryManager = registryManager;
}
}
14 changes: 0 additions & 14 deletions remappedSrc/cutefox/betterenchanting/Utils.java

This file was deleted.

Loading

0 comments on commit 9ef96c3

Please sign in to comment.