Skip to content

Commit

Permalink
Merge branch '1.20.2' into 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Jun 25, 2024
2 parents b19d49c + b26ce20 commit 03b1e9d
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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, BlockEntity> 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<BlockEntity> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<Boolean> original,
@Share("frozenLib$block") LocalRef<Block> 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<Boolean> original,
@Share("frozenLib$block") LocalRef<Block> customBlock
) {
blockEntity = BlockEntityWithoutLevelRendererRegistry.getBlockEntity(customBlock.get()).orElse(blockEntity);
return original.call(instance, blockEntity, poseStack, bufferSource, packedLight, packedOverlay);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/mixin/frozenlib.block.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}

0 comments on commit 03b1e9d

Please sign in to comment.