commit a50d5c3f7e1ef4413c6b8c3a8e5f724453c171f0 Author: Timo Ley Date: Sat Aug 6 12:08:08 2022 +0200 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cbbfe3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.jar +.gradle +build/ +run/ +!gradle-wrapper.jar diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..763e53e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2022 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..aae409b --- /dev/null +++ b/build.gradle @@ -0,0 +1,49 @@ +plugins { + id 'fabric-loom' version '0.12-SNAPSHOT' + id 'maven-publish' +} + +version = project.mod_version +group = project.maven_group + +repositories {} + +dependencies { + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" +} + +processResources { + inputs.property "version", project.version + filteringCharset "UTF-8" + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + +def targetJavaVersion = 17 +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" + if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { + it.options.release = targetJavaVersion + } +} + +java { + def javaVersion = JavaVersion.toVersion(targetJavaVersion) + if (JavaVersion.current() < javaVersion) { + toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) + } + archivesBaseName = project.archives_base_name + withSourcesJar() +} + +jar { + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}" } + } +} + diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..f5db5f5 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,8 @@ +org.gradle.jvmargs=-Xmx1G +minecraft_version=1.18.2 +yarn_mappings=1.18.2+build.4 +loader_version=0.14.8 +mod_version=1.0.0 +maven_group=dev.tilera.modding +archives_base_name=palettefix +fabric_version=0.58.0+1.18.2 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..94336fc Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..73bb918 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..f91a4fe --- /dev/null +++ b/settings.gradle @@ -0,0 +1,9 @@ +pluginManagement { + repositories { + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } +} diff --git a/src/main/java/dev/tilera/modding/palettefix/mixin/WorldChunkMixin.java b/src/main/java/dev/tilera/modding/palettefix/mixin/WorldChunkMixin.java new file mode 100644 index 0000000..ff9e56e --- /dev/null +++ b/src/main/java/dev/tilera/modding/palettefix/mixin/WorldChunkMixin.java @@ -0,0 +1,79 @@ +package dev.tilera.modding.palettefix.mixin; + +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.util.crash.CrashException; +import net.minecraft.util.crash.CrashReport; +import net.minecraft.util.crash.CrashReportSection; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.HeightLimitView; +import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.chunk.*; +import net.minecraft.world.gen.chunk.BlendingData; +import net.minecraft.world.gen.chunk.DebugChunkGenerator; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(WorldChunk.class) +public abstract class WorldChunkMixin extends Chunk { + + @Final + @Shadow + World world; + + public WorldChunkMixin(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry biome, long inhabitedTime, @Nullable ChunkSection[] sectionArrayInitializer, @Nullable BlendingData blendingData) { + super(pos, upgradeData, heightLimitView, biome, inhabitedTime, sectionArrayInitializer, blendingData); + } + + /** + * @author tilera + * @reason Prevent game from crashing + */ + @Overwrite + public BlockState getBlockState(BlockPos pos) { + int i = pos.getX(); + int j = pos.getY(); + int k = pos.getZ(); + if (this.world.isDebugWorld()) { + BlockState blockState = null; + if (j == 60) { + blockState = Blocks.BARRIER.getDefaultState(); + } + + if (j == 70) { + blockState = DebugChunkGenerator.getBlockState(i, k); + } + + return blockState == null ? Blocks.AIR.getDefaultState() : blockState; + } else { + try { + int l = this.getSectionIndex(j); + if (l >= 0 && l < this.sectionArray.length) { + ChunkSection chunkSection = this.sectionArray[l]; + if (!chunkSection.isEmpty()) { + return chunkSection.getBlockState(i & 15, j & 15, k & 15); + } + } + + return Blocks.AIR.getDefaultState(); + } catch (EntryMissingException e) { + e.printStackTrace(); + return Blocks.AIR.getDefaultState(); + } catch (Throwable var8) { + CrashReport crashReport = CrashReport.create(var8, "Getting block state"); + CrashReportSection crashReportSection = crashReport.addElement("Block being got"); + crashReportSection.add("Location", () -> { + return CrashReportSection.createPositionString((WorldChunk)(Object) this, i, j, k); + }); + throw new CrashException(crashReport); + } + } + } + +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..76db183 --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,11 @@ +{ + "schemaVersion": 1, + "id": "palettefix", + "version": "1.0.0", + "mixins": [ + { + "config": "palettefix.mixins.json", + "environment": "*" + } + ] +} diff --git a/src/main/resources/palettefix.mixins.json b/src/main/resources/palettefix.mixins.json new file mode 100644 index 0000000..0b8f741 --- /dev/null +++ b/src/main/resources/palettefix.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "dev.tilera.modding.palettefix.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "WorldChunkMixin" + ], + "injectors": { + "defaultRequire": 1 + } +}