Skip to content

Commit b25e9ac

Browse files
paulevsGitchmineLdivercalmilamsytelvarost
committed
Effects api 2 (#142)
* First version of tool items update * Initial GCAPI merge * Haha, oops * Mining levels graph * Migrate GCAPI to YAML files Comments are broke, I'll fix that later * Better config format, fix comments * Why didn't you commit * Effects API module * Infinity effects * Effect rendering refactor, effect names and descriptions * Effect packets * Player effect synchronisation * Exception instead of warning * Some cleanup * Fine, I'll fix the newlines myself. * Warning instead of exception for effects loaded from save files * Mining levels graph * Fix a bad mixin declaration in lifecycle events * Add RegistriesFrozenEvent * Sync back up with current StationAPI master branch * Migrate Effects API to StationAPI 2.0.0-alpha.3 * Effects clear test block, vanilla effects background, commented HMI offset * Remove unnecessary offset * Changed sizes to fit new frame better * Changed sizes to fit new frame better * Javadocs, renamed effect functions, changed infinity ticks constant size * Corrected javadocs, moved decrement * Removed unused return * Javadoc enhancement * Usage of vanilla texture instead of custom * Effects API redesign * Get effect ticks method for entities * Added visual effect sorting (long to top) * Proper infinite effect name, proper null check, additional null check * Removed unused IDs, make some functions final, removed client-side from keys, renamed NBT key * Factory instead of constructor, removed generics, usage of StAPI registry * Tabs to spaces. * Using type-specific Pair * Spelling mistake in EntityEffectRegistry * Fixed up the effects module to work with the new babric helper method * EntityEffectType * Fixed MixinEntity#removeAllEffects not invoking EntityEffect#onRemoved * Fixed packet side bindings * Fixed some packets using wrong PacketHelper methods * Using raw IDs in packets and types in runtime methods. * Better packet names * Better mixin names * Removed unnecessary side checks * Removed 2 unnecessary entity methods * Effect data server->client sync * appliedNow for EntityEffect#onAdded, renderer cut off fix, test client-side particles on inf effect. * Consistency in nbt methods * StationEffectsEntity#getEffect * Discourage usage of the other addEffect * Moved EntityEffectTypeRegistryEvent to a safer initialization point * Short-circuiting packets. Removed an impl only method from API. * Nuked all tabs while I'm at it * Docs --------- Co-authored-by: mine_diver <aabesedin@mail.ru> Co-authored-by: calmilamsy <bumbill00@gmail.com> Co-authored-by: telvarost <telontelvarost@gmail.com> Co-authored-by: mineLdiver <arsbsdn@gmail.com>
1 parent d750c35 commit b25e9ac

44 files changed

Lines changed: 1724 additions & 274 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ include(":station-transitive-access-wideners-v0")
4747
include(":station-maths-v0")
4848
include(":station-worldgen-api-v0")
4949
include(":station-api-configuration")
50+
include(":station-effects-api-v0")

src/main/resources/fabric.mod.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"station-dimensions-v0": "*",
5050
"station-tools-api-v1": "*",
5151
"station-flattening-v0": "*",
52-
"station-renderer-arsenic": "*"
52+
"station-renderer-arsenic": "*",
53+
"station-effects-api-v0": "*"
5354
}
5455
}

src/test/java/net/modificationstation/sltest/block/Blocks.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ public enum Blocks {
2929
EMISSION_CHECKER("emission_checker", "emissionChecker", LampBlock::new),
3030
INDISPENSABLE_BLOCK("indispensable_block", "indispensableBlock", IndispensableBlock::new),
3131
MODDED_LEAVES("modded_leaves", "moddedLeaves", id -> new TemplateLeavesBlock(id, 52)),
32-
MODDED_LOG("modded_log", "moddedLog", TemplateLogBlock::new);
32+
MODDED_LOG("modded_log", "moddedLog", TemplateLogBlock::new),
33+
EFFECT_BLOCK("effect_block", "effectBlock", EffectBlock::new),
34+
EFFECT_BLOCK_INF("effect_block_inf", "effectBlockInf", EffectBlockInf::new),
35+
EFFECT_BLOCK_CLEAR("effect_block_clear", "effectBlockClear", EffectBlockClear::new);
3336

3437
private final Runnable register;
3538
private Block block;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package net.modificationstation.sltest.block;
2+
3+
import net.minecraft.block.Material;
4+
import net.minecraft.entity.player.PlayerEntity;
5+
import net.minecraft.world.BlockView;
6+
import net.minecraft.world.World;
7+
import net.modificationstation.sltest.effect.TestPlayerEffect;
8+
import net.modificationstation.stationapi.api.template.block.TemplateBlock;
9+
import net.modificationstation.stationapi.api.util.Identifier;
10+
11+
public class EffectBlock extends TemplateBlock {
12+
public EffectBlock(Identifier id) {
13+
super(id, Material.WOOD);
14+
}
15+
16+
@Override
17+
public int getTextureId(BlockView view, int x, int y, int z, int side) {
18+
return (side & 1) == 0 ? GOLD_BLOCK.textureId : DIAMOND_BLOCK.textureId;
19+
}
20+
21+
@Override
22+
public int getTexture(int side) {
23+
return (side & 1) == 0 ? GOLD_BLOCK.textureId : DIAMOND_BLOCK.textureId;
24+
}
25+
26+
@Override
27+
public boolean onUse(World level, int x, int y, int z, PlayerEntity player) {
28+
if (player.hasEffect(TestPlayerEffect.TYPE)) return false;
29+
player.addEffect(TestPlayerEffect.TYPE, 200); // Effect for 10 seconds
30+
return true;
31+
}
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package net.modificationstation.sltest.block;
2+
3+
import net.minecraft.block.Material;
4+
import net.minecraft.entity.player.PlayerEntity;
5+
import net.minecraft.world.BlockView;
6+
import net.minecraft.world.World;
7+
import net.modificationstation.sltest.SLTest;
8+
import net.modificationstation.stationapi.api.template.block.TemplateBlock;
9+
import net.modificationstation.stationapi.api.util.Identifier;
10+
11+
public class EffectBlockClear extends TemplateBlock {
12+
public EffectBlockClear(Identifier id) {
13+
super(id, Material.WOOD);
14+
}
15+
16+
@Override
17+
public int getTextureId(BlockView view, int x, int y, int z, int side) {
18+
return (side & 1) == 0 ? OBSIDIAN.textureId : LAVA.textureId;
19+
}
20+
21+
@Override
22+
public int getTexture(int side) {
23+
return (side & 1) == 0 ? OBSIDIAN.textureId : LAVA.textureId;
24+
}
25+
26+
@Override
27+
public boolean onUse(World level, int x, int y, int z, PlayerEntity player) {
28+
player.removeAllEffects();
29+
return true;
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package net.modificationstation.sltest.block;
2+
3+
import net.minecraft.block.Material;
4+
import net.minecraft.entity.player.PlayerEntity;
5+
import net.minecraft.world.BlockView;
6+
import net.minecraft.world.World;
7+
import net.modificationstation.sltest.effect.TestPlayerInfEffect;
8+
import net.modificationstation.stationapi.api.template.block.TemplateBlock;
9+
import net.modificationstation.stationapi.api.util.Identifier;
10+
11+
public class EffectBlockInf extends TemplateBlock {
12+
public EffectBlockInf(Identifier id) {
13+
super(id, Material.WOOD);
14+
}
15+
16+
@Override
17+
public int getTextureId(BlockView view, int x, int y, int z, int side) {
18+
return (side & 1) == 0 ? LOG.textureId : PLANKS.textureId;
19+
}
20+
21+
@Override
22+
public int getTexture(int side) {
23+
return (side & 1) == 0 ? GOLD_BLOCK.textureId : DIAMOND_BLOCK.textureId;
24+
}
25+
26+
@Override
27+
public boolean onUse(World level, int x, int y, int z, PlayerEntity player) {
28+
player.addInfiniteEffect(TestPlayerInfEffect.TYPE);
29+
return true;
30+
}
31+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package net.modificationstation.sltest.effect;
2+
3+
import net.mine_diver.unsafeevents.listener.EventListener;
4+
import net.modificationstation.sltest.SLTest;
5+
import net.modificationstation.stationapi.api.StationAPI;
6+
import net.modificationstation.stationapi.api.event.effect.EntityEffectTypeRegistryEvent;
7+
8+
public class TestEffectListener {
9+
@EventListener
10+
public void registerEffects(EntityEffectTypeRegistryEvent event) {
11+
event.register(SLTest.NAMESPACE)
12+
.accept("test_effect", TestPlayerEffect.TYPE)
13+
.accept("infinity_effect", TestPlayerInfEffect.TYPE);
14+
StationAPI.LOGGER.info("Registered Entity Effects!");
15+
}
16+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package net.modificationstation.sltest.effect;
2+
3+
import net.minecraft.entity.Entity;
4+
import net.minecraft.entity.player.PlayerEntity;
5+
import net.minecraft.nbt.NbtCompound;
6+
import net.modificationstation.stationapi.api.effect.EntityEffect;
7+
import net.modificationstation.stationapi.api.effect.EntityEffectType;
8+
9+
public class TestPlayerEffect extends EntityEffect<TestPlayerEffect> {
10+
public static final EntityEffectType<TestPlayerEffect> TYPE = EntityEffectType
11+
.builder(TestPlayerEffect::new).build();
12+
13+
private int originalHealth;
14+
15+
public TestPlayerEffect(Entity entity, int ticks) {
16+
super(entity, ticks);
17+
if (!(entity instanceof PlayerEntity)) {
18+
throw new RuntimeException("Effect can be applied only on player");
19+
}
20+
}
21+
22+
@Override
23+
public void onAdded(boolean appliedNow) {
24+
PlayerEntity player = (PlayerEntity) entity;
25+
originalHealth = player.health;
26+
player.health = 5;
27+
}
28+
29+
@Override
30+
public void onTick() {}
31+
32+
@Override
33+
public void onRemoved() {
34+
((PlayerEntity) entity).health = originalHealth;
35+
}
36+
37+
@Override
38+
protected void writeNbt(NbtCompound tag) {
39+
tag.putInt("original_health", originalHealth);
40+
}
41+
42+
@Override
43+
protected void readNbt(NbtCompound tag) {
44+
originalHealth = tag.getInt("original_health");
45+
}
46+
47+
@Override
48+
public EntityEffectType<TestPlayerEffect> getType() {
49+
return TYPE;
50+
}
51+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package net.modificationstation.sltest.effect;
2+
3+
import net.fabricmc.api.EnvType;
4+
import net.fabricmc.loader.api.FabricLoader;
5+
import net.minecraft.entity.Entity;
6+
import net.minecraft.nbt.NbtCompound;
7+
import net.modificationstation.stationapi.api.effect.EntityEffect;
8+
import net.modificationstation.stationapi.api.effect.EntityEffectType;
9+
10+
public class TestPlayerInfEffect extends EntityEffect<TestPlayerInfEffect> {
11+
public static final EntityEffectType<TestPlayerInfEffect> TYPE = EntityEffectType
12+
.builder(TestPlayerInfEffect::new).build();
13+
14+
public TestPlayerInfEffect(Entity entity, int ticks) {
15+
super(entity, ticks);
16+
}
17+
18+
@Override
19+
public void onAdded(boolean appliedNow) {}
20+
21+
@Override
22+
public void onTick() {
23+
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
24+
entity.world.addParticle("heart", entity.x, entity.y + entity.eyeHeight + 1, entity.z, 0, 0.5, 0);
25+
}
26+
}
27+
28+
@Override
29+
public void onRemoved() {}
30+
31+
@Override
32+
protected void writeNbt(NbtCompound tag) {}
33+
34+
@Override
35+
protected void readNbt(NbtCompound tag) {}
36+
37+
@Override
38+
public EntityEffectType<TestPlayerInfEffect> getType() {
39+
return TYPE;
40+
}
41+
}

src/test/java/net/modificationstation/sltest/recipe/RecipeListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public void registerRecipes(RecipeRegisterEvent event) {
2424
case CRAFTING_SHAPELESS -> {
2525
CraftingRegistry.addShapelessRecipe(new ItemStack(ItemListener.testItem), new ItemStack(Block.DIRT));
2626
CraftingRegistry.addShapelessRecipe(new ItemStack(Blocks.TEST_BLOCK.get()), new ItemStack(Block.SAND));
27+
CraftingRegistry.addShapelessRecipe(new ItemStack(Blocks.EFFECT_BLOCK.get()), new ItemStack(Block.PLANKS));
28+
CraftingRegistry.addShapelessRecipe(new ItemStack(Blocks.EFFECT_BLOCK_INF.get()), new ItemStack(Blocks.EFFECT_BLOCK.get()));
2729
CraftingRegistry.addShapelessRecipe(new ItemStack(Item.FLINT_AND_STEEL), new ItemStack(Blocks.TEST_BLOCK.get()));
2830
CraftingRegistry.addShapelessRecipe(new ItemStack(Block.REDSTONE_WIRE), new ItemStack(Item.FLINT_AND_STEEL));
2931
CraftingRegistry.addShapelessRecipe(new ItemStack(Block.RAIL), new ItemStack(Block.REDSTONE_WIRE));

0 commit comments

Comments
 (0)