-
Notifications
You must be signed in to change notification settings - Fork 10
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
8 changed files
with
136 additions
and
8 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
32 changes: 32 additions & 0 deletions
32
src/client/java/dev/enjarai/trickster/mixin/client/BakedModelManagerMixin.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,32 @@ | ||
package dev.enjarai.trickster.mixin.client; | ||
|
||
import dev.enjarai.trickster.Trickster; | ||
import dev.enjarai.trickster.render.ScrollShelfBlockEntityRenderer; | ||
import net.minecraft.client.render.model.BakedModelManager; | ||
import net.minecraft.util.Identifier; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Mixin(BakedModelManager.class) | ||
public class BakedModelManagerMixin { | ||
@Final | ||
@Shadow @Mutable | ||
private static Map<Identifier, Identifier> LAYERS_TO_LOADERS; | ||
|
||
@Inject( | ||
method = "<clinit>", | ||
at = @At("TAIL") | ||
) | ||
private static void appendToAtlases(CallbackInfo ci) { | ||
LAYERS_TO_LOADERS = new HashMap<>(LAYERS_TO_LOADERS); | ||
LAYERS_TO_LOADERS.put(ScrollShelfBlockEntityRenderer.ATLAS_ID, Trickster.id("scroll_shelf")); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/client/java/dev/enjarai/trickster/render/ScrollShelfBlockEntityRenderer.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,70 @@ | ||
package dev.enjarai.trickster.render; | ||
|
||
import dev.enjarai.trickster.Trickster; | ||
import dev.enjarai.trickster.block.ScrollShelfBlock; | ||
import dev.enjarai.trickster.block.ScrollShelfBlockEntity; | ||
import net.minecraft.client.model.*; | ||
import net.minecraft.client.render.RenderLayer; | ||
import net.minecraft.client.render.VertexConsumerProvider; | ||
import net.minecraft.client.render.WorldRenderer; | ||
import net.minecraft.client.render.block.entity.BlockEntityRenderer; | ||
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; | ||
import net.minecraft.client.render.entity.model.EntityModelLayer; | ||
import net.minecraft.client.util.SpriteIdentifier; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.RotationAxis; | ||
|
||
import static dev.enjarai.trickster.block.ScrollShelfBlock.GRID_HEIGHT; | ||
import static dev.enjarai.trickster.block.ScrollShelfBlock.GRID_WIDTH; | ||
|
||
public class ScrollShelfBlockEntityRenderer implements BlockEntityRenderer<ScrollShelfBlockEntity> { | ||
public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Trickster.id("scroll_shelf"), "scroll_shelf"); | ||
public static final Identifier ATLAS_ID = Trickster.id("textures/atlas/scroll_shelf.png"); | ||
|
||
private final ModelPart[] scrollModels = new ModelPart[GRID_WIDTH * GRID_HEIGHT]; | ||
|
||
public static TexturedModelData getTexturedModelData() { | ||
ModelData modelData = new ModelData(); | ||
ModelPartData modelPartData = modelData.getRoot(); | ||
for (int i = 0; i < GRID_WIDTH * GRID_HEIGHT; i++) { | ||
var x = i % GRID_WIDTH; | ||
var y = i / GRID_HEIGHT; | ||
modelPartData.addChild("scroll_" + i, ModelPartBuilder.create() | ||
.uv(0, 0) | ||
.cuboid(16f / GRID_WIDTH * x - 1.5f, 16f - (16f / GRID_HEIGHT * y - 1.5f), 16f, 3f, 3f, 1f), | ||
ModelTransform.NONE); | ||
} | ||
return TexturedModelData.of(modelData, 16, 16); | ||
} | ||
|
||
public ScrollShelfBlockEntityRenderer(BlockEntityRendererFactory.Context ctx) { | ||
var model = ctx.getLayerModelPart(MODEL_LAYER); | ||
for (int i = 0; i < GRID_WIDTH * GRID_HEIGHT; i++) { | ||
scrollModels[i] = model.getChild("scroll_" + i); | ||
} | ||
} | ||
|
||
@Override | ||
public void render(ScrollShelfBlockEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { | ||
var facing = entity.getCachedState().get(ScrollShelfBlock.FACING); | ||
//noinspection DataFlowIssue | ||
light = WorldRenderer.getLightmapCoordinates(entity.getWorld(), entity.getPos().offset(facing)); | ||
|
||
matrices.push(); | ||
matrices.multiply(RotationAxis.NEGATIVE_Y.rotationDegrees(facing.asRotation())); | ||
|
||
for (int i = 0; i < GRID_WIDTH * GRID_HEIGHT; i++) { | ||
var stack = entity.getStack(i); | ||
if (!stack.isEmpty()) { | ||
var textureId = Registries.ITEM.getId(stack.getItem()).withPrefixedPath("entity/scroll_shelf/"); | ||
var spriteId = new SpriteIdentifier(ATLAS_ID, textureId); | ||
var vertexConsumer = spriteId.getVertexConsumer(vertexConsumers, RenderLayer::getEntityCutout); | ||
scrollModels[i].render(matrices, vertexConsumer, light, overlay); | ||
} | ||
} | ||
|
||
matrices.pop(); | ||
} | ||
} |
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
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
9 changes: 9 additions & 0 deletions
9
src/main/resources/assets/trickster/atlases/scroll_shelf.json
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": "directory", | ||
"source": "entity/scroll_shelf", | ||
"prefix": "entity/scroll_shelf/" | ||
} | ||
] | ||
} |
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
Binary file added
BIN
+124 Bytes
...in/resources/assets/trickster/textures/entity/scroll_shelf/scroll_and_quill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.