minecraft-src/net/minecraft/client/renderer/entity/ThrownItemRenderer.java
2025-07-04 01:41:11 +03:00

55 lines
2.1 KiB
Java

package net.minecraft.client.renderer.entity;
import com.mojang.blaze3d.vertex.PoseStack;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.ItemSupplier;
import net.minecraft.world.item.ItemDisplayContext;
@Environment(EnvType.CLIENT)
public class ThrownItemRenderer<T extends Entity & ItemSupplier> extends EntityRenderer<T> {
private static final float MIN_CAMERA_DISTANCE_SQUARED = 12.25F;
private final ItemRenderer itemRenderer;
private final float scale;
private final boolean fullBright;
public ThrownItemRenderer(EntityRendererProvider.Context context, float scale, boolean fullBright) {
super(context);
this.itemRenderer = context.getItemRenderer();
this.scale = scale;
this.fullBright = fullBright;
}
public ThrownItemRenderer(EntityRendererProvider.Context context) {
this(context, 1.0F, false);
}
@Override
protected int getBlockLightLevel(T entity, BlockPos pos) {
return this.fullBright ? 15 : super.getBlockLightLevel(entity, pos);
}
@Override
public void render(T entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if (entity.tickCount >= 2 || !(this.entityRenderDispatcher.camera.getEntity().distanceToSqr(entity) < 12.25)) {
poseStack.pushPose();
poseStack.scale(this.scale, this.scale, this.scale);
poseStack.mulPose(this.entityRenderDispatcher.cameraOrientation());
this.itemRenderer
.renderStatic(entity.getItem(), ItemDisplayContext.GROUND, packedLight, OverlayTexture.NO_OVERLAY, poseStack, bufferSource, entity.level(), entity.getId());
poseStack.popPose();
super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
}
}
@Override
public ResourceLocation getTextureLocation(Entity entity) {
return TextureAtlas.LOCATION_BLOCKS;
}
}