Skip to content

Commit

Permalink
Add hanging signs. (#1600)
Browse files Browse the repository at this point in the history
* Add hanging signs (model still missing).

* Update hanging sign models, add wall hanging sign.

* Add uv maps and proper textures.

* Add text to hanging signs.

* Fix hanging sign text size and line height.
  • Loading branch information
leMaik authored Sep 10, 2023
1 parent e27e28a commit 7be7fd6
Show file tree
Hide file tree
Showing 12 changed files with 882 additions and 48 deletions.
39 changes: 39 additions & 0 deletions chunky/src/java/se/llbit/chunky/block/HangingSign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package se.llbit.chunky.block;

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

public class HangingSign extends MinecraftBlockTranslucent {
private final String material;
private final int rotation;
private final boolean attached;

public HangingSign(String name, String material, int rotation, boolean attached) {
super(name, HangingSignEntity.textureFromMaterial(material));
this.material = material;
this.rotation = rotation;
this.attached = attached;
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 HangingSignEntity(position, entityTag, rotation, attached, material);
}
}
33 changes: 33 additions & 0 deletions chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,28 @@ private static void addBlocks(Texture texture, String... names) {
addBlock("calibrated_sculk_sensor", (name, tag) -> new CalibratedSculkSensor(
tag.get("Properties").get("sculk_sensor_phase").stringValue("cooldown"),
tag.get("Properties").get("facing").stringValue("north")));
addBlock("oak_hanging_sign", (name, tag) -> hangingSign(tag, "oak"));
addBlock("oak_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "oak"));
addBlock("spruce_hanging_sign", (name, tag) -> hangingSign(tag, "spruce"));
addBlock("spruce_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "spruce"));
addBlock("birch_hanging_sign", (name, tag) -> hangingSign(tag, "birch"));
addBlock("birch_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "birch"));
addBlock("jungle_hanging_sign", (name, tag) -> hangingSign(tag, "jungle"));
addBlock("jungle_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "jungle"));
addBlock("acacia_hanging_sign", (name, tag) -> hangingSign(tag, "acacia"));
addBlock("acacia_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "acacia"));
addBlock("dark_oak_hanging_sign", (name, tag) -> hangingSign(tag, "dark_oak"));
addBlock("dark_oak_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "dark_oak"));
addBlock("crimson_hanging_sign", (name, tag) -> hangingSign(tag, "crimson"));
addBlock("crimson_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "crimson"));
addBlock("warped_hanging_sign", (name, tag) -> hangingSign(tag, "warped"));
addBlock("warped_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "warped"));
addBlock("mangrove_hanging_sign", (name, tag) -> hangingSign(tag, "mangrove"));
addBlock("mangrove_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "mangrove"));
addBlock("bamboo_hanging_sign", (name, tag) -> hangingSign(tag, "bamboo"));
addBlock("bamboo_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "bamboo"));
addBlock("cherry_hanging_sign", (name, tag) -> hangingSign(tag, "cherry"));
addBlock("cherry_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "cherry"));
}

@Override
Expand Down Expand Up @@ -3255,6 +3277,17 @@ private static Block sign(Tag tag, String material) {
return new Sign(name, material, rotation);
}

private static Block hangingSign(Tag tag, String material) {
String name = BlockProvider.blockName(tag);
int rotation = BlockProvider.stringToInt(tag.get("Properties").get("rotation"), 0);
boolean attached = tag.get("Properties").get("attached").stringValue("false").equals("true");
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.HangingSignEntity;
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, HangingSignEntity.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";
}
}
}
}
4 changes: 4 additions & 0 deletions chunky/src/java/se/llbit/chunky/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public static Entity fromJson(JsonObject json) {
return DecoratedPotModel.DecoratedPotSpoutEntity.fromJson(json);
case "calibratedSculkSensorAmethyst":
return CalibratedSculkSensorAmethyst.fromJson(json);
case "hangingSign":
return HangingSignEntity.fromJson(json);
case "wallHangingSign":
return WallHangingSignEntity.fromJson(json);
}
return null;
}
Expand Down
Loading

0 comments on commit 7be7fd6

Please sign in to comment.