Skip to content

Commit

Permalink
Changes far too numerous to enumerate.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurisuika committed Dec 11, 2024
1 parent f6a5235 commit 6b582c3
Show file tree
Hide file tree
Showing 52 changed files with 737 additions and 581 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "fabric-loom" version "1.7-SNAPSHOT"
id "fabric-loom" version "1.9-SNAPSHOT"
id "maven-publish"
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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.11-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
128 changes: 35 additions & 93 deletions src/main/java/dev/yurisuika/blossom/Blossom.java
Original file line number Diff line number Diff line change
@@ -1,99 +1,52 @@
package dev.yurisuika.blossom;

import dev.yurisuika.blossom.client.particle.BlossomParticle;
import dev.yurisuika.blossom.mixin.world.entity.MobAccessor;
import dev.yurisuika.blossom.mixin.world.level.block.BlocksInvoker;
import dev.yurisuika.blossom.client.particle.FallingPetalsParticle;
import dev.yurisuika.blossom.core.particles.BlossomParticleTypes;
import dev.yurisuika.blossom.server.commands.BlossomCommand;
import dev.yurisuika.blossom.util.Validate;
import dev.yurisuika.blossom.util.config.Config;
import dev.yurisuika.blossom.world.entity.ai.goal.BlossomGoal;
import dev.yurisuika.blossom.world.entity.ai.goal.FruitGoal;
import dev.yurisuika.blossom.world.entity.animal.BeeInterface;
import dev.yurisuika.blossom.world.level.block.BlossomBlocks;
import dev.yurisuika.blossom.world.level.block.FloweringLeavesBlock;
import dev.yurisuika.blossom.world.level.block.FruitingLeavesBlock;
import dev.yurisuika.blossom.world.level.item.BlossomItems;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import net.fabricmc.fabric.api.registry.CompostingChanceRegistry;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.Registry;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.animal.Bee;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.FoliageColor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;

import java.util.Objects;

public class Blossom implements ModInitializer {

public static final Block FRUITING_OAK_LEAVES = new FruitingLeavesBlock(Blocks.OAK_LEAVES, Items.APPLE, FabricBlockSettings.of(Material.LEAVES)
.strength(0.2F)
.ticksRandomly()
.sounds(SoundType.GRASS)
.nonOpaque()
.allowsSpawning(BlocksInvoker::invokeOcelotOrParrot)
.suffocates(BlocksInvoker::invokeNever)
.blockVision(BlocksInvoker::invokeNever));
public static final Block FLOWERING_OAK_LEAVES = new FloweringLeavesBlock(Blocks.OAK_LEAVES, Blossom.FRUITING_OAK_LEAVES, FabricBlockSettings.of(Material.LEAVES)
.strength(0.2F)
.ticksRandomly()
.sounds(SoundType.GRASS)
.nonOpaque()
.allowsSpawning(BlocksInvoker::invokeOcelotOrParrot)
.suffocates(BlocksInvoker::invokeNever)
.blockVision(BlocksInvoker::invokeNever));

public static final SimpleParticleType BLOSSOM = FabricParticleTypes.simple(false);

public static void registerBlocks() {
Registry.register(Registry.BLOCK, new ResourceLocation("blossom", "flowering_oak_leaves"), FLOWERING_OAK_LEAVES);
Registry.register(Registry.BLOCK, new ResourceLocation("blossom", "fruiting_oak_leaves"), FRUITING_OAK_LEAVES);
}

public static void registerItems() {
Registry.register(Registry.ITEM, new ResourceLocation("blossom", "flowering_oak_leaves"), new BlockItem(FLOWERING_OAK_LEAVES, new Item.Properties().tab(CreativeModeTab.TAB_DECORATIONS)));
Registry.register(Registry.ITEM, new ResourceLocation("blossom", "fruiting_oak_leaves"), new BlockItem(FRUITING_OAK_LEAVES, new Item.Properties().tab(CreativeModeTab.TAB_DECORATIONS)));
}

public static void registerParticles() {
Registry.register(Registry.PARTICLE_TYPE, new ResourceLocation("blossom", "blossom"), BLOSSOM);
}

public static void registerCompostables() {
CompostingChanceRegistry.INSTANCE.add(FLOWERING_OAK_LEAVES, 0.3F);
CompostingChanceRegistry.INSTANCE.add(FRUITING_OAK_LEAVES, 0.3F);
CompostingChanceRegistry.INSTANCE.add(BlossomBlocks.FRUITING_OAK_LEAVES, 0.3F);
CompostingChanceRegistry.INSTANCE.add(BlossomBlocks.FLOWERING_OAK_LEAVES, 0.3F);
}

public static void registerFlammables() {
FlammableBlockRegistry.getDefaultInstance().add(FLOWERING_OAK_LEAVES, 30, 60);
FlammableBlockRegistry.getDefaultInstance().add(FRUITING_OAK_LEAVES, 30, 60);
FlammableBlockRegistry.getDefaultInstance().add(BlossomBlocks.FRUITING_OAK_LEAVES, 30, 60);
FlammableBlockRegistry.getDefaultInstance().add(BlossomBlocks.FLOWERING_OAK_LEAVES, 30, 60);
}

public static void registerServerEntityEvents() {
public static void registerGoals() {
ServerEntityEvents.ENTITY_LOAD.register((entity, level) -> {
if (entity instanceof Bee) {
((MobAccessor) entity).getGoalSelector().addGoal(4, new BlossomGoal((Bee) entity));
((MobAccessor) entity).getGoalSelector().addGoal(4, new FruitGoal((Bee) entity));
((BeeInterface) entity).registerGoals((Bee) entity);
}
});
}
Expand All @@ -107,65 +60,54 @@ public void onInitialize() {
Config.loadConfig();
Validate.checkBounds();

registerBlocks();
registerItems();
registerParticles();
BlossomBlocks.register();
BlossomItems.register();
BlossomParticleTypes.register();
registerFlammables();
registerCompostables();
registerServerEntityEvents();
registerCommands();
registerGoals();
}

public static class Client implements ClientModInitializer {

@Environment(EnvType.CLIENT)
public static void registerParticleFactories() {
ParticleFactoryRegistry.getInstance().register(BLOSSOM, BlossomParticle.Factory::new);
public static void registerParticles() {
ParticleFactoryRegistry.getInstance().register(BlossomParticleTypes.FLOWERING_OAK_LEAVES, FallingPetalsParticle.FloweringOakProvider::new);
}

@Environment(EnvType.CLIENT)
public static void registerRenderLayers() {
BlockRenderLayerMap.INSTANCE.putBlock(FLOWERING_OAK_LEAVES, RenderType.cutout());
BlockRenderLayerMap.INSTANCE.putBlock(FRUITING_OAK_LEAVES, RenderType.cutout());
BlockRenderLayerMap.INSTANCE.putBlock(BlossomBlocks.FRUITING_OAK_LEAVES, RenderType.cutout());
BlockRenderLayerMap.INSTANCE.putBlock(BlossomBlocks.FLOWERING_OAK_LEAVES, RenderType.cutout());
}

@Environment(EnvType.CLIENT)
public static void registerColorProviders() {
ColorProviderRegistry.BLOCK.register((state, level, pos, tintIndex) -> level != null && pos != null ? BiomeColors.getAverageFoliageColor(level, pos) : FoliageColor.get(0.5F, 1.0F), FLOWERING_OAK_LEAVES);
ColorProviderRegistry.BLOCK.register((state, level, pos, tintIndex) -> level != null && pos != null ? BiomeColors.getAverageFoliageColor(level, pos) : FoliageColor.get(0.5F, 1.0F), FRUITING_OAK_LEAVES);
public static void registerBlockColors() {
ColorProviderRegistry.BLOCK.register((state, level, pos, tintIndex) -> level != null && pos != null ? BiomeColors.getAverageFoliageColor(level, pos) : FoliageColor.get(0.5F, 1.0F), BlossomBlocks.FRUITING_OAK_LEAVES);
ColorProviderRegistry.BLOCK.register((state, level, pos, tintIndex) -> level != null && pos != null ? BiomeColors.getAverageFoliageColor(level, pos) : FoliageColor.get(0.5F, 1.0F), BlossomBlocks.FLOWERING_OAK_LEAVES);
}

ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex > 0 ? -1 : Minecraft.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().defaultBlockState(), null, null, tintIndex), FLOWERING_OAK_LEAVES);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex > 0 ? -1 : Minecraft.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().defaultBlockState(), null, null, tintIndex), FRUITING_OAK_LEAVES);
public static void registerItemColors() {
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex > 0 ? -1 : Minecraft.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().defaultBlockState(), null, null, tintIndex), BlossomBlocks.FRUITING_OAK_LEAVES);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex > 0 ? -1 : Minecraft.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().defaultBlockState(), null, null, tintIndex), BlossomBlocks.FLOWERING_OAK_LEAVES);
}

@Environment(EnvType.CLIENT)
public static void registerModelPredicateProviders() {
FabricModelPredicateProviderRegistry.register(FLOWERING_OAK_LEAVES.asItem(), new ResourceLocation("age"), (stack, world, entity) -> {
public static void registerItemProperties() {
FabricModelPredicateProviderRegistry.register(BlossomItems.FRUITING_OAK_LEAVES, ResourceLocation.tryParse("age"), (stack, world, entity) -> {
CompoundTag tag = stack.getTagElement("BlockStateTag");
try {
if (Objects.nonNull(tag) && Objects.nonNull(tag.get(FloweringLeavesBlock.AGE.getName()))) {
return Integer.parseInt(tag.get(FloweringLeavesBlock.AGE.getName()).getAsString()) / 4.0F;
}
} catch (NumberFormatException ignored) {}
return 0.0F;
return Objects.nonNull(tag) ? Integer.parseInt(tag.get(FruitingLeavesBlock.AGE.getName()).getAsString()) / 8.0F : 0.0F;
});
FabricModelPredicateProviderRegistry.register(FRUITING_OAK_LEAVES.asItem(), new ResourceLocation("age"), (stack, world, entity) -> {
FabricModelPredicateProviderRegistry.register(BlossomItems.FLOWERING_OAK_LEAVES, ResourceLocation.tryParse("age"), (stack, world, entity) -> {
CompoundTag tag = stack.getTagElement("BlockStateTag");
try {
if (Objects.nonNull(tag) && Objects.nonNull(tag.get(FruitingLeavesBlock.AGE.getName()))) {
return Integer.parseInt(tag.get(FruitingLeavesBlock.AGE.getName()).getAsString()) / 8.0F;
}
} catch (NumberFormatException ignored) {}
return 0.0F;
return Objects.nonNull(tag) ? Integer.parseInt(tag.get(FloweringLeavesBlock.AGE.getName()).getAsString()) / 4.0F : 0.0F;
});
}

@Override
public void onInitializeClient() {
registerParticleFactories();
registerParticles();
registerRenderLayers();
registerColorProviders();
registerModelPredicateProviders();
registerBlockColors();
registerItemColors();
registerItemProperties();
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package dev.yurisuika.blossom.client.particle;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.*;
import net.minecraft.core.particles.SimpleParticleType;

@Environment(EnvType.CLIENT)
public class BlossomParticle extends TextureSheetParticle {
public class FallingPetalsParticle extends TextureSheetParticle {

public float rotSpeed;
public final float particleRandom;
public final float spinAcceleration;

public BlossomParticle(ClientLevel level, double x, double y, double z, SpriteSet spriteSet) {
public FallingPetalsParticle(ClientLevel level, double x, double y, double z, SpriteSet spriteSet) {
super(level, x, y, z);
this.setSprite(spriteSet.get(random.nextInt(12), 12));
this.rotSpeed = (float)Math.toRadians(random.nextBoolean() ? -30.0F : 30.0F);
this.rotSpeed = (float) Math.toRadians(random.nextBoolean() ? -30.0F : 30.0F);
this.particleRandom = random.nextFloat();
this.spinAcceleration = (float)Math.toRadians(random.nextBoolean() ? -5.0F : 5.0F);
this.spinAcceleration = (float) Math.toRadians(random.nextBoolean() ? -5.0F : 5.0F);
this.lifetime = 300;
this.gravity = 7.5E-4F;
float f = this.random.nextBoolean() ? 0.05F : 0.075F;
Expand All @@ -30,17 +27,16 @@ public ParticleRenderType getRenderType() {
return ParticleRenderType.PARTICLE_SHEET_OPAQUE;
}

@Environment(EnvType.CLIENT)
public static class Factory implements ParticleProvider<SimpleParticleType> {
public static class FloweringOakProvider implements ParticleProvider<SimpleParticleType> {

public final SpriteSet spriteSet;

public Factory(SpriteSet spriteSet) {
public FloweringOakProvider(SpriteSet spriteSet) {
this.spriteSet = spriteSet;
}

public Particle createParticle(SimpleParticleType parameters, ClientLevel level, double x, double y, double z, double r, double g, double b) {
return new BlossomParticle(level, x, y, z, spriteSet);
return new FallingPetalsParticle(level, x, y, z, spriteSet);
}

}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/yurisuika/blossom/config/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
public class Options {

public Value value = new Value(
new Blossoming(0.2F, 10.0D),
new Fruiting(0.2F, 10.0D),
new Harvesting(3, 0.5714286F)
new Blossoming(0.2F),
new Fruiting(0.2F),
new Harvesting(0.5714286F, 3)
);
public Filter filter = new Filter(
new Temperature(-2.0F, 2.0F),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.yurisuika.blossom.core.particles;

import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import net.minecraft.core.Registry;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.resources.ResourceLocation;

public class BlossomParticleTypes {

public static final SimpleParticleType FLOWERING_OAK_LEAVES = FabricParticleTypes.simple(false);

public static void register() {
Registry.register(Registry.PARTICLE_TYPE, ResourceLocation.tryParse("blossom:flowering_oak_leaves"), FLOWERING_OAK_LEAVES);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.yurisuika.blossom.mixin.world.entity;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.Random;

@Mixin(Entity.class)
public abstract class EntityMixin {

@Shadow
public Level level;

@Final
@Shadow
protected Random random;

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.yurisuika.blossom.mixin.world.entity.animal;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.animal.Bee;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -18,4 +19,13 @@ public interface BeeInvoker {
@Invoker("getCropsGrownSincePollination")
int invokeGetCropsGrownSincePollination();

@Invoker("isTooFarAway")
boolean invokeIsTooFarAway(BlockPos pos);

@Invoker("pathfindRandomlyTowards")
void invokePathfindRandomlyTowards(BlockPos pos);

@Invoker("closerThan")
boolean invokeCloserThan(BlockPos pos, int distance);

}
Loading

0 comments on commit 6b582c3

Please sign in to comment.