实现LOD模型渲染
This commit is contained in:
parent
bcbf5d7e87
commit
bca2714a78
3 changed files with 50 additions and 3 deletions
|
@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.client.molang.MolangVariable;
|
|||
import com.atsuishio.superbwarfare.data.gun.GunData;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import software.bernie.geckolib.animatable.GeoAnimatable;
|
||||
|
@ -18,6 +19,14 @@ import java.util.function.DoubleSupplier;
|
|||
|
||||
public abstract class CustomGunModel<T extends GunItem & GeoAnimatable> extends GeoModel<T> {
|
||||
|
||||
public ResourceLocation getLODModelResource(T animatable) {
|
||||
return this.getModelResource(animatable);
|
||||
}
|
||||
|
||||
public ResourceLocation getLODTextureResource(T animatable) {
|
||||
return this.getTextureResource(animatable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyMolangQueries(AnimationState<T> animationState, double animTime) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
|
|
|
@ -30,11 +30,21 @@ public class Mp5ItemModel extends CustomGunModel<Mp5Item> {
|
|||
return Mod.loc("geo/mp_5.geo.json");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getLODModelResource(Mp5Item animatable) {
|
||||
return Mod.loc("geo/lod/mp_5.geo.json");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getTextureResource(Mp5Item animatable) {
|
||||
return Mod.loc("textures/item/mp_5.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getLODTextureResource(Mp5Item animatable) {
|
||||
return Mod.loc("textures/item/lod/mp_5.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomAnimations(Mp5Item animatable, long instanceId, AnimationState<Mp5Item> animationState) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package com.atsuishio.superbwarfare.client.renderer;
|
||||
|
||||
import com.atsuishio.superbwarfare.client.model.item.CustomGunModel;
|
||||
import com.atsuishio.superbwarfare.config.client.DisplayConfig;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -19,7 +21,7 @@ import software.bernie.geckolib.renderer.GeoItemRenderer;
|
|||
import software.bernie.geckolib.util.Color;
|
||||
import software.bernie.geckolib.util.RenderUtil;
|
||||
|
||||
public class CustomGunRenderer<T extends Item & GeoAnimatable> extends GeoItemRenderer<T> {
|
||||
public class CustomGunRenderer<T extends GunItem & GeoAnimatable> extends GeoItemRenderer<T> {
|
||||
|
||||
public static final float SCALE_RECIPROCAL = 1.0f / 16.0f;
|
||||
|
||||
|
@ -56,13 +58,39 @@ public class CustomGunRenderer<T extends Item & GeoAnimatable> extends GeoItemRe
|
|||
return RenderType.entityTranslucent(getTextureLocation(animatable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getTextureLocation(T animatable) {
|
||||
var geoModel = getGeoModel();
|
||||
|
||||
if (renderPerspective != ItemDisplayContext.FIRST_PERSON_RIGHT_HAND
|
||||
&& DisplayConfig.ENABLE_GUN_LOD.get()
|
||||
&& geoModel instanceof CustomGunModel<T> gunModel
|
||||
) {
|
||||
return gunModel.getLODTextureResource(animatable);
|
||||
}
|
||||
|
||||
return geoModel.getTextureResource(animatable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultRender(PoseStack poseStack, T animatable, MultiBufferSource bufferSource, @Nullable RenderType renderType, @Nullable VertexConsumer buffer, float yaw, float partialTick, int packedLight) {
|
||||
poseStack.pushPose();
|
||||
|
||||
Color renderColor = getRenderColor(animatable, partialTick, packedLight);
|
||||
int packedOverlay = getPackedOverlay(animatable, 0, partialTick);
|
||||
BakedGeoModel model = getGeoModel().getBakedModel(getGeoModel().getModelResource(animatable));
|
||||
|
||||
ResourceLocation modelLocation;
|
||||
var geoModel = getGeoModel();
|
||||
if (renderPerspective != ItemDisplayContext.FIRST_PERSON_RIGHT_HAND
|
||||
&& DisplayConfig.ENABLE_GUN_LOD.get()
|
||||
&& geoModel instanceof CustomGunModel<T> gunModel
|
||||
) {
|
||||
modelLocation = gunModel.getLODModelResource(animatable);
|
||||
} else {
|
||||
modelLocation = geoModel.getModelResource(animatable);
|
||||
}
|
||||
|
||||
BakedGeoModel model = geoModel.getBakedModel(modelLocation);
|
||||
|
||||
if (renderType == null)
|
||||
renderType = getRenderType(animatable, getTextureLocation(animatable), bufferSource, partialTick);
|
||||
|
|
Loading…
Add table
Reference in a new issue