Skip to content

Commit

Permalink
rotating works!
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Dec 2, 2023
1 parent 1b96719 commit 3576446
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ private BookcaseGeometryLoader() {

@Override
public BookcaseGeometry read(JsonObject jsonObject, JsonDeserializationContext context) throws JsonParseException {
jsonObject.remove("loader");
BlockModel base = context.deserialize(jsonObject, BlockModel.class);
BlockModel[] books = new BlockModel[16];
for (int i = 0; i < 16; i++) {
String book = "book_" + i;
books[i] = context.deserialize(GsonHelper.getAsJsonObject(jsonObject, book), BlockModel.class);
}
return new BookcaseGeometry(context.deserialize(GsonHelper.getAsJsonObject(jsonObject, "base"), BlockModel.class), books);
return new BookcaseGeometry(base, books);
}

public static class BookcaseGeometry implements IUnbakedGeometry<BookcaseGeometry> {
Expand All @@ -65,15 +67,12 @@ public BookcaseGeometry(BlockModel base, BlockModel[] books) {

@Override
public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation) {
BakedModel[] directionalBase = new BakedModel[4];
BakedModel[][] directionalBooks = new BakedModel[4][16];
for (int i = 0; i < directionalBooks.length; i++) {
directionalBase[i] = base.bake(baker, base, spriteGetter, BlockModelRotation.by(0, i * 90), modelLocation, context.useBlockLight());
for (int j = 0; j < directionalBooks[i].length; j++) {
directionalBooks[i][j] = books[j].bake(baker, books[j], spriteGetter, BlockModelRotation.by(0, i * 90), modelLocation, context.useBlockLight());
}
BakedModel base = this.base.bake(baker, this.base, spriteGetter, modelState, modelLocation, context.useBlockLight());
BakedModel[] books = new BakedModel[16];
for (int j = 0; j < books.length; j++) {
books[j] = this.books[j].bake(baker, this.books[j], spriteGetter, modelState, modelLocation, context.useBlockLight());
}
return new BookcaseDynamicModel(context.useAmbientOcclusion(), context.isGui3d(), context.useBlockLight(), spriteGetter.apply(base.getMaterial("particle")), directionalBase, directionalBooks);
return new BookcaseDynamicModel(context.useAmbientOcclusion(), context.isGui3d(), context.useBlockLight(), spriteGetter.apply(this.base.getMaterial("particle")), base, books);
}

@Override
Expand All @@ -90,10 +89,10 @@ public static class BookcaseDynamicModel implements IDynamicBakedModel {
private final boolean isGui3d;
private final boolean usesBlockLight;
private final TextureAtlasSprite particle;
private final BakedModel[] base;
private final BakedModel[][] books;
private final BakedModel base;
private final BakedModel[] books;

public BookcaseDynamicModel(boolean useAmbientOcclusion, boolean isGui3d, boolean usesBlockLight, TextureAtlasSprite particle, BakedModel[] base, BakedModel[][] books) {
public BookcaseDynamicModel(boolean useAmbientOcclusion, boolean isGui3d, boolean usesBlockLight, TextureAtlasSprite particle, BakedModel base, BakedModel[] books) {
this.useAmbientOcclusion = useAmbientOcclusion;
this.isGui3d = isGui3d;
this.usesBlockLight = usesBlockLight;
Expand All @@ -104,18 +103,11 @@ public BookcaseDynamicModel(boolean useAmbientOcclusion, boolean isGui3d, boolea

@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand, ModelData extraData, @Nullable RenderType renderType) {
int sideIndex = side == null ? 0 : switch (side) {
case NORTH -> 0;
case EAST -> 1;
case SOUTH -> 2;
case WEST -> 3;
default -> 0;
};
List<BakedQuad> quads = new ArrayList<>(base[sideIndex].getQuads(state, side, rand, extraData, renderType));
for (int i = 0; i < books[sideIndex].length; i++) {
List<BakedQuad> quads = new ArrayList<>(base.getQuads(state, side, rand, extraData, renderType));
for (int i = 0; i < books.length; i++) {
Boolean book = extraData.get(BookcaseBlockEntity.MODEL_PROPERTIES.get(i));
if (book == null || !book) continue;
quads.addAll(books[sideIndex][i].getQuads(state, side, rand, extraData, renderType));
quads.addAll(books[i].getQuads(state, side, rand, extraData, renderType));
}
return quads;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,104 @@
{
"loader": "bibliocraft:bookcase",
"base": {"parent": "bibliocraft:block/bookcase/base"},
"book_0": {"parent": "bibliocraft:block/bookcase/book_0"},
"book_1": {"parent": "bibliocraft:block/bookcase/book_1"},
"book_2": {"parent": "bibliocraft:block/bookcase/book_2"},
"book_3": {"parent": "bibliocraft:block/bookcase/book_3"},
"book_4": {"parent": "bibliocraft:block/bookcase/book_4"},
"book_5": {"parent": "bibliocraft:block/bookcase/book_5"},
"book_6": {"parent": "bibliocraft:block/bookcase/book_6"},
"book_7": {"parent": "bibliocraft:block/bookcase/book_7"},
"book_8": {"parent": "bibliocraft:block/bookcase/book_8"},
"book_9": {"parent": "bibliocraft:block/bookcase/book_9"},
"book_10": {"parent": "bibliocraft:block/bookcase/book_10"},
"book_11": {"parent": "bibliocraft:block/bookcase/book_11"},
"book_12": {"parent": "bibliocraft:block/bookcase/book_12"},
"book_13": {"parent": "bibliocraft:block/bookcase/book_13"},
"book_14": {"parent": "bibliocraft:block/bookcase/book_14"},
"book_15": {"parent": "bibliocraft:block/bookcase/book_15"}
"loader": "bibliocraft:bookcase",
"parent": "minecraft:block/block",
"textures": {
"0": "#texture",
"particle": "#texture"
},
"elements": [
{
"name": "bottom",
"from": [1, 0, 8],
"to": [15, 1, 15],
"faces": {
"north": {"uv": [1, 15, 15, 16], "texture": "#0"},
"east": {"uv": [0, 0, 7, 1], "texture": "#missing"},
"south": {"uv": [0, 0, 14, 1], "texture": "#missing"},
"west": {"uv": [0, 0, 7, 1], "texture": "#missing"},
"up": {"uv": [1, 8, 15, 15], "texture": "#0"},
"down": {"uv": [1, 1, 15, 8], "texture": "#0"}
}
},
{
"name": "middle",
"from": [1, 7, 8],
"to": [15, 9, 15],
"faces": {
"north": {"uv": [1, 7, 15, 9], "texture": "#0"},
"east": {"uv": [0, 0, 7, 2], "texture": "#missing"},
"south": {"uv": [0, 0, 14, 2], "texture": "#missing"},
"west": {"uv": [0, 0, 7, 2], "texture": "#missing"},
"up": {"uv": [1, 8, 15, 15], "texture": "#0"},
"down": {"uv": [1, 1, 15, 8], "texture": "#0"}
}
},
{
"name": "top",
"from": [1, 15, 8],
"to": [15, 16, 15],
"faces": {
"north": {"uv": [1, 0, 15, 1], "texture": "#0"},
"east": {"uv": [0, 0, 7, 1], "texture": "#missing"},
"south": {"uv": [0, 0, 14, 1], "texture": "#missing"},
"west": {"uv": [0, 0, 7, 1], "texture": "#missing"},
"up": {"uv": [1, 8, 15, 15], "texture": "#0"},
"down": {"uv": [1, 1, 15, 8], "texture": "#0"}
}
},
{
"name": "left",
"from": [15, 0, 8],
"to": [16, 16, 15],
"faces": {
"north": {"uv": [0, 0, 1, 16], "texture": "#0"},
"east": {"uv": [1, 0, 8, 16], "texture": "#0"},
"south": {"uv": [0, 0, 1, 16], "texture": "#missing"},
"west": {"uv": [8, 0, 15, 16], "texture": "#0"},
"up": {"uv": [15, 8, 16, 15], "texture": "#0"},
"down": {"uv": [15, 1, 16, 8], "texture": "#0"}
}
},
{
"name": "right",
"from": [0, 0, 8],
"to": [1, 16, 15],
"faces": {
"north": {"uv": [15, 0, 16, 16], "texture": "#0"},
"east": {"uv": [1, 0, 8, 16], "texture": "#0"},
"south": {"uv": [0, 0, 1, 16], "texture": "#missing"},
"west": {"uv": [8, 0, 15, 16], "texture": "#0"},
"up": {"uv": [0, 8, 1, 15], "texture": "#0"},
"down": {"uv": [0, 1, 1, 8], "texture": "#0"}
}
},
{
"name": "back",
"from": [0, 0, 15],
"to": [16, 16, 16],
"faces": {
"north": {"uv": [0, 0, 16, 16], "texture": "#0"},
"east": {"uv": [0, 0, 1, 16], "texture": "#0"},
"south": {"uv": [0, 0, 16, 16], "texture": "#0"},
"west": {"uv": [15, 0, 16, 16], "texture": "#0"},
"up": {"uv": [0, 15, 16, 16], "texture": "#0"},
"down": {"uv": [0, 0, 16, 1], "texture": "#0"}
}
}
],
"book_0": {"parent": "bibliocraft:block/bookcase/book_0"},
"book_1": {"parent": "bibliocraft:block/bookcase/book_1"},
"book_2": {"parent": "bibliocraft:block/bookcase/book_2"},
"book_3": {"parent": "bibliocraft:block/bookcase/book_3"},
"book_4": {"parent": "bibliocraft:block/bookcase/book_4"},
"book_5": {"parent": "bibliocraft:block/bookcase/book_5"},
"book_6": {"parent": "bibliocraft:block/bookcase/book_6"},
"book_7": {"parent": "bibliocraft:block/bookcase/book_7"},
"book_8": {"parent": "bibliocraft:block/bookcase/book_8"},
"book_9": {"parent": "bibliocraft:block/bookcase/book_9"},
"book_10": {"parent": "bibliocraft:block/bookcase/book_10"},
"book_11": {"parent": "bibliocraft:block/bookcase/book_11"},
"book_12": {"parent": "bibliocraft:block/bookcase/book_12"},
"book_13": {"parent": "bibliocraft:block/bookcase/book_13"},
"book_14": {"parent": "bibliocraft:block/bookcase/book_14"},
"book_15": {"parent": "bibliocraft:block/bookcase/book_15"}
}

0 comments on commit 3576446

Please sign in to comment.