diff --git a/CHANGELOG.md b/CHANGELOG.md index ea39c0546..08325f735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,4 +5,6 @@ Make sure to clear this after each release Put changelog here: ----------------- -- Configs now save after the game loads to ensure they're loaded properly. +- Optimized getting of `useWindOnNonFrozenServers` +- Added the `BlockEntityWithoutLevelRendererRegistry` to make rendering of items using Block Entities easier. +- Fixed removable tags causing ItemStacks to remain unstackable after said tags have been removed. diff --git a/build.gradle.kts b/build.gradle.kts index fb774eb1a..31aadda3f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -253,7 +253,7 @@ dependencies { modApi("com.terraformersmc:modmenu:${modmenu_version}") // Cloth Config - modApi("me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}") { + modCompileOnlyApi("me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}") { exclude(group = "net.fabricmc.fabric-api") exclude(group = "com.terraformersmc") } diff --git a/gradle.properties b/gradle.properties index 9a9471d5c..5e9c78e81 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ min_loader_version=0.15.10 # Mod Properties - mod_version = 1.7.3 + mod_version = 1.7.4 mod_loader = Fabric maven_group = net.frozenblock archives_base_name = FrozenLib diff --git a/src/main/java/net/frozenblock/lib/block/api/entity/BlockEntityWithoutLevelRendererRegistry.java b/src/main/java/net/frozenblock/lib/block/api/entity/BlockEntityWithoutLevelRendererRegistry.java new file mode 100644 index 000000000..388e94591 --- /dev/null +++ b/src/main/java/net/frozenblock/lib/block/api/entity/BlockEntityWithoutLevelRendererRegistry.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2024 FrozenBlock + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.frozenblock.lib.block.api.entity; + +import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import org.jetbrains.annotations.NotNull; +import java.util.Optional; + +public class BlockEntityWithoutLevelRendererRegistry { + private static final Object2ObjectLinkedOpenHashMap BLOCK_TO_BLOCK_ENTITY_MAP = new Object2ObjectLinkedOpenHashMap<>(); + + public static void register(Block block, @NotNull BlockEntityType blockEntityType) { + BLOCK_TO_BLOCK_ENTITY_MAP.put(block, blockEntityType.create(BlockPos.ZERO, block.defaultBlockState())); + } + + public static Optional getBlockEntity(Block block) { + return Optional.ofNullable(BLOCK_TO_BLOCK_ENTITY_MAP.get(block)); + } + + public static boolean hasBlock(Block block) { + return BLOCK_TO_BLOCK_ENTITY_MAP.containsKey(block); + } + +} diff --git a/src/main/java/net/frozenblock/lib/block/mixin/entity/client/BlockEntityWithoutLevelRendererMixin.java b/src/main/java/net/frozenblock/lib/block/mixin/entity/client/BlockEntityWithoutLevelRendererMixin.java new file mode 100644 index 000000000..230165091 --- /dev/null +++ b/src/main/java/net/frozenblock/lib/block/mixin/entity/client/BlockEntityWithoutLevelRendererMixin.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2024 FrozenBlock + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.frozenblock.lib.block.mixin.entity.client; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; +import com.mojang.blaze3d.vertex.PoseStack; +import net.frozenblock.lib.block.api.entity.BlockEntityWithoutLevelRendererRegistry; +import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Slice; + +@Mixin(BlockEntityWithoutLevelRenderer.class) +public class BlockEntityWithoutLevelRendererMixin { + + @WrapOperation( + method = "renderByItem", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z", + ordinal = 0 + ), + slice = @Slice( + from = @At( + value = "FIELD", + target = "Lnet/minecraft/world/level/block/Blocks;CONDUIT:Lnet/minecraft/world/level/block/Block;" + ) + ) + ) + public boolean frozenLib$selectBlockEntity( + BlockState instance, Block block, Operation original, + @Share("frozenLib$block") LocalRef customBlock + ) { + Block usedBlock = instance.getBlock(); + customBlock.set(usedBlock); + return original.call(instance, block) || BlockEntityWithoutLevelRendererRegistry.hasBlock(usedBlock); + } + + @WrapOperation( + method = "renderByItem", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderDispatcher;renderItem(Lnet/minecraft/world/level/block/entity/BlockEntity;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;II)Z", + ordinal = 0 + ) + ) + public boolean frozenLib$replaceWithNewBlockEntity( + BlockEntityRenderDispatcher instance, BlockEntity blockEntity, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, int packedOverlay, Operation original, + @Share("frozenLib$block") LocalRef customBlock + ) { + blockEntity = BlockEntityWithoutLevelRendererRegistry.getBlockEntity(customBlock.get()).orElse(blockEntity); + return original.call(instance, blockEntity, poseStack, bufferSource, packedLight, packedOverlay); + } + +} diff --git a/src/main/java/net/frozenblock/lib/config/frozenlib_config/FrozenLibConfig.java b/src/main/java/net/frozenblock/lib/config/frozenlib_config/FrozenLibConfig.java index 6cab5a82c..da4bc3adb 100644 --- a/src/main/java/net/frozenblock/lib/config/frozenlib_config/FrozenLibConfig.java +++ b/src/main/java/net/frozenblock/lib/config/frozenlib_config/FrozenLibConfig.java @@ -40,9 +40,23 @@ public class FrozenLibConfig { true, QuiltDataFixes.buildFixer(new QuiltDataFixerBuilder(0)), 0 - ) + ) { + @Override + public void onSave() throws Exception { + super.onSave(); + this.onSync(null); + } + + @Override + public void onSync(FrozenLibConfig syncInstance) { + var config = this.config(); + USE_WIND_ON_NON_FROZEN_SERVERS = config.useWindOnNonFrozenServers; + } + } ); + public static volatile boolean USE_WIND_ON_NON_FROZEN_SERVERS = true; + @Comment("Mods may override any of these options, but the config file will not change.") @EntrySyncData(value = "useWindOnNonFrozenServers", behavior = SyncBehavior.UNSYNCABLE) diff --git a/src/main/java/net/frozenblock/lib/wind/api/ClientWindManager.java b/src/main/java/net/frozenblock/lib/wind/api/ClientWindManager.java index 7a0d760ab..dda0c3ce3 100644 --- a/src/main/java/net/frozenblock/lib/wind/api/ClientWindManager.java +++ b/src/main/java/net/frozenblock/lib/wind/api/ClientWindManager.java @@ -128,7 +128,7 @@ public static double getWindZ(float partialTick) { } public static boolean shouldUseWind() { - return hasInitialized || FrozenLibConfig.get().useWindOnNonFrozenServers; + return hasInitialized || FrozenLibConfig.USE_WIND_ON_NON_FROZEN_SERVERS; } public static void tick(@NotNull ClientLevel level) { @@ -162,7 +162,7 @@ public static void tick(@NotNull ClientLevel level) { extension.clientTick(); } - if (!hasInitialized && time > 80D && FrozenLibConfig.get().useWindOnNonFrozenServers) { + if (!hasInitialized && time > 80D && FrozenLibConfig.USE_WIND_ON_NON_FROZEN_SERVERS) { RandomSource randomSource = AdvancedMath.random(); setSeed(randomSource.nextLong()); time = randomSource.nextLong(); diff --git a/src/main/resources/mixin/frozenlib.block.mixins.json b/src/main/resources/mixin/frozenlib.block.mixins.json index afd63bf63..e52d87162 100644 --- a/src/main/resources/mixin/frozenlib.block.mixins.json +++ b/src/main/resources/mixin/frozenlib.block.mixins.json @@ -4,10 +4,13 @@ "package": "net.frozenblock.lib.block.mixin", "compatibilityLevel": "JAVA_17", "injectors": { - "defaultRequire": 1 + "defaultRequire": 1 }, "mixins": [ "dripstone.PointedDripstoneBlockMixin", "tick.BlockBehaviourMixin" + ], + "client": [ + "entity.client.BlockEntityWithoutLevelRendererMixin" ] }