-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
147 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...in/java/net/frozenblock/lib/block/api/entity/BlockEntityWithoutLevelRendererRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...a/net/frozenblock/lib/block/mixin/entity/client/BlockEntityWithoutLevelRendererMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters