Skip to content

Commit

Permalink
wip particles
Browse files Browse the repository at this point in the history
  • Loading branch information
reoseah committed Oct 31, 2024
1 parent 2a6fe9f commit f7090c6
Show file tree
Hide file tree
Showing 23 changed files with 253 additions and 10 deletions.
13 changes: 9 additions & 4 deletions src/main/java/io/github/reoseah/magisterium/Magisterium.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package io.github.reoseah.magisterium;

import io.github.reoseah.magisterium.block.ArcaneTableBlock;
import io.github.reoseah.magisterium.block.GlyphBlock;
import io.github.reoseah.magisterium.block.IllusoryWallBlock;
import io.github.reoseah.magisterium.block.IllusoryWallBlockEntity;
import io.github.reoseah.magisterium.block.*;
import io.github.reoseah.magisterium.item.BookmarkItem;
import io.github.reoseah.magisterium.item.SpellBookItem;
import io.github.reoseah.magisterium.item.SpellPageItem;
import io.github.reoseah.magisterium.network.SlotLayoutPayload;
import io.github.reoseah.magisterium.network.StartUtterancePayload;
import io.github.reoseah.magisterium.network.StopUtterancePayload;
import io.github.reoseah.magisterium.network.UseBookmarkPayload;
import io.github.reoseah.magisterium.particle.MagisteriumParticles;
import io.github.reoseah.magisterium.recipe.*;
import io.github.reoseah.magisterium.screen.ArcaneTableScreenHandler;
import io.github.reoseah.magisterium.screen.SpellBookScreenHandler;
Expand Down Expand Up @@ -60,6 +58,8 @@ public void onInitialize() {
Registry.register(Registries.BLOCK, "magisterium:glyph", GlyphBlock.INSTANCE);
Registry.register(Registries.BLOCK, "magisterium:illusory_wall", IllusoryWallBlock.INSTANCE);

Registry.register(Registries.BLOCK, "magisterium:test", TestBlock.INSTANCE);

Registry.register(Registries.BLOCK_ENTITY_TYPE, "magisterium:illusory_wall", IllusoryWallBlockEntity.TYPE);

Registry.register(Registries.ITEM, "magisterium:arcane_table", new BlockItem(ArcaneTableBlock.INSTANCE, new Item.Settings()));
Expand Down Expand Up @@ -113,6 +113,11 @@ public void onInitialize() {
Registry.register(Registries.SCREEN_HANDLER, "magisterium:spell_book", SpellBookScreenHandler.TYPE);
Registry.register(Registries.SCREEN_HANDLER, "magisterium:arcane_table", ArcaneTableScreenHandler.TYPE);

Registry.register(Registries.PARTICLE_TYPE, "magisterium:energy", MagisteriumParticles.ENERGY);
Registry.register(Registries.PARTICLE_TYPE, "magisterium:glyph_a", MagisteriumParticles.GLYPH_A);
Registry.register(Registries.PARTICLE_TYPE, "magisterium:glyph_b", MagisteriumParticles.GLYPH_B);
Registry.register(Registries.PARTICLE_TYPE, "magisterium:glyph_c", MagisteriumParticles.GLYPH_C);

MagisteriumGameRules.initialize();
MagisteriumCommands.initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import io.github.reoseah.magisterium.block.IllusoryWallBlockEntity;
import io.github.reoseah.magisterium.block.IllusoryWallBlockEntityRenderer;
import io.github.reoseah.magisterium.item.SpellBookItem;
import io.github.reoseah.magisterium.particle.EnergyParticle;
import io.github.reoseah.magisterium.particle.GlyphParticle;
import io.github.reoseah.magisterium.particle.MagisteriumParticles;
import io.github.reoseah.magisterium.screen.ArcaneTableScreen;
import io.github.reoseah.magisterium.screen.ArcaneTableScreenHandler;
import io.github.reoseah.magisterium.screen.SpellBookScreen;
Expand All @@ -13,12 +16,12 @@
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.impl.resource.loader.ResourceManagerHelperImpl;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;

Expand All @@ -41,5 +44,10 @@ public void onInitializeClient() {
HandledScreens.register(ArcaneTableScreenHandler.TYPE, ArcaneTableScreen::new);

BlockEntityRendererFactories.register(IllusoryWallBlockEntity.TYPE, IllusoryWallBlockEntityRenderer::new);

ParticleFactoryRegistry.getInstance().register(MagisteriumParticles.ENERGY, EnergyParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(MagisteriumParticles.GLYPH_A, GlyphParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(MagisteriumParticles.GLYPH_B, GlyphParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(MagisteriumParticles.GLYPH_C, GlyphParticle.Factory::new);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.reoseah.magisterium;
package io.github.reoseah.magisterium.block;

import net.minecraft.block.Block;
import net.minecraft.registry.RegistryKeys;
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/io/github/reoseah/magisterium/block/TestBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.github.reoseah.magisterium.block;

import io.github.reoseah.magisterium.particle.MagisteriumParticles;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.particle.SimpleParticleType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;

public class TestBlock extends Block {
public static final Block INSTANCE = new TestBlock(Settings.create().nonOpaque().noCollision());

public TestBlock(Settings settings) {
super(settings);
}

@Override
protected BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.INVISIBLE;
}

@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
super.randomDisplayTick(state, world, pos, random);

var types = new SimpleParticleType[]{ //
MagisteriumParticles.GLYPH_A, //
MagisteriumParticles.GLYPH_B, //
MagisteriumParticles.GLYPH_C //
};

for (int i = 0; i < 1; i++) {
double x = pos.getX() + .5 + random.nextGaussian();
double y = pos.getY() + .5 + random.nextGaussian();
double z = pos.getZ() + .5 + random.nextGaussian();
world.addParticle(types[random.nextInt(types.length)], x, y, z, 0.0D, 0.0D, 0.0D);
}

for (int i = 0; i < 4; i++) {
double x = pos.getX() + .5 + random.nextGaussian();
double y = pos.getY() + .5 + random.nextGaussian();
double z = pos.getZ() + .5 + random.nextGaussian();
world.addParticle(MagisteriumParticles.ENERGY, x, y, z, 0.0D, 0.05D, 0.0D);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.reoseah.magisterium;
package io.github.reoseah.magisterium.item;

import net.minecraft.item.Item;
import net.minecraft.registry.RegistryKeys;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.github.reoseah.magisterium.particle;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.particle.*;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.SimpleParticleType;

public class EnergyParticle extends SpriteBillboardParticle {
protected EnergyParticle(ClientWorld clientWorld, double x, double y, double z, double velocityX, double velocityY, double velocityZ, SpriteProvider spriteProvider) {
super(clientWorld, x, y, z, velocityX, velocityY, velocityZ);
this.maxAge = 8 + this.random.nextInt(24);
this.setSprite(spriteProvider);
float brightness = this.random.nextFloat() * 0.6F + 0.4F;
this.red = brightness * 0.1F;
this.green = brightness * 0.5F;
this.blue = brightness;
this.gravityStrength = 0.01F;
this.scale = .25F;
this.velocityX = this.velocityX * 0.05 + velocityX;
this.velocityY = this.velocityY * 0.05 + velocityY;
this.velocityZ = this.velocityZ * 0.05 + velocityZ;
}

@Override
public ParticleTextureSheet getType() {
return ParticleTextureSheet.PARTICLE_SHEET_OPAQUE;
}

@Override
protected int getBrightness(float tint) {
return 240;
}

@Override
public void tick() {
this.prevPosX = this.x;
this.prevPosY = this.y;
this.prevPosZ = this.z;
if (this.maxAge-- <= 0) {
this.markDead();
return;
}
this.move(this.velocityX, this.velocityY, this.velocityZ);
this.velocityX *= 0.99D;
this.velocityY *= 0.99D;
this.velocityZ *= 0.99D;
}

@Environment(EnvType.CLIENT)
public static class Factory implements ParticleFactory<SimpleParticleType> {
private final SpriteProvider spriteProvider;

public Factory(SpriteProvider spriteProvider) {
this.spriteProvider = spriteProvider;
}

public Particle createParticle(SimpleParticleType simpleParticleType, ClientWorld clientWorld, double x, double y, double z, double velocityX, double velocityY, double velocityZ) {
return new EnergyParticle(clientWorld, x, y, z, velocityX, velocityY, velocityZ, this.spriteProvider);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.github.reoseah.magisterium.particle;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.particle.*;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.SimpleParticleType;

@Environment(EnvType.CLIENT)
public class GlyphParticle extends SpriteBillboardParticle {
private final SpriteProvider spriteProvider;

public GlyphParticle(ClientWorld clientWorld, double x, double y, double z, double velocityX, double velocityY, double velocityZ, SpriteProvider spriteProvider) {
super(clientWorld, x, y, z, velocityX, velocityY, velocityZ);
this.spriteProvider = spriteProvider;
this.maxAge = 16;
this.setSpriteForAge(spriteProvider);

this.scale = .5F;
this.velocityX = this.velocityX * 0.05 + velocityX;
this.velocityY = this.velocityY * 0.05 + velocityY;
this.velocityZ = this.velocityZ * 0.05 + velocityZ;
}

@Override
public ParticleTextureSheet getType() {
return ParticleTextureSheet.PARTICLE_SHEET_OPAQUE;
}

@Override
protected int getBrightness(float tint) {
return 0xFF;
}

@Override
public void tick() {
this.prevPosX = this.x;
this.prevPosY = this.y;
this.prevPosZ = this.z;
if (this.age++ >= this.maxAge) {
this.markDead();
} else {
this.velocityY = this.velocityY - this.gravityStrength;
this.move(this.velocityX, this.velocityY, this.velocityZ);
this.setSpriteForAge(this.spriteProvider);
}
}

@Environment(EnvType.CLIENT)
public static class Factory implements ParticleFactory<SimpleParticleType> {
private final SpriteProvider spriteProvider;

public Factory(SpriteProvider spriteProvider) {
this.spriteProvider = spriteProvider;
}

public Particle createParticle(SimpleParticleType simpleParticleType, ClientWorld clientWorld, double x, double y, double z, double velocityX, double velocityY, double velocityZ) {
return new GlyphParticle(clientWorld, x, y, z, velocityX, velocityY, velocityZ, this.spriteProvider);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.reoseah.magisterium.particle;

import net.minecraft.particle.SimpleParticleType;

public class MagisteriumParticles {
public static final SimpleParticleType ENERGY = new MagisteriumParticleType(true);
public static final SimpleParticleType GLYPH_A = new MagisteriumParticleType(true);
public static final SimpleParticleType GLYPH_B = new MagisteriumParticleType(true);
public static final SimpleParticleType GLYPH_C = new MagisteriumParticleType(true);

// makes constructor public
public static class MagisteriumParticleType extends SimpleParticleType {
public MagisteriumParticleType(boolean alwaysShow) {
super(alwaysShow);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.reoseah.magisterium.recipe;

import io.github.reoseah.magisterium.MagisteriumBlockTags;
import io.github.reoseah.magisterium.block.MagisteriumBlockTags;
import io.github.reoseah.magisterium.world.MagisteriumPlaygrounds;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.reoseah.magisterium.recipe;

import io.github.reoseah.magisterium.MagisteriumBlockTags;
import io.github.reoseah.magisterium.block.MagisteriumBlockTags;
import io.github.reoseah.magisterium.world.MagisteriumPlaygrounds;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.reoseah.magisterium.screen;

import com.mojang.datafixers.util.Pair;
import io.github.reoseah.magisterium.MagisteriumItemTags;
import io.github.reoseah.magisterium.item.MagisteriumItemTags;
import io.github.reoseah.magisterium.block.ArcaneTableBlock;
import io.github.reoseah.magisterium.item.SpellBookItem;
import net.minecraft.entity.player.PlayerEntity;
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/assets/magisterium/particles/energy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"textures": [
"minecraft:generic_0"
]
}
12 changes: 12 additions & 0 deletions src/main/resources/assets/magisterium/particles/glyph_a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"textures": [
"magisterium:glyph_a_1",
"magisterium:glyph_a_1",
"magisterium:glyph_a_1",
"magisterium:glyph_a_1",
"magisterium:glyph_a_0",
"magisterium:glyph_a_0",
"magisterium:glyph_1",
"magisterium:glyph_0"
]
}
12 changes: 12 additions & 0 deletions src/main/resources/assets/magisterium/particles/glyph_b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"textures": [
"magisterium:glyph_b_1",
"magisterium:glyph_b_1",
"magisterium:glyph_b_1",
"magisterium:glyph_b_1",
"magisterium:glyph_b_0",
"magisterium:glyph_b_0",
"magisterium:glyph_1",
"magisterium:glyph_0"
]
}
12 changes: 12 additions & 0 deletions src/main/resources/assets/magisterium/particles/glyph_c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"textures": [
"magisterium:glyph_c_1",
"magisterium:glyph_c_1",
"magisterium:glyph_c_1",
"magisterium:glyph_c_1",
"magisterium:glyph_c_0",
"magisterium:glyph_c_0",
"magisterium:glyph_1",
"magisterium:glyph_0"
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f7090c6

Please sign in to comment.