diff --git a/Common/src/main/java/at/petrak/hexcasting/GaslightingModel.java b/Common/src/main/java/at/petrak/hexcasting/GaslightingModel.java deleted file mode 100644 index e3b72b8d..00000000 --- a/Common/src/main/java/at/petrak/hexcasting/GaslightingModel.java +++ /dev/null @@ -1,69 +0,0 @@ -package at.petrak.hexcasting; - -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.block.model.ItemOverrides; -import net.minecraft.client.renderer.block.model.ItemTransforms; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.core.Direction; -import net.minecraft.util.RandomSource; -import net.minecraft.world.level.block.state.BlockState; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class GaslightingModel implements BakedModel { - private static int GASLIGHTING_AMOUNT = 0; - private static boolean HAS_RENDERED_THIS_FRAME = false; - - private final List variants; - private final BakedModel wrapped; - - public GaslightingModel(List variants) { - this.variants = variants; - this.wrapped = this.variants.get(0); - } - - @Override - public List getQuads(@Nullable BlockState state, @Nullable Direction direction, RandomSource random) { - HAS_RENDERED_THIS_FRAME = true; - - var idx = Math.abs(GASLIGHTING_AMOUNT % this.variants.size()); - return this.variants.get(idx).getQuads(state, direction, random); - } - - public boolean useAmbientOcclusion() { - return this.wrapped.useAmbientOcclusion(); - } - - public boolean isGui3d() { - return this.wrapped.isGui3d(); - } - - public boolean usesBlockLight() { - return this.wrapped.usesBlockLight(); - } - - public boolean isCustomRenderer() { - return this.wrapped.isCustomRenderer(); - } - - public TextureAtlasSprite getParticleIcon() { - return this.wrapped.getParticleIcon(); - } - - public ItemTransforms getTransforms() { - return this.wrapped.getTransforms(); - } - - public ItemOverrides getOverrides() { - return this.wrapped.getOverrides(); - } - - public static void postFrameCheckRendered() { - if (!HAS_RENDERED_THIS_FRAME) { - GASLIGHTING_AMOUNT += 1; - } - HAS_RENDERED_THIS_FRAME = false; - } -} diff --git a/Common/src/main/java/at/petrak/hexcasting/client/ClientTickCounter.java b/Common/src/main/java/at/petrak/hexcasting/client/ClientTickCounter.java index a0728ec3..c4f42d02 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/ClientTickCounter.java +++ b/Common/src/main/java/at/petrak/hexcasting/client/ClientTickCounter.java @@ -1,6 +1,6 @@ package at.petrak.hexcasting.client; -import at.petrak.hexcasting.GaslightingModel; +import at.petrak.hexcasting.client.be.BlockEntityQuenchedAllayRenderer; import net.minecraft.client.Minecraft; public class ClientTickCounter { @@ -19,7 +19,7 @@ public class ClientTickCounter { if (!Minecraft.getInstance().isPaused()) { ++ticksInGame; partialTicks = 0.0F; - GaslightingModel.postFrameCheckRendered(); + BlockEntityQuenchedAllayRenderer.postFrameCheckRendered(); } } } diff --git a/Common/src/main/java/at/petrak/hexcasting/client/RegisterClientStuff.java b/Common/src/main/java/at/petrak/hexcasting/client/RegisterClientStuff.java index e9e9f3a8..ae6db5e7 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/RegisterClientStuff.java +++ b/Common/src/main/java/at/petrak/hexcasting/client/RegisterClientStuff.java @@ -1,11 +1,11 @@ package at.petrak.hexcasting.client; -import at.petrak.hexcasting.GaslightingModel; import at.petrak.hexcasting.api.item.IotaHolderItem; import at.petrak.hexcasting.api.item.MediaHolderItem; import at.petrak.hexcasting.api.misc.MediaConstants; import at.petrak.hexcasting.api.utils.NBTHelper; import at.petrak.hexcasting.client.be.BlockEntityAkashicBookshelfRenderer; +import at.petrak.hexcasting.client.be.BlockEntityQuenchedAllayRenderer; import at.petrak.hexcasting.client.be.BlockEntitySlateRenderer; import at.petrak.hexcasting.client.entity.WallScrollRenderer; import at.petrak.hexcasting.common.blocks.BlockQuenchedAllay; @@ -27,7 +27,6 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.ModelBakery; -import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.world.item.Item; @@ -38,6 +37,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.function.BiConsumer; @@ -48,6 +48,8 @@ import java.util.function.ToIntFunction; import static at.petrak.hexcasting.api.HexAPI.modLoc; public class RegisterClientStuff { + public static List QUENCHED_ALLAY_VARIANTS = new ArrayList<>(); + public static void init() { registerSealableDataHolderOverrides(HexItems.FOCUS, stack -> HexItems.FOCUS.readIotaTag(stack) != null, @@ -204,6 +206,8 @@ public class RegisterClientStuff { registerer.registerBlockEntityRenderer(HexBlockEntities.SLATE_TILE, BlockEntitySlateRenderer::new); registerer.registerBlockEntityRenderer(HexBlockEntities.AKASHIC_BOOKSHELF_TILE, BlockEntityAkashicBookshelfRenderer::new); + registerer.registerBlockEntityRenderer(HexBlockEntities.QUENCHED_ALLAY_TILE, + BlockEntityQuenchedAllayRenderer::new); } @FunctionalInterface @@ -219,12 +223,10 @@ public class RegisterClientStuff { } public static void onModelBake(ModelBakery loader, Map map) { - var quenchedName = new ModelResourceLocation(modLoc("quenched_allay"), ""); - var variants = new ArrayList(BlockQuenchedAllay.VARIANTS); for (int i = 0; i < BlockQuenchedAllay.VARIANTS; i++) { var variantLoc = modLoc("block/quenched_allay_" + i); - variants.add(map.get(variantLoc)); + var model = map.get(variantLoc); + QUENCHED_ALLAY_VARIANTS.add(model); } - map.put(quenchedName, new GaslightingModel(variants)); } } diff --git a/Common/src/main/java/at/petrak/hexcasting/client/be/BlockEntityQuenchedAllayRenderer.java b/Common/src/main/java/at/petrak/hexcasting/client/be/BlockEntityQuenchedAllayRenderer.java new file mode 100644 index 00000000..fd5ad794 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/client/be/BlockEntityQuenchedAllayRenderer.java @@ -0,0 +1,70 @@ +package at.petrak.hexcasting.client.be; + +import at.petrak.hexcasting.client.RegisterClientStuff; +import at.petrak.hexcasting.common.blocks.BlockQuenchedAllay; +import at.petrak.hexcasting.common.blocks.entity.BlockEntityQuenchedAllay; +import at.petrak.hexcasting.mixin.accessor.client.AccessorBlockEntityRenderDispatcher; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.model.geom.EntityModelSet; +import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.world.item.ItemStack; + +public class BlockEntityQuenchedAllayRenderer implements BlockEntityRenderer { + private static int GASLIGHTING_AMOUNT = 0; + private static boolean HAS_RENDERED_THIS_FRAME = false; + + private final BlockEntityRendererProvider.Context ctx; + + public BlockEntityQuenchedAllayRenderer(BlockEntityRendererProvider.Context ctx) { + this.ctx = ctx; + } + + private static void doRender(BlockRenderDispatcher dispatcher, PoseStack ps, MultiBufferSource bufSource, + int packedLight, int packedOverlay) { + HAS_RENDERED_THIS_FRAME = true; + + var buffer = bufSource.getBuffer(RenderType.translucent()); + var pose = ps.last(); + + var idx = Math.abs(BlockEntityQuenchedAllayRenderer.GASLIGHTING_AMOUNT % BlockQuenchedAllay.VARIANTS); + var model = RegisterClientStuff.QUENCHED_ALLAY_VARIANTS.get(idx); + + dispatcher.getModelRenderer().renderModel(pose, buffer, null, model, 1f, 1f, 1f, packedLight, packedOverlay); + } + + @Override + public void render(BlockEntityQuenchedAllay blockEntity, float partialTick, PoseStack poseStack, + MultiBufferSource bufferSource, int packedLight, int packedOverlay) { + doRender(this.ctx.getBlockRenderDispatcher(), poseStack, bufferSource, packedLight, packedOverlay); + } + + public static void postFrameCheckRendered() { + if (!HAS_RENDERED_THIS_FRAME) { + GASLIGHTING_AMOUNT += 1; + } + HAS_RENDERED_THIS_FRAME = false; + } + + public static class BWELRWrapper extends BlockEntityWithoutLevelRenderer { + private final BlockRenderDispatcher dispatcher; + + public BWELRWrapper(BlockEntityRenderDispatcher blockEntityRenderDispatcher, EntityModelSet entityModelSet) { + super(blockEntityRenderDispatcher, entityModelSet); + this.dispatcher = + ((AccessorBlockEntityRenderDispatcher) blockEntityRenderDispatcher).hex$getBlockRenderDispatcher().get(); + } + + @Override + public void renderByItem(ItemStack stack, ItemTransforms.TransformType transformType, PoseStack poseStack, + MultiBufferSource buffer, int packedLight, int packedOverlay) { + doRender(this.dispatcher, poseStack, buffer, packedLight, packedOverlay); + } + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/BlockQuenchedAllay.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/BlockQuenchedAllay.java index fc9762e1..45fff790 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/BlockQuenchedAllay.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/BlockQuenchedAllay.java @@ -1,11 +1,29 @@ package at.petrak.hexcasting.common.blocks; +import at.petrak.hexcasting.common.blocks.entity.BlockEntityQuenchedAllay; +import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; -public class BlockQuenchedAllay extends Block { +public class BlockQuenchedAllay extends Block implements EntityBlock { public static final int VARIANTS = 4; public BlockQuenchedAllay(Properties properties) { super(properties); } + + @Nullable + @Override + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return new BlockEntityQuenchedAllay(pos, state); + } + + @Override + public RenderShape getRenderShape(BlockState state) { + return RenderShape.INVISIBLE; + } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/entity/BlockEntityQuenchedAllay.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/entity/BlockEntityQuenchedAllay.java new file mode 100644 index 00000000..e43f691f --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/entity/BlockEntityQuenchedAllay.java @@ -0,0 +1,26 @@ +package at.petrak.hexcasting.common.blocks.entity; + +import at.petrak.hexcasting.api.block.HexBlockEntity; +import at.petrak.hexcasting.common.lib.HexBlockEntities; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.block.state.BlockState; + +/** + * No-op BE just to have a BER + */ +public class BlockEntityQuenchedAllay extends HexBlockEntity { + public BlockEntityQuenchedAllay(BlockPos pos, BlockState blockState) { + super(HexBlockEntities.QUENCHED_ALLAY_TILE, pos, blockState); + } + + @Override + protected void saveModData(CompoundTag tag) { + + } + + @Override + protected void loadModData(CompoundTag tag) { + + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexBlockEntities.java b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexBlockEntities.java index 3e0d9894..3d416cdb 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexBlockEntities.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexBlockEntities.java @@ -3,10 +3,7 @@ package at.petrak.hexcasting.common.lib; import at.petrak.hexcasting.api.HexAPI; import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicBookshelf; import at.petrak.hexcasting.common.blocks.circles.BlockEntitySlate; -import at.petrak.hexcasting.common.blocks.entity.BlockEntityConjured; -import at.petrak.hexcasting.common.blocks.entity.BlockEntityLookingImpetus; -import at.petrak.hexcasting.common.blocks.entity.BlockEntityRightClickImpetus; -import at.petrak.hexcasting.common.blocks.entity.BlockEntityStoredPlayerImpetus; +import at.petrak.hexcasting.common.blocks.entity.*; import at.petrak.hexcasting.xplat.IXplatAbstractions; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; @@ -51,6 +48,9 @@ public class HexBlockEntities { "slate_tile", BlockEntitySlate::new, HexBlocks.SLATE); + public static final BlockEntityType QUENCHED_ALLAY_TILE = register( + "quenched_allay_tile", BlockEntityQuenchedAllay::new, HexBlocks.QUENCHED_ALLAY); + private static BlockEntityType register(String id, BiFunction func, Block... blocks) { var ret = IXplatAbstractions.INSTANCE.createBlockEntityType(func, blocks); diff --git a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexBlocks.java b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexBlocks.java index e7fb62da..8e740fab 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexBlocks.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexBlocks.java @@ -147,8 +147,12 @@ public class HexBlocks { public static final BlockAkashicLigature AKASHIC_LIGATURE = blockItem("akashic_connector", new BlockAkashicLigature(akashicWoodyHard().lightLevel(bs -> 4))); - public static final BlockQuenchedAllay QUENCHED_ALLAY = blockItem("quenched_allay", - new BlockQuenchedAllay(BlockBehaviour.Properties.copy(Blocks.AMETHYST_BLOCK))); + // we have to make it emit light because otherwise it occludes itself and is always dark + public static final BlockQuenchedAllay QUENCHED_ALLAY = blockItem("quenched_allay", new BlockQuenchedAllay( + BlockBehaviour.Properties + .copy(Blocks.AMETHYST_BLOCK) + .lightLevel($ -> 4) + .noOcclusion())); // Decoration?! public static final Block SLATE_BLOCK = blockItem("slate_block", new Block(slateish().strength(2f, 4f))); diff --git a/Common/src/main/java/at/petrak/hexcasting/mixin/accessor/client/AccessorBlockEntityRenderDispatcher.java b/Common/src/main/java/at/petrak/hexcasting/mixin/accessor/client/AccessorBlockEntityRenderDispatcher.java new file mode 100644 index 00000000..52294d04 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/mixin/accessor/client/AccessorBlockEntityRenderDispatcher.java @@ -0,0 +1,14 @@ +package at.petrak.hexcasting.mixin.accessor.client; + +import net.minecraft.client.renderer.block.BlockRenderDispatcher; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.function.Supplier; + +@Mixin(BlockEntityRenderDispatcher.class) +public interface AccessorBlockEntityRenderDispatcher { + @Accessor("blockRenderDispatcher") + Supplier hex$getBlockRenderDispatcher(); +} diff --git a/Common/src/main/resources/hexplat.mixins.json b/Common/src/main/resources/hexplat.mixins.json index 24fa76d1..f1deaf26 100644 --- a/Common/src/main/resources/hexplat.mixins.json +++ b/Common/src/main/resources/hexplat.mixins.json @@ -19,6 +19,7 @@ "accessor.CriteriaTriggersAccessor" ], "client": [ + "accessor.client.AccessorBlockEntityRenderDispatcher", "accessor.client.AccessorCompositeRenderType", "accessor.client.AccessorEmptyTextureStateShard", "accessor.client.AccessorMouseHandler",