144 lines
7.5 KiB
Java
144 lines
7.5 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* it.unimi.dsi.fastutil.ints.Int2IntFunction
|
|
* org.joml.Quaternionfc
|
|
* org.jspecify.annotations.Nullable
|
|
*/
|
|
package net.minecraft.client.renderer.blockentity;
|
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
import com.mojang.math.Axis;
|
|
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
|
import net.minecraft.client.model.ChestModel;
|
|
import net.minecraft.client.model.geom.ModelLayers;
|
|
import net.minecraft.client.renderer.Sheets;
|
|
import net.minecraft.client.renderer.SubmitNodeCollector;
|
|
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
|
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
|
import net.minecraft.client.renderer.blockentity.BrightnessCombiner;
|
|
import net.minecraft.client.renderer.blockentity.state.ChestRenderState;
|
|
import net.minecraft.client.renderer.feature.ModelFeatureRenderer;
|
|
import net.minecraft.client.renderer.rendertype.RenderType;
|
|
import net.minecraft.client.renderer.rendertype.RenderTypes;
|
|
import net.minecraft.client.renderer.state.CameraRenderState;
|
|
import net.minecraft.client.renderer.texture.OverlayTexture;
|
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|
import net.minecraft.client.resources.model.Material;
|
|
import net.minecraft.client.resources.model.MaterialSet;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.util.SpecialDates;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.ChestBlock;
|
|
import net.minecraft.world.level.block.CopperChestBlock;
|
|
import net.minecraft.world.level.block.DoubleBlockCombiner;
|
|
import net.minecraft.world.level.block.WeatheringCopper;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.block.entity.EnderChestBlockEntity;
|
|
import net.minecraft.world.level.block.entity.LidBlockEntity;
|
|
import net.minecraft.world.level.block.entity.TrappedChestBlockEntity;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.properties.ChestType;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import org.joml.Quaternionfc;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
public class ChestRenderer<T extends BlockEntity>
|
|
implements BlockEntityRenderer<T, ChestRenderState> {
|
|
private final MaterialSet materials;
|
|
private final ChestModel singleModel;
|
|
private final ChestModel doubleLeftModel;
|
|
private final ChestModel doubleRightModel;
|
|
private final boolean xmasTextures;
|
|
|
|
public ChestRenderer(BlockEntityRendererProvider.Context context) {
|
|
this.materials = context.materials();
|
|
this.xmasTextures = ChestRenderer.xmasTextures();
|
|
this.singleModel = new ChestModel(context.bakeLayer(ModelLayers.CHEST));
|
|
this.doubleLeftModel = new ChestModel(context.bakeLayer(ModelLayers.DOUBLE_CHEST_LEFT));
|
|
this.doubleRightModel = new ChestModel(context.bakeLayer(ModelLayers.DOUBLE_CHEST_RIGHT));
|
|
}
|
|
|
|
public static boolean xmasTextures() {
|
|
return SpecialDates.isExtendedChristmas();
|
|
}
|
|
|
|
@Override
|
|
public ChestRenderState createRenderState() {
|
|
return new ChestRenderState();
|
|
}
|
|
|
|
@Override
|
|
public void extractRenderState(T blockEntity, ChestRenderState state, float partialTicks, Vec3 cameraPosition, @Nullable ModelFeatureRenderer.CrumblingOverlay breakProgress) {
|
|
DoubleBlockCombiner.NeighborCombineResult<Object> combineResult;
|
|
Block block;
|
|
BlockEntityRenderer.super.extractRenderState(blockEntity, state, partialTicks, cameraPosition, breakProgress);
|
|
boolean hasLevel = ((BlockEntity)blockEntity).getLevel() != null;
|
|
BlockState blockState = hasLevel ? ((BlockEntity)blockEntity).getBlockState() : (BlockState)Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, Direction.SOUTH);
|
|
state.type = blockState.hasProperty(ChestBlock.TYPE) ? blockState.getValue(ChestBlock.TYPE) : ChestType.SINGLE;
|
|
state.angle = blockState.getValue(ChestBlock.FACING).toYRot();
|
|
state.material = this.getChestMaterial((BlockEntity)blockEntity, this.xmasTextures);
|
|
if (hasLevel && (block = blockState.getBlock()) instanceof ChestBlock) {
|
|
ChestBlock chestBlock = (ChestBlock)block;
|
|
combineResult = chestBlock.combine(blockState, ((BlockEntity)blockEntity).getLevel(), ((BlockEntity)blockEntity).getBlockPos(), true);
|
|
} else {
|
|
combineResult = DoubleBlockCombiner.Combiner::acceptNone;
|
|
}
|
|
state.open = combineResult.apply(ChestBlock.opennessCombiner((LidBlockEntity)blockEntity)).get(partialTicks);
|
|
if (state.type != ChestType.SINGLE) {
|
|
state.lightCoords = ((Int2IntFunction)combineResult.apply(new BrightnessCombiner())).applyAsInt(state.lightCoords);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void submit(ChestRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) {
|
|
poseStack.pushPose();
|
|
poseStack.translate(0.5f, 0.5f, 0.5f);
|
|
poseStack.mulPose((Quaternionfc)Axis.YP.rotationDegrees(-state.angle));
|
|
poseStack.translate(-0.5f, -0.5f, -0.5f);
|
|
float open = state.open;
|
|
open = 1.0f - open;
|
|
open = 1.0f - open * open * open;
|
|
Material material = Sheets.chooseMaterial(state.material, state.type);
|
|
RenderType renderType = material.renderType(RenderTypes::entityCutout);
|
|
TextureAtlasSprite sprite = this.materials.get(material);
|
|
if (state.type != ChestType.SINGLE) {
|
|
if (state.type == ChestType.LEFT) {
|
|
submitNodeCollector.submitModel(this.doubleLeftModel, Float.valueOf(open), poseStack, renderType, state.lightCoords, OverlayTexture.NO_OVERLAY, -1, sprite, 0, state.breakProgress);
|
|
} else {
|
|
submitNodeCollector.submitModel(this.doubleRightModel, Float.valueOf(open), poseStack, renderType, state.lightCoords, OverlayTexture.NO_OVERLAY, -1, sprite, 0, state.breakProgress);
|
|
}
|
|
} else {
|
|
submitNodeCollector.submitModel(this.singleModel, Float.valueOf(open), poseStack, renderType, state.lightCoords, OverlayTexture.NO_OVERLAY, -1, sprite, 0, state.breakProgress);
|
|
}
|
|
poseStack.popPose();
|
|
}
|
|
|
|
private ChestRenderState.ChestMaterialType getChestMaterial(BlockEntity entity, boolean xmasTextures) {
|
|
if (entity instanceof EnderChestBlockEntity) {
|
|
return ChestRenderState.ChestMaterialType.ENDER_CHEST;
|
|
}
|
|
if (xmasTextures) {
|
|
return ChestRenderState.ChestMaterialType.CHRISTMAS;
|
|
}
|
|
if (entity instanceof TrappedChestBlockEntity) {
|
|
return ChestRenderState.ChestMaterialType.TRAPPED;
|
|
}
|
|
Block block = entity.getBlockState().getBlock();
|
|
if (block instanceof CopperChestBlock) {
|
|
CopperChestBlock copperChestBlock = (CopperChestBlock)block;
|
|
return switch (copperChestBlock.getState()) {
|
|
default -> throw new MatchException(null, null);
|
|
case WeatheringCopper.WeatherState.UNAFFECTED -> ChestRenderState.ChestMaterialType.COPPER_UNAFFECTED;
|
|
case WeatheringCopper.WeatherState.EXPOSED -> ChestRenderState.ChestMaterialType.COPPER_EXPOSED;
|
|
case WeatheringCopper.WeatherState.WEATHERED -> ChestRenderState.ChestMaterialType.COPPER_WEATHERED;
|
|
case WeatheringCopper.WeatherState.OXIDIZED -> ChestRenderState.ChestMaterialType.COPPER_OXIDIZED;
|
|
};
|
|
}
|
|
return ChestRenderState.ChestMaterialType.REGULAR;
|
|
}
|
|
}
|
|
|