-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
3,477 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"sources": [ | ||
{ | ||
"type": "minecraft:directory", | ||
"prefix": "", | ||
"source": "shader" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/committee/nova/mods/avaritia/api/client/model/AlphaOverrideVertexConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package committee.nova.mods.avaritia.api.client.model; | ||
|
||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Name: Avaritia-forge / AlphaOverrideVertexConsumer | ||
* Author: cnlimiter | ||
* CreateTime: 2023/9/24 22:41 | ||
* Description: | ||
*/ | ||
|
||
public class AlphaOverrideVertexConsumer implements VertexConsumer { | ||
private final int alpha; | ||
protected final VertexConsumer delegate; | ||
|
||
public AlphaOverrideVertexConsumer(VertexConsumer delegate, int alpha) { | ||
this.delegate = delegate; | ||
this.alpha = alpha; | ||
} | ||
|
||
public AlphaOverrideVertexConsumer(VertexConsumer delegate, double alpha) { | ||
this.delegate = delegate; | ||
this.alpha = (int) (255 * alpha); | ||
} | ||
|
||
@Override | ||
public @NotNull VertexConsumer vertex(double x, double y, double z) { | ||
delegate.vertex(x, y, z); | ||
return this; | ||
} | ||
|
||
@Override | ||
public @NotNull VertexConsumer color(int r, int g, int b, int a) { | ||
delegate.color(r, g, b, alpha); | ||
return this; | ||
} | ||
|
||
@Override | ||
public @NotNull VertexConsumer uv(float u, float v) { | ||
delegate.uv(u, v); | ||
return this; | ||
} | ||
|
||
@Override | ||
public @NotNull VertexConsumer overlayCoords(int u, int v) { | ||
delegate.overlayCoords(u, v); | ||
return this; | ||
} | ||
|
||
@Override | ||
public @NotNull VertexConsumer uv2(int u, int v) { | ||
delegate.uv2(u, v); | ||
return this; | ||
} | ||
|
||
@Override | ||
public @NotNull VertexConsumer normal(float x, float y, float z) { | ||
delegate.normal(x, y, z); | ||
return this; | ||
} | ||
|
||
@Override | ||
public void endVertex() { | ||
delegate.endVertex(); | ||
} | ||
|
||
@Override | ||
public void defaultColor(int r, int g, int b, int a) { | ||
delegate.defaultColor(r, g, b, a); | ||
} | ||
|
||
|
||
@Override | ||
public void unsetDefaultColor() { | ||
delegate.unsetDefaultColor(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/committee/nova/mods/avaritia/api/client/model/IItemRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package committee.nova.mods.avaritia.api.client.model; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import committee.nova.mods.avaritia.util.client.TextureUtil; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.block.model.BakedQuad; | ||
import net.minecraft.client.renderer.block.model.ItemOverrides; | ||
import net.minecraft.client.renderer.texture.TextureAtlasSprite; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.item.ItemDisplayContext; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Author cnlimiter | ||
* CreateTime 2023/9/24 5:16 | ||
* Name IItemRenderer | ||
* Description | ||
*/ | ||
|
||
public interface IItemRenderer extends PerspectiveModel { | ||
void renderItem(ItemStack stack, ItemDisplayContext transformType, PoseStack mStack, MultiBufferSource source, int packedLight, int packedOverlay); | ||
|
||
//Useless methods for IItemRenderer. | ||
//@formatter:off | ||
@Override default@NotNull List<BakedQuad> getQuads(BlockState state, Direction side, RandomSource rand) { return Collections.emptyList(); } | ||
@Override default boolean isCustomRenderer() { return true; } | ||
@Override default@NotNull TextureAtlasSprite getParticleIcon() { return TextureUtil.getMissingSprite(); } | ||
@Override default@NotNull ItemOverrides getOverrides() { return ItemOverrides.EMPTY; } | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/committee/nova/mods/avaritia/api/client/model/PerspectiveModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package committee.nova.mods.avaritia.api.client.model; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.math.Transformation; | ||
import committee.nova.mods.avaritia.util.client.TransformUtil; | ||
import net.minecraft.client.renderer.block.model.ItemTransforms; | ||
import net.minecraft.client.resources.model.BakedModel; | ||
import net.minecraft.world.item.ItemDisplayContext; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.joml.Vector3f; | ||
|
||
/** | ||
* Name: Avaritia-forge / PerspectiveModel | ||
* Author: cnlimiter | ||
* CreateTime: 2023/9/24 5:08 | ||
* Description: | ||
*/ | ||
|
||
public interface PerspectiveModel extends BakedModel{ | ||
@Nullable | ||
PerspectiveModelState getModelState(); | ||
|
||
@Override | ||
default @NotNull BakedModel applyTransform(@NotNull ItemDisplayContext transformType, @NotNull PoseStack pStack, boolean leftFlip) { | ||
PerspectiveModelState modelState = getModelState(); | ||
if (modelState != null) { | ||
Transformation transform = getModelState().getTransform(transformType); | ||
|
||
Vector3f trans = transform.getTranslation(); | ||
pStack.translate(trans.x(), trans.y(), trans.z()); | ||
|
||
pStack.mulPose(transform.getLeftRotation()); | ||
|
||
Vector3f scale = transform.getScale(); | ||
pStack.scale(scale.x(), scale.y(), scale.z()); | ||
|
||
pStack.mulPose(transform.getRightRotation()); | ||
|
||
if (leftFlip) { | ||
TransformUtil.applyLeftyFlip(pStack); | ||
} | ||
return this; | ||
} | ||
return BakedModel.super.applyTransform(transformType, pStack, leftFlip); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/committee/nova/mods/avaritia/api/client/model/PerspectiveModelState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package committee.nova.mods.avaritia.api.client.model; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.mojang.math.Transformation; | ||
import net.minecraft.client.resources.model.ModelState; | ||
import net.minecraft.world.item.ItemDisplayContext; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Name: Avaritia-forge / PerspectiveModelStat | ||
* Author: cnlimiter | ||
* CreateTime: 2023/9/24 5:08 | ||
* Description: | ||
*/ | ||
|
||
public class PerspectiveModelState implements ModelState { | ||
public static final PerspectiveModelState IDENTITY = new PerspectiveModelState(ImmutableMap.of()); | ||
|
||
private final Map<ItemDisplayContext, Transformation> transforms; | ||
private final boolean isUvLocked; | ||
|
||
public PerspectiveModelState(Map<ItemDisplayContext, Transformation> transforms) { | ||
this(transforms, false); | ||
} | ||
|
||
public PerspectiveModelState(Map<ItemDisplayContext, Transformation> transforms, boolean isUvLocked) { | ||
this.transforms = ImmutableMap.copyOf(transforms); | ||
this.isUvLocked = isUvLocked; | ||
} | ||
|
||
public Transformation getTransform(ItemDisplayContext type) { | ||
return transforms.getOrDefault(type, Transformation.identity()); | ||
} | ||
|
||
@Override | ||
public boolean isUvLocked() { | ||
return isUvLocked; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/main/java/committee/nova/mods/avaritia/api/client/model/WrappedItemModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package committee.nova.mods.avaritia.api.client.model; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import committee.nova.mods.avaritia.util.client.TransformUtil; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import net.minecraft.client.renderer.ItemBlockRenderTypes; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.RenderType; | ||
import net.minecraft.client.renderer.block.model.BakedQuad; | ||
import net.minecraft.client.renderer.block.model.ItemOverrides; | ||
import net.minecraft.client.renderer.entity.ItemRenderer; | ||
import net.minecraft.client.renderer.texture.TextureAtlasSprite; | ||
import net.minecraft.client.resources.model.BakedModel; | ||
import net.minecraft.client.resources.model.ModelState; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraftforge.client.model.data.ModelData; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Name: Avaritia-forge / WrappedItemModel | ||
* Author: cnlimiter | ||
* CreateTime: 2023/9/24 5:17 | ||
* Description: | ||
*/ | ||
|
||
public abstract class WrappedItemModel implements BakedModel { | ||
protected final BakedModel wrapped; | ||
protected final ModelState parentState; | ||
@Nullable | ||
protected LivingEntity entity; | ||
@Nullable | ||
protected ClientLevel world; | ||
|
||
private final ItemOverrides overrideList = new ItemOverrides() { | ||
@Override | ||
public BakedModel resolve(@NotNull BakedModel originalModel, @NotNull ItemStack stack, @Nullable ClientLevel world, @Nullable LivingEntity entity, int seed) { | ||
WrappedItemModel.this.entity = entity; | ||
WrappedItemModel.this.world = world == null ? entity == null ? null : (ClientLevel) entity.level() : null; | ||
return originalModel; | ||
} | ||
}; | ||
|
||
public WrappedItemModel(BakedModel wrapped) { | ||
this.wrapped = wrapped; | ||
parentState = TransformUtil.stateFromItemTransforms(wrapped.getTransforms()); | ||
} | ||
|
||
@Override | ||
public @NotNull List<BakedQuad> getQuads(BlockState state, Direction side, @NotNull RandomSource rand) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public @NotNull TextureAtlasSprite getParticleIcon() { | ||
return wrapped.getParticleIcon(); | ||
} | ||
|
||
@Override | ||
public @NotNull TextureAtlasSprite getParticleIcon(@NotNull ModelData data) { | ||
return wrapped.getParticleIcon(data); | ||
} | ||
|
||
@Override | ||
public @NotNull ItemOverrides getOverrides() { | ||
return overrideList; | ||
} | ||
|
||
|
||
protected void renderWrapped(ItemStack stack, PoseStack pStack, MultiBufferSource buffers, int packedLight, int packedOverlay, boolean fabulous) { | ||
renderWrapped(stack, pStack, buffers, packedLight, packedOverlay, fabulous, Function.identity()); | ||
} | ||
|
||
|
||
protected void renderWrapped(ItemStack stack, PoseStack pStack, MultiBufferSource buffers, int packedLight, int packedOverlay, boolean fabulous, Function<VertexConsumer, VertexConsumer> consOverride) { | ||
BakedModel model = wrapped.getOverrides().resolve(wrapped, stack, world, entity, 0); | ||
|
||
ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); | ||
RenderType rType = ItemBlockRenderTypes.getRenderType(stack, fabulous); | ||
VertexConsumer builder = ItemRenderer.getFoilBuffer(buffers, rType, true, stack.hasFoil()); | ||
itemRenderer.renderModelLists(model, stack, packedLight, packedOverlay, pStack, consOverride.apply(builder)); | ||
} | ||
} |
Oops, something went wrong.