Skip to content

Commit 6d69f85

Browse files
committed
Allow Blocks and Entities to return multiple Entities
Lecterns are no longer poseable Lecterns now return both the lectern and its book.
1 parent b34f8a8 commit 6d69f85

32 files changed

Lines changed: 202 additions & 205 deletions

chunky/src/java/se/llbit/chunky/block/Block.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import se.llbit.nbt.CompoundTag;
1414
import se.llbit.nbt.Tag;
1515

16-
import java.util.List;
16+
import java.util.Collection;
1717
import java.util.Random;
1818

1919
public abstract class Block extends Material {
@@ -119,7 +119,7 @@ public boolean isBlockWithEntity() {
119119
return false;
120120
}
121121

122-
public Entity toEntity(Vector3 position) {
122+
public Collection<Entity> toEntity(Vector3 position) {
123123
throw new Error("This block type can not be converted to an entity: "
124124
+ getClass().getSimpleName());
125125
}

chunky/src/java/se/llbit/chunky/block/CakeWithCandle.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import se.llbit.chunky.resources.Texture;
77
import se.llbit.math.Vector3;
88

9+
import java.util.Collection;
10+
import java.util.Collections;
911
import java.util.Random;
1012

1113
public class CakeWithCandle extends AbstractModelBlock {
@@ -42,8 +44,8 @@ public boolean isBlockWithEntity() {
4244
}
4345

4446
@Override
45-
public Entity toEntity(Vector3 position) {
46-
return new FlameParticles(position, entity);
47+
public Collection<Entity> toEntity(Vector3 position) {
48+
return Collections.singletonList(new FlameParticles(position, entity));
4749
}
4850

4951
@Override

chunky/src/java/se/llbit/chunky/block/Candle.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import se.llbit.chunky.world.material.TextureMaterial;
99
import se.llbit.math.Vector3;
1010

11+
import java.util.Collection;
12+
import java.util.Collections;
1113
import java.util.Random;
1214

1315
public class Candle extends AbstractModelBlock {
@@ -70,11 +72,11 @@ public boolean isBlockWithEntity() {
7072
}
7173

7274
@Override
73-
public Entity toEntity(Vector3 position) {
75+
public Collection<Entity> toEntity(Vector3 position) {
7476
if (entity != null) {
75-
return new FlameParticles(position, entity);
77+
return Collections.singletonList(new FlameParticles(position, entity));
7678
} else {
77-
return new FlameParticles(position, this, new Vector3[0]);
79+
return Collections.singletonList(new FlameParticles(position, this, new Vector3[0]));
7880
}
7981
}
8082

chunky/src/java/se/llbit/chunky/block/CoralFan.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import se.llbit.chunky.entity.Entity;
55
import se.llbit.chunky.renderer.scene.Scene;
66
import se.llbit.chunky.resources.Texture;
7-
import se.llbit.math.Quad;
87
import se.llbit.math.Ray;
98
import se.llbit.math.Vector3;
10-
import se.llbit.math.Vector4;
9+
10+
import java.util.Collection;
11+
import java.util.Collections;
1112

1213
public class CoralFan extends MinecraftBlockTranslucent {
1314

@@ -55,7 +56,7 @@ public static Texture coralTexture(String coralType) {
5556
return true;
5657
}
5758

58-
@Override public Entity toEntity(Vector3 position) {
59-
return new CoralFanEntity(position, coralType);
59+
@Override public Collection<Entity> toEntity(Vector3 position) {
60+
return Collections.singletonList(new CoralFanEntity(position, coralType));
6061
}
6162
}

chunky/src/java/se/llbit/chunky/block/EnchantingTable.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import se.llbit.chunky.entity.Book;
44
import se.llbit.chunky.entity.Entity;
5-
import se.llbit.chunky.model.BlockModel;
65
import se.llbit.chunky.model.EnchantmentTableModel;
76
import se.llbit.chunky.resources.Texture;
87
import se.llbit.math.Vector3;
98

9+
import java.util.Collection;
10+
import java.util.Collections;
11+
1012
public class EnchantingTable extends AbstractModelBlock {
1113

1214
public EnchantingTable() {
@@ -27,7 +29,7 @@ public boolean isBlockWithEntity() {
2729
}
2830

2931
@Override
30-
public Entity toEntity(Vector3 position) {
32+
public Collection<Entity> toEntity(Vector3 position) {
3133
Vector3 newPosition = new Vector3(position);
3234
newPosition.add(0, 0.35, 0);
3335
Book book = new Book(
@@ -37,6 +39,6 @@ public Entity toEntity(Vector3 position) {
3739
Math.toRadians(180 - 30));
3840
book.setPitch(Math.toRadians(80));
3941
book.setYaw(Math.toRadians(45));
40-
return book;
42+
return Collections.singletonList(book);
4143
}
4244
}

chunky/src/java/se/llbit/chunky/block/Head.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import se.llbit.nbt.Tag;
3030
import se.llbit.util.mojangapi.MinecraftSkin;
3131

32+
import java.util.Collection;
33+
import java.util.Collections;
34+
3235
public class Head extends MinecraftBlockTranslucent {
3336

3437
private final String description;
@@ -60,8 +63,8 @@ public boolean isEntity() {
6063
}
6164

6265
@Override
63-
public Entity toEntity(Vector3 position) {
64-
return new SkullEntity(position, type, rotation, 1);
66+
public Collection<Entity> toEntity(Vector3 position) {
67+
return Collections.singletonList(new SkullEntity(position, type, rotation, 1));
6568
}
6669

6770
@Override

chunky/src/java/se/llbit/chunky/block/Lectern.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import se.llbit.math.Ray;
77
import se.llbit.math.Vector3;
88

9+
import java.util.Collection;
10+
911
public class Lectern extends MinecraftBlockTranslucent {
1012
private final String facing;
1113
private final boolean hasBook;
@@ -30,7 +32,7 @@ public boolean isEntity() {
3032
}
3133

3234
@Override
33-
public Entity toEntity(Vector3 position) {
34-
return new se.llbit.chunky.entity.Lectern(position, this.facing, this.hasBook);
35+
public Collection<Entity> toEntity(Vector3 position) {
36+
return se.llbit.chunky.entity.Lectern.create(position, this.facing, this.hasBook);
3537
}
3638
}

chunky/src/java/se/llbit/chunky/block/LilyPad.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import se.llbit.math.Vector3;
1010
import se.llbit.nbt.CompoundTag;
1111

12+
import java.util.Collection;
13+
import java.util.Collections;
14+
1215
public class LilyPad extends MinecraftBlockTranslucent {
1316
public LilyPad() {
1417
super("lily_pad", Texture.lilyPad);
@@ -25,7 +28,7 @@ public LilyPad() {
2528
return true;
2629
}
2730

28-
@Override public Entity toEntity(Vector3 position) {
29-
return new LilyPadEntity(position);
31+
@Override public Collection<Entity> toEntity(Vector3 position) {
32+
return Collections.singletonList(new LilyPadEntity(position));
3033
}
3134
}

chunky/src/java/se/llbit/chunky/block/SporeBlossom.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import se.llbit.math.Ray;
77
import se.llbit.math.Vector3;
88

9+
import java.util.Collection;
10+
import java.util.Collections;
11+
912
public class SporeBlossom extends Block {
1013

1114
public SporeBlossom() {
@@ -26,7 +29,7 @@ public boolean isEntity() {
2629
}
2730

2831
@Override
29-
public Entity toEntity(Vector3 position) {
30-
return new se.llbit.chunky.entity.SporeBlossom(position);
32+
public Collection<Entity> toEntity(Vector3 position) {
33+
return Collections.singletonList(new se.llbit.chunky.entity.SporeBlossom(position));
3134
}
3235
}

chunky/src/java/se/llbit/chunky/block/WallCoralFan.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import se.llbit.math.Ray;
88
import se.llbit.math.Vector3;
99

10+
import java.util.Collection;
11+
import java.util.Collections;
12+
1013
public class WallCoralFan extends MinecraftBlockTranslucent {
1114

1215
private final String coralType;
@@ -29,7 +32,7 @@ public WallCoralFan(String name, String coralType, String facing) {
2932
return true;
3033
}
3134

32-
@Override public Entity toEntity(Vector3 position) {
33-
return new WallCoralFanEntity(position, coralType, facing);
35+
@Override public Collection<Entity> toEntity(Vector3 position) {
36+
return Collections.singletonList(new WallCoralFanEntity(position, coralType, facing));
3437
}
3538
}

0 commit comments

Comments
 (0)