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 a1fc05c commit b2ef653
Show file tree
Hide file tree
Showing 48 changed files with 931 additions and 778 deletions.
141 changes: 49 additions & 92 deletions src/main/java/dev/yurisuika/blossom/Blossom.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
package dev.yurisuika.blossom;

import dev.yurisuika.blossom.client.particle.BlossomParticle;
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.mixin.world.level.block.ComposterBlockInvoker;
import dev.yurisuika.blossom.mixin.world.level.block.FireBlockInvoker;
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.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.animal.Bee;
import net.minecraft.world.item.*;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
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.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RegisterColorHandlersEvent;
import net.minecraftforge.client.event.RegisterParticleProvidersEvent;
Expand All @@ -41,59 +38,24 @@
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import java.util.Objects;
import java.util.function.Supplier;

@Mod("blossom")
public class Blossom {

public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "blossom");
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "blossom");
public static final DeferredRegister<ParticleType<?>> PARTICLES = DeferredRegister.create(ForgeRegistries.PARTICLE_TYPES, "blossom");

public static final RegistryObject<Block> FRUITING_OAK_LEAVES = register("fruiting_oak_leaves", () -> new FruitingLeavesBlock(Blocks.OAK_LEAVES, Items.APPLE, BlockBehaviour.Properties.of(Material.LEAVES)
.strength(0.2F)
.randomTicks()
.sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn(BlocksInvoker::invokeOcelotOrParrot)
.isSuffocating(BlocksInvoker::invokeNever)
.isViewBlocking(BlocksInvoker::invokeNever)), new Item.Properties());
public static final RegistryObject<Block> FLOWERING_OAK_LEAVES = register("flowering_oak_leaves", () -> new FloweringLeavesBlock(Blocks.OAK_LEAVES, Blossom.FRUITING_OAK_LEAVES.get(), BlockBehaviour.Properties.of(Material.LEAVES)
.strength(0.2F)
.randomTicks()
.sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn(BlocksInvoker::invokeOcelotOrParrot)
.isSuffocating(BlocksInvoker::invokeNever)
.isViewBlocking(BlocksInvoker::invokeNever)), new Item.Properties());

public static final RegistryObject<SimpleParticleType> BLOSSOM = PARTICLES.register("blossom", () -> new SimpleParticleType(false));

public static <T extends Block> RegistryObject<T> register(String name, Supplier<T> supplier, Item.Properties properties) {
RegistryObject<T> block = BLOCKS.register(name, supplier);
ITEMS.register(name, () -> new BlockItem(block.get(), properties));
return block;
}

@Mod.EventBusSubscriber(modid = "blossom")
public static class CommonForgeEvents {

@SubscribeEvent
public static void registerCommandsEvents(RegisterCommandsEvent event) {
public static void registerCommands(RegisterCommandsEvent event) {
BlossomCommand.register(event.getDispatcher(), event.getBuildContext(), event.getCommandSelection());
}

@SubscribeEvent
public static void entityJoinLevelEvents(EntityJoinLevelEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Bee) {
((Bee) entity).getGoalSelector().addGoal(4, new BlossomGoal((Bee) entity));
((Bee) entity).getGoalSelector().addGoal(4, new FruitGoal((Bee) entity));
public static void registerGoals(EntityJoinLevelEvent event) {
if (event.getEntity() instanceof Bee entity) {
((BeeInterface) entity).registerGoals(entity);
}
}

Expand All @@ -103,69 +65,64 @@ public static void entityJoinLevelEvents(EntityJoinLevelEvent event) {
public static class CommonModBusEvents {

@SubscribeEvent
public static void commonSetup(FMLCommonSetupEvent event) {
ComposterBlockInvoker.invokeAdd(0.3F, Blossom.FLOWERING_OAK_LEAVES.get());
ComposterBlockInvoker.invokeAdd(0.3F, Blossom.FRUITING_OAK_LEAVES.get());

((FireBlockInvoker) Blocks.FIRE).invokeSetFlammable(Blossom.FLOWERING_OAK_LEAVES.get(), 30, 60);
((FireBlockInvoker) Blocks.FIRE).invokeSetFlammable(Blossom.FRUITING_OAK_LEAVES.get(), 30, 60);
public static void registerCompostables(FMLCommonSetupEvent event) {
ComposterBlockInvoker.invokeAdd(0.3F, BlossomBlocks.FRUITING_OAK_LEAVES.get());
ComposterBlockInvoker.invokeAdd(0.3F, BlossomBlocks.FLOWERING_OAK_LEAVES.get());
}

@SubscribeEvent
public static void registerParticleProvidersEvents(RegisterParticleProvidersEvent event) {
Minecraft.getInstance().particleEngine.register(BLOSSOM.get(), BlossomParticle.Factory::new);
public static void registerFlammables(FMLCommonSetupEvent event) {
((FireBlockInvoker) Blocks.FIRE).invokeSetFlammable(BlossomBlocks.FRUITING_OAK_LEAVES.get(), 30, 60);
((FireBlockInvoker) Blocks.FIRE).invokeSetFlammable(BlossomBlocks.FLOWERING_OAK_LEAVES.get(), 30, 60);
}

}

@Mod.EventBusSubscriber(modid = "blossom", bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public static class ClientModBusEvents {

@SuppressWarnings("removal")
@SubscribeEvent
public static void clientSetup(FMLClientSetupEvent event) {
ItemBlockRenderTypes.setRenderLayer(Blossom.FLOWERING_OAK_LEAVES.get(), RenderType.cutout());
ItemBlockRenderTypes.setRenderLayer(Blossom.FRUITING_OAK_LEAVES.get(), RenderType.cutout());
public static void registerParticles(RegisterParticleProvidersEvent event) {
Minecraft.getInstance().particleEngine.register(BlossomParticleTypes.FLOWERING_OAK_LEAVES.get(), FallingPetalsParticle.FloweringOakProvider::new);
}

@SubscribeEvent
public static void registerRenderLayers(FMLClientSetupEvent event) {
ItemBlockRenderTypes.setRenderLayer(BlossomBlocks.FRUITING_OAK_LEAVES.get(), RenderType.cutout());
ItemBlockRenderTypes.setRenderLayer(BlossomBlocks.FLOWERING_OAK_LEAVES.get(), RenderType.cutout());
}

ItemProperties.register(FLOWERING_OAK_LEAVES.get().asItem(), new ResourceLocation("age"), (stack, world, entity, seed) -> {
@SubscribeEvent
public static void registerItemProperties(FMLClientSetupEvent event) {
ItemProperties.register(BlossomItems.FRUITING_OAK_LEAVES.get(), ResourceLocation.tryParse("age"), (stack, world, entity, seed) -> {
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;
});
ItemProperties.register(FRUITING_OAK_LEAVES.get().asItem(), new ResourceLocation("age"), (stack, world, entity, seed) -> {
ItemProperties.register(BlossomItems.FLOWERING_OAK_LEAVES.get(), ResourceLocation.tryParse("age"), (stack, world, entity, seed) -> {
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()) / 8.0F;
}
} catch (NumberFormatException ignored) {}
return 0.0F;
return Objects.nonNull(tag) ? Integer.parseInt(tag.get(FloweringLeavesBlock.AGE.getName()).getAsString()) / 4.0F : 0.0F;
});
}

@SubscribeEvent
public static void registerBlockColorHandlersEvents(RegisterColorHandlersEvent.Block event) {
event.getBlockColors().register((state, level, pos, tintIndex) -> level != null && pos != null ? BiomeColors.getAverageFoliageColor(level, pos) : FoliageColor.get(0.5F, 1.0F), Blossom.FLOWERING_OAK_LEAVES.get());
event.getBlockColors().register((state, level, pos, tintIndex) -> level != null && pos != null ? BiomeColors.getAverageFoliageColor(level, pos) : FoliageColor.get(0.5F, 1.0F), Blossom.FRUITING_OAK_LEAVES.get());
public static void registerBlockColors(RegisterColorHandlersEvent.Block event) {
event.getBlockColors().register((state, level, pos, tintIndex) -> level != null && pos != null ? BiomeColors.getAverageFoliageColor(level, pos) : FoliageColor.get(0.5F, 1.0F), BlossomBlocks.FRUITING_OAK_LEAVES.get());
event.getBlockColors().register((state, level, pos, tintIndex) -> level != null && pos != null ? BiomeColors.getAverageFoliageColor(level, pos) : FoliageColor.get(0.5F, 1.0F), BlossomBlocks.FLOWERING_OAK_LEAVES.get());
}

@SubscribeEvent
public static void registerItemColorHandlersEvents(RegisterColorHandlersEvent.Item event) {
event.getItemColors().register((stack, tintIndex) -> tintIndex > 0 ? -1 : Minecraft.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().defaultBlockState(), null, null, tintIndex), FLOWERING_OAK_LEAVES.get());
event.getItemColors().register((stack, tintIndex) -> tintIndex > 0 ? -1 : Minecraft.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().defaultBlockState(), null, null, tintIndex), FRUITING_OAK_LEAVES.get());
public static void registerItemColors(RegisterColorHandlersEvent.Item event) {
event.getItemColors().register((stack, tintIndex) -> tintIndex > 0 ? -1 : Minecraft.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().defaultBlockState(), null, null, tintIndex), BlossomBlocks.FRUITING_OAK_LEAVES.get());
event.getItemColors().register((stack, tintIndex) -> tintIndex > 0 ? -1 : Minecraft.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().defaultBlockState(), null, null, tintIndex), BlossomBlocks.FLOWERING_OAK_LEAVES.get());
}

@SubscribeEvent
public static void registerCreativeModeTabEvents(CreativeModeTabEvent.BuildContents event) {
public static void registerCreativeModeTabs(CreativeModeTabEvent.BuildContents event) {
if(event.getTab() == CreativeModeTabs.NATURAL_BLOCKS) {
event.accept(FLOWERING_OAK_LEAVES);
event.getEntries().putAfter(Items.FLOWERING_AZALEA_LEAVES.getDefaultInstance(), FLOWERING_OAK_LEAVES.get().asItem().getDefaultInstance(), CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS);
event.accept(FRUITING_OAK_LEAVES);
event.getEntries().putAfter(FLOWERING_OAK_LEAVES.get().asItem().getDefaultInstance(), FRUITING_OAK_LEAVES.get().asItem().getDefaultInstance(), CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS);
event.accept(BlossomBlocks.FRUITING_OAK_LEAVES.get());
event.getEntries().putAfter(Items.FLOWERING_AZALEA_LEAVES.getDefaultInstance(), BlossomItems.FRUITING_OAK_LEAVES.get().getDefaultInstance(), CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS);
event.accept(BlossomBlocks.FLOWERING_OAK_LEAVES.get());
event.getEntries().putAfter(Items.FLOWERING_AZALEA_LEAVES.getDefaultInstance(), BlossomItems.FLOWERING_OAK_LEAVES.get().getDefaultInstance(), CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS);
}
}

Expand All @@ -175,11 +132,11 @@ public Blossom() {
Config.loadConfig();
Validate.checkBounds();

MinecraftForge.EVENT_BUS.register(this);
BlossomBlocks.register(FMLJavaModLoadingContext.get().getModEventBus());
BlossomItems.register(FMLJavaModLoadingContext.get().getModEventBus());
BlossomParticleTypes.register(FMLJavaModLoadingContext.get().getModEventBus());

BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
PARTICLES.register(FMLJavaModLoadingContext.get().getModEventBus());
MinecraftForge.EVENT_BUS.register(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
import net.minecraft.client.particle.*;
import net.minecraft.core.particles.SimpleParticleType;

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 @@ -28,10 +28,10 @@ public ParticleRenderType getRenderType() {
return ParticleRenderType.PARTICLE_SHEET_OPAQUE;
}

public record Factory(SpriteSet spriteSet) implements ParticleProvider<SimpleParticleType> {
public record FloweringOakProvider(SpriteSet spriteSet) implements ParticleProvider<SimpleParticleType> {

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,20 @@
package dev.yurisuika.blossom.core.particles;

import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class BlossomParticleTypes {

public static final DeferredRegister<ParticleType<?>> PARTICLES = DeferredRegister.create(ForgeRegistries.PARTICLE_TYPES, "blossom");

public static final RegistryObject<SimpleParticleType> FLOWERING_OAK_LEAVES = PARTICLES.register("flowering_oak_leaves", () -> new SimpleParticleType(false));

public static void register(IEventBus eventBus) {
PARTICLES.register(eventBus);
}

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

import net.minecraft.util.RandomSource;
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;

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

@Shadow
public Level level;

@Final
@Shadow
protected RandomSource 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 b2ef653

Please sign in to comment.