diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/CustomGunModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/CustomGunModel.java index 08ac11678..afadc0352 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/CustomGunModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/CustomGunModel.java @@ -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 extends GeoModel { + public ResourceLocation getLODModelResource(T animatable) { + return this.getModelResource(animatable); + } + + public ResourceLocation getLODTextureResource(T animatable) { + return this.getTextureResource(animatable); + } + @Override public void applyMolangQueries(AnimationState animationState, double animTime) { Minecraft mc = Minecraft.getInstance(); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Mp5ItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Mp5ItemModel.java index 7315a0db6..940b8c213 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Mp5ItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Mp5ItemModel.java @@ -30,11 +30,21 @@ public class Mp5ItemModel extends CustomGunModel { 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 animationState) { Player player = Minecraft.getInstance().player; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/CustomGunRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/CustomGunRenderer.java index 12c8498c7..de02fbd6a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/CustomGunRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/CustomGunRenderer.java @@ -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 extends GeoItemRenderer { +public class CustomGunRenderer extends GeoItemRenderer { public static final float SCALE_RECIPROCAL = 1.0f / 16.0f; @@ -56,13 +58,39 @@ public class CustomGunRenderer 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 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 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);