yeah a BE was the way to go
This commit is contained in:
parent
88a0234cec
commit
99e32ac84e
10 changed files with 150 additions and 84 deletions
|
@ -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<BakedModel> variants;
|
||||
private final BakedModel wrapped;
|
||||
|
||||
public GaslightingModel(List<BakedModel> variants) {
|
||||
this.variants = variants;
|
||||
this.wrapped = this.variants.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> 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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<BakedModel> 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<ResourceLocation, BakedModel> map) {
|
||||
var quenchedName = new ModelResourceLocation(modLoc("quenched_allay"), "");
|
||||
var variants = new ArrayList<BakedModel>(BlockQuenchedAllay.VARIANTS);
|
||||
for (int i = 0; i < BlockQuenchedAllay.VARIANTS; i++) {
|
||||
var variantLoc = modLoc("block/quenched_allay_" + i);
|
||||
variants.add(map.get(variantLoc));
|
||||
}
|
||||
map.put(quenchedName, new GaslightingModel(variants));
|
||||
var model = map.get(variantLoc);
|
||||
QUENCHED_ALLAY_VARIANTS.add(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<BlockEntityQuenchedAllay> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
|
@ -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<BlockEntityQuenchedAllay> QUENCHED_ALLAY_TILE = register(
|
||||
"quenched_allay_tile", BlockEntityQuenchedAllay::new, HexBlocks.QUENCHED_ALLAY);
|
||||
|
||||
private static <T extends BlockEntity> BlockEntityType<T> register(String id,
|
||||
BiFunction<BlockPos, BlockState, T> func, Block... blocks) {
|
||||
var ret = IXplatAbstractions.INSTANCE.createBlockEntityType(func, blocks);
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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<BlockRenderDispatcher> hex$getBlockRenderDispatcher();
|
||||
}
|
|
@ -19,6 +19,7 @@
|
|||
"accessor.CriteriaTriggersAccessor"
|
||||
],
|
||||
"client": [
|
||||
"accessor.client.AccessorBlockEntityRenderDispatcher",
|
||||
"accessor.client.AccessorCompositeRenderType",
|
||||
"accessor.client.AccessorEmptyTextureStateShard",
|
||||
"accessor.client.AccessorMouseHandler",
|
||||
|
|
Loading…
Reference in a new issue