Merge pull request #18 from quiqueck/main
Datafixer update, WoodMaterial and BuildSystem improvements
This commit is contained in:
commit
eb4f70b8a2
8 changed files with 615 additions and 241 deletions
8
bclib-composit.gradle
Normal file
8
bclib-composit.gradle
Normal file
|
@ -0,0 +1,8 @@
|
|||
plugins {
|
||||
id 'idea'
|
||||
id 'eclipse'
|
||||
id 'fabric-loom'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
apply from: "bclib.gradle"
|
169
bclib.gradle
Normal file
169
bclib.gradle
Normal file
|
@ -0,0 +1,169 @@
|
|||
buildscript {
|
||||
dependencies {
|
||||
classpath 'org.kohsuke:github-api:1.114'
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
sourceCompatibility = JavaVersion.VERSION_16
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
repositories {
|
||||
maven { url "https://maven.dblsaiko.net/" }
|
||||
maven { url "https://server.bbkr.space:8081/artifactory/libs-release/" }
|
||||
maven { url "https://maven.fabricmc.net/" }
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven { url 'https://maven.blamejared.com' }
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings minecraft.officialMojangMappings()
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
//useApi "vazkii.patchouli:Patchouli:1.16.4-${project.patchouli_version}"
|
||||
}
|
||||
|
||||
def useOptional(String dep) {
|
||||
dependencies.modRuntime (dep) {
|
||||
exclude group: 'net.fabricmc.fabric-api'
|
||||
exclude group: 'net.fabricmc'
|
||||
if (!dep.contains("me.shedaniel")) {
|
||||
exclude group: 'me.shedaniel.cloth'
|
||||
exclude group: 'me.shedaniel'
|
||||
}
|
||||
}
|
||||
dependencies.modCompileOnly (dep) {
|
||||
exclude group: 'net.fabricmc.fabric-api'
|
||||
exclude group: 'net.fabricmc'
|
||||
if (!dep.contains("me.shedaniel")) {
|
||||
exclude group: 'me.shedaniel.cloth'
|
||||
exclude group: 'me.shedaniel'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def useApi(String dep) {
|
||||
dependencies.modApi (dep) {
|
||||
exclude group: 'net.fabricmc.fabric-api'
|
||||
exclude group: 'net.fabricmc'
|
||||
if (!dep.contains("me.shedaniel")) {
|
||||
exclude group: 'me.shedaniel.cloth'
|
||||
exclude group: 'me.shedaniel'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
println "Version: ${project.mod_version}"
|
||||
inputs.property "version", project.mod_version
|
||||
// duplicatesStrategy = 'WARN'
|
||||
|
||||
// from(sourceSets.main.resources.srcDirs) {
|
||||
// include "fabric.mod.json"
|
||||
// expand "version": version
|
||||
// }
|
||||
|
||||
// from(sourceSets.main.resources.srcDirs) {
|
||||
// exclude "fabric.mod.json"
|
||||
// }
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": project.mod_version
|
||||
}
|
||||
}
|
||||
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
it.options.release = 16
|
||||
}
|
||||
|
||||
javadoc {
|
||||
options.tags = [ "reason" ]
|
||||
options.stylesheetFile = new File(projectDir, "javadoc.css");
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this task, sources will not be generated.
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
jar {
|
||||
from "LICENSE"
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
}
|
||||
|
||||
def env = System.getenv()
|
||||
|
||||
import org.kohsuke.github.GHReleaseBuilder
|
||||
import org.kohsuke.github.GitHub
|
||||
|
||||
task release(dependsOn: [remapJar, sourcesJar, javadocJar]) {
|
||||
onlyIf {
|
||||
env.GITHUB_TOKEN
|
||||
}
|
||||
|
||||
doLast {
|
||||
def github = GitHub.connectUsingOAuth(env.GITHUB_TOKEN as String)
|
||||
def repository = github.getRepository("paulevsGitch/BCLib")
|
||||
|
||||
def releaseBuilder = new GHReleaseBuilder(repository, version as String)
|
||||
releaseBuilder.name("${archivesBaseName}-${version}")
|
||||
releaseBuilder.body("A changelog can be found at https://github.com/paulevsGitch/BCLib/commits")
|
||||
releaseBuilder.commitish("main")
|
||||
|
||||
def ghRelease = releaseBuilder.create()
|
||||
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");
|
||||
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}-sources.jar"), "application/java-archive");
|
||||
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}-javadoc.jar"), "application/java-archive");
|
||||
}
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
gpr(MavenPublication) {
|
||||
artifactId archivesBaseName
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// select the repositories you want to publish to
|
||||
repositories {
|
||||
maven {
|
||||
name = "GitHubPackages"
|
||||
url = uri("https://maven.pkg.github.com/paulevsgitch/bclib")
|
||||
credentials {
|
||||
username = env.GITHUB_USER
|
||||
password = env.GITHUB_TOKEN
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
164
build.gradle
164
build.gradle
|
@ -1,168 +1,8 @@
|
|||
buildscript {
|
||||
dependencies {
|
||||
classpath 'org.kohsuke:github-api:1.114'
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'idea'
|
||||
id 'eclipse'
|
||||
id 'fabric-loom' version '0.8-SNAPSHOT'
|
||||
id 'fabric-loom' version "${loom_version}"
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_16
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
repositories {
|
||||
maven { url "https://maven.dblsaiko.net/" }
|
||||
maven { url "https://server.bbkr.space:8081/artifactory/libs-release/" }
|
||||
maven { url "https://maven.fabricmc.net/" }
|
||||
maven { url 'https://maven.blamejared.com' }
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings minecraft.officialMojangMappings()
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
//useApi "vazkii.patchouli:Patchouli:1.16.4-${project.patchouli_version}"
|
||||
}
|
||||
|
||||
def useOptional(String dep) {
|
||||
dependencies.modRuntime (dep) {
|
||||
exclude group: 'net.fabricmc.fabric-api'
|
||||
exclude group: 'net.fabricmc'
|
||||
if (!dep.contains("me.shedaniel")) {
|
||||
exclude group: 'me.shedaniel.cloth'
|
||||
exclude group: 'me.shedaniel'
|
||||
}
|
||||
}
|
||||
dependencies.modCompileOnly (dep) {
|
||||
exclude group: 'net.fabricmc.fabric-api'
|
||||
exclude group: 'net.fabricmc'
|
||||
if (!dep.contains("me.shedaniel")) {
|
||||
exclude group: 'me.shedaniel.cloth'
|
||||
exclude group: 'me.shedaniel'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def useApi(String dep) {
|
||||
dependencies.modApi (dep) {
|
||||
exclude group: 'net.fabricmc.fabric-api'
|
||||
exclude group: 'net.fabricmc'
|
||||
if (!dep.contains("me.shedaniel")) {
|
||||
exclude group: 'me.shedaniel.cloth'
|
||||
exclude group: 'me.shedaniel'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
duplicatesStrategy = 'WARN'
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include "fabric.mod.json"
|
||||
expand "version": project.version
|
||||
}
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude "fabric.mod.json"
|
||||
}
|
||||
}
|
||||
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
javadoc {
|
||||
options.tags = [ "reason" ]
|
||||
options.stylesheetFile = new File(projectDir, "javadoc.css");
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this task, sources will not be generated.
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
jar {
|
||||
from "LICENSE"
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
}
|
||||
|
||||
def env = System.getenv()
|
||||
|
||||
import org.kohsuke.github.GHReleaseBuilder
|
||||
import org.kohsuke.github.GitHub
|
||||
|
||||
task release(dependsOn: [remapJar, sourcesJar, javadocJar]) {
|
||||
onlyIf {
|
||||
env.GITHUB_TOKEN
|
||||
}
|
||||
|
||||
doLast {
|
||||
def github = GitHub.connectUsingOAuth(env.GITHUB_TOKEN as String)
|
||||
def repository = github.getRepository("paulevsGitch/BCLib")
|
||||
|
||||
def releaseBuilder = new GHReleaseBuilder(repository, version as String)
|
||||
releaseBuilder.name("${archivesBaseName}-${version}")
|
||||
releaseBuilder.body("A changelog can be found at https://github.com/paulevsGitch/BCLib/commits")
|
||||
releaseBuilder.commitish("main")
|
||||
|
||||
def ghRelease = releaseBuilder.create()
|
||||
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");
|
||||
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}-sources.jar"), "application/java-archive");
|
||||
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}-javadoc.jar"), "application/java-archive");
|
||||
}
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
gpr(MavenPublication) {
|
||||
artifactId archivesBaseName
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// select the repositories you want to publish to
|
||||
repositories {
|
||||
maven {
|
||||
name = "GitHubPackages"
|
||||
url = uri("https://maven.pkg.github.com/paulevsgitch/bclib")
|
||||
credentials {
|
||||
username = env.GITHUB_USER
|
||||
password = env.GITHUB_TOKEN
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
apply from: "bclib.gradle"
|
|
@ -1,11 +1,14 @@
|
|||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs=-Xmx2G
|
||||
|
||||
#Loom
|
||||
loom_version=0.8-SNAPSHOT
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
# check these on https://fabricmc.net/versions.html
|
||||
minecraft_version= 1.17.1
|
||||
yarn_mappings= 6
|
||||
loader_version= 0.11.6
|
||||
fabric_version = 0.36.1+1.17
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 0.3.0
|
||||
|
@ -13,6 +16,4 @@ maven_group = ru.bclib
|
|||
archives_base_name = bclib
|
||||
|
||||
# Dependencies
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
patchouli_version = 50-FABRIC
|
||||
fabric_version = 0.36.1+1.17
|
||||
patchouli_version = 50-FABRIC
|
|
@ -35,63 +35,131 @@ public class DataFixerAPI {
|
|||
LOGGER.info("Everything up to date");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean[] allOk = {true};
|
||||
|
||||
List<File> regions = getAllRegions(dir, null);
|
||||
boolean[] allOk = {true};
|
||||
regions.parallelStream()
|
||||
.forEach((file) -> {
|
||||
try {
|
||||
LOGGER.info("Inspecting " + file);
|
||||
boolean[] changed = new boolean[1];
|
||||
RegionFile region = new RegionFile(file, file.getParentFile(), true);
|
||||
for (int x = 0; x < 32; x++) {
|
||||
for (int z = 0; z < 32; z++) {
|
||||
ChunkPos pos = new ChunkPos(x, z);
|
||||
changed[0] = false;
|
||||
if (region.hasChunk(pos)) {
|
||||
DataInputStream input = region.getChunkDataInputStream(pos);
|
||||
CompoundTag root = NbtIo.read(input);
|
||||
// if ((root.toString().contains("betternether") || root.toString().contains("bclib")) && root.toString().contains("chest")) {
|
||||
// NbtIo.write(root, new File(file.toString() + "-" + x + "-" + z + ".nbt"));
|
||||
// }
|
||||
input.close();
|
||||
|
||||
ListTag tileEntities = root.getCompound("Level")
|
||||
.getList("TileEntities", 10);
|
||||
fixItemArrayWithID(tileEntities, changed, data, true);
|
||||
|
||||
ListTag sections = root.getCompound("Level")
|
||||
.getList("Sections", 10);
|
||||
sections.forEach((tag) -> {
|
||||
ListTag palette = ((CompoundTag) tag).getList("Palette", 10);
|
||||
palette.forEach((blockTag) -> {
|
||||
CompoundTag blockTagCompound = ((CompoundTag) blockTag);
|
||||
changed[0] = data.replaceStringFromIDs(blockTagCompound, "Name");
|
||||
});
|
||||
});
|
||||
if (changed[0]) {
|
||||
LOGGER.warning("Writing '{}': {}/{}", file, x, z);
|
||||
DataOutputStream output = region.getChunkDataOutputStream(pos);
|
||||
NbtIo.write(root, output);
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
region.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
allOk[0] = false;
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
regions.parallelStream().forEach((file) -> fixRegion(data, allOk, file));
|
||||
|
||||
List<File> players = getAllPlayers(dir);
|
||||
players.parallelStream().forEach((file) -> fixPlayer(data, allOk, file));
|
||||
|
||||
fixLevel(data, allOk, new File(dir, "level.dat"));
|
||||
|
||||
if (allOk[0]) {
|
||||
data.markApplied();
|
||||
WorldDataAPI.saveFile(BCLib.MOD_ID);
|
||||
}
|
||||
}
|
||||
|
||||
private static void fixLevel(MigrationProfile data, boolean[] allOk, File file) {
|
||||
try {
|
||||
LOGGER.info("Inspecting " + file);
|
||||
CompoundTag level = NbtIo.readCompressed(file);
|
||||
boolean[] changed = { false };
|
||||
|
||||
if (level.contains("Data")) {
|
||||
CompoundTag dataTag = (CompoundTag)level.get("Data");
|
||||
if (dataTag.contains("Player")) {
|
||||
CompoundTag player = (CompoundTag)dataTag.get("Player");
|
||||
fixPlayerNbt(player, changed, data);
|
||||
}
|
||||
}
|
||||
|
||||
if (changed[0]) {
|
||||
LOGGER.warning("Writing '{}'", file);
|
||||
NbtIo.writeCompressed(level, file);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
allOk[0] = false;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void fixPlayer(MigrationProfile data, boolean[] allOk, File file) {
|
||||
try {
|
||||
LOGGER.info("Inspecting " + file);
|
||||
CompoundTag player = NbtIo.readCompressed(file);
|
||||
boolean[] changed = { false };
|
||||
fixPlayerNbt(player, changed, data);
|
||||
|
||||
if (changed[0]) {
|
||||
LOGGER.warning("Writing '{}'", file);
|
||||
NbtIo.writeCompressed(player, file);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
allOk[0] = false;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void fixPlayerNbt(CompoundTag player, boolean[] changed, MigrationProfile data) {
|
||||
//Checking Inventory
|
||||
ListTag inventory = player.getList("Inventory", 10);
|
||||
fixInventory(inventory, changed, data, true);
|
||||
|
||||
//Checking EnderChest
|
||||
ListTag enderitems = player.getList("EnderItems", 10);
|
||||
fixInventory(enderitems, changed, data, true);
|
||||
}
|
||||
|
||||
private static void fixRegion(MigrationProfile data, boolean[] allOk, File file) {
|
||||
try {
|
||||
LOGGER.info("Inspecting " + file);
|
||||
boolean[] changed = new boolean[1];
|
||||
RegionFile region = new RegionFile(file, file.getParentFile(), true);
|
||||
for (int x = 0; x < 32; x++) {
|
||||
for (int z = 0; z < 32; z++) {
|
||||
ChunkPos pos = new ChunkPos(x, z);
|
||||
changed[0] = false;
|
||||
if (region.hasChunk(pos)) {
|
||||
DataInputStream input = region.getChunkDataInputStream(pos);
|
||||
CompoundTag root = NbtIo.read(input);
|
||||
// if ((root.toString().contains("betternether:chest") || root.toString().contains("bclib:chest"))) {
|
||||
// NbtIo.write(root, new File(file.toString() + "-" + x + "-" + z + ".nbt"));
|
||||
// }
|
||||
input.close();
|
||||
|
||||
//Checking TileEntities
|
||||
ListTag tileEntities = root.getCompound("Level")
|
||||
.getList("TileEntities", 10);
|
||||
fixItemArrayWithID(tileEntities, changed, data, true);
|
||||
|
||||
//Checking Entities
|
||||
ListTag entities = root.getList("Entities", 10);
|
||||
fixItemArrayWithID(entities, changed, data, true);
|
||||
|
||||
//Checking Block Palette
|
||||
ListTag sections = root.getCompound("Level")
|
||||
.getList("Sections", 10);
|
||||
sections.forEach((tag) -> {
|
||||
ListTag palette = ((CompoundTag) tag).getList("Palette", 10);
|
||||
palette.forEach((blockTag) -> {
|
||||
CompoundTag blockTagCompound = ((CompoundTag) blockTag);
|
||||
changed[0] |= data.replaceStringFromIDs(blockTagCompound, "Name");
|
||||
});
|
||||
});
|
||||
|
||||
if (changed[0]) {
|
||||
LOGGER.warning("Writing '{}': {}/{}", file, x, z);
|
||||
// NbtIo.write(root, new File(file.toString() + "-" + x + "-" + z + "-changed.nbt"));
|
||||
DataOutputStream output = region.getChunkDataOutputStream(pos);
|
||||
NbtIo.write(root, output);
|
||||
output.close();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
region.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
allOk[0] = false;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static CompoundTag patchConfTag = null;
|
||||
static CompoundTag getPatchData(){
|
||||
if (patchConfTag==null) {
|
||||
|
@ -99,19 +167,56 @@ public class DataFixerAPI {
|
|||
}
|
||||
return patchConfTag;
|
||||
}
|
||||
|
||||
private static boolean fixItemArrayWithID(ListTag items, boolean[] changed, MigrationProfile data, boolean recursive) {
|
||||
items.forEach(inTag -> {
|
||||
final CompoundTag tag = (CompoundTag) inTag;
|
||||
|
||||
changed[0] |= data.replaceStringFromIDs(tag, "id");
|
||||
|
||||
if (recursive && tag.contains("Items")) {
|
||||
changed[0] |= fixItemArrayWithID(tag.getList("Items", 10), changed, data, true);
|
||||
|
||||
private static void fixInventory(ListTag inventory, boolean[] changed, MigrationProfile data, boolean recursive) {
|
||||
inventory.forEach(item -> {
|
||||
changed[0] |= data.replaceStringFromIDs((CompoundTag)item, "id");
|
||||
|
||||
if (((CompoundTag) item).contains("tag")) {
|
||||
CompoundTag tag = (CompoundTag)((CompoundTag) item).get("tag");
|
||||
if (tag.contains("BlockEntityTag")){
|
||||
CompoundTag blockEntityTag = (CompoundTag)((CompoundTag) tag).get("BlockEntityTag");
|
||||
ListTag items = blockEntityTag.getList("Items", 10);
|
||||
fixItemArrayWithID(items, changed, data, recursive);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return changed[0];
|
||||
}
|
||||
|
||||
private static void fixItemArrayWithID(ListTag items, boolean[] changed, MigrationProfile data, boolean recursive) {
|
||||
items.forEach(inTag -> {
|
||||
fixID((CompoundTag) inTag, changed, data, recursive);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static void fixID(CompoundTag inTag, boolean[] changed, MigrationProfile data, boolean recursive) {
|
||||
final CompoundTag tag = inTag;
|
||||
|
||||
changed[0] |= data.replaceStringFromIDs(tag, "id");
|
||||
if (tag.contains("Item")) {
|
||||
CompoundTag item = (CompoundTag)tag.get("Item");
|
||||
fixID(item, changed, data, recursive);
|
||||
}
|
||||
|
||||
if (recursive && tag.contains("Items")) {
|
||||
fixItemArrayWithID(tag.getList("Items", 10), changed, data, true);
|
||||
}
|
||||
if (recursive && tag.contains("Inventory")) {
|
||||
ListTag inventory = tag.getList("Inventory", 10);
|
||||
fixInventory(inventory, changed, data, recursive);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<File> getAllPlayers(File dir) {
|
||||
List<File> list = new ArrayList<>();
|
||||
dir = new File(dir, "playerdata");
|
||||
for (File file : dir.listFiles()) {
|
||||
if (file.isFile() && file.getName().endsWith(".dat")) {
|
||||
list.add(file);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static List<File> getAllRegions(File dir, List<File> list) {
|
||||
|
@ -121,9 +226,7 @@ public class DataFixerAPI {
|
|||
for (File file : dir.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
getAllRegions(file, list);
|
||||
}
|
||||
else if (file.isFile() && file.getName()
|
||||
.endsWith(".mca")) {
|
||||
} else if (file.isFile() && file.getName().endsWith(".mca")) {
|
||||
list.add(file);
|
||||
}
|
||||
}
|
||||
|
|
246
src/main/java/ru/bclib/blocks/complex/WoodenMaterial.java
Normal file
246
src/main/java/ru/bclib/blocks/complex/WoodenMaterial.java
Normal file
|
@ -0,0 +1,246 @@
|
|||
package ru.bclib.blocks.complex;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.MaterialColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import ru.bclib.api.TagAPI;
|
||||
import ru.bclib.blocks.BaseBarkBlock;
|
||||
import ru.bclib.blocks.BaseBarrelBlock;
|
||||
import ru.bclib.blocks.BaseBlock;
|
||||
import ru.bclib.blocks.BaseBookshelfBlock;
|
||||
import ru.bclib.blocks.BaseChestBlock;
|
||||
import ru.bclib.blocks.BaseComposterBlock;
|
||||
import ru.bclib.blocks.BaseCraftingTableBlock;
|
||||
import ru.bclib.blocks.BaseDoorBlock;
|
||||
import ru.bclib.blocks.BaseFenceBlock;
|
||||
import ru.bclib.blocks.BaseGateBlock;
|
||||
import ru.bclib.blocks.BaseLadderBlock;
|
||||
import ru.bclib.blocks.BaseRotatedPillarBlock;
|
||||
import ru.bclib.blocks.BaseSignBlock;
|
||||
import ru.bclib.blocks.BaseSlabBlock;
|
||||
import ru.bclib.blocks.BaseStairsBlock;
|
||||
import ru.bclib.blocks.BaseStripableLogBlock;
|
||||
import ru.bclib.blocks.BaseTrapdoorBlock;
|
||||
import ru.bclib.blocks.BaseWoodenButtonBlock;
|
||||
import ru.bclib.blocks.StripableBarkBlock;
|
||||
import ru.bclib.blocks.WoodenPressurePlateBlock;
|
||||
import ru.bclib.config.Configs;
|
||||
import ru.bclib.recipes.GridRecipe;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class WoodenMaterial {
|
||||
public final static String NAME_STRIPPED_LOG = "stripped_log";
|
||||
public final static String NAME_STRIPPED_BARK = "stripped_bark";
|
||||
public final static String NAME_LOG = "log";
|
||||
public final static String NAME_BARK = "bark";
|
||||
public final static String NAME_PLANKS = "planks";
|
||||
public final static String NAME_STAIRS = "stairs";
|
||||
public final static String NAME_SLAB = "slab";
|
||||
public final static String NAME_FENCE = "fence";
|
||||
public final static String NAME_GATE = "gate";
|
||||
public final static String NAME_BUTTON = "button";
|
||||
public final static String NAME_PLATE = "plate";
|
||||
public final static String NAME_TRAPDOOR = "trapdoor";
|
||||
public final static String NAME_DOOR = "door";
|
||||
public final static String NAME_CRAFTING_TABLE = "crafting_table";
|
||||
public final static String NAME_LADDER = "ladder";
|
||||
public final static String NAME_SIGN = "sign";
|
||||
public final static String NAME_CHEST = "chest";
|
||||
public final static String NAME_BARREL = "barrel";
|
||||
public final static String NAME_BOOKSHELF = "bookshelf";
|
||||
public final static String NAME_COMPOSTER = "composter";
|
||||
|
||||
public final static String NAME_PRESSURE_PLATE = "pressure_plate";
|
||||
public final static String NAME_SHULKER = "shulker";
|
||||
|
||||
public final Block log;
|
||||
public final Block bark;
|
||||
|
||||
public final Block log_stripped;
|
||||
public final Block bark_stripped;
|
||||
|
||||
public final Block planks;
|
||||
|
||||
public final Block stairs;
|
||||
public final Block slab;
|
||||
public final Block fence;
|
||||
public final Block gate;
|
||||
public final Block button;
|
||||
public final Block pressurePlate;
|
||||
public final Block trapdoor;
|
||||
public final Block door;
|
||||
|
||||
public final Block craftingTable;
|
||||
public final Block ladder;
|
||||
public final Block sign;
|
||||
|
||||
public final Block chest;
|
||||
public final Block barrel;
|
||||
//public final Block shelf;
|
||||
//public final Block composter;
|
||||
|
||||
protected final FabricBlockSettings materialPlanks;
|
||||
protected final String modID;
|
||||
protected final String name;
|
||||
protected final String receipGroupPrefix;
|
||||
|
||||
public final Tag.Named<Block> logBlockTag;
|
||||
public final Tag.Named<Item> logItemTag;
|
||||
|
||||
protected Block newLogStripped(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseRotatedPillarBlock(materialPlanks); }
|
||||
protected Block newBarkStripped(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseBarkBlock(materialPlanks); }
|
||||
protected Block newLog(FabricBlockSettings materialPlanks, MaterialColor woodColor) { if (log_stripped!=null) return new BaseStripableLogBlock(woodColor, log_stripped); else return null;}
|
||||
protected Block newBark(FabricBlockSettings materialPlanks, MaterialColor woodColor) { if (bark_stripped!=null) return new StripableBarkBlock(woodColor, bark_stripped); else return null;}
|
||||
protected Block newPlanks(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseBlock(materialPlanks); }
|
||||
protected Block newStairs(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseStairsBlock(planks); }
|
||||
protected Block newSlab(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseSlabBlock(planks); }
|
||||
protected Block newFence(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseFenceBlock(planks); }
|
||||
protected Block newGate(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseGateBlock(planks); }
|
||||
protected Block newButton(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseWoodenButtonBlock(planks); }
|
||||
protected Block newPressurePlate(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new WoodenPressurePlateBlock(planks); }
|
||||
protected Block newTrapdoor(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseTrapdoorBlock(planks); }
|
||||
protected Block newDoor(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseDoorBlock(planks); }
|
||||
protected Block newCraftingTable(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseCraftingTableBlock(planks); }
|
||||
protected Block newLadder(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseLadderBlock(planks); }
|
||||
protected Block newSign(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseSignBlock(planks); }
|
||||
protected Block newChest(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseChestBlock(planks); }
|
||||
protected Block newBarrel(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseBarrelBlock(planks); }
|
||||
//protected Block newShelf(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseBookshelfBlock(planks); }
|
||||
//protected Block newComposter(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseComposterBlock(planks); }
|
||||
|
||||
public WoodenMaterial(String modID, String name, MaterialColor woodColor, MaterialColor planksColor, String receipGroupPrefix, BiFunction<String, Block, Block> registerBlock) {
|
||||
materialPlanks = FabricBlockSettings.copyOf(Blocks.OAK_PLANKS).mapColor(planksColor);
|
||||
this.modID = modID;
|
||||
this.receipGroupPrefix = receipGroupPrefix;
|
||||
this.name = name;
|
||||
|
||||
log_stripped = registerBlock.apply(name + "_" + NAME_STRIPPED_LOG, newLogStripped(materialPlanks, woodColor));
|
||||
bark_stripped = registerBlock.apply(name + "_" + NAME_STRIPPED_BARK, newBarkStripped(materialPlanks, woodColor));
|
||||
|
||||
log = registerBlock.apply(name + "_" + NAME_LOG, newLog(materialPlanks, woodColor));
|
||||
bark = registerBlock.apply(name + "_" + NAME_BARK, newBark(materialPlanks, woodColor));
|
||||
|
||||
planks = registerBlock.apply(name + "_" + NAME_PLANKS, newPlanks(materialPlanks, woodColor));
|
||||
stairs = registerBlock.apply(name + "_" + NAME_STAIRS, newStairs(materialPlanks, woodColor));
|
||||
slab = registerBlock.apply(name + "_" + NAME_SLAB, newSlab(materialPlanks, woodColor));
|
||||
fence = registerBlock.apply(name + "_" + NAME_FENCE, newFence(materialPlanks, woodColor));
|
||||
gate = registerBlock.apply(name + "_" + NAME_GATE, newGate(materialPlanks, woodColor));
|
||||
button = registerBlock.apply(name + "_" + NAME_BUTTON, newButton(materialPlanks, woodColor));
|
||||
pressurePlate = registerBlock.apply(name + "_" + NAME_PLATE, newPressurePlate(materialPlanks, woodColor));
|
||||
trapdoor = registerBlock.apply(name + "_" + NAME_TRAPDOOR, newTrapdoor(materialPlanks, woodColor));
|
||||
door = registerBlock.apply(name + "_" + NAME_DOOR, newDoor(materialPlanks, woodColor));
|
||||
|
||||
craftingTable = registerBlock.apply(name + "_" + NAME_CRAFTING_TABLE, newCraftingTable(materialPlanks, woodColor));
|
||||
ladder = registerBlock.apply(name + "_" + NAME_LADDER, newLadder(materialPlanks, woodColor));
|
||||
sign = registerBlock.apply(name + "_" + NAME_SIGN, newSign(materialPlanks, woodColor));
|
||||
|
||||
chest = registerBlock.apply(name + "_" + NAME_CHEST, newChest(materialPlanks, woodColor));
|
||||
barrel = registerBlock.apply(name + "_" + NAME_BARREL, newBarrel(materialPlanks, woodColor));
|
||||
//shelf = registerBlock.apply(name + "_" + NAME_BOOKSHELF, newShelf(materialPlanks, woodColor));
|
||||
//composter = registerBlock.apply(name + "_" + NAME_COMPOSTER, newComposter(materialPlanks, woodColor));
|
||||
|
||||
// Recipes //
|
||||
GridRecipe.make(modID, name + "_" + NAME_PLANKS, planks).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(4).setList("#").addMaterial('#', log, bark, log_stripped, bark_stripped).setGroup(receipGroupPrefix + "_planks").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_STAIRS, stairs).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(4).setShape("# ", "## ", "###").addMaterial('#', planks).setGroup(receipGroupPrefix + "_planks_stairs").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_SLAB, slab).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(6).setShape("###").addMaterial('#', planks).setGroup(receipGroupPrefix + "_planks_slabs").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_FENCE, fence).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(3).setShape("#I#", "#I#").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup(receipGroupPrefix + "_planks_fences").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_GATE, gate).checkConfig(Configs.RECIPE_CONFIG).setShape("I#I", "I#I").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup(receipGroupPrefix + "_planks_gates").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_BUTTON, button).checkConfig(Configs.RECIPE_CONFIG).setList("#").addMaterial('#', planks).setGroup(receipGroupPrefix + "_planks_buttons").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_PRESSURE_PLATE, pressurePlate).checkConfig(Configs.RECIPE_CONFIG).setShape("##").addMaterial('#', planks).setGroup(receipGroupPrefix + "_planks_plates").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_TRAPDOOR, trapdoor).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(2).setShape("###", "###").addMaterial('#', planks).setGroup(receipGroupPrefix + "_trapdoors").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_DOOR, door).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(3).setShape("##", "##", "##").addMaterial('#', planks).setGroup(receipGroupPrefix + "_doors").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_CRAFTING_TABLE, craftingTable).checkConfig(Configs.RECIPE_CONFIG).setShape("##", "##").addMaterial('#', planks).setGroup(receipGroupPrefix + "_tables").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_LADDER, ladder).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(3).setShape("I I", "I#I", "I I").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup(receipGroupPrefix + "_ladders").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_SIGN, sign).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(3).setShape("###", "###", " I ").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup(receipGroupPrefix + "_signs").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_CHEST, chest).checkConfig(Configs.RECIPE_CONFIG).setShape("###", "# #", "###").addMaterial('#', planks).setGroup(receipGroupPrefix + "_chests").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_BARREL, barrel).checkConfig(Configs.RECIPE_CONFIG).setShape("#S#", "# #", "#S#").addMaterial('#', planks).addMaterial('S', slab).setGroup(receipGroupPrefix + "_barrels").build();
|
||||
//GridRecipe.make(modID, name + "_" + NAME_BOOKSHELF, shelf).checkConfig(Configs.RECIPE_CONFIG).setShape("###", "PPP", "###").addMaterial('#', planks).addMaterial('P', Items.BOOK).setGroup(receipGroupPrefix + "_bookshelves").build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_BARK, bark).checkConfig(Configs.RECIPE_CONFIG).setShape("##", "##").addMaterial('#', log).setOutputCount(3).build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_LOG, log).checkConfig(Configs.RECIPE_CONFIG).setShape("##", "##").addMaterial('#', bark).setOutputCount(3).build();
|
||||
//GridRecipe.make(modID, name + "_" + NAME_COMPOSTER, composter).checkConfig(Configs.RECIPE_CONFIG).setShape("# #", "# #", "###").addMaterial('#', slab).build();
|
||||
GridRecipe.make(modID, name + "_" + NAME_SHULKER, Items.SHULKER_BOX).checkConfig(Configs.RECIPE_CONFIG).setShape("S", "#", "S").addMaterial('S', Items.SHULKER_SHELL).addMaterial('#', chest).build();
|
||||
|
||||
// Item Tags //
|
||||
TagAPI.addTag(ItemTags.PLANKS, planks);
|
||||
TagAPI.addTag(ItemTags.WOODEN_PRESSURE_PLATES, pressurePlate);
|
||||
TagAPI.addTag(ItemTags.LOGS, log, bark, log_stripped, bark_stripped);
|
||||
TagAPI.addTag(ItemTags.LOGS_THAT_BURN, log, bark, log_stripped, bark_stripped);
|
||||
|
||||
|
||||
TagAPI.addTags(button, ItemTags.WOODEN_BUTTONS, ItemTags.BUTTONS);
|
||||
TagAPI.addTags(door, ItemTags.WOODEN_DOORS, ItemTags.DOORS);
|
||||
TagAPI.addTags(fence, ItemTags.WOODEN_FENCES, ItemTags.FENCES);
|
||||
TagAPI.addTags(slab, ItemTags.WOODEN_SLABS, ItemTags.SLABS);
|
||||
TagAPI.addTags(stairs, ItemTags.WOODEN_STAIRS, ItemTags.STAIRS);
|
||||
TagAPI.addTags(trapdoor, ItemTags.WOODEN_TRAPDOORS, ItemTags.TRAPDOORS);
|
||||
TagAPI.addTag(TagAPI.ITEM_CHEST, chest);
|
||||
|
||||
// Block Tags //
|
||||
TagAPI.addTag(BlockTags.PLANKS, planks);
|
||||
TagAPI.addTag(BlockTags.CLIMBABLE, ladder);
|
||||
TagAPI.addTag(BlockTags.LOGS, log, bark, log_stripped, bark_stripped);
|
||||
TagAPI.addTag(BlockTags.LOGS_THAT_BURN, log, bark, log_stripped, bark_stripped);
|
||||
|
||||
|
||||
TagAPI.addTags(button, BlockTags.WOODEN_BUTTONS, BlockTags.BUTTONS);
|
||||
TagAPI.addTags(door, BlockTags.WOODEN_DOORS, BlockTags.DOORS);
|
||||
TagAPI.addTags(fence, BlockTags.WOODEN_FENCES, BlockTags.FENCES);
|
||||
TagAPI.addTags(slab, BlockTags.WOODEN_SLABS, BlockTags.SLABS);
|
||||
TagAPI.addTags(stairs, BlockTags.WOODEN_STAIRS, BlockTags.STAIRS);
|
||||
TagAPI.addTags(trapdoor, BlockTags.WOODEN_TRAPDOORS, BlockTags.TRAPDOORS);
|
||||
//TagAPI.addTag(TagAPI.BLOCK_BOOKSHELVES, shelf);
|
||||
TagAPI.addTag(TagAPI.BLOCK_CHEST, chest);
|
||||
|
||||
logBlockTag = TagAPI.makeBlockTag(modID, name + "_logs");
|
||||
logItemTag = TagAPI.makeItemTag(modID, name + "_logs");
|
||||
TagAPI.addTag(logBlockTag, log_stripped, bark_stripped, log, bark);
|
||||
TagAPI.addTag(logItemTag, log_stripped, bark_stripped, log, bark);
|
||||
|
||||
addFlammable();
|
||||
}
|
||||
|
||||
protected void addFlammable() {
|
||||
FlammableBlockRegistry.getDefaultInstance().add(log, 5, 5);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(bark, 5, 5);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(log_stripped, 5, 5);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(bark_stripped, 5, 5);
|
||||
|
||||
FlammableBlockRegistry.getDefaultInstance().add(planks, 5, 20);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(stairs, 5, 20);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(slab, 5, 20);
|
||||
|
||||
FlammableBlockRegistry.getDefaultInstance().add(fence, 5, 20);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(gate, 5, 20);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(button, 5, 20);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(pressurePlate, 5, 20);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(trapdoor, 5, 20);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(door, 5, 20);
|
||||
|
||||
FlammableBlockRegistry.getDefaultInstance().add(craftingTable, 5, 20);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(ladder, 5, 20);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(sign, 5, 20);
|
||||
|
||||
FlammableBlockRegistry.getDefaultInstance().add(chest, 5, 20);
|
||||
FlammableBlockRegistry.getDefaultInstance().add(barrel, 5, 20);
|
||||
//FlammableBlockRegistry.getDefaultInstance().add(shelf, 5, 20);
|
||||
//FlammableBlockRegistry.getDefaultInstance().add(composter, 5, 20);
|
||||
}
|
||||
|
||||
public boolean isTreeLog(Block block) {
|
||||
return block!=null && (block == log || block == bark);
|
||||
}
|
||||
|
||||
public boolean isTreeLog(BlockState state) {
|
||||
return isTreeLog(state.getBlock());
|
||||
}
|
||||
}
|
|
@ -5,18 +5,25 @@ import net.minecraft.resources.ResourceKey;
|
|||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.ServerResources;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.level.storage.WorldData;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import ru.bclib.api.BiomeAPI;
|
||||
import ru.bclib.api.WorldDataAPI;
|
||||
import ru.bclib.api.datafixer.DataFixerAPI;
|
||||
import ru.bclib.recipes.BCLRecipeManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
@ -33,7 +40,15 @@ public class MinecraftServerMixin {
|
|||
@Final
|
||||
@Shadow
|
||||
protected WorldData worldData;
|
||||
|
||||
|
||||
@Inject(method="convertFromRegionFormatIfNeeded", at = @At("HEAD"))
|
||||
private static void bclib_applyPatches(LevelStorageSource.LevelStorageAccess session, CallbackInfo ci){
|
||||
File levelPath = session.getLevelPath(LevelResource.ROOT).toFile();
|
||||
WorldDataAPI.load(new File(levelPath, "data"));
|
||||
DataFixerAPI.fixData(levelPath);
|
||||
}
|
||||
|
||||
|
||||
@Inject(method = "reloadResources", at = @At(value = "RETURN"), cancellable = true)
|
||||
private void bclib_reloadResources(Collection<String> collection, CallbackInfoReturnable<CompletableFuture<Void>> info) {
|
||||
bclib_injectRecipes();
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.minecraft.world.level.storage.WritableLevelData;
|
|||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import ru.bclib.api.BiomeAPI;
|
||||
import ru.bclib.api.WorldDataAPI;
|
||||
|
@ -32,7 +33,7 @@ public abstract class ServerLevelMixin extends Level {
|
|||
protected ServerLevelMixin(WritableLevelData writableLevelData, ResourceKey<Level> resourceKey, DimensionType dimensionType, Supplier<ProfilerFiller> supplier, boolean bl, boolean bl2, long l) {
|
||||
super(writableLevelData, resourceKey, dimensionType, supplier, bl, bl2, l);
|
||||
}
|
||||
|
||||
|
||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||
private void bclib_onServerWorldInit(MinecraftServer server, Executor workerExecutor, LevelStorageSource.LevelStorageAccess session, ServerLevelData properties, ResourceKey<Level> registryKey, DimensionType dimensionType, ChunkProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List<CustomSpawner> list, boolean bl, CallbackInfo info) {
|
||||
BiomeAPI.initRegistry(server);
|
||||
|
@ -42,14 +43,5 @@ public abstract class ServerLevelMixin extends Level {
|
|||
}
|
||||
|
||||
bclib_lastWorld = session.getLevelId();
|
||||
|
||||
ServerLevel world = ServerLevel.class.cast(this);
|
||||
File dir = session.getDimensionPath(world.dimension());
|
||||
if (!new File(dir, "level.dat").exists()) {
|
||||
dir = dir.getParentFile();
|
||||
}
|
||||
|
||||
WorldDataAPI.load(new File(dir, "data"));
|
||||
DataFixerAPI.fixData(dir);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue