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
103 changes: 78 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import net.minecraftforge.gradle.common.task.SignJar
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url = "http://files.minecraftforge.net/maven" }
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
}
}

plugins {
id "com.matthewprenger.cursegradle" version "1.0.7"
}

apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'maven-publish'

ext.buildnumber = 0
Expand All @@ -41,9 +44,59 @@ if (project.hasProperty('mod_appendix')) {
}

minecraft {
mappings = "snapshot_20171212"
version = "${minecraft_version}-${forge_version}"
runDir = 'run'
mappings channel: 'snapshot', version: "20201028-1.16.3"

runs {
client {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

mods {
examplemod {
source sourceSets.main
}
}
}

server {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

mods {
examplemod {
source sourceSets.main
}
}
}

data {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/')

mods {
examplemod {
source sourceSets.main
}
}
}
}
}

jar {
Expand All @@ -53,6 +106,7 @@ jar {
}

dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.2.0"
testRuntime "org.junit.jupiter:junit-jupiter-engine:5.2.0"
}
Expand All @@ -61,22 +115,6 @@ configurations {
compile.extendsFrom exportedCompile
}

processResources {
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version

from(sourceSets.main.resources.srcDirs) {
include '**/*.info'
include '**/*.properties'

expand 'version': project.version, 'mcversion': project.minecraft.version
}

from(sourceSets.main.resources.srcDirs) {
exclude '**/*.info'
exclude '**/*.properties'
}
}

test {
useJUnitPlatform()
Expand All @@ -102,15 +140,21 @@ if (JavaVersion.current().isJava8Compatible()) {
}
}

build.dependsOn sourceJar, javadoc

task srcJar(type: Jar) {
from(sourceSets.main.output)
classifier = 'srcs'
}

build.dependsOn srcJar, javadoc

publishing {
tasks.publish.dependsOn 'build'
publications {
mavenJava(MavenPublication) {
from components.java

artifact sourceJar
artifact srcJar
}
}

Expand All @@ -127,6 +171,15 @@ publishing {
} else {
maven { url maven2_url }
}
}
if (project.hasProperty('use_hypherion') && project.use_hypherion) {
maven {
url hypherion_mavenURL
credentials {
username System.getenv('MAVEN_USER')
password System.getenv('MAVEN_PASS')
}
}
} else {
mavenLocal()
}
Expand Down Expand Up @@ -174,7 +227,7 @@ task mkKeyStore(type:Exec) {
commandLine 'keytool', '-genkey', '-alias', 'signFiles', '-keystore', 'autosavestore.jks', '-storepass', '123456', '-noprompt', '-dname', 'CN='+getCN(), '-keypass', '123456'
}

task signJar(type: SignJar, dependsOn: reobfJar) {
task signJar(type: SignJar, dependsOn: jar) {
inputFile = jar.archivePath
outputFile = jar.archivePath
keyStore = 'autosavestore.jks'
Expand Down
8 changes: 6 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
minecraft_version=1.12.2
forge_version=14.23.5.2847
minecraft_version=1.16.3
forge_version=34.1.42

mod_version=1.0

Expand All @@ -8,3 +8,7 @@ mod_version=1.0

# Not made yet, does it need to be?
projectId=999999

# Hypherion's Maven Stuff
use_hypherion=true
hypherion_mavenURL=https://maven.hypherionmc.me
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
21 changes: 11 additions & 10 deletions src/main/java/info/loenwind/autoconfig/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

import info.loenwind.autoconfig.factory.ByteBufAdapters;
import info.loenwind.autoconfig.factory.IRootFactory;
import info.loenwind.autoconfig.util.Configuration;
import info.loenwind.autoconfig.util.Log;
import info.loenwind.autoconfig.util.NullHelper;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.loading.FMLPaths;

public class ConfigHandler {

Expand All @@ -21,18 +22,18 @@ public class ConfigHandler {

protected final IRootFactory factory;

public ConfigHandler(FMLPreInitializationEvent event, IRootFactory factory) {
public ConfigHandler(FMLCommonSetupEvent event, IRootFactory factory) {
this(event, factory, null);
}

public ConfigHandler(FMLPreInitializationEvent event, IRootFactory factory, @Nullable String folder) {
public ConfigHandler(FMLCommonSetupEvent event, IRootFactory factory, @Nullable String folder) {
this.factory = factory;
ByteBufAdapters.NONE.getClass(); // trigger system init
MinecraftForge.EVENT_BUS.register(this);
if (folder != null) {
configDirectory = new File(event.getModConfigurationDirectory(), folder);
configDirectory = new File(FMLPaths.CONFIGDIR.get().toFile(), folder);
} else {
configDirectory = NullHelper.notnullF(event.getModConfigurationDirectory(), "FMLPreInitializationEvent has no config folder");
configDirectory = NullHelper.notnullF(FMLPaths.CONFIGDIR.get().toFile(), "FMLCommonSetupEvent has no config folder");
}
if (!configDirectory.exists()) {
configDirectory.mkdir();
Expand All @@ -57,8 +58,8 @@ public void syncConfig() {
}

@SubscribeEvent
public void onConfigChanged(OnConfigChangedEvent event) {
if (event.getModID().equals(factory.getModid())) {
public void onConfigChanged(ModConfig.ModConfigEvent event) {
if (event.getConfig().getModId().equals(factory.getModid())) {
Log.info("Updating config...");
syncConfig();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import info.loenwind.autoconfig.util.NullHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public abstract class AbstractValue<T> implements IValue<T> {

Expand Down Expand Up @@ -95,15 +95,15 @@ public IValue<T> startup() {
return sync();
}

@SideOnly(Side.CLIENT)
@OnlyIn(Dist.CLIENT)
public void onServerSync(Map<String, Object> serverConfig) {
if (isStartup && serverConfig.containsKey(keyname)) {
@SuppressWarnings("unchecked")
T serverValue = (T) serverConfig.get(keyname);
T clientValue = get();
if (!clientValue.equals(serverValue)) {
Log.error(Lang.NETWORK_BAD_CONFIG.get(section, keyname, serverValue));
Minecraft.getMinecraft().player.connection.getNetworkManager().closeChannel(Lang.NETWORK_BAD_CONFIG.toChat(section, keyname, serverValue));
Minecraft.getInstance().player.connection.getNetworkManager().closeChannel(Lang.NETWORK_BAD_CONFIG.toChat(section, keyname, serverValue));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import java.util.Random;

import javax.annotation.Nullable;

import net.minecraftforge.common.config.Property;
import info.loenwind.autoconfig.util.ConfigProperty;

class BooleanValue extends AbstractValue<Boolean> {

Expand All @@ -14,7 +13,7 @@ protected BooleanValue(IValueFactory owner, String section, String keyname, Bool

@Override
protected @Nullable Boolean makeValue() {
Property prop = owner.getConfig().get(section, keyname, defaultValue);
ConfigProperty prop = owner.getConfig().get(section, keyname, defaultValue);
prop.setLanguageKey(keyname);
prop.setComment(getText() + " [default: " + defaultValue + "]");
prop.setRequiresMcRestart(isStartup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import info.loenwind.autoconfig.util.NullHelper;
import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import io.netty.buffer.ByteBufUtil;
import net.minecraft.network.PacketBuffer;

public final class ByteBufAdapterRegistry {

Expand All @@ -31,21 +32,21 @@ public static void saveMapping(ByteBuf buf) {
synchronized (NAME2ID) {
buf.writeByte(ID2ADAPTER.size());
for (IByteBufAdapter<?> adapter : ID2ADAPTER) {
ByteBufUtils.writeUTF8String(buf, adapter.getName());
ByteBufUtil.writeUtf8(buf, adapter.getName());
}
}
}

// side-only: client
public static void loadMapping(ByteBuf buf) {
public static void loadMapping(PacketBuffer buf) {
synchronized (NAME2ID) {
int count = buf.readByte();
if (count != ID2ADAPTER.size()) {
throw new RuntimeException("Server and client ByteBufAdapter lists are out of sync. Server has " + count + ", client has " + ID2ADAPTER.size());
}
List<IByteBufAdapter<?>> synced = new ArrayList<>();
for (int i = 0; i < count; i++) {
String name = ByteBufUtils.readUTF8String(buf);
String name = buf.readString();
Integer oldID = NAME2ID.get(name);
if (oldID == null) {
throw new RuntimeException("Server and client ByteBufAdapter lists are out of sync. Server has " + name + ", client doesn't know that one");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

import info.loenwind.autoconfig.util.NullHelper;
import io.netty.buffer.ByteBuf;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.ForgeRegistries;

public class ByteBufAdapters {

Expand Down Expand Up @@ -251,7 +254,7 @@ public String getName() {

@Override
public void saveValue(ByteBuf buf, @Nonnull Fluid value) {
final byte[] vbytes = NullHelper.first(FluidRegistry.getFluidName(value), "").getBytes(Charset.forName("UTF-8"));
final byte[] vbytes = NullHelper.first(value.getRegistryName().toString(), "").getBytes(Charset.forName("UTF-8"));
if (vbytes.length > 0x7F) {
throw new RuntimeException("Fluid name too long");
}
Expand All @@ -264,7 +267,8 @@ public void saveValue(ByteBuf buf, @Nonnull Fluid value) {
final int len = buf.readByte();
final byte[] bytes = new byte[len];
buf.readBytes(bytes, 0, len);
return FluidRegistry.getFluid(new String(bytes, Charset.forName("UTF-8")));
return ForgeRegistries.FLUIDS.getValue(ResourceLocation.tryCreate(new String(bytes, Charset.forName("UTF-8"))));
//return FluidRegistry.getFluid(new String(bytes, Charset.forName("UTF-8")));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import javax.annotation.Nullable;

import net.minecraftforge.common.config.Property;
import info.loenwind.autoconfig.util.ConfigProperty;

class DoubleValue extends AbstractValue<Double> {

Expand All @@ -16,7 +16,7 @@ protected DoubleValue(IValueFactory owner, String section, String keyname, Doubl
protected @Nullable Double makeValue() {
String comment = getText() + " [range: " + (minValue != null ? minValue : Double.NEGATIVE_INFINITY) + " ~ "
+ (maxValue != null ? maxValue : Double.MAX_VALUE) + ", default: " + defaultValue + "]";
final Property property = owner.getConfig().get(section, keyname, defaultValue, comment);
final ConfigProperty property = owner.getConfig().get(section, keyname, defaultValue, comment);
if (minValue != null) {
property.setMinValue(minValue);
}
Expand Down
Loading