Skip to content

Commit

Permalink
Update hanging sign models, add wall hanging sign.
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik committed Aug 29, 2023
1 parent f9f9e69 commit a9900d7
Show file tree
Hide file tree
Showing 7 changed files with 568 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ private static void addBlocks(Texture texture, String... names) {
addBlock("cherry_sign", (name, tag) -> sign(tag, "cherry"));
addBlock("cherry_hanging_sign", (name, tag) -> hangingSign(tag, "cherry"));
addBlock("cherry_wall_sign", (name, tag) -> wallSign(tag, "cherry"));
addBlock("cherry_wall_hanging_sign", (name, tag) -> hangingSign(tag, "cherry"));
addBlock("cherry_wall_hanging_sign", (name, tag) -> wallHangingSign(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));
Expand Down Expand Up @@ -3268,6 +3268,10 @@ private static Block hangingSign(Tag tag, String material) {
return new HangingSign(name, material, rotation, attached);
}

private static Block wallHangingSign(Tag tag, String material) {
return new WallHangingSign(BlockProvider.blockName(tag), material, BlockProvider.facing(tag));
}

private static Block banner(Tag tag, Texture texture, int color) {
String name = BlockProvider.blockName(tag);
int rotation = BlockProvider.stringToInt(tag.get("Properties").get("rotation"), 0);
Expand Down
71 changes: 71 additions & 0 deletions chunky/src/java/se/llbit/chunky/block/WallHangingSign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package se.llbit.chunky.block;

import se.llbit.chunky.entity.Entity;
import se.llbit.chunky.entity.SignEntity;
import se.llbit.chunky.entity.WallHangingSignEntity;
import se.llbit.chunky.renderer.scene.Scene;
import se.llbit.math.Ray;
import se.llbit.math.Vector3;
import se.llbit.nbt.CompoundTag;

public class WallHangingSign extends MinecraftBlockTranslucent {
private final String material;
private final Facing facing;

public WallHangingSign(String name, String material, String facing) {
super(name, SignEntity.textureFromMaterial(material));
this.material = material;
this.facing = Facing.fromString(facing);
invisible = true;
solid = false;
localIntersect = true;
}

@Override
public boolean intersect(Ray ray, Scene scene) {
return false;
}

@Override
public boolean isBlockEntity() {
return true;
}

@Override
public Entity toBlockEntity(Vector3 position, CompoundTag entityTag) {
return new WallHangingSignEntity(position, entityTag, facing, material);
}

public enum Facing {
NORTH, EAST, SOUTH, WEST;

public static Facing fromString(String facing) {
switch (facing) {
case "east":
return EAST;
case "south":
return SOUTH;
case "west":
return WEST;
case "north":
default:
return NORTH;
}
}

@Override
public String toString() {
switch (this) {
case EAST:
return "east";
case SOUTH:
return "south";
case WEST:
return "west";
case NORTH:
default:
return "north";
}
}
}
}
2 changes: 2 additions & 0 deletions chunky/src/java/se/llbit/chunky/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public static Entity fromJson(JsonObject json) {
return CalibratedSculkSensorAmethyst.fromJson(json);
case "hangingSign":
return HangingSignEntity.fromJson(json);
case "wallHangingSign":
return WallHangingSignEntity.fromJson(json);
}
return null;
}
Expand Down
211 changes: 204 additions & 7 deletions chunky/src/java/se/llbit/chunky/entity/HangingSignEntity.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,212 @@
package se.llbit.chunky.entity;

import se.llbit.chunky.model.Model;
import se.llbit.chunky.resources.SignTexture;
import se.llbit.chunky.resources.Texture;
import se.llbit.chunky.world.material.TextureMaterial;
import se.llbit.json.JsonArray;
import se.llbit.json.JsonObject;
import se.llbit.json.JsonValue;
import se.llbit.math.Quad;
import se.llbit.math.Transform;
import se.llbit.math.Vector3;
import se.llbit.math.Vector4;
import se.llbit.math.primitive.Primitive;
import se.llbit.nbt.CompoundTag;

import java.util.Collection;
import java.util.LinkedHashSet;

import static se.llbit.chunky.entity.SignEntity.*;

public class HangingSignEntity extends Entity {
private static final Quad[] quadsAttached = new Quad[]{
new Quad(
new Vector3(-7 / 16.0, 10 / 16.0, 1 / 16.0),
new Vector3(7 / 16.0, 10 / 16.0, 1 / 16.0),
new Vector3(-7 / 16.0, 10 / 16.0, -1 / 16.0),
new Vector4(0 / 16.0, 16 / 16.0, 0 / 16.0, 16 / 16.0)
),
new Quad(
new Vector3(-7 / 16.0, 0 / 16.0, -1 / 16.0),
new Vector3(7 / 16.0, 0 / 16.0, -1 / 16.0),
new Vector3(-7 / 16.0, 0 / 16.0, 1 / 16.0),
new Vector4(0 / 16.0, 16 / 16.0, 0 / 16.0, 16 / 16.0)
),
new Quad(
new Vector3(-7 / 16.0, 10 / 16.0, 1 / 16.0),
new Vector3(-7 / 16.0, 10 / 16.0, -1 / 16.0),
new Vector3(-7 / 16.0, 0 / 16.0, 1 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(7 / 16.0, 10 / 16.0, -1 / 16.0),
new Vector3(7 / 16.0, 10 / 16.0, 1 / 16.0),
new Vector3(7 / 16.0, 0 / 16.0, -1 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(-7 / 16.0, 10 / 16.0, -1 / 16.0),
new Vector3(7 / 16.0, 10 / 16.0, -1 / 16.0),
new Vector3(-7 / 16.0, 0 / 16.0, -1 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(7 / 16.0, 10 / 16.0, 1 / 16.0),
new Vector3(-7 / 16.0, 10 / 16.0, 1 / 16.0),
new Vector3(7 / 16.0, 0 / 16.0, 1 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(-6 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(6 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(-6 / 16.0, 10 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(6 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(-6 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(6 / 16.0, 10 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
)
};

private static final Quad[] quadsNotAttached = Model.join(
new Quad[]{
new Quad(
new Vector3(-7 / 16.0, 10 / 16.0, 1 / 16.0),
new Vector3(7 / 16.0, 10 / 16.0, 1 / 16.0),
new Vector3(-7 / 16.0, 10 / 16.0, -1 / 16.0),
new Vector4(0 / 16.0, 16 / 16.0, 0 / 16.0, 16 / 16.0)
),
new Quad(
new Vector3(-7 / 16.0, 0 / 16.0, -1 / 16.0),
new Vector3(7 / 16.0, 0 / 16.0, -1 / 16.0),
new Vector3(-7 / 16.0, 0 / 16.0, 1 / 16.0),
new Vector4(0 / 16.0, 16 / 16.0, 0 / 16.0, 16 / 16.0)
),
new Quad(
new Vector3(-7 / 16.0, 10 / 16.0, 1 / 16.0),
new Vector3(-7 / 16.0, 10 / 16.0, -1 / 16.0),
new Vector3(-7 / 16.0, 0 / 16.0, 1 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(7 / 16.0, 10 / 16.0, -1 / 16.0),
new Vector3(7 / 16.0, 10 / 16.0, 1 / 16.0),
new Vector3(7 / 16.0, 0 / 16.0, -1 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(-7 / 16.0, 10 / 16.0, -1 / 16.0),
new Vector3(7 / 16.0, 10 / 16.0, -1 / 16.0),
new Vector3(-7 / 16.0, 0 / 16.0, -1 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(7 / 16.0, 10 / 16.0, 1 / 16.0),
new Vector3(-7 / 16.0, 10 / 16.0, 1 / 16.0),
new Vector3(7 / 16.0, 0 / 16.0, 1 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
)
},
Model.transform(
new Quad[]{
new Quad(
new Vector3(-1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(-1.5 / 16.0, 10 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(-1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(1.5 / 16.0, 10 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
)
},
Transform.NONE
.translate(0.5, 0.5, 0.5)
.rotateY(Math.toRadians(-45))
.translate(-0.5, -0.5, -0.5)
.translate(-5 / 16.0, 0 / 16.0, 0 / 16.0)
),
Model.transform(
new Quad[]{
new Quad(
new Vector3(-1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(-1.5 / 16.0, 10 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(-1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(1.5 / 16.0, 10 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
)
},
Transform.NONE
.translate(0.5, 0.5, 0.5)
.rotateY(Math.toRadians(45))
.translate(-0.5, -0.5, -0.5)
.translate(-5 / 16.0, 0 / 16.0, 0 / 16.0)
),
Model.transform(
new Quad[]{
new Quad(
new Vector3(-1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(-1.5 / 16.0, 10 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(-1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(1.5 / 16.0, 10 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
)
},
Transform.NONE
.translate(0.5, 0.5, 0.5)
.rotateY(Math.toRadians(-45))
.translate(-0.5, -0.5, -0.5)
.translate(5 / 16.0, 0 / 16.0, 0 / 16.0)
),
Model.transform(
new Quad[]{
new Quad(
new Vector3(-1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(-1.5 / 16.0, 10 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
),
new Quad(
new Vector3(1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(-1.5 / 16.0, 16 / 16.0, 0 / 16.0),
new Vector3(1.5 / 16.0, 10 / 16.0, 0 / 16.0),
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
)
},
Transform.NONE
.translate(0.5, 0.5, 0.5)
.rotateY(Math.toRadians(45))
.translate(-0.5, -0.5, -0.5)
.translate(5 / 16.0, 0 / 16.0, 0 / 16.0)
)
);

private static Quad[][] rotatedQuadsAttached = new Quad[16][];
private static Quad[][] rotatedQuadsNotAttached = new Quad[16][];

static {
rotatedQuadsAttached[0] = Model.translate(quadsAttached, 0.5, 0, 0.5);
rotatedQuadsNotAttached[0] = Model.translate(quadsNotAttached, 0.5, 0, 0.5);

for (int i = 1; i < 16; ++i) {
rotatedQuadsAttached[i] = Model.rotateY(rotatedQuadsAttached[0], -i * Math.PI / 8);
rotatedQuadsNotAttached[i] = Model.rotateY(rotatedQuadsNotAttached[0], -i * Math.PI / 8);
}
}

private final JsonArray[] frontText;
private final JsonArray[] backText;
private final int angle;
Expand All @@ -25,7 +217,7 @@ public class HangingSignEntity extends Entity {
private final String material;

public HangingSignEntity(Vector3 position, CompoundTag entityTag, int rotation, boolean attached, String material) {
this(position, getFrontTextLines(entityTag), getBackTextLines(entityTag), rotation, attached, material);
this(position, SignEntity.getFrontTextLines(entityTag), SignEntity.getBackTextLines(entityTag), rotation, attached, material);
}

public HangingSignEntity(Vector3 position, JsonArray[] frontText, JsonArray[] backText, int rotation, boolean attached, String material) {
Expand All @@ -43,8 +235,13 @@ public HangingSignEntity(Vector3 position, JsonArray[] frontText, JsonArray[] ba

@Override
public Collection<Primitive> primitives(Vector3 offset) {
// TODO
return new LinkedHashSet<>();
LinkedHashSet<Primitive> set = new LinkedHashSet<>();
Quad[] quads = attached ? rotatedQuadsAttached[angle] : rotatedQuadsNotAttached[angle];
for (Quad quad : quads) {
quad.addTriangles(set, new TextureMaterial(Texture.redWool),
Transform.NONE.translate(position.x + offset.x, position.y + offset.y, position.z + offset.z));
}
return set;
}

@Override
Expand Down Expand Up @@ -72,11 +269,11 @@ public static Entity fromJson(JsonObject json) {
position.fromJson(json.get("position").object());
JsonArray[] frontText = null;
if (json.get("text").isArray()) {
frontText = textFromJson(json.get("text"));
frontText = SignEntity.textFromJson(json.get("text"));
}
JsonArray[] backText = null;
if (json.get("backText").isArray()) {
backText = textFromJson(json.get("backText"));
backText = SignEntity.textFromJson(json.get("backText"));
}
int direction = json.get("direction").intValue(0);
boolean attached = json.get("attached").boolValue(false);
Expand Down
Loading

0 comments on commit a9900d7

Please sign in to comment.