From d9fe92ff49f0729df3001e635a401e855c4daaae Mon Sep 17 00:00:00 2001 From: Maik Marschner Date: Sun, 27 Oct 2024 02:43:24 +0200 Subject: [PATCH] Fix trapdoor textures. (#1787) --- .../chunky/block/MinecraftBlockProvider.java | 27 +- .../block/minecraft/OrientableTrapdoor.java | 40 +++ .../chunky/block/minecraft/Trapdoor.java | 31 +- .../minecraft/OrientableTrapdoorModel.java | 194 ++++++++++++ .../chunky/model/minecraft/TrapdoorModel.java | 297 ++++++++---------- 5 files changed, 388 insertions(+), 201 deletions(-) create mode 100644 chunky/src/java/se/llbit/chunky/block/minecraft/OrientableTrapdoor.java create mode 100644 chunky/src/java/se/llbit/chunky/model/minecraft/OrientableTrapdoorModel.java diff --git a/chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java b/chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java index d64ca3aa22..96dd0b8823 100644 --- a/chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java +++ b/chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java @@ -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()); @@ -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)); @@ -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)); @@ -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": @@ -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": @@ -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"); diff --git a/chunky/src/java/se/llbit/chunky/block/minecraft/OrientableTrapdoor.java b/chunky/src/java/se/llbit/chunky/block/minecraft/OrientableTrapdoor.java new file mode 100644 index 0000000000..4477df85ca --- /dev/null +++ b/chunky/src/java/se/llbit/chunky/block/minecraft/OrientableTrapdoor.java @@ -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 . + */ + +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; + } +} diff --git a/chunky/src/java/se/llbit/chunky/block/minecraft/Trapdoor.java b/chunky/src/java/se/llbit/chunky/block/minecraft/Trapdoor.java index 722a56cc23..77785fe330 100644 --- a/chunky/src/java/se/llbit/chunky/block/minecraft/Trapdoor.java +++ b/chunky/src/java/se/llbit/chunky/block/minecraft/Trapdoor.java @@ -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 diff --git a/chunky/src/java/se/llbit/chunky/model/minecraft/OrientableTrapdoorModel.java b/chunky/src/java/se/llbit/chunky/model/minecraft/OrientableTrapdoorModel.java new file mode 100644 index 0000000000..8df4e545bd --- /dev/null +++ b/chunky/src/java/se/llbit/chunky/model/minecraft/OrientableTrapdoorModel.java @@ -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 . + */ +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; + } +} diff --git a/chunky/src/java/se/llbit/chunky/model/minecraft/TrapdoorModel.java b/chunky/src/java/se/llbit/chunky/model/minecraft/TrapdoorModel.java index 7d473cd448..88bb3b07d2 100644 --- a/chunky/src/java/se/llbit/chunky/model/minecraft/TrapdoorModel.java +++ b/chunky/src/java/se/llbit/chunky/model/minecraft/TrapdoorModel.java @@ -17,6 +17,7 @@ */ 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; @@ -26,177 +27,145 @@ import java.util.Arrays; public class TrapdoorModel extends QuadModel { - //region Model - private static final Quad[][] faces = { - // low - { - // front - new Quad(new Vector3(1, 0, 0), new Vector3(0, 0, 0), new Vector3(1, .1875, 0), - new Vector4(1, 0, 0, .1875)), - - // back - new Quad(new Vector3(0, 0, 1), new Vector3(1, 0, 1), new Vector3(0, .1875, 1), - new Vector4(0, 1, 0, .1875)), - - // right - new Quad(new Vector3(0, 0, 0), new Vector3(0, 0, 1), new Vector3(0, .1875, 0), - new Vector4(0, 1, 0, .1875)), - - // left - new Quad(new Vector3(1, 0, 1), new Vector3(1, 0, 0), new Vector3(1, .1875, 1), - new Vector4(1, 0, 0, .1875)), - - // top - new Quad(new Vector3(1, .1875, 0), new Vector3(0, .1875, 0), new Vector3(1, .1875, 1), - new Vector4(1, 0, 0, 1)), - - // bottom - new Quad(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1), - new Vector4(0, 1, 0, 1)) - }, - - // high - { - // front - new Quad(new Vector3(1, .8125, 0), new Vector3(0, .8125, 0), new Vector3(1, 1, 0), - new Vector4(1, 0, 0, .1875)), - - // back - new Quad(new Vector3(0, .8125, 1), new Vector3(1, .8125, 1), new Vector3(0, 1, 1), - new Vector4(0, 1, 0, .1875)), - - // right - new Quad(new Vector3(0, .8125, 0), new Vector3(0, .8125, 1), new Vector3(0, 1, 0), - new Vector4(0, 1, 0, .1875)), - - // left - new Quad(new Vector3(1, .8125, 1), new Vector3(1, .8125, 0), new Vector3(1, 1, 1), - new Vector4(1, 0, 0, .1875)), - - // top - new Quad(new Vector3(1, 1, 0), new Vector3(0, 1, 0), new Vector3(1, 1, 1), - new Vector4(1, 0, 0, 1)), - - // bottom - new Quad(new Vector3(0, 13 / 16., 0), new Vector3(1, 13 / 16., 0), - new Vector3(0, 13 / 16., 1), new Vector4(0, 1, 0, 1)) - }, - - // facing north - { - // north - new Quad(new Vector3(1, 0, .8125), new Vector3(0, 0, .8125), new Vector3(1, 1, .8125), - new Vector4(1, 0, 0, 1)), - - // south - new Quad(new Vector3(0, 0, 1), new Vector3(1, 0, 1), new Vector3(0, 1, 1), - new Vector4(0, 1, 0, 1)), - - // west - new Quad(new Vector3(0, 0, .8125), new Vector3(0, 0, 1), new Vector3(0, 1, .8125), - new Vector4(.8125, 1, 0, 1)), - - // east - new Quad(new Vector3(1, 0, 1), new Vector3(1, 0, .8125), new Vector3(1, 1, 1), - new Vector4(1, .8125, 0, 1)), - - // top - new Quad(new Vector3(1, 1, .8125), new Vector3(0, 1, .8125), new Vector3(1, 1, 1), - new Vector4(1, 0, .8125, 1)), - - // bottom - new Quad(new Vector3(0, 0, .8125), new Vector3(1, 0, .8125), new Vector3(0, 0, 1), - new Vector4(0, 1, .8125, 1)) - }, - - // facing south - { - // north - new Quad(new Vector3(1, 0, 0), new Vector3(0, 0, 0), new Vector3(1, 1, 0), - new Vector4(1, 0, 0, 1)), - - // south - new Quad(new Vector3(0, 0, .1875), new Vector3(1, 0, .1875), new Vector3(0, 1, .1875), - new Vector4(0, 1, 0, 1)), - - // west - new Quad(new Vector3(0, 0, 0), new Vector3(0, 0, .1875), new Vector3(0, 1, 0), - new Vector4(0, .1875, 0, 1)), - - // east - new Quad(new Vector3(1, 0, .1875), new Vector3(1, 0, 0), new Vector3(1, 1, .1875), - new Vector4(.1875, 0, 0, 1)), - - // top - new Quad(new Vector3(1, 1, 0), new Vector3(0, 1, 0), new Vector3(1, 1, .1875), - new Vector4(1, 0, 0, .1875)), - - // bottom - new Quad(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 0, .1875), - new Vector4(0, 1, 0, .1875)) - }, - - // facing west - { - // north - new Quad(new Vector3(1, 0, 0), new Vector3(.8125, 0, 0), new Vector3(1, 1, 0), - new Vector4(1, .8125, 0, 1)), - - // south - new Quad(new Vector3(.8125, 0, 1), new Vector3(1, 0, 1), new Vector3(.8125, 1, 1), - new Vector4(.8125, 1, 0, 1)), - - // west - new Quad(new Vector3(.8125, 0, 0), new Vector3(.8125, 0, 1), new Vector3(.8125, 1, 0), - new Vector4(0, 1, 0, 1)), - - // east - new Quad(new Vector3(1, 0, 1), new Vector3(1, 0, 0), new Vector3(1, 1, 1), - new Vector4(1, 0, 0, 1)), - - // top - new Quad(new Vector3(1, 1, 0), new Vector3(.8125, 1, 0), new Vector3(1, 1, 1), - new Vector4(1, .8125, 0, 1)), - - // bottom - new Quad(new Vector3(.8125, 0, 0), new Vector3(1, 0, 0), new Vector3(.8125, 0, 1), - new Vector4(.8125, 1, 0, 1)) - }, - - // facing east - { - // north - new Quad(new Vector3(.1875, 0, 0), new Vector3(0, 0, 0), new Vector3(.1875, 1, 0), - new Vector4(.1875, 0, 0, 1)), - - // south - new Quad(new Vector3(0, 0, 1), new Vector3(.1875, 0, 1), new Vector3(0, 1, 1), - new Vector4(0, .1875, 0, 1)), - - // west - new Quad(new Vector3(0, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 1, 0), - new Vector4(0, 1, 0, 1)), - - // east - new Quad(new Vector3(.1875, 0, 1), new Vector3(.1875, 0, 0), new Vector3(.1875, 1, 1), - new Vector4(1, 0, 0, 1)), + 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, 0 / 16.0, 16 / 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, 0 / 16.0, 3 / 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, 0 / 16.0, 3 / 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, 0 / 16.0, 3 / 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, 0 / 16.0, 3 / 16.0) + ) + }; - // top - new Quad(new Vector3(.1875, 1, 0), new Vector3(0, 1, 0), new Vector3(.1875, 1, 1), - new Vector4(.1875, 0, 0, 1)), + 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, 0 / 16.0, 16 / 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, 0 / 16.0, 3 / 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, 0 / 16.0, 3 / 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, 0 / 16.0, 3 / 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, 0 / 16.0, 3 / 16.0) + ) + }; - // bottom - new Quad(new Vector3(0, 0, 0), new Vector3(.1875, 0, 0), new Vector3(0, 0, 1), - new Vector4(0, .1875, 0, 1)) - } + 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, 3 / 16.0, 0 / 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, 0 / 16.0, 3 / 16.0) + ), + new Quad( + new Vector3(0 / 16.0, 16 / 16.0, 16 / 16.0), + new Vector3(0 / 16.0, 16 / 16.0, 13 / 16.0), + new Vector3(0 / 16.0, 0 / 16.0, 16 / 16.0), + new Vector4(13 / 16.0, 16 / 16.0, 16 / 16.0, 0 / 16.0) + ), + new Quad( + new Vector3(16 / 16.0, 16 / 16.0, 13 / 16.0), + new Vector3(16 / 16.0, 16 / 16.0, 16 / 16.0), + new Vector3(16 / 16.0, 0 / 16.0, 13 / 16.0), + new Vector4(16 / 16.0, 13 / 16.0, 16 / 16.0, 0 / 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, 16 / 16.0, 0 / 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, 16 / 16.0, 0 / 16.0) + ) }; - //endregion private final Quad[] quads; private final Texture[] textures; - public TrapdoorModel(Texture texture, int state) { - quads = (state & 4) == 0 ? faces[state >> 3] : faces[(state & 3) + 2]; + public TrapdoorModel(Texture texture, String half, String facing, boolean open) { + if (open) { + if (facing.equals("east")) { + quads = Model.rotateY(quadsOpen, Math.toRadians(90)); + } else if (facing.equals("south")) { + quads = Model.rotateY(quadsOpen, Math.toRadians(180)); + } else if (facing.equals("west")) { + quads = Model.rotateY(quadsOpen, Math.toRadians(270)); + } else { + quads = quadsOpen; + } + } else { + if (half.equals("bottom")) { + quads = quadsBottom; + } else { + quads = quadsTop; + } + } + textures = new Texture[quads.length]; Arrays.fill(textures, texture); }