Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trapdoor textures. #1787

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ private static void addBlocks(Texture texture, String... names) {
addBlock("mangrove_wall_sign", (name, tag) -> wallSign(tag, "mangrove"));
addBlock("mangrove_slab", (name, tag) -> slab(tag, Texture.mangrovePlanks));
addBlock("mangrove_stairs", (name, tag) -> stairs(tag, Texture.mangrovePlanks));
addBlock("mangrove_trapdoor", (name, tag) -> trapdoor(tag, Texture.mangroveTrapdoor));
addBlock("mangrove_trapdoor", (name, tag) -> orientableTrapdoor(tag, Texture.mangroveTrapdoor));
addBlock("mangrove_wood", (name, tag) -> log(tag, Texture.mangroveLog, Texture.mangroveLog));
addBlock("stripped_mangrove_wood", (name, tag) -> log(tag, Texture.strippedMangroveLog, Texture.strippedMangroveLog));
addBlock("mangrove_roots", (name, tag) -> new MangroveRoots());
Expand Down Expand Up @@ -1005,7 +1005,7 @@ private static void addBlocks(Texture texture, String... names) {
addBlock("bamboo_stairs", (name, tag) -> stairs(tag, Texture.bambooPlanks));
addBlock("bamboo_mosaic_slab", (name, tag) -> slab(tag, Texture.bambooMosaic));
addBlock("bamboo_mosaic_stairs", (name, tag) -> stairs(tag, Texture.bambooMosaic));
addBlock("bamboo_trapdoor", (name, tag) -> trapdoor(tag, Texture.bambooTrapdoor));
addBlock("bamboo_trapdoor", (name, tag) -> orientableTrapdoor(tag, Texture.bambooTrapdoor));
addBlock("cherry_button", (name, tag) -> button(tag, Texture.cherryPlanks));
addBlock("cherry_door", (name, tag) -> door(tag, Texture.cherryDoorTop, Texture.cherryDoorBottom));
addBlock("cherry_fence", (name, tag) -> fence(tag, Texture.cherryPlanks));
Expand All @@ -1019,7 +1019,7 @@ private static void addBlocks(Texture texture, String... names) {
addBlock("cherry_wall_sign", (name, tag) -> wallSign(tag, "cherry"));
addBlock("cherry_slab", (name, tag) -> slab(tag, Texture.cherryPlanks));
addBlock("cherry_stairs", (name, tag) -> stairs(tag, Texture.cherryPlanks));
addBlock("cherry_trapdoor", (name, tag) -> trapdoor(tag, Texture.cherryTrapdoor));
addBlock("cherry_trapdoor", (name, tag) -> orientableTrapdoor(tag, Texture.cherryTrapdoor));
addBlock("cherry_wood", (name, tag) -> log(tag, Texture.cherryLog, Texture.cherryLog));
addBlock("stripped_cherry_wood", (name, tag) -> log(tag, Texture.strippedCherryLog, Texture.strippedCherryLog));
addBlock("cherry_sapling", (name, tag) -> new SpriteBlock(name, Texture.cherrySapling));
Expand Down Expand Up @@ -1600,13 +1600,13 @@ public Block getBlockByTag(String namespacedName, Tag tag) {
case "oak_trapdoor":
return trapdoor(tag, Texture.trapdoor);
case "spruce_trapdoor":
return trapdoor(tag, Texture.spruceTrapdoor);
return orientableTrapdoor(tag, Texture.spruceTrapdoor);
case "birch_trapdoor":
return trapdoor(tag, Texture.birchTrapdoor);
return orientableTrapdoor(tag, Texture.birchTrapdoor);
case "jungle_trapdoor":
return trapdoor(tag, Texture.jungleTrapdoor);
return orientableTrapdoor(tag, Texture.jungleTrapdoor);
case "acacia_trapdoor":
return trapdoor(tag, Texture.acaciaTrapdoor);
return orientableTrapdoor(tag, Texture.acaciaTrapdoor);
case "dark_oak_trapdoor":
return trapdoor(tag, Texture.darkOakTrapdoor);
case "infested_stone_bricks":
Expand Down Expand Up @@ -2768,9 +2768,9 @@ public Block getBlockByTag(String namespacedName, Tag tag) {
case "warped_door":
return door(tag, Texture.warpedDoorTop, Texture.warpedDoorBottom);
case "crimson_trapdoor":
return trapdoor(tag, Texture.crimsonTrapdoor);
return orientableTrapdoor(tag, Texture.crimsonTrapdoor);
case "warped_trapdoor":
return trapdoor(tag, Texture.warpedTrapdoor);
return orientableTrapdoor(tag, Texture.warpedTrapdoor);
case "soul_fire":
return new SoulFire();
case "lodestone":
Expand Down Expand Up @@ -3458,6 +3458,15 @@ private static Block trapdoor(Tag tag, Texture texture) {
return new Trapdoor(name, texture, half, facing, open.equals("true"));
}

private static Block orientableTrapdoor(Tag tag, Texture texture) {
String name = BlockProvider.blockName(tag);
Tag properties = tag.get("Properties");
String half = properties.get("half").stringValue("bottom");
String facing = BlockProvider.facing(tag);
String open = properties.get("open").stringValue("false");
return new OrientableTrapdoor(name, texture, half, facing, open.equals("true"));
}

private Block vine(Tag tag) {
Tag properties = tag.get("Properties");
String north = properties.get("north").stringValue("false");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2024 Chunky contributors
*
* This file is part of Chunky.
*
* Chunky is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chunky is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Chunky. If not, see <http://www.gnu.org/licenses/>.
*/

package se.llbit.chunky.block.minecraft;

import se.llbit.chunky.block.AbstractModelBlock;
import se.llbit.chunky.model.minecraft.OrientableTrapdoorModel;
import se.llbit.chunky.resources.Texture;

public class OrientableTrapdoor extends AbstractModelBlock {
private final String description;

public OrientableTrapdoor(String name, Texture texture,
String half, String facing, boolean open) {
super(name, texture);
solid = false;
this.description = String.format("half=%s, facing=%s, open=%s", half, facing, open);
this.model = new OrientableTrapdoorModel(texture, half, facing, open);
}

@Override
public String description() {
return description;
}
}
31 changes: 3 additions & 28 deletions chunky/src/java/se/llbit/chunky/block/minecraft/Trapdoor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,15 @@
import se.llbit.chunky.model.minecraft.TrapdoorModel;
import se.llbit.chunky.resources.Texture;

// TODO: fix rendering/texturing bugs.
public class Trapdoor extends AbstractModelBlock {

private final String description;

public Trapdoor(String name, Texture texture,
String half, String facing, boolean open) {
String half, String facing, boolean open) {
super(name, texture);
solid = false;
this.description = String.format("half=%s, facing=%s, open=%s",
half, facing, open);
int state;
switch (facing) {
default:
case "north":
state = 0;
break;
case "south":
state = 1;
break;
case "east":
state = 3;
break;
case "west":
state = 2;
break;
}
if (open) {
state |= 4;
}
if (half.equals("top")) {
state |= 8;
}
this.model = new TrapdoorModel(texture, state);
this.description = String.format("half=%s, facing=%s, open=%s", half, facing, open);
this.model = new TrapdoorModel(texture, half, facing, open);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/*
* Copyright (c) 2024 Chunky contributors
*
* This file is part of Chunky.
*
* Chunky is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chunky is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Chunky. If not, see <http://www.gnu.org/licenses/>.
*/
package se.llbit.chunky.model.minecraft;

import se.llbit.chunky.model.Model;
import se.llbit.chunky.model.QuadModel;
import se.llbit.chunky.resources.Texture;
import se.llbit.math.Quad;
import se.llbit.math.Vector3;
import se.llbit.math.Vector4;

import java.util.Arrays;

public class OrientableTrapdoorModel extends QuadModel {
private static final Quad[] quadsTop = new Quad[]{
new Quad(
new Vector3(0 / 16.0, 16 / 16.0, 16 / 16.0),
new Vector3(16 / 16.0, 16 / 16.0, 16 / 16.0),
new Vector3(0 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector4(0 / 16.0, 16 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(0 / 16.0, 13 / 16.0, 0 / 16.0),
new Vector3(16 / 16.0, 13 / 16.0, 0 / 16.0),
new Vector3(0 / 16.0, 13 / 16.0, 16 / 16.0),
new Vector4(0 / 16.0, 16 / 16.0, 0 / 16.0, 16 / 16.0)
),
new Quad(
new Vector3(0 / 16.0, 16 / 16.0, 16 / 16.0),
new Vector3(0 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(0 / 16.0, 13 / 16.0, 16 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 13 / 16.0)
),
new Quad(
new Vector3(16 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(16 / 16.0, 16 / 16.0, 16 / 16.0),
new Vector3(16 / 16.0, 13 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 13 / 16.0)
),
new Quad(
new Vector3(0 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(16 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(0 / 16.0, 13 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 13 / 16.0)
),
new Quad(
new Vector3(16 / 16.0, 16 / 16.0, 16 / 16.0),
new Vector3(0 / 16.0, 16 / 16.0, 16 / 16.0),
new Vector3(16 / 16.0, 13 / 16.0, 16 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 13 / 16.0)
)
};

private static final Quad[] quadsBottom = new Quad[]{
new Quad(
new Vector3(0 / 16.0, 3 / 16.0, 16 / 16.0),
new Vector3(16 / 16.0, 3 / 16.0, 16 / 16.0),
new Vector3(0 / 16.0, 3 / 16.0, 0 / 16.0),
new Vector4(0 / 16.0, 16 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(0 / 16.0, 0 / 16.0, 0 / 16.0),
new Vector3(16 / 16.0, 0 / 16.0, 0 / 16.0),
new Vector3(0 / 16.0, 0 / 16.0, 16 / 16.0),
new Vector4(0 / 16.0, 16 / 16.0, 0 / 16.0, 16 / 16.0)
),
new Quad(
new Vector3(0 / 16.0, 3 / 16.0, 16 / 16.0),
new Vector3(0 / 16.0, 3 / 16.0, 0 / 16.0),
new Vector3(0 / 16.0, 0 / 16.0, 16 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 13 / 16.0)
),
new Quad(
new Vector3(16 / 16.0, 3 / 16.0, 0 / 16.0),
new Vector3(16 / 16.0, 3 / 16.0, 16 / 16.0),
new Vector3(16 / 16.0, 0 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 13 / 16.0)
),
new Quad(
new Vector3(0 / 16.0, 3 / 16.0, 0 / 16.0),
new Vector3(16 / 16.0, 3 / 16.0, 0 / 16.0),
new Vector3(0 / 16.0, 0 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 13 / 16.0)
),
new Quad(
new Vector3(16 / 16.0, 3 / 16.0, 16 / 16.0),
new Vector3(0 / 16.0, 3 / 16.0, 16 / 16.0),
new Vector3(16 / 16.0, 0 / 16.0, 16 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 13 / 16.0)
)
};

private static final Quad[] quadsOpen = new Quad[]{
new Quad(
new Vector3(0 / 16.0, 16 / 16.0, 16 / 16.0),
new Vector3(16 / 16.0, 16 / 16.0, 16 / 16.0),
new Vector3(0 / 16.0, 16 / 16.0, 13 / 16.0),
new Vector4(0 / 16.0, 16 / 16.0, 16 / 16.0, 13 / 16.0)
),
new Quad(
new Vector3(0 / 16.0, 0 / 16.0, 13 / 16.0),
new Vector3(16 / 16.0, 0 / 16.0, 13 / 16.0),
new Vector3(0 / 16.0, 0 / 16.0, 16 / 16.0),
new Vector4(0 / 16.0, 16 / 16.0, 13 / 16.0, 16 / 16.0)
),
new Quad(
new Vector3(0 / 16.0, 0 / 16.0, 16 / 16.0),
new Vector3(0 / 16.0, 16 / 16.0, 16 / 16.0),
new Vector3(0 / 16.0, 0 / 16.0, 13 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 13 / 16.0)
),
new Quad(
new Vector3(16 / 16.0, 0 / 16.0, 13 / 16.0),
new Vector3(16 / 16.0, 16 / 16.0, 13 / 16.0),
new Vector3(16 / 16.0, 0 / 16.0, 16 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 13 / 16.0, 16 / 16.0)
),
new Quad(
new Vector3(0 / 16.0, 16 / 16.0, 13 / 16.0),
new Vector3(16 / 16.0, 16 / 16.0, 13 / 16.0),
new Vector3(0 / 16.0, 0 / 16.0, 13 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 0 / 16.0, 16 / 16.0)
),
new Quad(
new Vector3(16 / 16.0, 16 / 16.0, 16 / 16.0),
new Vector3(0 / 16.0, 16 / 16.0, 16 / 16.0),
new Vector3(16 / 16.0, 0 / 16.0, 16 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 0 / 16.0, 16 / 16.0)
)
};

private Quad[] quads;
private final Texture[] textures;

public OrientableTrapdoorModel(Texture texture, String half, String facing, boolean open) {
if (open) {
quads = quadsOpen;
} else if (half.equals("top")) {
quads = quadsTop;
} else {
quads = quadsBottom;
}

if (facing.equals("east")) {
if (open && half.equals("top")) {
quads = Model.rotateX(Model.rotateY(quads, Math.toRadians(270)), Math.toRadians(180));
} else {
quads = Model.rotateY(quads, Math.toRadians(90));
}
} else if (facing.equals("north") && open && half.equals("top")) {
quads = Model.rotateX(Model.rotateY(quads, Math.toRadians(180)), Math.toRadians(180));
} else if (facing.equals("south")) {
if (half.equals("top") && open) {
quads = Model.rotateX(quads, Math.toRadians(180));
} else {
quads = Model.rotateY(quads, Math.toRadians(180));
}
} else {
if (half.equals("top") && open) {
quads = Model.rotateY(Model.rotateX(quads, Math.toRadians(180)), Math.toRadians(90));
} else {
quads = Model.rotateY(quads, Math.toRadians(270));
}
}

textures = new Texture[quads.length];
Arrays.fill(textures, texture);
}

@Override
public Quad[] getQuads() {
return quads;
}

@Override
public Texture[] getTextures() {
return textures;
}
}
Loading