-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix BE components ticking only on subclasses, closes #127
- Loading branch information
Showing
15 changed files
with
252 additions
and
14 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
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
51 changes: 51 additions & 0 deletions
51
cardinal-components-block/src/testmod/java/dev/onyxstudios/cca/test/block/BlockVita.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,51 @@ | ||
/* | ||
* Cardinal-Components-API | ||
* Copyright (C) 2019-2022 OnyxStudios | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
* OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package dev.onyxstudios.cca.test.block; | ||
|
||
import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; | ||
import dev.onyxstudios.cca.api.v3.component.tick.ServerTickingComponent; | ||
import dev.onyxstudios.cca.test.base.BaseVita; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.world.World; | ||
|
||
public class BlockVita extends BaseVita implements AutoSyncedComponent, ServerTickingComponent { | ||
private final BlockEntity owner; | ||
|
||
public BlockVita(BlockEntity owner) { | ||
this.owner = owner; | ||
} | ||
|
||
@Override | ||
public void setVitality(int value) { | ||
super.setVitality(value); | ||
this.owner.syncComponent(KEY); | ||
} | ||
|
||
@Override | ||
public void serverTick() { | ||
World world = this.owner.getWorld(); | ||
if (world != null && world.getTime() % 3 == 0) { | ||
this.setVitality(this.getVitality() + 1); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...nal-components-block/src/testmod/java/dev/onyxstudios/cca/test/block/CcaBlockTestMod.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,45 @@ | ||
/* | ||
* Cardinal-Components-API | ||
* Copyright (C) 2019-2022 OnyxStudios | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
* OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package dev.onyxstudios.cca.test.block; | ||
|
||
import dev.onyxstudios.cca.api.v3.block.BlockComponentFactoryRegistry; | ||
import dev.onyxstudios.cca.api.v3.block.BlockComponentInitializer; | ||
import dev.onyxstudios.cca.test.base.TickingTestComponent; | ||
import net.fabricmc.api.ModInitializer; | ||
import net.minecraft.block.entity.EndGatewayBlockEntity; | ||
import net.minecraft.block.entity.EndPortalBlockEntity; | ||
|
||
public class CcaBlockTestMod implements ModInitializer, BlockComponentInitializer { | ||
public static final String MOD_ID = "cca-block-test"; | ||
|
||
@Override | ||
public void registerBlockComponentFactories(BlockComponentFactoryRegistry registry) { | ||
registry.registerFor(EndGatewayBlockEntity.class, VitaCompound.KEY, VitaCompound::new); | ||
registry.registerFor(EndPortalBlockEntity.class, TickingTestComponent.KEY, be -> new TickingTestComponent()); | ||
} | ||
|
||
@Override | ||
public void onInitialize() { | ||
|
||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...l-components-block/src/testmod/java/dev/onyxstudios/cca/test/block/CcaBlockTestSuite.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,70 @@ | ||
/* | ||
* Cardinal-Components-API | ||
* Copyright (C) 2019-2022 OnyxStudios | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
* OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package dev.onyxstudios.cca.test.block; | ||
|
||
import dev.onyxstudios.cca.test.base.TickingTestComponent; | ||
import dev.onyxstudios.cca.test.base.Vita; | ||
import io.github.ladysnake.elmendorf.GameTestUtil; | ||
import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.test.GameTest; | ||
import net.minecraft.test.TestContext; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
import java.util.Objects; | ||
|
||
public class CcaBlockTestSuite implements FabricGameTest { | ||
@GameTest(templateName = EMPTY_STRUCTURE) | ||
public void beSerialize(TestContext ctx) { | ||
BlockEntity be = Objects.requireNonNull( | ||
BlockEntityType.END_GATEWAY.instantiate( | ||
ctx.getAbsolutePos(BlockPos.ORIGIN), | ||
Blocks.END_GATEWAY.getDefaultState() | ||
) | ||
); | ||
be.getComponent(Vita.KEY).setVitality(42); | ||
NbtCompound nbt = be.createNbt(); | ||
BlockEntity be1 = Objects.requireNonNull( | ||
BlockEntityType.END_GATEWAY.instantiate( | ||
ctx.getAbsolutePos(BlockPos.ORIGIN), Blocks.END_GATEWAY.getDefaultState() | ||
) | ||
); | ||
GameTestUtil.assertTrue("New BlockEntity should have values zeroed", be1.getComponent(Vita.KEY).getVitality() == 0); | ||
be1.readNbt(nbt); | ||
GameTestUtil.assertTrue("BlockEntity component data should survive deserialization", be1.getComponent(Vita.KEY).getVitality() == 42); | ||
ctx.complete(); | ||
} | ||
|
||
@GameTest(templateName = EMPTY_STRUCTURE) | ||
public void beComponentsTick(TestContext ctx) { | ||
ctx.setBlockState(BlockPos.ORIGIN, Blocks.END_PORTAL); | ||
ctx.waitAndRun(5, () -> { | ||
int ticks = Objects.requireNonNull(ctx.getBlockEntity(BlockPos.ORIGIN)).getComponent(TickingTestComponent.KEY).serverTicks(); | ||
GameTestUtil.assertTrue("Component should tick 5 times", ticks == 5); | ||
ctx.complete(); | ||
}); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
cardinal-components-block/src/testmod/java/dev/onyxstudios/cca/test/block/package-info.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,29 @@ | ||
/* | ||
* Cardinal-Components-API | ||
* Copyright (C) 2019-2022 OnyxStudios | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
* OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
@MethodsReturnNonnullByDefault | ||
@ParametersAreNonnullByDefault | ||
package dev.onyxstudios.cca.test.block; | ||
|
||
import dev.onyxstudios.cca.api.v3.util.MethodsReturnNonnullByDefault; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
31 changes: 31 additions & 0 deletions
31
cardinal-components-block/src/testmod/resources/fabric.mod.json
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,31 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"environment": "*", | ||
"id": "cca-block-test", | ||
"name": "Cardinal Components API Test Mod", | ||
"description": "Test mod for Cardinal Components API", | ||
"version": "${version}", | ||
"entrypoints": { | ||
"main": [ | ||
"dev.onyxstudios.cca.test.block.CcaBlockTestMod" | ||
], | ||
"cardinal-components": [ | ||
"dev.onyxstudios.cca.test.block.CcaBlockTestMod" | ||
], | ||
"fabric-gametest": [ | ||
"dev.onyxstudios.cca.test.block.CcaBlockTestSuite" | ||
] | ||
}, | ||
"depends": { | ||
"fabric-api-base": "*" | ||
}, | ||
"authors": [ | ||
"Pyrofab" | ||
], | ||
"license": "MIT", | ||
"custom": { | ||
"cardinal-components": [ | ||
"cca-block-test:vita_compound" | ||
] | ||
} | ||
} |
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
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
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