Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 47 additions & 169 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,189 +1,67 @@
plugins {
id 'java-library'
id 'maven-publish'
id 'net.neoforged.moddev' version '2.0.131'
id 'idea'
id 'com.gtnewhorizons.retrofuturagradle' version '1.4.1'
}

tasks.named('wrapper', Wrapper).configure {
// Define wrapper values here so as to not have to always do so when updating gradlew.properties.
// Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with
// documentation attached on cursor hover of gradle classes and methods. However, this comes with increased
// file size for Gradle. If you do switch this to ALL, run the Gradle wrapper task twice afterwards.
// (Verify by checking gradle/wrapper/gradle-wrapper.properties to see if distributionUrl now points to `-all`)
distributionType = Wrapper.DistributionType.BIN
}

version = mod_version
group = mod_group_id

repositories {
mavenLocal()
}

base {
archivesName = mod_id
}

// Mojang ships Java 21 to end users starting in 1.20.5, so mods should target Java 21.
java.toolchain.languageVersion = JavaLanguageVersion.of(21)

neoForge {
// Specify the version of NeoForge to use.
version = project.neo_version
version = project.mod_version
group = project.mod_group_id
archivesBaseName = project.mod_id

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

// This line is optional. Access Transformers are automatically detected
// accessTransformers = project.files('src/main/resources/META-INF/accesstransformer.cfg')

// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
client()

// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}

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

// This run config launches GameTestServer and runs all registered gametests, then exits.
// By default, the server will crash when no gametests are provided.
// The gametest system is also enabled by default for other run configs under the /test command.
gameTestServer {
type = "gameTestServer"
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}

data {
clientData()

// example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it
// gameDirectory = project.file('run-data')

// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
}

// applies to all the run configs above
configureEach {
// Recommended logging data for a userdev environment
// The markers can be added/remove as needed separated by commas.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
systemProperty 'forge.logging.markers', 'REGISTRIES'

// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
logLevel = org.slf4j.event.Level.DEBUG
}
}

mods {
// define mod <-> source bindings
// these are used to tell the game which sources are for which mod
// multi mod projects should define one per mod
"${mod_id}" {
sourceSet(sourceSets.main)
}
// Use Java 17 but target Java 8
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
}

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
minecraft {
mcVersion = project.minecraft_version
mcpMappingChannel = 'stable'
mcpMappingVersion = '39'
}

// Sets up a dependency configuration called 'localRuntime'.
// This configuration should be used instead of 'runtimeOnly' to declare
// a dependency that will be present for runtime testing but that is
// "optional", meaning it will not be pulled by dependents of this mod.
configurations {
runtimeClasspath.extendsFrom localRuntime
repositories {
mavenCentral()
}

dependencies {
// Example optional mod dependency with JEI
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}"
// compileOnly "mezz.jei:jei-${mc_version}-neoforge-api:${jei_version}"
// We add the full version to localRuntime, not runtimeOnly, so that we do not publish a dependency on it
// localRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}"

// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
// The group id is ignored when searching -- in this case, it is "blank"
// implementation "blank:coolmod-${mc_version}:${coolmod_version}"

// Example mod dependency using a file as dependency
// implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar")

// Example project dependency using a sister or child project:
// implementation project(":myproject")

// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
// No additional dependencies needed
}

// This block of code expands all declared replace properties in the specified resource targets.
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) {
var replaceProperties = [
minecraft_version : minecraft_version,
minecraft_version_range: minecraft_version_range,
neo_version : neo_version,
neo_version_range : neo_version_range,
loader_version_range : loader_version_range,
mod_id : mod_id,
mod_name : mod_name,
mod_license : mod_license,
mod_version : mod_version,
mod_authors : mod_authors,
mod_description : mod_description
]
inputs.properties replaceProperties
expand replaceProperties
from "src/main/templates"
into "build/generated/sources/modMetadata"
processResources {
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft_version
inputs.property "modid", project.mod_id
inputs.property "modname", project.mod_name
inputs.property "moddescription", project.mod_description
inputs.property "modauthors", project.mod_authors

filesMatching('mcmod.info') {
expand 'version': project.version,
'mcversion': project.minecraft_version,
'modid': project.mod_id,
'modname': project.mod_name,
'moddescription': project.mod_description,
'modauthors': project.mod_authors
}
}
// Include the output of "generateModMetadata" as an input directory for the build
// this works with both building through Gradle and the IDE.
sourceSets.main.resources.srcDir generateModMetadata
// To avoid having to run "generateModMetadata" manually, make it run on every project reload
neoForge.ideSyncTask generateModMetadata

// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
register('mavenJava', MavenPublication) {
from components.java
}
}
repositories {
maven {
url "file://${project.projectDir}/repo"
}
jar {
manifest {
attributes([
"Specification-Title": project.mod_id,
"Specification-Vendor": project.mod_authors,
"Specification-Version": "1",
"Implementation-Title": project.mod_name,
"Implementation-Version": "${version}",
"Implementation-Vendor": project.mod_authors,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}

// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
idea {
module {
downloadSources = true
downloadJavadoc = true
}
options.encoding = 'UTF-8'
}
43 changes: 7 additions & 36 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,45 +1,16 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
org.gradle.jvmargs=-Xmx1G
# Sets default memory used for gradle commands
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configuration-cache=true

#read more on this at https://github.com/neoforged/ModDevGradle?tab=readme-ov-file#better-minecraft-parameter-names--javadoc-parchment
# you can also find the latest versions at: https://parchmentmc.org/docs/getting-started
parchment_minecraft_version=1.21.4
parchment_mappings_version=2025.01.05
# Environment Properties
# You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge
# The Minecraft version must agree with the Neo version to get a valid artifact
minecraft_version=1.21.11
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.21.11]
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=21.11.34-beta
# The Neo version range can use any version of Neo as bounds
neo_version_range=[21.11.25-beta,)
# The loader version range can only use the major version of FML as bounds
loader_version_range=[1,)
# Minecraft/Forge versions
minecraft_version=1.12.2
forge_version=14.23.5.2860

## Mod Properties

# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
mod_id=randomloot
# The human-readable display name for the mod.
mod_name=Random Loot 2
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
# The mod version. See https://semver.org/
mod_version=1.1.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
mod_version=1.0.0-1.12.2
mod_group_id=dev.marston.randomloot
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
mod_authors=Marston Connell
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=An RPG style loot system built from the ground up to make Minecraft loot feel more personal.
mod_description=An RPG style loot system built from the ground up to make Minecraft loot feel more personal.
4 changes: 1 addition & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JAVA_HOME="$HOME/.jdks/zulu8.78.0.19-ca-jdk8.0.412-macosx_x64" arch -x86_64 ./gradlew runClient
11 changes: 8 additions & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
pluginManagement {
repositories {
mavenLocal()
maven {
name = 'GTNH Maven'
url = 'https://nexus.gtnewhorizons.com/repository/public/'
}
gradlePluginPortal()
maven { url = 'https://maven.neoforged.net/releases' }
mavenCentral()
}
}

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.9.0'
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}

rootProject.name = 'randomloot'
69 changes: 69 additions & 0 deletions src/main/java/dev/marston/randomloot/ClientProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package dev.marston.randomloot;

import dev.marston.randomloot.items.ModItems;
import dev.marston.randomloot.loot.LootNBT;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;

@Mod.EventBusSubscriber(modid = RandomLoot.MODID, value = Side.CLIENT)
public class ClientProxy extends CommonProxy {

@Override
public void preInit(FMLPreInitializationEvent event) {
super.preInit(event);
}

@Override
public void init(FMLInitializationEvent event) {
super.init(event);
registerItemPropertyOverrides();
}

@SubscribeEvent
public static void registerModels(ModelRegistryEvent event) {
registerModel(ModItems.TOOL, 0, "tool");
registerModel(ModItems.CASE, 0, "case");
}

private static void registerModel(Item item, int meta, String name) {
ModelLoader.setCustomModelResourceLocation(item, meta,
new ModelResourceLocation(new ResourceLocation(RandomLoot.MODID, name), "inventory"));
}

private void registerItemPropertyOverrides() {
// Register custom property for dynamic texture selection
// Encoding matches tool.json overrides:
// 0.1xxx = pickaxe, 0.2xxx = shovel, 0.3xxx = axe, 0.4xxx = sword
ModItems.TOOL.addPropertyOverride(
new ResourceLocation(RandomLoot.MODID, "cosmetic"),
(stack, world, entity) -> {
if (stack.isEmpty() || !stack.hasTagCompound()) {
return 0.0f;
}
int toolType = LootNBT.getToolTypeOrdinal(stack);
int texture = LootNBT.getTexture(stack);

// Map tool type ordinal to JSON encoding
// PICKAXE=0->0.1, SHOVEL=1->0.2, AXE=2->0.3, SWORD=3->0.4
float base;
switch (toolType) {
case 0: base = 0.1f; break; // PICKAXE
case 1: base = 0.2f; break; // SHOVEL
case 2: base = 0.3f; break; // AXE
case 3: base = 0.4f; break; // SWORD
default: base = 0.0f; break;
}

return base + texture * 0.0001f;
}
);
}
}
Loading
Loading