-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hanging signs (model still missing).
- Loading branch information
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package se.llbit.chunky.block; | ||
|
||
import se.llbit.chunky.entity.Entity; | ||
import se.llbit.chunky.entity.HangingSignEntity; | ||
import se.llbit.chunky.entity.SignEntity; | ||
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, SignEntity.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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
chunky/src/java/se/llbit/chunky/entity/HangingSignEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package se.llbit.chunky.entity; | ||
|
||
import se.llbit.chunky.resources.SignTexture; | ||
import se.llbit.chunky.resources.Texture; | ||
import se.llbit.json.JsonArray; | ||
import se.llbit.json.JsonObject; | ||
import se.llbit.json.JsonValue; | ||
import se.llbit.math.Vector3; | ||
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 final JsonArray[] frontText; | ||
private final JsonArray[] backText; | ||
private final int angle; | ||
private final boolean attached; | ||
private final SignTexture frontTexture; | ||
private final SignTexture backTexture; | ||
private final Texture texture; | ||
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); | ||
} | ||
|
||
public HangingSignEntity(Vector3 position, JsonArray[] frontText, JsonArray[] backText, int rotation, boolean attached, String material) { | ||
super(position); | ||
Texture signTexture = SignEntity.textureFromMaterial(material); | ||
this.frontText = frontText; | ||
this.backText = backText; | ||
this.angle = rotation; | ||
this.attached = attached; | ||
this.frontTexture = frontText != null ? new SignTexture(frontText, signTexture, false) : null; | ||
this.backTexture = backText != null ? new SignTexture(backText, signTexture, true) : null; | ||
this.texture = signTexture; | ||
this.material = material; | ||
} | ||
|
||
@Override | ||
public Collection<Primitive> primitives(Vector3 offset) { | ||
// TODO | ||
return new LinkedHashSet<>(); | ||
} | ||
|
||
@Override | ||
public JsonValue toJson() { | ||
JsonObject json = new JsonObject(); | ||
json.add("kind", "hangingSign"); | ||
json.add("position", position.toJson()); | ||
if (frontText != null) { | ||
json.add("text", SignEntity.textToJson(frontText)); | ||
} | ||
if (backText != null) { | ||
json.add("backText", SignEntity.textToJson(backText)); | ||
} | ||
json.add("direction", angle); | ||
json.add("attached", attached); | ||
json.add("material", material); | ||
return json; | ||
} | ||
|
||
/** | ||
* Unmarshalls a sign entity from JSON data. | ||
*/ | ||
public static Entity fromJson(JsonObject json) { | ||
Vector3 position = new Vector3(); | ||
position.fromJson(json.get("position").object()); | ||
JsonArray[] frontText = null; | ||
if (json.get("text").isArray()) { | ||
frontText = textFromJson(json.get("text")); | ||
} | ||
JsonArray[] backText = null; | ||
if (json.get("backText").isArray()) { | ||
backText = textFromJson(json.get("backText")); | ||
} | ||
int direction = json.get("direction").intValue(0); | ||
boolean attached = json.get("attached").boolValue(false); | ||
String material = json.get("material").stringValue("oak"); | ||
return new HangingSignEntity(position, frontText, backText, direction, attached, material); | ||
} | ||
} | ||
|