|
21 | 21 | import se.llbit.chunky.model.minecraft.DecoratedPotModel; |
22 | 22 | import se.llbit.json.JsonObject; |
23 | 23 | import se.llbit.json.JsonValue; |
| 24 | +import se.llbit.log.Log; |
24 | 25 | import se.llbit.math.Grid; |
25 | 26 | import se.llbit.math.Octree; |
26 | 27 | import se.llbit.math.Vector3; |
27 | 28 | import se.llbit.math.Vector3i; |
28 | 29 | import se.llbit.math.primitive.Primitive; |
29 | 30 |
|
30 | 31 | import java.util.Collection; |
| 32 | +import java.util.LinkedList; |
31 | 33 |
|
32 | 34 | /** |
33 | 35 | * Represents Minecraft entities that are not stored in the octree. |
@@ -68,70 +70,51 @@ public void loadDataFromOctree(Octree octree, BlockPalette palette, Vector3i ori |
68 | 70 | /** |
69 | 71 | * Unmarshalls an entity object from JSON data. |
70 | 72 | * |
| 73 | + * <p>This method only returns a {@link Collection} to support legacy scenes.</p> |
| 74 | + * |
71 | 75 | * @param json json data. |
72 | | - * @return unmarshalled entity, or {@code null} if it was not a valid entity. |
| 76 | + * @return The entities, or an empty collection if no entity was found. |
73 | 77 | */ |
74 | | - public static Collection<Entity> fromJson(JsonObject json) { |
| 78 | + public static Collection<Entity> entitiesFromJson(JsonObject json) { |
75 | 79 | String kind = json.get("kind").stringValue(""); |
| 80 | + Collection<Entity> entities = new LinkedList<>(); |
76 | 81 | switch (kind) { |
77 | | - case "painting": |
78 | | - return PaintingEntity.fromJson(json); |
79 | | - case "sign": |
80 | | - return SignEntity.fromJson(json); |
81 | | - case "wallsign": |
82 | | - return WallSignEntity.fromJson(json); |
83 | | - case "skull": |
84 | | - return SkullEntity.fromJson(json); |
85 | | - case "head": |
86 | | - return HeadEntity.fromJson(json); |
87 | | - case "player": |
88 | | - return PlayerEntity.fromJson(json); |
89 | | - case "standing_banner": |
90 | | - return StandingBanner.fromJson(json); |
91 | | - case "wall_banner": |
92 | | - return WallBanner.fromJson(json); |
93 | | - case "armor_stand": |
94 | | - return ArmorStand.fromJson(json); |
95 | | - case "lily_pad": |
96 | | - return LilyPadEntity.fromJson(json); |
97 | | - case "coral_fan": |
98 | | - return CoralFanEntity.fromJson(json); |
99 | | - case "wall_coral_fan": |
100 | | - return WallCoralFanEntity.fromJson(json); |
101 | | - case "lectern": |
102 | | - return Lectern.fromJson(json); |
103 | | - case "campfire": |
104 | | - return Campfire.fromJson(json); |
105 | | - case "book": |
106 | | - return Book.fromJson(json); |
107 | | - case "flameParticles": |
108 | | - return FlameParticles.fromJson(json); |
109 | | - case "beaconBeam": |
110 | | - return BeaconBeam.fromJson(json); |
111 | | - case "sporeBlossom": |
112 | | - return SporeBlossom.fromJson(json); |
113 | | - case "decoratedPotSpout": |
114 | | - return DecoratedPotModel.DecoratedPotSpoutEntity.fromJson(json); |
115 | | - case "calibratedSculkSensorAmethyst": |
116 | | - return CalibratedSculkSensorAmethyst.fromJson(json); |
117 | | - case "hangingSign": |
118 | | - return HangingSignEntity.fromJson(json); |
119 | | - case "wallHangingSign": |
120 | | - return WallHangingSignEntity.fromJson(json); |
121 | | - case "sheep": |
122 | | - return SheepEntity.fromJson(json); |
123 | | - case "cow": |
124 | | - return CowEntity.fromJson(json); |
125 | | - case "chicken": |
126 | | - return ChickenEntity.fromJson(json); |
127 | | - case "pig": |
128 | | - return PigEntity.fromJson(json); |
129 | | - case "mooshroom": |
130 | | - return MooshroomEntity.fromJson(json); |
131 | | - case "squid": |
132 | | - return SquidEntity.fromJson(json); |
| 82 | + case "painting" -> entities.add(PaintingEntity.fromJson(json)); |
| 83 | + case "sign" -> entities.add(SignEntity.fromJson(json)); |
| 84 | + case "wallsign" -> entities.add(WallSignEntity.fromJson(json)); |
| 85 | + case "skull" -> entities.add(SkullEntity.fromJson(json)); |
| 86 | + case "head" -> entities.add(HeadEntity.fromJson(json)); |
| 87 | + case "player" -> entities.add(PlayerEntity.fromJson(json)); |
| 88 | + case "standing_banner" -> entities.add(StandingBanner.fromJson(json)); |
| 89 | + case "wall_banner" -> entities.add(WallBanner.fromJson(json)); |
| 90 | + case "armor_stand" -> entities.add(ArmorStand.fromJson(json)); |
| 91 | + case "lily_pad" -> entities.add(LilyPadEntity.fromJson(json)); |
| 92 | + case "coral_fan" -> entities.add(CoralFanEntity.fromJson(json)); |
| 93 | + case "wall_coral_fan" -> entities.add(WallCoralFanEntity.fromJson(json)); |
| 94 | + case "lectern" -> { |
| 95 | + if (json.get("book").isObject()) { // we still get the book from the lectern json to be compatible with the old format |
| 96 | + entities.add(Book.fromJson(json.get("book").object())); |
| 97 | + } |
| 98 | + entities.add(Lectern.fromJson(json)); |
| 99 | + } |
| 100 | + case "campfire" -> entities.add(Campfire.fromJson(json)); |
| 101 | + case "book" -> entities.add(Book.fromJson(json)); |
| 102 | + case "flameParticles" -> entities.add(FlameParticles.fromJson(json)); |
| 103 | + case "beaconBeam" -> entities.add(BeaconBeam.fromJson(json)); |
| 104 | + case "sporeBlossom" -> entities.add(SporeBlossom.fromJson(json)); |
| 105 | + case "decoratedPotSpout" -> entities.add(DecoratedPotModel.DecoratedPotSpoutEntity.fromJson(json)); |
| 106 | + case "calibratedSculkSensorAmethyst" -> entities.add(CalibratedSculkSensorAmethyst.fromJson(json)); |
| 107 | + case "hangingSign" -> entities.add(HangingSignEntity.fromJson(json)); |
| 108 | + case "wallHangingSign" -> entities.add(WallHangingSignEntity.fromJson(json)); |
| 109 | + case "sheep" -> entities.add(SheepEntity.fromJson(json)); |
| 110 | + case "cow" -> entities.add(CowEntity.fromJson(json)); |
| 111 | + case "chicken" -> entities.add(ChickenEntity.fromJson(json)); |
| 112 | + case "pig" -> entities.add(PigEntity.fromJson(json)); |
| 113 | + case "mooshroom" -> entities.add(MooshroomEntity.fromJson(json)); |
| 114 | + case "squid" -> entities.add(SquidEntity.fromJson(json)); |
| 115 | + default -> Log.errorf("Found unknown entity %s when loading from scene.", kind); |
133 | 116 | } |
134 | | - return null; |
| 117 | + return entities; |
135 | 118 | } |
136 | 119 |
|
137 | 120 | public Vector3 getPosition() { |
|
0 commit comments