Skip to content

Commit

Permalink
Succesfully Ported to 1.21 NeoForge
Browse files Browse the repository at this point in the history
  • Loading branch information
MeAlam1 committed Sep 5, 2024
1 parent 2038712 commit dea8f1c
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class RexEntity extends TamableAnimal implements IVariantEntity, GeoEntit
* @Co-author MeAlam, Dan
* @since 1.0.0
*/
protected final String entityName = "Rex";
protected final String entityName = "rex";

/**
* Constructs a new {@link RexEntity} instance with the specified entity type and level.
Expand Down
109 changes: 66 additions & 43 deletions NeoForge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
plugins {
plugins {
id 'java-library'
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.97'
id 'net.neoforged.moddev' version '1.0.19'
}

tasks.named('wrapper', Wrapper).configure {
distributionType = Wrapper.DistributionType.BIN
}

version = mod_version
group = mod_group_id

repositories {
mavenLocal()
maven {
url "https://cursemaven.com"
}
mavenCentral()
mavenLocal()
}

base {
Expand All @@ -23,34 +27,55 @@ base {

java.toolchain.languageVersion = JavaLanguageVersion.of(java_version)

//minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg')
//minecraft.accessTransformers.entry public net.minecraft.client.Minecraft textureManager # textureManager
neoForge {
version = project.neo_version

parchment {
mappingsVersion = project.parchment_mappings_version
minecraftVersion = project.parchment_minecraft_version
}

runs {
configureEach {
systemProperty 'forge.logging.markers', 'REGISTRIES'
runs {
client {
client()

// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
systemProperty 'forge.logging.console.level', 'debug'
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}

modSource project.sourceSets.main
}
server {
server()
programArgument '--nogui'
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}

client {
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
}
gameTestServer {
type = "gameTestServer"
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}

server {
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
programArgument '--nogui'
}
data {
data()

programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
}

gameTestServer {
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id

configureEach {

systemProperty 'forge.logging.markers', 'REGISTRIES'

// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
logLevel = org.slf4j.event.Level.DEBUG
}
}

data {
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
mods {
"${mod_id}" {
sourceSet(sourceSets.main)
}
"geckolib" {
sourceSet(sourceSets.main)
}
}
}

Expand All @@ -61,27 +86,11 @@ configurations {
}

dependencies {
implementation "net.neoforged:neoforge:${neo_version}"
runtimeOnly "curse.maven:geckolib-388172:${geckolib_file}"
compileOnly "curse.maven:geckolib-388172:${geckolib_file}"
}

jar {
manifest {
attributes([
"Specification-Title" : mod_name,
"Specification-Vendor" : mod_authors,
"Specification-Version" : mod_version,
"Implementation-Title" : mod_name,
"Implementation-Version" : mod_version,
"Implementation-Vendor" : mod_authors,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
])
}
}

// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
tasks.withType(ProcessResources).configureEach {
var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) {
var replaceProperties = [
minecraft_version : minecraft_version,
minecraft_version_range: minecraft_version_range,
Expand All @@ -96,9 +105,23 @@ tasks.withType(ProcessResources).configureEach {
mod_description : mod_description
]
inputs.properties replaceProperties

filesMatching(['META-INF/mods.toml']) {
expand replaceProperties
expand replaceProperties
from "src/main/templates"
into "build/generated/sources/modMetadata"
}
sourceSets.main.resources.srcDir generateModMetadata
neoForge.ideSyncTask generateModMetadata

publishing {
publications {
register('mavenJava', MavenPublication) {
from components.java
}
}
repositories {
maven {
url "file://${project.projectDir}/repo"
}
}
}

Expand Down
30 changes: 17 additions & 13 deletions NeoForge/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
#org.gradle.jvmargs=
org.gradle.daemon=false
org.gradle.debug=false
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
org.gradle.jvmargs=-Xmx1G
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configuration-cache=true

neogradle.subsystems.parchment.minecraftVersion=1.20.3
neogradle.subsystems.parchment.mappingsVersion=2023.12.31
minecraft_version=1.20.4
minecraft_version_range=[1.20.2,1.21)
neo_version=20.4.237
neo_version_range=[20.4,)
loader_version_range=[2,)
## geckolib_file is the cursemaven file you get from curseforge
geckolib_file=5188406
java_version=17
parchment_minecraft_version=1.21
parchment_mappings_version=2024.07.28

minecraft_version=1.21
minecraft_version_range=[1.21,1.21.1)
neo_version=21.0.167
neo_version_range=[21.0.0-beta,)
loader_version_range=[4,)

geckolib_file=5679344
java_version=21

## Mod Properties


mod_id=bluelib
mod_name=BlueLib
mod_license=MIT License
Expand Down
13 changes: 9 additions & 4 deletions NeoForge/src/main/java/software/bluelib/BlueLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.common.NeoForge;
import software.bluelib.example.event.ClientEvents;
import software.bluelib.example.init.ModEntities;

Expand All @@ -24,7 +26,7 @@
* <p>
* Key Methods:
* <ul>
* <li>{@link #BlueLib(IEventBus)} - Constructs the {@link BlueLib} instance and registers the mod event bus.</li>
* <li>{@link #BlueLib(IEventBus, ModContainer)} - Constructs the {@link BlueLib} instance and registers the mod event bus.</li>
* <li>{@link #onLoadComplete(FMLLoadCompleteEvent)} - Handles the event when the mod loading is complete and prints a thank-you message if in developer mode.</li>
* <li>{@link #isDeveloperMode()} - Determines if the mod is running in developer mode.</li>
* </ul>
Expand Down Expand Up @@ -61,17 +63,20 @@ public class BlueLib {
* Constructs a new {@link BlueLib} instance and registers the mod event bus.
*
* @param pModEventBus {@link IEventBus} - The event bus to which the mod will register its event handlers.
* @param pModContainer {@link ModContainer} - The mod container for the mod instance.
* @author MeAlam
* @Co-author Dan
* @since 1.0.0
*/
public BlueLib(IEventBus pModEventBus) {
public BlueLib(IEventBus pModEventBus, ModContainer pModContainer) {
pModEventBus.register(this);
if (isDeveloperMode()) {
ModEntities.REGISTRY.register(pModEventBus);

pModEventBus.addListener(ClientEvents::registerAttributes);
pModEventBus.addListener(ClientEvents::registerRenderers);
if (FMLEnvironment.dist.isClient()) {
pModEventBus.addListener(ClientEvents::registerAttributes);
pModEventBus.addListener(ClientEvents::registerRenderers);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public class ReloadEventHandler {
* @since 1.0.0
*/
protected static void registerEntityVariants(MinecraftServer pServer, String pEntityName, String pModID, String pModPathLocation, String pDataPathLocation) {
ResourceLocation modLocation = new ResourceLocation(pModID, pModPathLocation);
ResourceLocation dataLocation = new ResourceLocation(pModID, pDataPathLocation);
ResourceLocation modLocation = ResourceLocation.fromNamespaceAndPath(pModID, pModPathLocation);
ResourceLocation dataLocation = ResourceLocation.fromNamespaceAndPath(pModID, pDataPathLocation);
try {
VariantLoader.loadVariants(modLocation, dataLocation, pServer, pEntityName);
} catch (JsonParseException pException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil;
import software.bluelib.interfaces.variant.IVariantEntity;
import software.bluelib.utils.ParameterUtils;
Expand All @@ -33,10 +34,10 @@
* <p>
* Key Methods:
* <ul>
* <li>{@link #defineSynchedData()} - Defines the synchronized data for the dragon entity, including its variant.</li>
* <li>{@link #defineSynchedData(SynchedEntityData.Builder)} - Defines the synchronized data for the dragon entity, including its variant.</li>
* <li>{@link #addAdditionalSaveData(CompoundTag)} - Adds custom data to the entity's NBT for saving.</li>
* <li>{@link #readAdditionalSaveData(CompoundTag)} - Reads custom data from the entity's NBT for loading.</li>
* <li>{@link #finalizeSpawn(ServerLevelAccessor, DifficultyInstance, MobSpawnType, SpawnGroupData, CompoundTag)} - Finalizes the spawning process and sets up parameters.</li>
* <li>{@link #finalizeSpawn(ServerLevelAccessor, DifficultyInstance, MobSpawnType, SpawnGroupData)} - Finalizes the spawning process and sets up parameters.</li>
* <li>{@link #setVariantName(String)} - Sets the variant name of the dragon.</li>
* <li>{@link #getVariantName()} - Retrieves the current variant name of the dragon.</li>
* </ul>
Expand Down Expand Up @@ -89,9 +90,9 @@ public DragonEntity(EntityType<? extends TamableAnimal> pEntityType, Level pLeve
* @Co-author Dan
*/
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(VARIANT, "normal");
protected void defineSynchedData(SynchedEntityData.@NotNull Builder pBuilder) {
super.defineSynchedData(pBuilder);
pBuilder.define(VARIANT, "normal");
}

/**
Expand Down Expand Up @@ -140,15 +141,14 @@ public void readAdditionalSaveData(@NotNull CompoundTag pCompound) {
* @param pDifficulty {@link DifficultyInstance} - The difficulty instance for spawning.
* @param pReason {@link MobSpawnType} - The reason for spawning the entity.
* @param pSpawnData {@link SpawnGroupData} - Data related to the spawn.
* @param pDataTag {@link CompoundTag} - Additional data for spawning.
* @return {@link SpawnGroupData} - Updated spawn data.
*
* @since 1.0.0
* @author MeAlam
* @Co-author Dan
*/
@Override
public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor pLevel, @NotNull DifficultyInstance pDifficulty, @NotNull MobSpawnType pReason, @Nullable SpawnGroupData pSpawnData, @Nullable CompoundTag pDataTag) {
public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor pLevel, @NotNull DifficultyInstance pDifficulty, @NotNull MobSpawnType pReason, @Nullable SpawnGroupData pSpawnData) {
if (getVariantName() == null || getVariantName().isEmpty()) {
this.setVariantName(getRandomVariant(getEntityVariants(entityName), "normal"));
ParameterUtils.ParameterBuilder.forVariant(entityName,this.getVariantName())
Expand All @@ -158,7 +158,7 @@ public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor pLevel, @NotNul
.withParameter("array")
.connect();
}
return super.finalizeSpawn(pLevel, pDifficulty, pReason, pSpawnData, pDataTag);
return super.finalizeSpawn(pLevel, pDifficulty, pReason, pSpawnData);
}

/**
Expand Down Expand Up @@ -217,4 +217,9 @@ public AnimatableInstanceCache getAnimatableInstanceCache() {
public AgeableMob getBreedOffspring(@NotNull ServerLevel pLevel, @NotNull AgeableMob pOtherParent) {
return null;
}

@Override
public boolean isFood(@NotNull ItemStack pItemStack) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DragonModel extends GeoModel<DragonEntity> {
// Get the Model Location
@Override
public ResourceLocation getModelResource(DragonEntity pObject) {
return new ResourceLocation(BlueLib.MODID, "geo/dragon.geo.json");
return ResourceLocation.fromNamespaceAndPath(BlueLib.MODID, "geo/dragon.geo.json");
}

// Get the Texture Location
Expand All @@ -24,6 +24,6 @@ public ResourceLocation getTextureResource(DragonEntity pObject) {
// Get the Animation Location
@Override
public ResourceLocation getAnimationResource(DragonEntity pAnimatable) {
return new ResourceLocation(BlueLib.MODID, "animations/dragon.animation.json");
return ResourceLocation.fromNamespaceAndPath(BlueLib.MODID, "animations/dragon.animation.json");
}
}
Loading

0 comments on commit dea8f1c

Please sign in to comment.