[WIP] beginning port to 1.16.5

+most of the stuff is working
This commit is contained in:
octarine-noise
2021-05-14 22:40:04 +02:00
parent 79ef6cfaa9
commit 81d3a2eba4
30 changed files with 89 additions and 85 deletions

View File

@@ -2,7 +2,7 @@ import net.fabricmc.loom.task.RemapJarTask
import org.ajoberstar.grgit.Grgit import org.ajoberstar.grgit.Grgit
plugins { plugins {
id("fabric-loom").version("0.2.6-SNAPSHOT") id("fabric-loom").version("0.6-SNAPSHOT")
kotlin("jvm").version("1.4.31") kotlin("jvm").version("1.4.31")
id("org.ajoberstar.grgit").version("3.1.1") id("org.ajoberstar.grgit").version("3.1.1")
} }
@@ -13,9 +13,10 @@ val semVer = "${project.version}+$gitHash"
val jarName = "BetterFoliage-$semVer-Fabric-${properties["mcVersion"]}" val jarName = "BetterFoliage-$semVer-Fabric-${properties["mcVersion"]}"
repositories { repositories {
maven("http://maven.fabricmc.net/") maven("https://maven.fabricmc.net/")
maven("https://minecraft.curseforge.com/api/maven") maven("https://minecraft.curseforge.com/api/maven")
maven("http://maven.modmuss50.me/") maven("https://maven.modmuss50.me/")
maven("https://maven.shedaniel.me/")
maven("https://grondag-repo.appspot.com").credentials { username = "guest"; password = "" } maven("https://grondag-repo.appspot.com").credentials { username = "guest"; password = "" }
maven("https://jitpack.io") maven("https://jitpack.io")
} }
@@ -32,7 +33,7 @@ dependencies {
// configuration handling // configuration handling
"modImplementation"("io.github.prospector:modmenu:${properties["modMenuVersion"]}") "modImplementation"("io.github.prospector:modmenu:${properties["modMenuVersion"]}")
listOf("modImplementation", "include").forEach { configuration -> listOf("modImplementation", "include").forEach { configuration ->
configuration("me.shedaniel.cloth:config-2:${properties["clothConfigVersion"]}") configuration("me.shedaniel.cloth:cloth-config-fabric:${properties["clothConfigVersion"]}")
configuration("me.zeroeightsix:fiber:${properties["fiberVersion"]}") configuration("me.zeroeightsix:fiber:${properties["fiberVersion"]}")
} }

View File

@@ -5,16 +5,16 @@ group = com.github.octarine-noise
name = betterfoliage name = betterfoliage
jarName = BetterFoliage-Forge jarName = BetterFoliage-Forge
version = 2.6.0 version = 2.6.2
mcVersion = 1.15.2 mcVersion = 1.16.5
yarnMappings=1.15.2+build.17 yarnMappings=1.16.5+build.6
loaderVersion=0.11.3 loaderVersion=0.11.3
fabricVersion=0.28.5+1.15 fabricVersion=0.32.5+1.16
kotlinVersion=1.3.60 kotlinVersion=1.3.60
fabricKotlinVersion=1.5.0+kotlin.1.4.31 fabricKotlinVersion=1.5.0+kotlin.1.4.31
clothConfigVersion=2.14.2 clothConfigVersion=4.11.24
modMenuVersion=1.10.6 modMenuVersion=1.16.9
fiberVersion=0.8.0-2 fiberVersion=0.8.0-2

View File

@@ -1,6 +1,7 @@
package mods.betterfoliage.mixin; package mods.betterfoliage.mixin;
import mods.betterfoliage.Hooks; import mods.betterfoliage.Hooks;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@@ -14,10 +15,11 @@ import org.spongepowered.asm.mixin.injection.Redirect;
* *
* Needed to avoid excessive darkening of Round Logs at the corners, now that they are not full blocks. * Needed to avoid excessive darkening of Round Logs at the corners, now that they are not full blocks.
*/ */
@Mixin(BlockState.class) @Mixin(AbstractBlock.AbstractBlockState.class)
@SuppressWarnings({"UnnecessaryQualifiedMemberReference", "deprecation"}) @SuppressWarnings({"deprecation"})
public class MixinBlockState { public class MixinBlockState {
private static final String callFrom = "Lnet/minecraft/block/BlockState;getAmbientOcclusionLightLevel(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)F"; private static final String callFrom = "Lnet/minecraft/block/AbstractBlock$AbstractBlockState;getAmbientOcclusionLightLevel(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)F";
// why is the INVOKEVIRTUAL target class Block in the bytecode, not AbstractBlock?
private static final String callTo = "Lnet/minecraft/block/Block;getAmbientOcclusionLightLevel(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)F"; private static final String callTo = "Lnet/minecraft/block/Block;getAmbientOcclusionLightLevel(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)F";
@Redirect(method = callFrom, at = @At(value = "INVOKE", target = callTo)) @Redirect(method = callFrom, at = @At(value = "INVOKE", target = callTo))

View File

@@ -3,10 +3,10 @@ package mods.betterfoliage.mixin;
import mods.betterfoliage.ClientChunkLoadCallback; import mods.betterfoliage.ClientChunkLoadCallback;
import net.minecraft.client.world.ClientChunkManager; import net.minecraft.client.world.ClientChunkManager;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.world.World;
import net.minecraft.world.biome.source.BiomeArray; import net.minecraft.world.biome.source.BiomeArray;
import net.minecraft.world.chunk.WorldChunk; import net.minecraft.world.chunk.WorldChunk;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@@ -15,10 +15,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ClientChunkManager.class) @Mixin(ClientChunkManager.class)
public class MixinClientChunkManager { public class MixinClientChunkManager {
private static final String onLoadChunkFromPacket = "loadChunkFromPacket(IILnet/minecraft/world/biome/source/BiomeArray;Lnet/minecraft/util/PacketByteBuf;Lnet/minecraft/nbt/CompoundTag;I)Lnet/minecraft/world/chunk/WorldChunk;"; private static final String onLoadChunkFromPacket = "Lnet/minecraft/client/world/ClientChunkManager;loadChunkFromPacket(IILnet/minecraft/world/biome/source/BiomeArray;Lnet/minecraft/network/PacketByteBuf;Lnet/minecraft/nbt/CompoundTag;IZ)Lnet/minecraft/world/chunk/WorldChunk;";
@Inject(method = onLoadChunkFromPacket, at = @At(value = "RETURN", ordinal = 2)) @Inject(method = onLoadChunkFromPacket, at = @At(value = "RETURN", ordinal = 2))
void onLoadChunkFromPacket(int chunkX, int chunkZ, BiomeArray biomeArray, PacketByteBuf data, CompoundTag nbt, int updatedSectionsBits, CallbackInfoReturnable<WorldChunk> ci) { void onLoadChunkFromPacket(int x, int z, @Nullable BiomeArray biomes, PacketByteBuf buf, CompoundTag tag, int verticalStripBitmask, boolean complete, CallbackInfoReturnable<WorldChunk> ci) {
ClientChunkLoadCallback.EVENT.invoker().loadChunk(ci.getReturnValue()); ClientChunkLoadCallback.EVENT.invoker().loadChunk(ci.getReturnValue());
} }
} }

View File

@@ -8,6 +8,8 @@ import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.profiler.Profiler; import net.minecraft.util.profiler.Profiler;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.level.LevelInfo; import net.minecraft.world.level.LevelInfo;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -16,12 +18,13 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Random; import java.util.Random;
import java.util.function.Supplier;
@Mixin(ClientWorld.class) @Mixin(ClientWorld.class)
public class MixinClientWorld { public class MixinClientWorld {
private static final String ctor = "<init>(Lnet/minecraft/client/network/ClientPlayNetworkHandler;Lnet/minecraft/world/level/LevelInfo;Lnet/minecraft/world/dimension/DimensionType;ILnet/minecraft/util/profiler/Profiler;Lnet/minecraft/client/render/WorldRenderer;)V"; private static final String ctor = "Lnet/minecraft/client/world/ClientWorld;<init>(Lnet/minecraft/client/network/ClientPlayNetworkHandler;Lnet/minecraft/client/world/ClientWorld$Properties;Lnet/minecraft/util/registry/RegistryKey;Lnet/minecraft/world/dimension/DimensionType;ILjava/util/function/Supplier;Lnet/minecraft/client/render/WorldRenderer;ZJ)V";
private static final String checkBlockRender = "Lnet/minecraft/client/world/ClientWorld;checkBlockRerender(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;)V"; private static final String scheduleBlockRerenderIfNeeded = "Lnet/minecraft/client/world/ClientWorld;scheduleBlockRerenderIfNeeded(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;)V";
private static final String rendererNotify = "Lnet/minecraft/client/render/WorldRenderer;method_21596(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;)V"; private static final String rendererNotify = "Lnet/minecraft/client/render/WorldRenderer;method_21596(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;)V";
private static final String worldDisplayTick = "randomBlockDisplayTick(IIIILjava/util/Random;ZLnet/minecraft/util/math/BlockPos$Mutable;)V"; private static final String worldDisplayTick = "randomBlockDisplayTick(IIIILjava/util/Random;ZLnet/minecraft/util/math/BlockPos$Mutable;)V";
private static final String blockDisplayTick = "Lnet/minecraft/block/Block;randomDisplayTick(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Ljava/util/Random;)V"; private static final String blockDisplayTick = "Lnet/minecraft/block/Block;randomDisplayTick(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Ljava/util/Random;)V";
@@ -30,13 +33,13 @@ public class MixinClientWorld {
* Inject callback to get notified of client-side blockstate changes. * Inject callback to get notified of client-side blockstate changes.
* Used to invalidate caches in the {@link mods.betterfoliage.chunk.ChunkOverlayManager} * Used to invalidate caches in the {@link mods.betterfoliage.chunk.ChunkOverlayManager}
*/ */
@Inject(method = checkBlockRender, at = @At(value = "HEAD")) @Inject(method = scheduleBlockRerenderIfNeeded, at = @At(value = "HEAD"))
void onClientBlockChanged(BlockPos pos, BlockState oldState, BlockState newState, CallbackInfo ci) { void onClientBlockChanged(BlockPos pos, BlockState oldState, BlockState newState, CallbackInfo ci) {
Hooks.onClientBlockChanged((ClientWorld) (Object) this, pos, oldState, newState); Hooks.onClientBlockChanged((ClientWorld) (Object) this, pos, oldState, newState);
} }
@Inject(method = ctor, at = @At("RETURN")) @Inject(method = ctor, at = @At("RETURN"))
void onClientWorldCreated(ClientPlayNetworkHandler netHandler, LevelInfo levelInfo, DimensionType dimensionType, int i, Profiler profiler, WorldRenderer worldRenderer, CallbackInfo ci) { void onClientWorldCreated(ClientPlayNetworkHandler networkHandler, ClientWorld.Properties properties, RegistryKey<World> registryRef, DimensionType dimensionType, int loadDistance, Supplier<Profiler> profiler, WorldRenderer worldRenderer, boolean debugWorld, long seed, CallbackInfo ci) {
ClientWorldLoadCallback.EVENT.invoker().loadWorld((ClientWorld) (Object) this); ClientWorldLoadCallback.EVENT.invoker().loadWorld((ClientWorld) (Object) this);
} }

View File

@@ -13,6 +13,7 @@ import mods.betterfoliage.resource.discovery.BlockTypeCache
import mods.betterfoliage.resource.generated.GeneratedBlockTexturePack import mods.betterfoliage.resource.generated.GeneratedBlockTexturePack
import net.fabricmc.api.ClientModInitializer import net.fabricmc.api.ClientModInitializer
import net.fabricmc.fabric.api.resource.ResourceManagerHelper import net.fabricmc.fabric.api.resource.ResourceManagerHelper
import net.fabricmc.fabric.mixin.resource.loader.ResourcePackManagerAccessor
import net.fabricmc.loader.api.FabricLoader import net.fabricmc.loader.api.FabricLoader
import net.minecraft.block.BlockState import net.minecraft.block.BlockState
import net.minecraft.client.MinecraftClient import net.minecraft.client.MinecraftClient
@@ -56,7 +57,8 @@ object BetterFoliage : ClientModInitializer {
override fun onInitializeClient() { override fun onInitializeClient() {
// Register generated resource pack // Register generated resource pack
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(generatedPack.reloader) ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(generatedPack.reloader)
MinecraftClient.getInstance().resourcePackManager.registerProvider(generatedPack.finder) (MinecraftClient.getInstance().resourcePackManager as ResourcePackManagerAccessor)
.providers.add(generatedPack.finder)
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(blockConfig) ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(blockConfig)

View File

@@ -2,15 +2,9 @@ package mods.betterfoliage
import it.unimi.dsi.fastutil.ints.IntList import it.unimi.dsi.fastutil.ints.IntList
import mods.betterfoliage.util.YarnHelper import mods.betterfoliage.util.YarnHelper
import net.minecraft.client.render.model.BakedModel
import net.minecraft.client.texture.Sprite import net.minecraft.client.texture.Sprite
import net.minecraft.util.WeightedPicker
import net.minecraft.world.World import net.minecraft.world.World
val WeightedBakedModel_totalWeight = YarnHelper.requiredField<Int>("net.minecraft.class_1097", "field_5433", "I")
val WeightedBakedModel_models = YarnHelper.requiredField<List<WeightedPicker.Entry>>("net.minecraft.class_1097", "field_5434", "Ljava/util/List;")
val WeightedBakedModelEntry_model = YarnHelper.requiredField<BakedModel>("net.minecraft.class_1097\$class_1099", "field_5437", "Lnet/minecraft/class_1087;")
val WeightedPickerEntry_weight = YarnHelper.requiredField<Int>("net.minecraft.class_3549\$class_3550", "field_15774", "I")
val VertexFormat_offsets = YarnHelper.requiredField<IntList>("net.minecraft.class_293", "field_1597", "Lit/unimi/dsi/fastutil/ints/IntList;") val VertexFormat_offsets = YarnHelper.requiredField<IntList>("net.minecraft.class_293", "field_1597", "Lit/unimi/dsi/fastutil/ints/IntList;")
val BakedQuad_sprite = YarnHelper.requiredField<Sprite>("net.minecraft.class_777", "field_4176", "Lnet/minecraft/class_1058;") val BakedQuad_sprite = YarnHelper.requiredField<Sprite>("net.minecraft.class_777", "field_4176", "Lnet/minecraft/class_1058;")
val WorldChunk_world = YarnHelper.requiredField<World>("net.minecraft.class_2818", "field_12858", "Lnet/minecraft/class_1937;") val WorldChunk_world = YarnHelper.requiredField<World>("net.minecraft.class_2818", "field_12858", "Lnet/minecraft/class_1937;")

View File

@@ -52,7 +52,7 @@ fun onRandomDisplayTick(world: ClientWorld, pos: BlockPos) {
world.isAir(pos + Direction.DOWN.offset) && world.isAir(pos + Direction.DOWN.offset) &&
randomD() < BetterFoliage.config.fallingLeaves.chance) { randomD() < BetterFoliage.config.fallingLeaves.chance) {
BetterFoliage.blockTypes.getTyped<LeafParticleKey>(state)?.let { key -> BetterFoliage.blockTypes.getTyped<LeafParticleKey>(state)?.let { key ->
val blockColor = MinecraftClient.getInstance().blockColorMap.getColor(state, world, pos, 0) val blockColor = MinecraftClient.getInstance().blockColors.getColor(state, world, pos, 0)
FallingLeafParticle(world, pos, key, blockColor, random).addIfValid() FallingLeafParticle(world, pos, key, blockColor, random).addIfValid()
} }
} }

View File

@@ -34,7 +34,7 @@ interface BlockCtx {
(world as? WorldView)?.getBiome(pos) ?: (world as? WorldView)?.getBiome(pos) ?:
(world as? ChunkRendererRegion)?.let { ChunkRendererRegion_world[it]?.getBiome(pos) } (world as? ChunkRendererRegion)?.let { ChunkRendererRegion_world[it]?.getBiome(pos) }
val isNormalCube: Boolean get() = state.isSimpleFullBlock(world, pos) val isNormalCube: Boolean get() = state.isOpaqueFullCube(world, pos)
fun shouldSideBeRendered(side: Direction) = Block.shouldDrawSide(state, world, pos, side) fun shouldSideBeRendered(side: Direction) = Block.shouldDrawSide(state, world, pos, side)

View File

@@ -22,8 +22,8 @@ import kotlin.collections.mutableMapOf
import kotlin.collections.set import kotlin.collections.set
val BlockRenderView.dimType: DimensionType get() = when { val BlockRenderView.dimType: DimensionType get() = when {
this is WorldView -> dimension.type this is WorldView -> dimension
this is ChunkRendererRegion -> this[ChunkRendererRegion_world]!!.dimension.type this is ChunkRendererRegion -> this[ChunkRendererRegion_world]!!.dimension
// this.isInstance(ChunkCacheOF) -> this[ChunkCacheOF.chunkCache]!!.dimType // this.isInstance(ChunkCacheOF) -> this[ChunkCacheOF.chunkCache]!!.dimType
else -> throw IllegalArgumentException("DimensionType of world with class ${this::class.qualifiedName} cannot be determined!") else -> throw IllegalArgumentException("DimensionType of world with class ${this::class.qualifiedName} cannot be determined!")
} }

View File

@@ -8,12 +8,16 @@ import me.zeroeightsix.fiber.tree.ConfigLeaf
import me.zeroeightsix.fiber.tree.ConfigNode import me.zeroeightsix.fiber.tree.ConfigNode
import me.zeroeightsix.fiber.tree.ConfigValue import me.zeroeightsix.fiber.tree.ConfigValue
import net.minecraft.client.resource.language.I18n import net.minecraft.client.resource.language.I18n
import net.minecraft.text.LiteralText
import java.util.* import java.util.*
import kotlin.properties.ReadOnlyProperty import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
const val MAX_LINE_LEN = 30 const val MAX_LINE_LEN = 30
fun textify(string: String) = LiteralText(string)
fun textify(strings: Array<String>) = strings.map(::LiteralText).toTypedArray()
sealed class DelegatingConfigNode<N: ConfigLeaf>(val fiberNode: N) { sealed class DelegatingConfigNode<N: ConfigLeaf>(val fiberNode: N) {
abstract fun createClothNode(names: List<String>): AbstractConfigListEntry<*> abstract fun createClothNode(names: List<String>): AbstractConfigListEntry<*>
} }
@@ -24,9 +28,9 @@ open class DelegatingConfigGroup(fiberNode: ConfigNode) : DelegatingConfigNode<C
val children = mutableListOf<DelegatingConfigNode<*>>() val children = mutableListOf<DelegatingConfigNode<*>>()
override fun createClothNode(names: List<String>): SubCategoryListEntry { override fun createClothNode(names: List<String>): SubCategoryListEntry {
val builder = ConfigEntryBuilder.create() val builder = ConfigEntryBuilder.create()
.startSubCategory(names.joinToString(".").translate()) .startSubCategory(textify(names.joinToString(".").translate()))
.setTooltip(*names.joinToString(".").translateTooltip()) .setTooltip(*textify(names.joinToString(".").translateTooltip()))
.setExpended(false) .setExpanded(false)
children.forEach { builder.add(it.createClothNode(names + it.fiberNode.name!!)) } children.forEach { builder.add(it.createClothNode(names + it.fiberNode.name!!)) }
return builder.build() return builder.build()
} }
@@ -85,8 +89,8 @@ fun boolean(
.build() .build()
override fun createClothNode(node: ConfigValue<Boolean>, names: List<String>) = ConfigEntryBuilder.create() override fun createClothNode(node: ConfigValue<Boolean>, names: List<String>) = ConfigEntryBuilder.create()
.startBooleanToggle(langKey(names).translate(), node.value!!) .startBooleanToggle(textify(langKey(names).translate()), node.value!!)
.setTooltip(langKey(names).let { if (I18n.hasTranslation("$it.tooltip")) Optional.of(it.translateTooltip()) else Optional.empty() }) .setTooltip(langKey(names).let { if (I18n.hasTranslation("$it.tooltip")) Optional.of(textify(it.translateTooltip())) else Optional.empty() })
.setSaveConsumer { node.value = valueOverride(it) } .setSaveConsumer { node.value = valueOverride(it) }
.build() .build()
} }
@@ -104,8 +108,8 @@ fun integer(
.build() .build()
override fun createClothNode(node: ConfigValue<Int>, names: List<String>) = ConfigEntryBuilder.create() override fun createClothNode(node: ConfigValue<Int>, names: List<String>) = ConfigEntryBuilder.create()
.startIntField(langKey(names).translate(), node.value!!) .startIntField(textify(langKey(names).translate()), node.value!!)
.setTooltip(langKey(names).let { if (I18n.hasTranslation("$it.tooltip")) Optional.of(it.translateTooltip()) else Optional.empty() }) .setTooltip(langKey(names).let { if (I18n.hasTranslation("$it.tooltip")) Optional.of(textify(it.translateTooltip())) else Optional.empty() })
.setMin(min).setMax(max) .setMin(min).setMax(max)
.setSaveConsumer { node.value = valueOverride(it) } .setSaveConsumer { node.value = valueOverride(it) }
.build() .build()
@@ -124,8 +128,8 @@ fun double(
.build() .build()
override fun createClothNode(node: ConfigValue<Double>, names: List<String>) = ConfigEntryBuilder.create() override fun createClothNode(node: ConfigValue<Double>, names: List<String>) = ConfigEntryBuilder.create()
.startDoubleField(langKey(names).translate(), node.value!!) .startDoubleField(textify(langKey(names).translate()), node.value!!)
.setTooltip(langKey(names).let { if (I18n.hasTranslation("$it.tooltip")) Optional.of(it.translateTooltip()) else Optional.empty() }) .setTooltip(langKey(names).let { if (I18n.hasTranslation("$it.tooltip")) Optional.of(textify(it.translateTooltip())) else Optional.empty() })
.setMin(min).setMax(max) .setMin(min).setMax(max)
.setSaveConsumer { node.value = valueOverride(it) } .setSaveConsumer { node.value = valueOverride(it) }
.build() .build()

View File

@@ -8,6 +8,7 @@ import mods.betterfoliage.resource.discovery.BakeWrapperManager
import net.minecraft.client.MinecraftClient import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.screen.Screen import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.resource.language.I18n import net.minecraft.client.resource.language.I18n
import net.minecraft.text.LiteralText
import java.util.function.Function import java.util.function.Function
object ModMenu : ModMenuApi { object ModMenu : ModMenuApi {
@@ -16,9 +17,9 @@ object ModMenu : ModMenuApi {
override fun getConfigScreenFactory() = Function { screen: Screen -> override fun getConfigScreenFactory() = Function { screen: Screen ->
val builder = ConfigBuilder.create() val builder = ConfigBuilder.create()
.setParentScreen(screen) .setParentScreen(screen)
.setTitle(I18n.translate("betterfoliage.title")) .setTitle(LiteralText(I18n.translate("betterfoliage.title")))
BetterFoliage.config.createClothNode(listOf("betterfoliage")).value.forEach { rootOption -> BetterFoliage.config.createClothNode(listOf("betterfoliage")).value.forEach { rootOption ->
builder.getOrCreateCategory("main").addEntry(rootOption) builder.getOrCreateCategory(LiteralText("main")).addEntry(rootOption)
} }
builder.savingRunnable = Runnable { builder.savingRunnable = Runnable {
JanksonSettings().serialize(BetterFoliage.config.fiberNode, BetterFoliage.configFile.outputStream(), false) JanksonSettings().serialize(BetterFoliage.config.fiberNode, BetterFoliage.configFile.outputStream(), false)

View File

@@ -100,7 +100,7 @@ fun unbakeQuads(model: BakedModel, state: BlockState?, random: Random, unshade:
/** Get the byte offset of the [VertexFormatElement] matching the given criteria */ /** Get the byte offset of the [VertexFormatElement] matching the given criteria */
fun VertexFormat.getByteOffset(type: VertexFormatElement.Type, format: VertexFormatElement.Format, count: Int, index: Int = 0): Int? { fun VertexFormat.getByteOffset(type: VertexFormatElement.Type, format: VertexFormatElement.Format, count: Int, index: Int = 0): Int? {
elements.forEachIndexed { idx, element -> elements.forEachIndexed { idx, element ->
if (element.type == type && element.format == format && element.count == count && element.index == index) if (element == VertexFormatElement(index, format, type, count))
return VertexFormat_offsets[this]!!.getInt(idx) return VertexFormat_offsets[this]!!.getInt(idx)
} }
return null return null

View File

@@ -167,7 +167,7 @@ fun Array<List<Quad>>.withOpposites() = map { it.withOpposites() }.toTypedArray(
* Pour quad data into a fabric-renderer-api Mesh * Pour quad data into a fabric-renderer-api Mesh
*/ */
fun List<Quad>.build(blendMode: BlendMode, noDiffuse: Boolean = false, flatLighting: Boolean = false): Mesh { fun List<Quad>.build(blendMode: BlendMode, noDiffuse: Boolean = false, flatLighting: Boolean = false): Mesh {
val renderer = RendererAccess.INSTANCE.renderer val renderer = RendererAccess.INSTANCE.renderer!!
val material = renderer.materialFinder().blendMode(0, blendMode).disableAo(0, flatLighting).disableDiffuse(0, noDiffuse).find() val material = renderer.materialFinder().blendMode(0, blendMode).disableAo(0, flatLighting).disableDiffuse(0, noDiffuse).find()
val builder = renderer.meshBuilder() val builder = renderer.meshBuilder()
builder.emitter.apply { builder.emitter.apply {

View File

@@ -46,7 +46,7 @@ fun fullCubeTextured(spriteId: Identifier, tintIndex: Int, scrambleUV: Boolean =
.map { if (!scrambleUV) it else it.rotateUV(randomI(max = 4)) } .map { if (!scrambleUV) it else it.rotateUV(randomI(max = 4)) }
.map { it.sprite(sprite) } .map { it.sprite(sprite) }
.map { it.colorIndex(tintIndex) } .map { it.colorIndex(tintIndex) }
.build(BlendMode.SOLID) .build(BlendMode.SOLID, noDiffuse = true)
} }
fun crossModelsRaw(num: Int, size: Double, hOffset: Double, vOffset: Double): Array<List<Quad>> { fun crossModelsRaw(num: Int, size: Double, hOffset: Double, vOffset: Double): Array<List<Quad>> {

View File

@@ -12,7 +12,7 @@ import net.minecraft.client.render.RenderLayers
import net.minecraft.client.render.model.BakedModel import net.minecraft.client.render.model.BakedModel
import net.minecraft.client.render.model.BasicBakedModel import net.minecraft.client.render.model.BasicBakedModel
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import net.minecraft.util.WeightedPicker import net.minecraft.util.collection.WeightedPicker
import net.minecraft.util.math.BlockPos import net.minecraft.util.math.BlockPos
import net.minecraft.world.BlockRenderView import net.minecraft.world.BlockRenderView
import java.util.* import java.util.*

View File

@@ -109,7 +109,7 @@ class StandardGrassModel(wrapped: BakedModel, val key: StandardGrassKey) : Wrapp
Array(64) { fullCubeTextured(key.grassLocation, key.tintIndex) } Array(64) { fullCubeTextured(key.grassLocation, key.tintIndex) }
} }
val snowFullBlockMeshes by LazyInvalidatable(BakeWrapperManager) { val snowFullBlockMeshes by LazyInvalidatable(BakeWrapperManager) {
Array(64) { fullCubeTextured(Identifier("block/snow"), Color.white.asInt) } Array(64) { fullCubeTextured(Identifier("block/snow"), -1) }
} }
} }
} }

View File

@@ -3,7 +3,6 @@ package mods.betterfoliage.render.block.vanilla
import mods.betterfoliage.BetterFoliage import mods.betterfoliage.BetterFoliage
import mods.betterfoliage.model.ModelWrapKey import mods.betterfoliage.model.ModelWrapKey
import mods.betterfoliage.model.meshifySolid import mods.betterfoliage.model.meshifySolid
import mods.betterfoliage.model.meshifyStandard
import mods.betterfoliage.render.column.ColumnBlockKey import mods.betterfoliage.render.column.ColumnBlockKey
import mods.betterfoliage.render.column.ColumnMeshSet import mods.betterfoliage.render.column.ColumnMeshSet
import mods.betterfoliage.render.column.ColumnModelBase import mods.betterfoliage.render.column.ColumnModelBase
@@ -19,7 +18,7 @@ import mods.betterfoliage.util.Atlas
import mods.betterfoliage.util.LazyMap import mods.betterfoliage.util.LazyMap
import mods.betterfoliage.util.tryDefault import mods.betterfoliage.util.tryDefault
import net.minecraft.block.BlockState import net.minecraft.block.BlockState
import net.minecraft.block.LogBlock import net.minecraft.block.PillarBlock
import net.minecraft.client.render.model.BakedModel import net.minecraft.client.render.model.BakedModel
import net.minecraft.client.render.model.BasicBakedModel import net.minecraft.client.render.model.BasicBakedModel
import net.minecraft.util.Identifier import net.minecraft.util.Identifier
@@ -49,7 +48,7 @@ object StandardRoundLogDiscovery : ConfigurableModelDiscovery() {
} }
fun getAxis(state: BlockState): Axis? { fun getAxis(state: BlockState): Axis? {
val axis = tryDefault(null) { state.get(LogBlock.AXIS).toString() } ?: val axis = tryDefault(null) { state.get(PillarBlock.AXIS).toString() } ?:
state.entries.entries.find { it.key.getName().toLowerCase() == "axis" }?.value?.toString() state.entries.entries.find { it.key.getName().toLowerCase() == "axis" }?.value?.toString()
return when (axis) { return when (axis) {
"x" -> Axis.X "x" -> Axis.X

View File

@@ -7,10 +7,11 @@ import net.minecraft.client.render.Camera
import net.minecraft.client.render.VertexConsumer import net.minecraft.client.render.VertexConsumer
import net.minecraft.client.texture.Sprite import net.minecraft.client.texture.Sprite
import net.minecraft.client.util.math.Vector3f import net.minecraft.client.util.math.Vector3f
import net.minecraft.client.world.ClientWorld
import net.minecraft.util.math.MathHelper import net.minecraft.util.math.MathHelper
import net.minecraft.world.World import net.minecraft.world.World
abstract class AbstractParticle(world: World, x: Double, y: Double, z: Double) : SpriteBillboardParticle(world, x, y, z) { abstract class AbstractParticle(world: ClientWorld, x: Double, y: Double, z: Double) : SpriteBillboardParticle(world, x, y, z) {
companion object { companion object {
// @JvmStatic val sin = Array(64) { idx -> Math.sin(PI2 / 64.0 * idx) } // @JvmStatic val sin = Array(64) { idx -> Math.sin(PI2 / 64.0 * idx) }

View File

@@ -11,7 +11,6 @@ import mods.betterfoliage.util.randomD
import mods.betterfoliage.util.randomF import mods.betterfoliage.util.randomF
import mods.betterfoliage.util.randomI import mods.betterfoliage.util.randomI
import net.fabricmc.fabric.api.event.world.WorldTickCallback import net.fabricmc.fabric.api.event.world.WorldTickCallback
import net.minecraft.client.MinecraftClient
import net.minecraft.client.particle.ParticleTextureSheet import net.minecraft.client.particle.ParticleTextureSheet
import net.minecraft.client.world.ClientWorld import net.minecraft.client.world.ClientWorld
import net.minecraft.util.math.BlockPos import net.minecraft.util.math.BlockPos
@@ -23,7 +22,7 @@ import kotlin.math.cos
import kotlin.math.sin import kotlin.math.sin
class FallingLeafParticle( class FallingLeafParticle(
world: World, pos: BlockPos, leaf: LeafParticleKey, blockColor: Int, random: Random world: ClientWorld, pos: BlockPos, leaf: LeafParticleKey, blockColor: Int, random: Random
) : AbstractParticle( ) : AbstractParticle(
world, pos.x.toDouble() + 0.5, pos.y.toDouble(), pos.z.toDouble() + 0.5 world, pos.x.toDouble() + 0.5, pos.y.toDouble(), pos.z.toDouble() + 0.5
) { ) {

View File

@@ -70,7 +70,7 @@ object LeafParticleRegistry : HasLogger(), ClientSpriteRegistryCallback, VeryEar
} }
init { init {
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.PARTICLE_ATLAS_TEX).register(this) ClientSpriteRegistryCallback.event(SpriteAtlasTexture.PARTICLE_ATLAS_TEXTURE).register(this)
} }
} }

View File

@@ -3,20 +3,26 @@ package mods.betterfoliage.render.particle
import mods.betterfoliage.BetterFoliage import mods.betterfoliage.BetterFoliage
import mods.betterfoliage.model.SpriteDelegate import mods.betterfoliage.model.SpriteDelegate
import mods.betterfoliage.model.SpriteSetDelegate import mods.betterfoliage.model.SpriteSetDelegate
import mods.betterfoliage.util.* import mods.betterfoliage.util.Atlas
import mods.betterfoliage.util.Double3
import mods.betterfoliage.util.PI2
import mods.betterfoliage.util.forEachPairIndexed
import mods.betterfoliage.util.randomD
import mods.betterfoliage.util.randomI
import net.minecraft.client.particle.ParticleTextureSheet import net.minecraft.client.particle.ParticleTextureSheet
import net.minecraft.client.render.Camera import net.minecraft.client.render.Camera
import net.minecraft.client.render.VertexConsumer import net.minecraft.client.render.VertexConsumer
import net.minecraft.client.world.ClientWorld
import net.minecraft.util.Identifier import net.minecraft.util.Identifier
import net.minecraft.util.math.BlockPos import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.MathHelper import net.minecraft.util.math.MathHelper
import net.minecraft.world.World import java.util.Deque
import java.util.* import java.util.LinkedList
import kotlin.math.cos import kotlin.math.cos
import kotlin.math.sin import kotlin.math.sin
class RisingSoulParticle( class RisingSoulParticle(
world: World, pos: BlockPos world: ClientWorld, pos: BlockPos
) : AbstractParticle( ) : AbstractParticle(
world, pos.x.toDouble() + 0.5, pos.y.toDouble() + 1.0, pos.z.toDouble() + 0.5 world, pos.x.toDouble() + 0.5, pos.y.toDouble() + 1.0, pos.z.toDouble() + 0.5
) { ) {

View File

@@ -66,7 +66,7 @@ interface ModelBakingKey {
object BakeWrapperManager : HasLogger(), Invalidator, ModelLoadingCallback, ClientSpriteRegistryCallback, BlockModelsReloadCallback { object BakeWrapperManager : HasLogger(), Invalidator, ModelLoadingCallback, ClientSpriteRegistryCallback, BlockModelsReloadCallback {
init { init {
ModelLoadingCallback.EVENT.register(this) ModelLoadingCallback.EVENT.register(this)
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEX).register(this) ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register(this)
} }
val discoverers = mutableListOf<ModelDiscovery>() val discoverers = mutableListOf<ModelDiscovery>()
override val callbacks = mutableListOf<WeakReference<()->Unit>>() override val callbacks = mutableListOf<WeakReference<()->Unit>>()

View File

@@ -4,6 +4,7 @@ import com.google.common.base.Joiner
import mods.betterfoliage.util.HasLogger import mods.betterfoliage.util.HasLogger
import mods.betterfoliage.util.YarnHelper import mods.betterfoliage.util.YarnHelper
import mods.betterfoliage.util.get import mods.betterfoliage.util.get
import net.minecraft.block.Block
import net.minecraft.client.render.block.BlockModels import net.minecraft.client.render.block.BlockModels
import net.minecraft.client.render.model.ModelLoader import net.minecraft.client.render.model.ModelLoader
import net.minecraft.client.render.model.json.JsonUnbakedModel import net.minecraft.client.render.model.json.JsonUnbakedModel
@@ -19,7 +20,7 @@ abstract class AbstractModelDiscovery : HasLogger(), ModelDiscovery {
sprites: MutableSet<Identifier>, sprites: MutableSet<Identifier>,
replacements: MutableMap<Identifier, ModelBakingKey> replacements: MutableMap<Identifier, ModelBakingKey>
) { ) {
Registry.BLOCK (Registry.BLOCK as Iterable<Block>)
.flatMap { block -> block.stateManager.states } .flatMap { block -> block.stateManager.states }
.forEach { state -> .forEach { state ->
val location = BlockModels.getModelId(state) val location = BlockModels.getModelId(state)

View File

@@ -3,24 +3,20 @@ package mods.betterfoliage.resource.generated
import mods.betterfoliage.util.Atlas import mods.betterfoliage.util.Atlas
import mods.betterfoliage.util.HasLogger import mods.betterfoliage.util.HasLogger
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener
import net.minecraft.client.resource.ClientResourcePackProfile
import net.minecraft.resource.* import net.minecraft.resource.*
import net.minecraft.resource.ResourceType.CLIENT_RESOURCES import net.minecraft.resource.ResourceType.CLIENT_RESOURCES
import net.minecraft.resource.metadata.ResourceMetadataReader import net.minecraft.resource.metadata.ResourceMetadataReader
import net.minecraft.text.LiteralText import net.minecraft.text.LiteralText
import net.minecraft.util.Identifier import net.minecraft.util.Identifier
import net.minecraft.util.profiler.Profiler import net.minecraft.util.profiler.Profiler
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.Level.INFO import org.apache.logging.log4j.Level.INFO
import org.apache.logging.log4j.Logger
import java.io.IOException import java.io.IOException
import java.lang.IllegalStateException
import java.util.* import java.util.*
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutionException import java.util.concurrent.ExecutionException
import java.util.concurrent.Executor import java.util.concurrent.Executor
import java.util.function.Consumer
import java.util.function.Predicate import java.util.function.Predicate
import java.util.function.Supplier
/** /**
* [ResourcePack] containing generated block textures * [ResourcePack] containing generated block textures
@@ -69,21 +65,18 @@ class GeneratedBlockTexturePack(
type == CLIENT_RESOURCES && resources.containsKey(id) type == CLIENT_RESOURCES && resources.containsKey(id)
/** /**
* Supplier for this resource pack. Adds pack as always-on and hidden. * Provider for this resource pack. Adds pack as always-on and hidden.
*/ */
val finder = object : ResourcePackProvider { val finder = object : ResourcePackProvider {
val packInfo = ClientResourcePackProfile( val packInfo = ResourcePackProfile(
packName, true, Supplier { this@GeneratedBlockTexturePack }, packName, true, { this@GeneratedBlockTexturePack },
LiteralText(packName), LiteralText(packName),
LiteralText(packDesc), LiteralText(packDesc),
ResourcePackCompatibility.COMPATIBLE, ResourcePackProfile.InsertionPosition.TOP, true, null ResourcePackCompatibility.COMPATIBLE, ResourcePackProfile.InsertionPosition.TOP, true, null
) )
override fun <T : ResourcePackProfile> register( override fun register(consumer: Consumer<ResourcePackProfile>, factory: ResourcePackProfile.Factory) {
registry: MutableMap<String, T>, consumer.accept(packInfo)
factory: ResourcePackProfile.Factory<T>
) {
(registry as MutableMap<String, ResourcePackProfile>)[reloadId.toString()] = packInfo
} }
} }

View File

@@ -73,9 +73,9 @@ data class Double3(var x: Double, var y: Double, var z: Double) {
/** Rotate vector by the given [Quaternion] */ /** Rotate vector by the given [Quaternion] */
fun rotate(quat: Quaternion) = fun rotate(quat: Quaternion) =
quat.copy() quat.copy()
.apply { hamiltonProduct(Quaternion(x.toFloat(), y.toFloat(), z.toFloat(), 0.0F)) } .apply { hamiltonProduct(Quaternion(this@Double3.x.toFloat(), this@Double3.y.toFloat(), this@Double3.z.toFloat(), 0.0F)) }
.apply { hamiltonProduct(quat.copy().apply(Quaternion::conjugate)) } .apply { hamiltonProduct(quat.copy().apply(Quaternion::conjugate)) }
.let { Double3(it.b, it.c, it.d) } .let { Double3(it.x, it.y, it.z) }
// mutable operations // mutable operations
fun setTo(other: Double3): Double3 { x = other.x; y = other.y; z = other.z; return this } fun setTo(other: Double3): Double3 { x = other.x; y = other.y; z = other.z; return this }

View File

@@ -8,8 +8,6 @@ import net.minecraft.util.Formatting
import net.minecraft.util.Identifier import net.minecraft.util.Identifier
import net.minecraft.util.math.BlockPos import net.minecraft.util.math.BlockPos
import net.minecraft.world.World import net.minecraft.world.World
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.Logger
import java.lang.Math.* import java.lang.Math.*
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
@@ -71,6 +69,6 @@ abstract class HasLogger {
} }
fun textComponent(msg: String, color: Formatting = Formatting.GRAY): LiteralText { fun textComponent(msg: String, color: Formatting = Formatting.GRAY): LiteralText {
val style = Style().apply { this.color = color } val style = Style.EMPTY.withColor(color)
return LiteralText(msg).apply { this.style = style } return LiteralText(msg).apply { this.style = style }
} }

View File

@@ -18,8 +18,8 @@ import javax.imageio.ImageIO
import kotlin.math.atan2 import kotlin.math.atan2
enum class Atlas(val resourceId: Identifier) { enum class Atlas(val resourceId: Identifier) {
BLOCKS(SpriteAtlasTexture.BLOCK_ATLAS_TEX), BLOCKS(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE),
PARTICLES(SpriteAtlasTexture.PARTICLE_ATLAS_TEX); PARTICLES(SpriteAtlasTexture.PARTICLE_ATLAS_TEXTURE);
/** Get the fully-qualified resource name for sprites belonging to this atlas */ /** Get the fully-qualified resource name for sprites belonging to this atlas */
fun file(resource: Identifier) = Identifier(resource.namespace, "textures/${resource.path}.png") fun file(resource: Identifier) = Identifier(resource.namespace, "textures/${resource.path}.png")
@@ -62,7 +62,7 @@ val Sprite.averageColor: HSB get() {
var sumBrightness = 0.0f var sumBrightness = 0.0f
for (x in 0 until width) for (x in 0 until width)
for (y in 0 until height) { for (y in 0 until height) {
val pixel = this[Sprite_images]!![0].getPixelRgba(x, y) val pixel = this[Sprite_images]!![0].getPixelColor(x, y)
val alpha = (pixel shr 24) and 255 val alpha = (pixel shr 24) and 255
val hsb = HSB.fromColor(pixel) val hsb = HSB.fromColor(pixel)
if (alpha == 255) { if (alpha == 255) {

View File

@@ -18,7 +18,7 @@ import net.minecraft.util.math.Direction
val AoCalculator_computeFace = YarnHelper.requiredMethod<Any>( val AoCalculator_computeFace = YarnHelper.requiredMethod<Any>(
"net.fabricmc.fabric.impl.client.indigo.renderer.aocalc.AoCalculator", "computeFace", "net.fabricmc.fabric.impl.client.indigo.renderer.aocalc.AoCalculator", "computeFace",
"(Lnet/minecraft/util/math/Direction;Z)Lnet/fabricmc/fabric/impl/client/indigo/renderer/aocalc/AoFaceData;" "(Lnet/minecraft/util/math/Direction;ZZ)Lnet/fabricmc/fabric/impl/client/indigo/renderer/aocalc/AoFaceData;"
) )
val AoFaceData_toArray = YarnHelper.requiredMethod<Unit>( val AoFaceData_toArray = YarnHelper.requiredMethod<Unit>(
"net.fabricmc.fabric.impl.client.indigo.renderer.aocalc.AoFaceData", "toArray", "net.fabricmc.fabric.impl.client.indigo.renderer.aocalc.AoFaceData", "toArray",
@@ -78,7 +78,7 @@ open class ModifiedTerrainMeshConsumer(
override fun fillAoData(lightFace: Direction) { override fun fillAoData(lightFace: Direction) {
if (!aoValid[lightFace.ordinal]) { if (!aoValid[lightFace.ordinal]) {
AoFaceData_toArray.invoke( AoFaceData_toArray.invoke(
AoCalculator_computeFace.invoke(aoCalc, lightFace, true), AoCalculator_computeFace.invoke(aoCalc, lightFace, true, false),
aoFull, aoFull,
lightFull, lightFull,
cornerDirFromAo[lightFace.ordinal] cornerDirFromAo[lightFace.ordinal]

View File

@@ -42,6 +42,6 @@
"fabricloader": ">=0.11.3", "fabricloader": ">=0.11.3",
"fabric": "*", "fabric": "*",
"fabric-language-kotlin": "*", "fabric-language-kotlin": "*",
"minecraft": "1.15.2" "minecraft": "1.16.5"
} }
} }