Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Celestial Events API #115

Draft
wants to merge 30 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c36d9a4
First version of tool items update
mineLdiver May 2, 2024
433fa82
Mining levels graph
mineLdiver May 7, 2024
a6dfbdc
Fix a bad mixin declaration in lifecycle events
calmilamsy Jul 8, 2024
6a63f39
Add RegistriesFrozenEvent
calmilamsy Jul 9, 2024
b7c658f
Merge branch 'refs/heads/master' into 2.0-alpha.3
mineLdiver Jul 13, 2024
94629ef
Start of Celestial Events
Atilist May 9, 2024
c798dd1
Time Manager
Atilist May 9, 2024
d639f06
Improved Object Creation and more Tests
Atilist May 9, 2024
3344e9a
Time Management Overhaul
Atilist May 9, 2024
d15a44f
New useful Methods and more Examples
Atilist May 22, 2024
a0829db
Functional Saving and Loading
Atilist May 24, 2024
d5d9f10
Improvements to Saving and Loading
Atilist May 24, 2024
fef6ae6
API Documentation and small Fixes.
Atilist May 25, 2024
3997c40
Improved Initialization Logic
Atilist May 31, 2024
2b01bad
Event Dependency Feature and important Bug Fix
Atilist Jun 8, 2024
eb5723e
Add missing Newline to a Lang File
Atilist Jun 25, 2024
560bb9c
Reduce to single Newline
Atilist Jun 25, 2024
7202653
Merge branch 'refs/heads/2.0-alpha.3' into fork/Atilist/master
mineLdiver Jul 16, 2024
1a78567
Remove redundant Parameter
Atilist Jul 17, 2024
f3006da
Remove useless local value
Atilist Jul 17, 2024
fab448c
Merge branch 'master' into 2.0-alpha.3
calmilamsy Aug 16, 2024
1db84ab
Yeet deprecated code
calmilamsy Aug 16, 2024
450432c
Merge branch 'master' into 2.0-alpha.3
calmilamsy Aug 16, 2024
150d672
Merge branch 'master' into 2.0-alpha.3
mineLdiver Sep 4, 2024
25fc29f
Merge branch 'master' into 2.0-alpha.3
mineLdiver Sep 6, 2024
bf4e97e
*actually* remove deprecated stuff
mineLdiver Sep 6, 2024
43fa59b
Merge branch 'master' into 2.0-alpha.3
calmilamsy Oct 11, 2024
80a2bdb
Merge branch '2.0-alpha.3' into pr/115
calmilamsy Oct 11, 2024
a1361bf
Fix most outstanding issues
calmilamsy Oct 11, 2024
455eee5
Fix registering on world load
calmilamsy Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import net.modificationstation.stationapi.gradle.SubprojectHelpers.addDependency

plugins {
id("maven-publish")
id("fabric-loom") version "1.7.2"
id("babric-loom-extension") version "1.7.3"
id("fabric-loom") version "1.8.8"
id("babric-loom-extension") version "1.8.5"
}

// https://stackoverflow.com/a/40101046 - Even with kotlin, gradle can't get it's shit together.
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ include(":station-gui-api-v0")
include(":station-transitive-access-wideners-v0")
include(":station-maths-v0")
include(":station-worldgen-api-v0")
include(":station-celestial-events-v0")
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

public enum Blocks {

TEST_BLOCK("test_block", "testBlock", id -> new TemplateBlock(id, Material.CLAY).setHardness(1)),
TEST_BLOCK("test_block", "testBlock", id -> new TemplateBlock(id, Material.STONE).setHardness(1)),
TEST_ANIMATED_BLOCK("test_animated_block", "testAnimatedBlock", id -> new ModdedMetaBlock(id, Material.NETHER_PORTAL)),
CUSTOM_MODEL_BLOCK("farlands_block", "farlands_block", id -> new ModdedModelBlock(id, Material.SOIL).setHardness(1)),
FREEZER("freezer", "freezer", id -> new BlockFreezer(id).setHardness(2.5F).setSoundGroup(TemplateBlock.DEFAULT_SOUND_GROUP)),
ALTAR("altar", "altar", id -> new BlockAltar(id, Material.STONE).setHardness(3)),
VARIATION_BLOCK("variation_block", "variationBlock", id -> new VariationBlock(id, Material.STONE).setHardness(.5F).setSoundGroup(Block.DEFAULT_SOUND_GROUP).disableAutoItemRegistration()),
EMISSION_CHECKER("emission_checker", "emissionChecker", LampBlock::new),
INDISPENSABLE_BLOCK("indispensable_block", "indispensableBlock", IndispensableBlock::new);
INDISPENSABLE_BLOCK("indispensable_block", "indispensableBlock", IndispensableBlock::new),
TIME_MACHINE_BLOCK("time_machine_block", "timeMachineBlock", TimeMachineBlock::new);

private final Runnable register;
private Block block;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.modificationstation.sltest.block;

import net.minecraft.block.Material;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.modificationstation.sltest.celestial.CelestialListener;
import net.modificationstation.stationapi.api.template.block.TemplateBlock;
import net.modificationstation.stationapi.api.util.Identifier;

import java.util.Random;

public class TimeMachineBlock extends TemplateBlock {
public TimeMachineBlock(Identifier identifier) {
super(identifier, Material.METAL);
this.setTickRandomly(true);
}

@Override
public boolean onUse(World world, int x, int y, int z, PlayerEntity player) {
world.setTime(world.getTime() + 1000);
return true;
}

@Override
public void onTick(World world, int x, int y, int z, Random random) {
super.onTick(world, x, y, z, random);
if (CelestialListener.flyingDimando.isActive()) {
world.method_287(new ItemEntity(world, x + 0.5, y + 1, z + 0.5, new ItemStack(Item.DIAMOND)));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.modificationstation.sltest.celestial;

import net.mine_diver.unsafeevents.listener.EventListener;
import net.modificationstation.sltest.SLTest;
import net.modificationstation.stationapi.api.celestial.CelestialActivityStateManager;
import net.modificationstation.stationapi.api.celestial.DayQuarter;
import net.modificationstation.stationapi.api.event.celestial.CelestialEvent;
import net.modificationstation.stationapi.api.util.Identifier;

public class CelestialListener {

public static net.modificationstation.stationapi.api.celestial.CelestialEvent flyingDimando;
public static net.modificationstation.stationapi.api.celestial.CelestialEvent fallingDimando;
public static net.modificationstation.stationapi.api.celestial.CelestialEvent crashingDimando;
public static net.modificationstation.stationapi.api.celestial.CelestialEvent spinningDimando;
public static net.modificationstation.stationapi.api.celestial.CelestialEvent burningDimando;
public static net.modificationstation.stationapi.api.celestial.CelestialEvent longDimando;

@EventListener
public void registerCelestialEvents(CelestialEvent event) {
SLTest.LOGGER.info("Register celestial events for testing");
flyingDimando = new FlyingDimando(4, Identifier.of(SLTest.NAMESPACE, "flying_dimando"));
fallingDimando = new DebugCelestialEvent(2, Identifier.of(SLTest.NAMESPACE, "falling_dimando"));
crashingDimando = new DebugCelestialEvent(2, Identifier.of(SLTest.NAMESPACE, "crashing_dimando"));
spinningDimando = new DebugCelestialEvent(4, Identifier.of(SLTest.NAMESPACE, "spinning_dimando")).setDayOffset(event.world, 1);
burningDimando = new DebugCelestialEvent(2, Identifier.of(SLTest.NAMESPACE, "burning_dimando")).setDayOffset(event.world, 1);
longDimando = new DebugCelestialEvent(12, Identifier.of(SLTest.NAMESPACE, "long_dimando")).setExtraDays(event.world, 4);
flyingDimando.addIncompatibleEvent(fallingDimando);
spinningDimando.addIncompatibleEvent(burningDimando);
crashingDimando.addDependency(longDimando);
((CelestialActivityStateManager) event.world).getCelestialTimeManager().addCelestialEvent(flyingDimando, DayQuarter.MORNING, DayQuarter.MORNING);
((CelestialActivityStateManager) event.world).getCelestialTimeManager().addCelestialEvent(fallingDimando, DayQuarter.NOON, DayQuarter.MIDNIGHT);
((CelestialActivityStateManager) event.world).getCelestialTimeManager().addCelestialEvent(crashingDimando, DayQuarter.NOON, DayQuarter.NOON);
((CelestialActivityStateManager) event.world).getCelestialTimeManager().addCelestialEvent(spinningDimando, DayQuarter.EVENING, DayQuarter.NOON);
((CelestialActivityStateManager) event.world).getCelestialTimeManager().addCelestialEvent(burningDimando, DayQuarter.MIDNIGHT, DayQuarter.EVENING);
((CelestialActivityStateManager) event.world).getCelestialTimeManager().addCelestialEvent(longDimando, DayQuarter.MIDNIGHT, DayQuarter.MIDNIGHT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.modificationstation.sltest.celestial;

import net.minecraft.world.World;
import net.modificationstation.stationapi.api.celestial.CelestialEvent;
import net.modificationstation.stationapi.api.util.Identifier;

public class DebugCelestialEvent extends CelestialEvent {
public DebugCelestialEvent(int frequency, Identifier name) {
super(frequency, name);
}

@Override
public void onActivation(World world) {
super.onActivation(world);
System.out.println(this.getIdentifier() + " has begun");
}

@Override
public void onDeactivation(World world) {
super.onDeactivation(world);
System.out.println(this.getIdentifier() + " is over");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.modificationstation.sltest.celestial;

import net.minecraft.world.World;
import net.modificationstation.stationapi.api.util.Identifier;

public class FlyingDimando extends DebugCelestialEvent {
public FlyingDimando(int frequency, Identifier name) {
super(frequency, name);
}

@Override
public void onActivation(World world) {
super.onActivation(world);
world.method_262().setRaining(true);
world.method_262().setRainTime(200);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.modificationstation.sltest.item;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.modificationstation.sltest.celestial.CelestialListener;
import net.modificationstation.stationapi.api.template.item.TemplateItem;
import net.modificationstation.stationapi.api.util.Identifier;

public class CelestialTestItem extends TemplateItem {
public CelestialTestItem(Identifier identifier) {
super(identifier);
}

@Override
public ItemStack use(ItemStack item, World world, PlayerEntity player) {
if (CelestialListener.flyingDimando.isActive()) System.out.println("Event is happening");
else System.out.println("No event");
return super.use(item, world, player);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.modificationstation.sltest.item;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.modificationstation.sltest.celestial.CelestialListener;
import net.modificationstation.stationapi.api.template.item.TemplateItem;
import net.modificationstation.stationapi.api.util.Identifier;

public class CelestialToggleItem extends TemplateItem {
public CelestialToggleItem(Identifier identifier) {
super(identifier);
}

@Override
public ItemStack use(ItemStack item, World world, PlayerEntity player) {
if (CelestialListener.fallingDimando.isActive()) {
CelestialListener.fallingDimando.stopEvent(world);
System.out.println("Stopping Falling Dimando");
} else if (CelestialListener.fallingDimando.activateEvent(world, world.getTime(), random)) {
System.out.println("Activating Falling Dimando");
} else {
System.out.println("Falling Dimando not activated");
}
if (CelestialListener.flyingDimando.isActive()) {
CelestialListener.flyingDimando.stopEvent(world);
System.out.println("Stopping Flying Dimando");
} else if (CelestialListener.flyingDimando.activateEvent(world, world.getTime(), random)) {
System.out.println("Activating Flying Dimando");
} else {
System.out.println("Flying Dimando not activated");
}
return super.use(item, world, player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import net.modificationstation.sltest.block.Blocks;
import net.modificationstation.sltest.block.VariationBlock;
import net.modificationstation.stationapi.api.event.registry.ItemRegistryEvent;
import net.modificationstation.stationapi.api.item.tool.MiningLevelManager;
import net.modificationstation.stationapi.api.item.tool.ToolMaterialFactory;
import net.modificationstation.stationapi.api.registry.BlockRegistry;
import net.modificationstation.stationapi.api.registry.ItemRegistry;
import net.modificationstation.stationapi.api.registry.Registry;
import net.modificationstation.stationapi.api.tag.TagKey;
import net.modificationstation.stationapi.api.template.item.BlockStateItem;

import static net.modificationstation.sltest.SLTest.NAMESPACE;
Expand All @@ -17,8 +20,13 @@ public class ItemListener {

@EventListener
public void registerItems(ItemRegistryEvent event) {
MiningLevelManager.LevelNode moddedNode = new MiningLevelManager.LevelNode(TagKey.of(BlockRegistry.KEY, NAMESPACE.id("needs_tool_level_modded")));
MiningLevelManager.GRAPH.putEdge(ToolMaterial.STONE.getMiningLevelNode(), moddedNode);
MiningLevelManager.GRAPH.putEdge(moddedNode, ToolMaterial.IRON.getMiningLevelNode());
MiningLevelManager.invalidateCache();

testItem = new ModdedItem(NAMESPACE.id("test_item")).setTranslationKey(NAMESPACE, "testItem"); //8475
testMaterial = ToolMaterialFactory.create("testMaterial", 3, Integer.MAX_VALUE, Float.MAX_VALUE, Integer.MAX_VALUE - 2);
testMaterial = ToolMaterialFactory.create("testMaterial", 3, Integer.MAX_VALUE, Float.MAX_VALUE, Integer.MAX_VALUE - 2).miningLevelNode(moddedNode);
testPickaxe = new ModdedPickaxeItem(NAMESPACE.id("test_pickaxe"), testMaterial).setTranslationKey(NAMESPACE, "testPickaxe"); //8476
testNBTItem = new NBTItem(NAMESPACE.id("nbt_item")).setTranslationKey(NAMESPACE, "nbt_item"); //8477
testModelItem = new ModelItem(NAMESPACE.id("model_item")).setMaxCount(1).setTranslationKey(NAMESPACE, "idkSomething");
Expand All @@ -30,6 +38,8 @@ public void registerItems(ItemRegistryEvent event) {
testShears = new TestShearsItem(NAMESPACE.id("test_shears")).setTranslationKey(NAMESPACE, "test_shears");
pacifistSword = new PacifistSwordItem(NAMESPACE.id("pacifist_sword")).setTranslationKey(NAMESPACE, "pacifist_sword");
dullPickaxe = new DullPickaxeItem(NAMESPACE.id("dull_pickaxe")).setTranslationKey(NAMESPACE, "dull_pickaxe");
celestialTestItem = new CelestialTestItem(NAMESPACE.id("test_celestial")).setTranslationKey(NAMESPACE, "test_celestial");
celestialToggleItem = new CelestialToggleItem(NAMESPACE.id("toggle_celestial")).setTranslationKey(NAMESPACE, "toggle_celestial");
}

public static Item testItem;
Expand All @@ -45,4 +55,6 @@ public void registerItems(ItemRegistryEvent event) {
public static Item testShears;
public static Item pacifistSword;
public static Item dullPickaxe;
public static Item celestialTestItem;
public static Item celestialToggleItem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package net.modificationstation.sltest.mixin;

import net.minecraft.entity.Entity;
import net.modificationstation.sltest.celestial.CelestialListener;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Entity.class)
public class EntityMixin {

@Shadow public float yaw;

@Shadow public float pitch;

@Shadow public double velocityY;

@Shadow public double velocityX;

@Shadow public double velocityZ;

@Inject(
method = "tick",
at = @At("HEAD")
)
public void spinEntity(CallbackInfo ci) {
if (CelestialListener.spinningDimando.isActive()) {
this.yaw = (this.yaw + 0.1F) % 360.0F;
this.pitch = (this.pitch + 0.1F) % 360.0F;
}
if (CelestialListener.flyingDimando.isActive()) {
if (this.velocityY < 0.5F) {
this.velocityY += 0.05F;
}
}
if (CelestialListener.fallingDimando.isActive()) {
if (this.velocityY > -0.1F) {
this.velocityY -= 0.05F;
}
}
if (CelestialListener.longDimando.isActive()) {
this.velocityX *= 1.1F;
this.velocityZ *= 1.1F;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.modificationstation.sltest.mixin;

import net.minecraft.block.Block;
import net.minecraft.block.GrassBlock;
import net.minecraft.world.World;
import net.modificationstation.sltest.celestial.CelestialListener;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Random;

@Mixin(GrassBlock.class)
public class GrassBlockMixin {
@Inject(
method = "onTick",
at = @At("TAIL")
)
public void setStuffOnFire(World world, int x, int y, int z, Random random, CallbackInfo ci) {
if (CelestialListener.burningDimando.isActive()) {
if (random.nextInt(100) == 0 && world.getBlockId(x, y + 1, z) == 0) world.method_200(x, y + 1, z, Block.FIRE.id);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void registerTextures(TextureRegisterEvent event) {
TEST_ANIMATED_BLOCK.get().textureId = terrain.addTexture(of(NAMESPACE, "blocks/testAnimatedBlock")).index;
FREEZER.get().textureId = terrain.addTexture(of(NAMESPACE, "blocks/FreezerTop")).index;
((BlockFreezer) FREEZER.get()).sideTexture = terrain.addTexture(of(NAMESPACE, "blocks/FreezerSide")).index;
TIME_MACHINE_BLOCK.get().textureId = terrain.addTexture(of(NAMESPACE, "blocks/timeMachineBlock")).index;

altarTextures[Direction.DOWN.ordinal()] = terrain.addTexture(of(NAMESPACE, "blocks/altar_bottom")).index;
altarTextures[Direction.UP.ordinal()] = terrain.addTexture(of(NAMESPACE, "blocks/altar_top")).index;
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/assets/sltest/stationapi/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ [email protected]=Variation Block Passive
[email protected]=Variation Block Active
[email protected]_shears.name=Test Shears
[email protected]_sword.name=Pacifist Sword
[email protected]_pickaxe.name=Dull Pickaxe
[email protected]_pickaxe.name=Dull Pickaxe
[email protected]=Time Machine
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"sltest:test_block"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"sltest:test_block"
]
}
3 changes: 2 additions & 1 deletion src/test/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"net.modificationstation.sltest.datafixer.DataFixerListener",
"net.modificationstation.sltest.worldgen.TestWorldgenListener",
"net.modificationstation.sltest.bonemeal.BonemealListener",
"net.modificationstation.sltest.dispenser.DispenserListener"
"net.modificationstation.sltest.dispenser.DispenserListener",
"net.modificationstation.sltest.celestial.CelestialListener"
],
"stationapi:event_bus_client": [
"net.modificationstation.sltest.gui.GuiListener",
Expand Down
4 changes: 3 additions & 1 deletion src/test/resources/sltest.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"MixinLevel",
"MixinNetherLevelSource",
"MixinObsidian",
"OverworldTestMixin"
"OverworldTestMixin",
"GrassBlockMixin",
"EntityMixin"
],
"server": [
],
Expand Down
9 changes: 9 additions & 0 deletions station-celestial-events-v0/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import net.modificationstation.stationapi.gradle.SubprojectHelpers.getSubprojectVersion
import net.modificationstation.stationapi.gradle.SubprojectHelpers.addModuleDependencies
base.archivesName.set("station-celestial-events-v0")
version = getSubprojectVersion(project, "1.0.0")

addModuleDependencies(project,
"station-api-base",
"station-registry-api-v0",
)
Loading