Skip to content

Commit

Permalink
Merge pull request #3 from KatatsumuriPan/develop
Browse files Browse the repository at this point in the history
v1.4.0へ更新
  • Loading branch information
KatatsumuriPan authored Oct 13, 2023
2 parents 4ede31b + aa7129f commit 4c37eec
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 39 deletions.
63 changes: 43 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
classpath 'net.minecraftforge.gradle:ForgeGradle:3.+'
}
}

apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'
Expand Down Expand Up @@ -45,18 +45,18 @@ dependencies {
jar {
manifest {
attributes([
"Specification-Title": "UntranslatedItems-AlsoFluids",
"Specification-Vendor": "Katatsumuri.pan",
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": project.name,
"Implementation-Version": "${version}",
"Implementation-Vendor" :"Katatsumuri.pan",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
"Specification-Title" : "UntranslatedItems-AlsoFluids",
"Specification-Vendor" : "Katatsumuri.pan",
"Specification-Version" : "1", // We are version 1 of ourselves
"Implementation-Title" : project.name,
"Implementation-Version" : "${version}",
"Implementation-Vendor" : "Katatsumuri.pan",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}

jar.finalizedBy('reobfJar')
jar.finalizedBy('reobfJar')
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
//publish.dependsOn('reobfJar')

Expand All @@ -73,48 +73,71 @@ publishing {
}
}
//*****************Start Basic*****************
//mcmod.infoのversionを解決
version = loadProperties("/src/main/resources/version.properties").getProperty('untranslateditems_alsofluids.version')
//mcmod.info等のversionを解決
def majorVersion = loadProperties("/version.properties").getProperty('majorVersion')
def minorVersion = loadProperties("/version.properties").getProperty('minorVersion')
def patchVersion = loadProperties("/version.properties").getProperty('patchVersion')
version = "${majorVersion}.${minorVersion}.${patchVersion}"
processResources {
// this will ensure that this task is redone when the versions change.
//inputs.property "version", project.version //comment out to always update
inputs.property "version", project.version //comment out to always update

// replace stuff in mcmod.info, nothing else
// resourcesの中のmcmod.infoとversion.propertiesが対象(処理後のファイルがjarに格納される)
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'

include 'version.properties'

// replace version and mcversion
expand 'version':project.version, 'mcversion':"1.12.2"
expand 'version': project.version, 'mcversion': "1.12.2"
}
// copy everything else except the mcmod.info

// mcmod.info以外が対象(特に編集せずにそのままコピー)
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
exclude 'version.properties'
}
}

def loadProperties(filename) {
def props = new Properties()
file(filename).withInputStream {
props.load(it)
}
return props
}
//libs内にjarを入れればそれも使ってコンパイル
//compileは非推奨に、implementationを使う
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
//implementation fg.deobf("curse.maven:ModNameInCurseForgeModUrl-ProjectId:FileIdInUrl")
}
//template内のソースコードを編集したうえでコピー
//バージョン情報の埋め込み等に
task generateJava(type: Copy) {
def templateContext = [version: project.version, majorVersion: majorVersion, minorVersion: minorVersion, patchVersion: patchVersion]
inputs.properties templateContext // for gradle up-to-date check
from 'src/template/java'
into "$buildDir/generated/java"
expand templateContext
}
sourceSets.main.java.srcDir "$buildDir/generated/java" // add the extra source dir
compileJava.dependsOn generateJava // wire the generateJava task into the DAG
//*****************End Basic*****************
//*****************Start Basic Intellij*****************
//Fix resources dir not loaded with Intellij debug.
apply plugin: 'idea'
sourceSets {
main {
output.resourcesDir = java.outputDir
}
output.resourcesDir = java.outputDir
}
}
idea.module.outputDir file("out/production/classes")
//*****************End Basic Intellij*****************
//*****************Start Coremod*****************
jar {
manifest {
attributes FMLCorePlugin: 'kpan.uti_alsofluids.asm.core.AsmPlugin'
attributes FMLCorePluginContainsFMLMod : 'true'
attributes FMLCorePluginContainsFMLMod: 'true'
}
}
//*****************End Coremod*****************
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/kpan/uti_alsofluids/ModMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
//.langをちゃんと使うのを推奨

@Mod(modid = ModReference.MOD_ID, name = ModReference.MOD_NAME
, guiFactory = ModReference.SRC_DIR + ".config.ModGuiFactory"
, acceptableRemoteVersions = "1.3"
, dependencies = ""
, acceptableRemoteVersions = BuildInfo.MAJOR_VERSION + "." + BuildInfo.MINOR_VERSION
//
//,serverSideOnly = true, acceptableRemoteVersions = "*"//この2つによりサーバーのみのModにできる(デバッグ時は消す必要あり)
//, serverSideOnly = true //サーバーのみにする場合に必要(acceptableRemoteVersionsを*に変えないとダメ)、デバッグ時はオフにする
)
public class ModMain {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import kpan.uti_alsofluids.asm.tf.integration.ae2.TF_GuiFluidSlot;
import kpan.uti_alsofluids.asm.tf.integration.ae2.TF_GuiFluidTank;
import kpan.uti_alsofluids.asm.tf.integration.ae2.TF_GuiFluidTerminal;
import kpan.uti_alsofluids.asm.tf.integration.gregtech.TF_MaterialFluid;
import kpan.uti_alsofluids.asm.tf.integration.gregtech.TF_MetaTileEntityFluidHatch;
import kpan.uti_alsofluids.asm.tf.integration.gregtech.TF_MetaTileEntityQuantumTank;
import kpan.uti_alsofluids.asm.tf.integration.gregtech.TF_PhantomFluidWidget;
Expand Down Expand Up @@ -58,6 +59,7 @@ public byte[] transform(String name, String transformedName, byte[] bytes) {
cv = TF_GuiFluidTank.appendVisitor(cv, transformedName);
cv = TF_GuiFluidTerminal.appendVisitor(cv, transformedName);
cv = TF_LanguageMapUs.appendVisitor(cv, transformedName);
cv = TF_MaterialFluid.appendVisitor(cv, transformedName);
cv = TF_MetaTileEntityQuantumTank.appendVisitor(cv, transformedName);
cv = TF_MetaTileEntityFluidHatch.appendVisitor(cv, transformedName);
cv = TF_TankWidget.appendVisitor(cv, transformedName);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/kpan/uti_alsofluids/asm/hook/HK_Fluid.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

@SuppressWarnings("deprecation")
public class HK_Fluid {

public static boolean setThreadAlready = false;

public static String getLocalizedName(Fluid fluid, FluidStack stack) {
if (ModMain.proxy.hasClientSide()) {
Expand All @@ -31,8 +29,6 @@ public static String getLocalizedName(Fluid fluid) {
String s = fluid.getUnlocalizedName();
if (s == null)
return "";
if (setThreadAlready)
return I18n.translateToLocal(s);
synchronized (langmapus.getDisplayNameLock) {
try {
if (langmapus.getDisplayNameThread != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

@SuppressWarnings("deprecation")
public class HK_FluidRegistry_LAVA {

public static String getLocalizedName(Fluid fluid, FluidStack stack) {
String s = "tile.lava.name";
if (HK_Fluid.setThreadAlready)
return I18n.translateToLocal(s);
if (ModMain.proxy.hasClientSide())
return ClientOnly.getLocalizedName(s);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

@SuppressWarnings("deprecation")
public class HK_FluidRegistry_WATER {

public static String getLocalizedName(Fluid fluid, FluidStack stack) {
String s = "tile.water.name";
if (HK_Fluid.setThreadAlready)
return I18n.translateToLocal(s);
if (ModMain.proxy.hasClientSide())
return ClientOnly.getLocalizedName(s);
else
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/kpan/uti_alsofluids/asm/hook/HK_FluidStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public static String getLocalizedName(FluidStack stack) {
recursion++;
} else {
langmapus.getDisplayNameThread = Thread.currentThread();
HK_Fluid.setThreadAlready = true;
}
return stack.getFluid().getLocalizedName(stack);
} catch (Exception e) {
Expand All @@ -35,7 +34,6 @@ public static String getLocalizedName(FluidStack stack) {
} finally {
if (recursion == 0) {
langmapus.getDisplayNameThread = null;
HK_Fluid.setThreadAlready = false;
} else {
recursion--;
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/kpan/uti_alsofluids/asm/hook/LocalizedName.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import bre.nti.LanguageMapUs;
import kpan.uti_alsofluids.config.ConfigHolder;
import net.minecraft.client.Minecraft;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fluids.FluidStack;

public class LocalizedName {
Expand Down Expand Up @@ -35,13 +35,14 @@ public static String getLocalizedName(FluidStack fluidStack) {
}

public static String getUsLocalizedName(String unlocalizedName) {
return I18n.translateToLocal(unlocalizedName);
return I18n.format(unlocalizedName);
}

public static String getLocalizedName(String unlocalizedName) {
synchronized (langmapus.localizedLock) {
try {
return I18n.translateToLocal(unlocalizedName);
langmapus.localizedThread = Thread.currentThread();
return I18n.format(unlocalizedName);
} catch (Exception e) {
e.printStackTrace();
return "";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package kpan.uti_alsofluids.asm.hook.integration.gregtech;

import bre.nti.LanguageMapUs;
import gregtech.api.fluids.MaterialFluid;
import kpan.uti_alsofluids.ModMain;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fluids.FluidStack;

public class HK_MaterialFluid {

public static String getLocalizedName(MaterialFluid self, FluidStack stack) {
if (ModMain.proxy.hasClientSide()) {
return ClientOnly.getLocalizedName(self);
} else {
return getLocalizedName(self);
}
}

private static class ClientOnly {

private static LanguageMapUs langmapus = LanguageMapUs.getInstanceUs();
private static int recursion = 0;

public static String getLocalizedName(MaterialFluid materialFluid) {
String s = materialFluid.getUnlocalizedName();
if (s == null)
return "";
synchronized (langmapus.getDisplayNameLock) {
try {
if (langmapus.getDisplayNameThread != null) {
recursion++;
} else {
langmapus.getDisplayNameThread = Thread.currentThread();
}
return HK_MaterialFluid.getLocalizedName(materialFluid);
} catch (Exception e) {
e.printStackTrace();
return s;
} finally {
if (recursion == 0) {
langmapus.getDisplayNameThread = null;
} else {
recursion--;
}
}
}
}
}

private static String getLocalizedName(MaterialFluid materialFluid) {
String localizedName;
String customTranslationKey = "fluid." + materialFluid.getMaterial().getUnlocalizedName();

if (I18n.hasKey(customTranslationKey)) {
localizedName = I18n.format(customTranslationKey);
} else {
localizedName = I18n.format(materialFluid.getUnlocalizedName());
}

if (materialFluid.getFluidType() != null) {
return I18n.format(materialFluid.getFluidType().getLocalization(), localizedName);
}
return localizedName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kpan.uti_alsofluids.asm.tf.integration.gregtech;

import kpan.uti_alsofluids.asm.core.AsmTypes;
import kpan.uti_alsofluids.asm.core.AsmUtil;
import kpan.uti_alsofluids.asm.core.adapters.MyClassVisitor;
import kpan.uti_alsofluids.asm.core.adapters.ReplaceRefMethodAdapter;
import org.objectweb.asm.ClassVisitor;

public class TF_MaterialFluid {

private static final String TARGET = "gregtech.api.fluids.MaterialFluid";
private static final String HOOK = AsmTypes.HOOK + "integration/gregtech/" + "HK_" + "MaterialFluid";

public static ClassVisitor appendVisitor(ClassVisitor cv, String className) {
if (TARGET.equals(className)) {
MyClassVisitor newcv = new ReplaceRefMethodAdapter(cv, HOOK, TARGET, "getLocalizedName", AsmUtil.toMethodDesc(AsmTypes.STRING, AsmTypes.FLUIDSTACK));
newcv.setSuccessExpectedMin(0);//サーバーだと見つからない
return newcv;
}
return cv;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version 1.4.0 :
Fix GTCEu fluid localized bug.
version 1.3.2 :
Fix bug that prevented clients from joining to servers with different patch versions.
version 1.3.1 :
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
untranslateditems_alsofluids.version=1.3.2
te.version=${version}
8 changes: 8 additions & 0 deletions src/template/java/kpan/uti_alsofluids/BuildInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package kpan.uti_alsofluids;

public class BuildInfo {
public static final String VERSION = "${version}";
public static final String MAJOR_VERSION = "${majorVersion}";
public static final String MINOR_VERSION = "${minorVersion}";
public static final String PATCH_VERSION = "${patchVersion}";
}
3 changes: 3 additions & 0 deletions version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
majorVersion=1
minorVersion=4
patchVersion=0

0 comments on commit 4c37eec

Please sign in to comment.