Skip to content

Commit

Permalink
initial trans flag heart particle impl :3
Browse files Browse the repository at this point in the history
  • Loading branch information
IAMSolaara committed Jul 2, 2024
1 parent acfb262 commit 25f8869
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/java/net/solaara/beeyourself/BeeYourself.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.particle.DefaultParticleType;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
Expand All @@ -23,6 +25,8 @@ public class BeeYourself implements ModInitializer {
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LoggerFactory.getLogger("bee-yourself");

public static final DefaultParticleType TRANS_FLAG_HEART_PARTICLE = FabricParticleTypes.simple();

public static final EntityType<TransBeeEntity> TRANS_BEE = Registry.register(
Registry.ENTITY_TYPE,
new Identifier("beeyourself", "transbee"),
Expand All @@ -41,6 +45,8 @@ public void onInitialize() {
FabricDefaultAttributeRegistry.register(TRANS_BEE, TransBeeEntity.create_transbee_attributes());

Registry.register(Registry.ITEM, new Identifier("bee-yourself", "trans_bee_spawn_egg"), TRANS_BEE_SPAWN_EGG);
Registry.register(Registry.PARTICLE_TYPE, new Identifier("bee-yourself", "trans_flag_heart"),
TRANS_FLAG_HEART_PARTICLE);

LOGGER.info("BeeYourself onInitialize()");
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/solaara/beeyourself/BeeYourselfClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
import net.minecraft.client.particle.EmotionParticle.HeartFactory;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.Identifier;
import net.solaara.beeyourself.transbee.TransBeeEntityModel;
import net.solaara.beeyourself.transbee.TransBeeEntityRenderer;
import net.solaara.beeyourself.transflagheart.TransFlagHeartParticle;

@Environment(EnvType.CLIENT)
public class BeeYourselfClient implements ClientModInitializer {
Expand All @@ -21,6 +26,9 @@ public void onInitializeClient() {
return new TransBeeEntityRenderer(context);
});

ParticleFactoryRegistry.getInstance().register(BeeYourself.TRANS_FLAG_HEART_PARTICLE,
TransFlagHeartParticle.Factory::new);

EntityModelLayerRegistry.register(MODEL_TRANSBEE_LAYER, TransBeeEntityModel::getTexturedModelData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ public ActionResult interactMob(PlayerEntity player, Hand hand) {
double d = this.random.nextGaussian() * 0.2;
double e = this.random.nextGaussian() * 0.2;
double f = this.random.nextGaussian() * 0.2;
ModUtils.spawnForcedParticles((ServerWorld) world, ParticleTypes.HEART, this.getParticleX(1.0),
ModUtils.spawnForcedParticles((ServerWorld) world, BeeYourself.TRANS_FLAG_HEART_PARTICLE,
this.getParticleX(1.0),
this.getRandomBodyY() + 0.5,
this.getParticleZ(1.0), 7, d, e,
this.getParticleZ(1.0), 17, d, e,
f, 1);

this.setTarget(player);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package net.solaara.beeyourself.transflagheart;

import net.fabricmc.api.Environment;
import net.fabricmc.api.EnvType;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleFactory;
import net.minecraft.client.particle.ParticleTextureSheet;
import net.minecraft.client.particle.SpriteBillboardParticle;
import net.minecraft.client.particle.SpriteProvider;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.DefaultParticleType;
import net.solaara.beeyourself.BeeYourself;

@Environment(EnvType.CLIENT)
public class TransFlagHeartParticle extends SpriteBillboardParticle {
// The sprite provider which is used to determine the particle's texture
private final SpriteProvider spriteProvider;
private final int variant;

TransFlagHeartParticle(ClientWorld world, double x, double y, double z, double velX, double velY, double velZ,
SpriteProvider spriteProvider) {
super(world, x, y, z);
this.spriteProvider = spriteProvider; // Sets the sprite provider from above to the sprite provider in the
// constructor parameters
this.x = x; // The x from the constructor parameters
this.y = y;
this.z = z;
this.alpha = 1.0f; // Setting the alpha to 1.0f means there will be no opacity change until the
// alpha value is changed
this.velocityMultiplier = 0.86F;
this.velocityX *= 0.01F;
this.velocityY *= 0.01F;
this.velocityZ *= 0.01F;
this.velocityY += 0.1;
this.scale *= 1.5F;
this.maxAge = 16;
this.collidesWithWorld = false;
this.setSpriteForAge(spriteProvider); // Required
this.variant = world.random.nextInt(1, 4);
var test = this.spriteProvider.getSprite(this.variant, this.variant);

BeeYourself.LOGGER.info("variant " + this.variant);
BeeYourself.LOGGER.info("variant " + test);
}

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

@Environment(EnvType.CLIENT)
public static class Factory implements ParticleFactory<DefaultParticleType> {
// The factory used in a particle's registry
private final SpriteProvider spriteProvider;

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

public Particle createParticle(DefaultParticleType defaultParticleType, ClientWorld clientWorld, double x,
double y, double z, double velX, double velY, double velZ) {
return new TransFlagHeartParticle(clientWorld, x, y, z, velX, velY, velZ, this.spriteProvider);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"textures": [
"bee-yourself:trans_flag_heart_1",
"bee-yourself:trans_flag_heart_2",
"bee-yourself:trans_flag_heart_3"
]
}
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 25f8869

Please sign in to comment.