-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
10 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
48 changes: 48 additions & 0 deletions
48
...ponents-block/src/testmod/java/dev/onyxstudios/cca/test/block/GlobalTickingComponent.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,48 @@ | ||
package dev.onyxstudios.cca.test.block; | ||
|
||
import dev.onyxstudios.cca.api.v3.component.Component; | ||
import dev.onyxstudios.cca.api.v3.component.ComponentKey; | ||
import dev.onyxstudios.cca.api.v3.component.ComponentRegistry; | ||
import dev.onyxstudios.cca.api.v3.component.tick.ServerTickingComponent; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.util.Identifier; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Optional; | ||
import java.util.function.BooleanSupplier; | ||
|
||
public class GlobalTickingComponent implements Component, ServerTickingComponent { | ||
|
||
public static final ComponentKey<GlobalTickingComponent> KEY = ComponentRegistry.getOrCreate(new Identifier(CcaBlockTestMod.MOD_ID, "global_ticking_test"), GlobalTickingComponent.class); | ||
|
||
public GlobalTickingComponent(Object provider) { | ||
// NO-OP | ||
} | ||
|
||
@Nullable | ||
private BooleanSupplier onTick; | ||
|
||
void setTickAction(@Nullable BooleanSupplier onTick) { | ||
this.onTick = onTick; | ||
} | ||
|
||
@Override public void serverTick() { | ||
if(this.onTick != null) { | ||
if(!this.onTick.getAsBoolean()) { | ||
this.onTick = null; | ||
} | ||
} | ||
} | ||
|
||
public Optional<BooleanSupplier> getTickAction() { | ||
return Optional.ofNullable(this.onTick); | ||
} | ||
|
||
@Override public void readFromNbt(NbtCompound tag) { | ||
// NO-OP | ||
} | ||
|
||
@Override public void writeToNbt(NbtCompound tag) { | ||
// NO-OP | ||
} | ||
} |
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