4444import java .util .function .BooleanSupplier ;
4545
4646public class CcaBlockTestSuite implements FabricGameTest {
47- @ GameTest (templateName = EMPTY_STRUCTURE )
48- public void beSerialize (TestContext ctx ) {
47+ @ GameTest (templateName = EMPTY_STRUCTURE ) public void beSerialize (TestContext ctx ) {
4948 BlockPos pos = ctx .getAbsolutePos (BlockPos .ORIGIN );
50- BlockEntity be = Objects .requireNonNull (
51- BlockEntityType .END_GATEWAY .instantiate (
52- pos ,
53- Blocks .END_GATEWAY .getDefaultState ()
54- )
55- );
49+ BlockEntity be = Objects .requireNonNull (BlockEntityType .END_GATEWAY .instantiate (pos , Blocks .END_GATEWAY .getDefaultState ()));
5650 be .getComponent (Vita .KEY ).setVitality (42 );
5751 NbtCompound nbt = be .createNbt ();
58- BlockEntity be1 = Objects .requireNonNull (
59- BlockEntityType .END_GATEWAY .instantiate (
60- pos , Blocks .END_GATEWAY .getDefaultState ()
61- )
62- );
52+ BlockEntity be1 = Objects .requireNonNull (BlockEntityType .END_GATEWAY .instantiate (pos , Blocks .END_GATEWAY .getDefaultState ()));
6353 GameTestUtil .assertTrue ("New BlockEntity should have values zeroed" , be1 .getComponent (Vita .KEY ).getVitality () == 0 );
6454 be1 .readNbt (nbt );
6555 GameTestUtil .assertTrue ("BlockEntity component data should survive deserialization" , be1 .getComponent (Vita .KEY ).getVitality () == 42 );
6656 ctx .complete ();
6757 }
6858
69- @ GameTest (templateName = EMPTY_STRUCTURE )
70- public void canQueryThroughLookup (TestContext ctx ) {
59+ @ GameTest (templateName = EMPTY_STRUCTURE ) public void canQueryThroughLookup (TestContext ctx ) {
7160 BlockPos pos = ctx .getAbsolutePos (BlockPos .ORIGIN );
72- BlockEntity be = Objects .requireNonNull (
73- BlockEntityType .END_GATEWAY .instantiate (
74- pos ,
75- Blocks .END_GATEWAY .getDefaultState ()
76- )
77- );
61+ BlockEntity be = Objects .requireNonNull (BlockEntityType .END_GATEWAY .instantiate (pos , Blocks .END_GATEWAY .getDefaultState ()));
7862 getVita (ctx , pos , be ).setVitality (42 );
7963 NbtCompound nbt = be .createNbt ();
80- BlockEntity be1 = Objects .requireNonNull (
81- BlockEntityType .END_GATEWAY .instantiate (
82- pos , Blocks .END_GATEWAY .getDefaultState ()
83- )
84- );
64+ BlockEntity be1 = Objects .requireNonNull (BlockEntityType .END_GATEWAY .instantiate (pos , Blocks .END_GATEWAY .getDefaultState ()));
8565 GameTestUtil .assertTrue ("New BlockEntity should have values zeroed" , getVita (ctx , pos , be1 ).getVitality () == 0 );
8666 be1 .readNbt (nbt );
8767 GameTestUtil .assertTrue ("BlockEntity component data should survive deserialization" , getVita (ctx , pos , be1 ).getVitality () == 42 );
@@ -92,8 +72,7 @@ public void canQueryThroughLookup(TestContext ctx) {
9272 return Objects .requireNonNull (CcaBlockTestMod .VITA_API_LOOKUP .find (ctx .getWorld (), pos , null , be , Direction .DOWN ));
9373 }
9474
95- @ GameTest (templateName = EMPTY_STRUCTURE )
96- public void beComponentsTick (TestContext ctx ) {
75+ @ GameTest (templateName = EMPTY_STRUCTURE ) public void beComponentsTick (TestContext ctx ) {
9776 ctx .setBlockState (BlockPos .ORIGIN , Blocks .END_PORTAL );
9877
9978 var blockentity = ctx .getBlockEntity (BlockPos .ORIGIN );
@@ -111,31 +90,20 @@ public void beComponentsTick(TestContext ctx) {
11190 });
11291 }
11392
114- @ GameTest (templateName = EMPTY_STRUCTURE )
115- public void beComponentsLoadUnload (TestContext ctx ) {
93+ @ GameTest (templateName = EMPTY_STRUCTURE ) public void beComponentsLoadUnload (TestContext ctx ) {
11694 BlockEntity firstCommandBlock = new CommandBlockBlockEntity (ctx .getAbsolutePos (BlockPos .ORIGIN ), Blocks .CHAIN_COMMAND_BLOCK .getDefaultState ());
117- GameTestUtil .assertTrue (
118- "Load counter should not be incremented until the block entity joins the world" ,
119- LoadAwareTestComponent .KEY .get (firstCommandBlock ).getLoadCounter () == 0
120- );
95+ GameTestUtil .assertTrue ("Load counter should not be incremented until the block entity joins the world" , LoadAwareTestComponent .KEY .get (firstCommandBlock ).getLoadCounter () == 0 );
12196 ctx .setBlockState (BlockPos .ORIGIN , Blocks .CHAIN_COMMAND_BLOCK );
12297 BlockEntity commandBlock = Objects .requireNonNull (ctx .getBlockEntity (BlockPos .ORIGIN ));
123- GameTestUtil .assertTrue (
124- "Load counter should be incremented once when the block entity joins the world" ,
125- LoadAwareTestComponent .KEY .get (commandBlock ).getLoadCounter () == 1
126- );
98+ GameTestUtil .assertTrue ("Load counter should be incremented once when the block entity joins the world" , LoadAwareTestComponent .KEY .get (commandBlock ).getLoadCounter () == 1 );
12799 ctx .setBlockState (BlockPos .ORIGIN , Blocks .AIR );
128100 ctx .waitAndRun (1 , () -> {
129- GameTestUtil .assertTrue (
130- "Load counter should be decremented when the block entity leaves the world" ,
131- LoadAwareTestComponent .KEY .get (commandBlock ).getLoadCounter () == 0
132- );
101+ GameTestUtil .assertTrue ("Load counter should be decremented when the block entity leaves the world" , LoadAwareTestComponent .KEY .get (commandBlock ).getLoadCounter () == 0 );
133102 ctx .complete ();
134103 });
135104 }
136105
137- @ GameTest (templateName = EMPTY_STRUCTURE )
138- public void rootClassServerTicker (TestContext ctx ) {
106+ @ GameTest (templateName = EMPTY_STRUCTURE ) public void rootClassServerTicker (TestContext ctx ) {
139107 ctx .setBlockState (BlockPos .ORIGIN , Blocks .BARREL );
140108
141109 var blockentity = ctx .getBlockEntity (BlockPos .ORIGIN );
@@ -164,4 +132,23 @@ public void rootClassServerTicker(TestContext ctx) {
164132 ctx .complete ();
165133 });
166134 }
135+
136+ /**
137+ * same as {@link CcaBlockTestSuite#rootClassServerTicker(TestContext)} but for a BlockEntity that has an explicit
138+ * component registered, so that {@link StaticBlockComponentPlugin#requiresStaticFactory(Class)} returns true for
139+ * the class itself rather than delegating to the parent class.
140+ */
141+ @ GameTest (templateName = EMPTY_STRUCTURE )
142+ public void rootClassServerTickerWithExplicitRegistration (TestContext ctx ) {
143+ ctx .setBlockState (BlockPos .ORIGIN , Blocks .COMMAND_BLOCK );
144+
145+ var blockentity = ctx .getBlockEntity (BlockPos .ORIGIN );
146+ GameTestUtil .assertTrue ("Block entity should not be null" , blockentity != null );
147+ GameTestUtil .assertTrue ("Class should be registered as server ticker" , StaticBlockComponentPlugin .INSTANCE .serverTicking .contains (blockentity .getClass ()));
148+
149+ var component = GlobalTickingComponent .KEY .getNullable (blockentity );
150+ GameTestUtil .assertTrue ("Component should exist" , component != null );
151+
152+ ctx .complete ();
153+ }
167154}
0 commit comments