|
1 | 1 | package com.simibubi.create.content.logistics.tableCloth;
|
2 | 2 |
|
3 |
| -import java.util.ArrayList; |
4 |
| -import java.util.EnumSet; |
5 |
| -import java.util.HashMap; |
6 |
| -import java.util.List; |
7 |
| -import java.util.Map; |
8 |
| - |
9 |
| -import org.jetbrains.annotations.NotNull; |
10 |
| -import org.jetbrains.annotations.Nullable; |
11 |
| - |
12 |
| -import com.simibubi.create.AllPartialModels; |
13 |
| -import com.simibubi.create.foundation.model.BakedQuadHelper; |
14 |
| - |
15 |
| -import dev.engine_room.flywheel.lib.model.baked.PartialModel; |
16 |
| -import net.createmod.catnip.render.SpriteShiftEntry; |
17 |
| -import net.createmod.catnip.data.Iterate; |
18 |
| -import net.minecraft.client.renderer.RenderType; |
19 |
| -import net.minecraft.client.renderer.block.model.BakedQuad; |
20 |
| -import net.minecraft.client.renderer.texture.TextureAtlasSprite; |
21 |
| -import net.minecraft.client.resources.model.BakedModel; |
22 |
| -import net.minecraft.core.BlockPos; |
23 |
| -import net.minecraft.core.Direction; |
24 |
| -import net.minecraft.core.Direction.Axis; |
25 |
| -import net.minecraft.util.RandomSource; |
26 |
| -import net.minecraft.world.level.BlockAndTintGetter; |
27 |
| -import net.minecraft.world.level.block.Block; |
28 |
| -import net.minecraft.world.level.block.state.BlockState; |
29 |
| - |
30 |
| -public class TableClothModel extends BakedModelWrapperWithData { |
31 |
| - |
32 |
| - private static final ModelProperty<CullData> CULL_PROPERTY = new ModelProperty<>(); |
33 |
| - |
34 |
| - private static final Map<TableClothBlock, List<List<BakedQuad>>> CORNERS = new HashMap<>(); |
35 |
| - |
36 |
| - public TableClothModel(BakedModel originalModel) { |
37 |
| - super(originalModel); |
38 |
| - } |
39 |
| - |
40 |
| - public static void reload() { |
41 |
| - CORNERS.clear(); |
42 |
| - } |
43 |
| - |
44 |
| - @Override |
45 |
| - public boolean useAmbientOcclusion() { |
46 |
| - return false; |
47 |
| - } |
48 |
| - |
49 |
| - private List<BakedQuad> getCorner(TableClothBlock block, int corner, @NotNull RandomSource rand, |
50 |
| - @Nullable RenderType renderType) { |
51 |
| - if (!CORNERS.containsKey(block)) { |
52 |
| - TextureAtlasSprite targetSprite = getParticleIcon(ModelData.EMPTY); |
53 |
| - List<List<BakedQuad>> list = new ArrayList<>(); |
54 |
| - |
55 |
| - for (PartialModel pm : List.of(AllPartialModels.TABLE_CLOTH_SW, AllPartialModels.TABLE_CLOTH_NW, |
56 |
| - AllPartialModels.TABLE_CLOTH_NE, AllPartialModels.TABLE_CLOTH_SE)) |
57 |
| - list.add(getCornerQuads(rand, renderType, targetSprite, pm)); |
58 |
| - |
59 |
| - CORNERS.put(block, list); |
60 |
| - } |
61 |
| - |
62 |
| - return CORNERS.get(block) |
63 |
| - .get(corner); |
64 |
| - } |
65 |
| - |
66 |
| - private List<BakedQuad> getCornerQuads(RandomSource rand, RenderType renderType, TextureAtlasSprite targetSprite, |
67 |
| - PartialModel pm) { |
68 |
| - List<BakedQuad> quads = new ArrayList<>(); |
69 |
| - |
70 |
| - for (BakedQuad quad : pm.get() |
71 |
| - .getQuads(null, null, rand, ModelData.EMPTY, renderType)) { |
72 |
| - TextureAtlasSprite original = quad.getSprite(); |
73 |
| - BakedQuad newQuad = BakedQuadHelper.clone(quad); |
74 |
| - int[] vertexData = newQuad.getVertices(); |
75 |
| - for (int vertex = 0; vertex < 4; vertex++) { |
76 |
| - BakedQuadHelper.setU(vertexData, vertex, targetSprite |
77 |
| - .getU(SpriteShiftEntry.getUnInterpolatedU(original, BakedQuadHelper.getU(vertexData, vertex)))); |
78 |
| - BakedQuadHelper.setV(vertexData, vertex, targetSprite |
79 |
| - .getV(SpriteShiftEntry.getUnInterpolatedV(original, BakedQuadHelper.getV(vertexData, vertex)))); |
80 |
| - } |
81 |
| - quads.add(newQuad); |
82 |
| - } |
83 |
| - |
84 |
| - return quads; |
85 |
| - } |
86 |
| - |
87 |
| - @Override |
88 |
| - protected Builder gatherModelData(Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, |
89 |
| - ModelData blockEntityData) { |
90 |
| - List<Direction> culledSides = new ArrayList<>(); |
91 |
| - for (Direction side : Iterate.horizontalDirections) |
92 |
| - if (!Block.shouldRenderFace(state, world, pos, side, pos.relative(side))) |
93 |
| - culledSides.add(side); |
94 |
| - if (culledSides.isEmpty()) |
95 |
| - return builder; |
96 |
| - return builder.with(CULL_PROPERTY, new CullData(EnumSet.copyOf(culledSides))); |
97 |
| - } |
98 |
| - |
99 |
| - @Override |
100 |
| - public @NotNull List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, |
101 |
| - @NotNull RandomSource rand, @NotNull ModelData extraData, @Nullable RenderType renderType) { |
102 |
| - @NotNull |
103 |
| - List<BakedQuad> mainQuads = super.getQuads(state, side, rand, extraData, renderType); |
104 |
| - if (side == null || side.getAxis() == Axis.Y) |
105 |
| - return mainQuads; |
106 |
| - |
107 |
| - CullData cullData = extraData.get(CULL_PROPERTY); |
108 |
| - if (cullData != null && cullData.culled() |
109 |
| - .contains(side.getClockWise())) |
110 |
| - return mainQuads; |
111 |
| - if (state == null || !(state.getBlock() instanceof TableClothBlock dcb)) |
112 |
| - return mainQuads; |
113 |
| - |
114 |
| - List<BakedQuad> copyOf = new ArrayList<>(mainQuads); |
115 |
| - copyOf.addAll(getCorner(dcb, side.get2DDataValue(), rand, renderType)); |
116 |
| - return copyOf; |
117 |
| - } |
118 |
| - |
119 |
| - private static record CullData(EnumSet<Direction> culled) { |
120 |
| - } |
121 |
| - |
122 |
| -} |
| 3 | +//public class TableClothModel extends BakedModelWrapperWithData { |
| 4 | +// |
| 5 | +// private static final ModelProperty<CullData> CULL_PROPERTY = new ModelProperty<>(); |
| 6 | +// |
| 7 | +// private static final Map<TableClothBlock, List<List<BakedQuad>>> CORNERS = new HashMap<>(); |
| 8 | +// |
| 9 | +// public TableClothModel(BakedModel originalModel) { |
| 10 | +// super(originalModel); |
| 11 | +// } |
| 12 | +// |
| 13 | +// public static void reload() { |
| 14 | +// CORNERS.clear(); |
| 15 | +// } |
| 16 | +// |
| 17 | +// @Override |
| 18 | +// public boolean useAmbientOcclusion() { |
| 19 | +// return false; |
| 20 | +// } |
| 21 | +// |
| 22 | +// private List<BakedQuad> getCorner(TableClothBlock block, int corner, @NotNull RandomSource rand, |
| 23 | +// @Nullable RenderType renderType) { |
| 24 | +// if (!CORNERS.containsKey(block)) { |
| 25 | +// TextureAtlasSprite targetSprite = getParticleIcon(ModelData.EMPTY); |
| 26 | +// List<List<BakedQuad>> list = new ArrayList<>(); |
| 27 | +// |
| 28 | +// for (PartialModel pm : List.of(AllPartialModels.TABLE_CLOTH_SW, AllPartialModels.TABLE_CLOTH_NW, |
| 29 | +// AllPartialModels.TABLE_CLOTH_NE, AllPartialModels.TABLE_CLOTH_SE)) |
| 30 | +// list.add(getCornerQuads(rand, renderType, targetSprite, pm)); |
| 31 | +// |
| 32 | +// CORNERS.put(block, list); |
| 33 | +// } |
| 34 | +// |
| 35 | +// return CORNERS.get(block) |
| 36 | +// .get(corner); |
| 37 | +// } |
| 38 | +// |
| 39 | +// private List<BakedQuad> getCornerQuads(RandomSource rand, RenderType renderType, TextureAtlasSprite targetSprite, |
| 40 | +// PartialModel pm) { |
| 41 | +// List<BakedQuad> quads = new ArrayList<>(); |
| 42 | +// |
| 43 | +// for (BakedQuad quad : pm.get() |
| 44 | +// .getQuads(null, null, rand, ModelData.EMPTY, renderType)) { |
| 45 | +// TextureAtlasSprite original = quad.getSprite(); |
| 46 | +// BakedQuad newQuad = BakedQuadHelper.clone(quad); |
| 47 | +// int[] vertexData = newQuad.getVertices(); |
| 48 | +// for (int vertex = 0; vertex < 4; vertex++) { |
| 49 | +// BakedQuadHelper.setU(vertexData, vertex, targetSprite |
| 50 | +// .getU(SpriteShiftEntry.getUnInterpolatedU(original, BakedQuadHelper.getU(vertexData, vertex)))); |
| 51 | +// BakedQuadHelper.setV(vertexData, vertex, targetSprite |
| 52 | +// .getV(SpriteShiftEntry.getUnInterpolatedV(original, BakedQuadHelper.getV(vertexData, vertex)))); |
| 53 | +// } |
| 54 | +// quads.add(newQuad); |
| 55 | +// } |
| 56 | +// |
| 57 | +// return quads; |
| 58 | +// } |
| 59 | +// |
| 60 | +// @Override |
| 61 | +// protected Builder gatherModelData(Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, |
| 62 | +// ModelData blockEntityData) { |
| 63 | +// List<Direction> culledSides = new ArrayList<>(); |
| 64 | +// for (Direction side : Iterate.horizontalDirections) |
| 65 | +// if (!Block.shouldRenderFace(state, world, pos, side, pos.relative(side))) |
| 66 | +// culledSides.add(side); |
| 67 | +// if (culledSides.isEmpty()) |
| 68 | +// return builder; |
| 69 | +// return builder.with(CULL_PROPERTY, new CullData(EnumSet.copyOf(culledSides))); |
| 70 | +// } |
| 71 | +// |
| 72 | +// @Override |
| 73 | +// public @NotNull List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, |
| 74 | +// @NotNull RandomSource rand, @NotNull ModelData extraData, @Nullable RenderType renderType) { |
| 75 | +// @NotNull |
| 76 | +// List<BakedQuad> mainQuads = super.getQuads(state, side, rand, extraData, renderType); |
| 77 | +// if (side == null || side.getAxis() == Axis.Y) |
| 78 | +// return mainQuads; |
| 79 | +// |
| 80 | +// CullData cullData = extraData.get(CULL_PROPERTY); |
| 81 | +// if (cullData != null && cullData.culled() |
| 82 | +// .contains(side.getClockWise())) |
| 83 | +// return mainQuads; |
| 84 | +// if (state == null || !(state.getBlock() instanceof TableClothBlock dcb)) |
| 85 | +// return mainQuads; |
| 86 | +// |
| 87 | +// List<BakedQuad> copyOf = new ArrayList<>(mainQuads); |
| 88 | +// copyOf.addAll(getCorner(dcb, side.get2DDataValue(), rand, renderType)); |
| 89 | +// return copyOf; |
| 90 | +// } |
| 91 | +// |
| 92 | +// private static record CullData(EnumSet<Direction> culled) { |
| 93 | +// } |
| 94 | +// |
| 95 | +//} |
0 commit comments