Skip to content

Commit

Permalink
polytone expermimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobgranberry committed Feb 8, 2025
1 parent b085268 commit c467c2b
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 63 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx2G
org.gradle.parallel=true

# Fabric Properties
Expand All @@ -9,7 +9,7 @@ yarn_mappings=1.21.1+build.3
loader_version=0.16.9

# Mod Properties
mod_version=1.0.0
mod_version=1.4
maven_group=com.westerosblocks
archives_base_name=westerosblocks

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/westerosblocks/WesterosBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public class WesterosBlocks implements ModInitializer {
public void onInitialize() {
WesterosBlocksDefLoader.initialize();
ModBlock.initialize();
ModParticles.initialize();
ModConfig.register();
WesterosCreativeModeTabs.registerCreativeModeTabs();
ModBlocks.registerModBlocks();
ModItems.registerModItems();
ModSounds.registerSounds();
ModParticles.init();
ModBlockEntities.registerModEntities();

ServerLifecycleEvents.SERVER_STOPPING.register(server -> {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/westerosblocks/WesterosBlocksClient.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.westerosblocks;

import com.westerosblocks.particle.ModParticles;
import com.westerosblocks.particle.custom.WildfireParticle;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.particle.EndRodParticle;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
Expand All @@ -19,7 +19,8 @@ public void onInitializeClient() {
.registerReloadListener(new WesterosResourceReloadListener());
initRenderRegistry();
ColorHandlers.registerColorProviders();
ModParticles.registerParticles();

ModParticles.initializeClient();
}

private static class WesterosResourceReloadListener implements SimpleSynchronousResourceReloadListener {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/westerosblocks/block/ModBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class ModBlock extends ModBlockStateRecord {
public static final String SHAPE_CROSSED = "crossed";
// TODO wood type for wood blocks like fencegate. see WoodTypeUtil class
public String woodType = null;
public String particle;
public String[] particles;

private transient Map<String, String> parsedType;
private final transient boolean hasCollisionBoxes = false;
Expand Down Expand Up @@ -446,7 +446,6 @@ public String getTypeValue(String key) {
private static final Map<String, BlockSoundGroup> stepSoundTable = new HashMap<>();
// private static final Map<String, CreativeModeTab> tabTable = new HashMap<>();
private static final Map<String, ModBlockFactory> typeTable = new HashMap<String, ModBlockFactory>();
private static final Map<String, ParticleType<?>> particles = new HashMap<String, ParticleType<?>>();

private transient boolean didInit = false;

Expand Down
28 changes: 25 additions & 3 deletions src/main/java/com/westerosblocks/block/custom/WCFireBlock.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.westerosblocks.block.custom;

import com.westerosblocks.WesterosBlocks;
import com.westerosblocks.block.ModBlocks;
import com.westerosblocks.block.ModBlock;
import com.westerosblocks.block.ModBlockFactory;
import com.westerosblocks.block.ModBlockLifecycle;
import com.westerosblocks.particle.WesterosParticleSystem;
import com.westerosblocks.particle.ModParticles;
//import com.westerosblocks.particle.WesterosParticleSystem;
import net.minecraft.block.*;
import net.minecraft.client.particle.ParticleFactory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
Expand All @@ -23,6 +27,7 @@
import net.minecraft.world.WorldView;

import java.util.List;
import java.util.Objects;

public class WCFireBlock extends FireBlock implements ModBlockLifecycle {
private ModBlock def;
Expand Down Expand Up @@ -60,6 +65,7 @@ public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Ran

@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
// Keep the original fire ambient sound
if (random.nextInt(24) == 0) {
world.playSound(
pos.getX() + 0.5,
Expand All @@ -73,8 +79,24 @@ public void randomDisplayTick(BlockState state, World world, BlockPos pos, Rando
);
}

if (def.particle != null) {
WesterosParticleSystem.spawnFireParticles(world, pos, random, def.particle);
// Handle custom particles
if (def.particles != null && def.particles.length > 0) {
for (String particleType : def.particles) {
ParticleEffect particle = ModParticles.get(particleType);
if (particle != null && random.nextFloat() < 0.7f) { // Add randomness to spawn rate
// Calculate random position within block space
double x = pos.getX() + 0.5 + (random.nextFloat() - 0.5) * 0.2;
double y = pos.getY() + 0.2 + random.nextFloat() * 0.6;
double z = pos.getZ() + 0.5 + (random.nextFloat() - 0.5) * 0.2;

// Add some vertical velocity and slight random horizontal movement
double velocityX = (random.nextFloat() - 0.5) * 0.02;
double velocityY = 0.05 + random.nextFloat() * 0.02;
double velocityZ = (random.nextFloat() - 0.5) * 0.02;

world.addParticle(particle, x, y, z, velocityX, velocityY, velocityZ);
}
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/westerosblocks/config/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;
import me.shedaniel.autoconfig.serializer.GsonConfigSerializer;
import me.shedaniel.clothconfig2.api.ConfigBuilder;
import net.minecraft.text.Text;

// example of how to run n your code
// boolean autoRestore = ModConfig.get().autoRestoreAllHalfDoors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,5 @@ public void generateTranslations(RegistryWrapper.WrapperLookup registryLookup, T
translationBuilder.add("text.autoconfig.westerosblocks.option.doorNoConnect.@Tooltip[0]", "Avoid doors connecting to walls/panes/etc");
translationBuilder.add("text.autoconfig.westerosblocks.option.seaLevelOverride", "Sea Level Override");
translationBuilder.add("text.autoconfig.westerosblocks.option.seaLevelOverride.@Tooltip[0]", "Override sea level (default for Westeros=33, 0=disable override)");

}
}
25 changes: 15 additions & 10 deletions src/main/java/com/westerosblocks/particle/ModParticles.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.westerosblocks.particle.custom.WildfireParticle;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import net.minecraft.client.particle.EndRodParticle;
import net.minecraft.client.particle.FlameParticle;
import net.minecraft.particle.*;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
Expand All @@ -13,11 +15,9 @@

public class ModParticles {
private static final Map<String, ParticleEffect> PARTICLE_EFFECTS = new HashMap<>();

public static final SimpleParticleType WILDFIRE = FabricParticleTypes.simple();

public static void init() {
// Register vanilla particle references
public static void initialize() {
PARTICLE_EFFECTS.put("hugeexplosion", ParticleTypes.EXPLOSION);
PARTICLE_EFFECTS.put("fireworksSpark", ParticleTypes.FIREWORK);
PARTICLE_EFFECTS.put("bubble", ParticleTypes.BUBBLE);
Expand Down Expand Up @@ -49,17 +49,22 @@ public static void init() {
PARTICLE_EFFECTS.put("happyVillager", ParticleTypes.HAPPY_VILLAGER);
PARTICLE_EFFECTS.put("soul_flame", ParticleTypes.SOUL_FIRE_FLAME);

// custom
PARTICLE_EFFECTS.put("wildfire", WILDFIRE);
registerParticle("wildfire", WILDFIRE);
}

public static void registerParticles() {
Registry.register(Registries.PARTICLE_TYPE, WesterosBlocks.id("wildfire"), WILDFIRE);
ParticleFactoryRegistry.getInstance().register(ModParticles.WILDFIRE, WildfireParticle.Factory::new);
public static void initializeClient() {
// ParticleFactoryRegistry.getInstance().register(WILDFIRE, WildfireParticle.Factory::new);
// Register with base sprite factory - this lets Polytone handle the behavior
ParticleFactoryRegistry.getInstance().register(WILDFIRE,
FlameParticle.Factory::new); // Using BlockLeakParticle as a base
}

public static ParticleEffect getParticle(String name) {
return PARTICLE_EFFECTS.get(name);
private static void registerParticle(String name, SimpleParticleType particleType) {
Registry.register(Registries.PARTICLE_TYPE, WesterosBlocks.id(name), particleType);
PARTICLE_EFFECTS.put(name, particleType);
}

public static ParticleEffect get(String name) {
return PARTICLE_EFFECTS.get(name);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,61 @@
@Environment(EnvType.CLIENT)
public class WildfireParticle extends SpriteBillboardParticle {
private final SpriteProvider spriteProvider;
private float baseScale;

protected WildfireParticle(ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ, SpriteProvider spriteProvider) {
protected WildfireParticle(ClientWorld world, double x, double y, double z,
double velocityX, double velocityY, double velocityZ,
SpriteProvider spriteProvider) {
super(world, x, y, z, velocityX, velocityY, velocityZ);

this.spriteProvider = spriteProvider;
this.red = 0.3f;
this.green = 0.8f;
this.blue = 0.3f;
this.alpha = 0.8f;
this.scale *= 0.8F;
this.maxAge = 20 + this.random.nextInt(10);
this.velocityMultiplier = 0.9F;
this.maxAge = 15 + this.random.nextInt(10);
this.baseScale = 0.5F + this.random.nextFloat() * 0.3F;
this.scale = this.baseScale;

// Set green flame colors
this.red = 0.2F;
this.green = 0.8F + this.random.nextFloat() * 0.2F;
this.blue = 0.3F;
this.alpha = 0.8F;

// Set initial velocities
this.velocityX = velocityX * 0.1D + (this.random.nextGaussian() * 0.02D);
this.velocityY = velocityY * 0.1D + 0.03D + (this.random.nextFloat() * 0.02D);
this.velocityZ = velocityZ * 0.1D + (this.random.nextGaussian() * 0.02D);

this.setSpriteForAge(spriteProvider);
}

@Override
public void tick() {
super.tick();
float lifeProgress = (float) this.age / (float) this.maxAge;
this.alpha = 0.8F * (1.0F - lifeProgress);
this.setSpriteForAge(spriteProvider);
this.velocityX += (this.random.nextFloat() - 0.5) * 0.05;
this.velocityZ += (this.random.nextFloat() - 0.5) * 0.05;
if (this.alpha < 0.01F) this.markDead();
this.prevPosX = this.x;
this.prevPosY = this.y;
this.prevPosZ = this.z;

if (this.age++ >= this.maxAge) {
this.markDead();
return;
}

// More volatile movement
this.velocityX *= 1.02D;
this.velocityY *= 0.98D;
this.velocityZ *= 1.02D;

// Add sine wave motion for more chaotic movement
double ageOffset = this.age / 3.0;
this.velocityX += Math.sin(ageOffset) * 0.01D;
this.velocityZ += Math.cos(ageOffset) * 0.01D;

this.move(this.velocityX, this.velocityY, this.velocityZ);

// Update appearance
float lifeProgress = (float)this.age / (float)this.maxAge;
this.alpha = Math.max(0, 0.8F - lifeProgress * 0.8F);
this.scale = this.baseScale * (1.0F + lifeProgress * 0.5F);

this.setSpriteForAge(this.spriteProvider);
}

@Override
Expand All @@ -49,7 +81,8 @@ public Factory(SpriteProvider spriteProvider) {

@Override
public Particle createParticle(SimpleParticleType type, ClientWorld world,
double x, double y, double z, double velX, double velY, double velZ) {
double x, double y, double z,
double velX, double velY, double velZ) {
return new WildfireParticle(world, x, y, z, velX, velY, velZ, this.spriteProvider);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"initializer": {
"lifetime": "10",
"alpha": "0.8",
"size": "0.5"
},
"render_type": "translucent",
"liquid_affinity": "non_liquids",
"has_physics": false
}
2 changes: 1 addition & 1 deletion src/main/resources/definitions/blocks/fire/wildfire.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"creativeTab": "westeros_lighting_tab",
"lightValue": 1,
"label": "Wildfire",
"particle": "wildfire",
"particles": ["wildfire","largesmoke"],
"material": "fire",
"tooltips": [
"Very hot fire",
Expand Down
5 changes: 1 addition & 4 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"contact": {
"homepage": "https://westeroscraft.com/",
"sources": "https://github.com/WesterosCraft/WesterosBlocksFabric"
"sources": "https://github.com/WesterosCraft/WesterosBlocks"
},
"license": "Apache Public License v2",
"icon": "assets/westerosblocks/icon.png",
Expand Down Expand Up @@ -37,8 +37,5 @@
"java": ">=21",
"fabric-api": "*",
"cloth-config": ">=11.0.99"
},
"suggests": {
"another-mod": "*"
}
}

0 comments on commit c467c2b

Please sign in to comment.