Skip to content

Commit

Permalink
mojmap
Browse files Browse the repository at this point in the history
  • Loading branch information
yurisuika committed Oct 16, 2024
1 parent 4492a68 commit a0f70be
Show file tree
Hide file tree
Showing 50 changed files with 2,350 additions and 1,896 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
- run: chmod +x gradlew
- run: ./gradlew build --stacktrace --info
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: Blossom
path: build/libs/
Expand Down
14 changes: 9 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "dev.architectury.loom" version "1.4-SNAPSHOT"
id "dev.architectury.loom" version "1.7-SNAPSHOT"
id "maven-publish"
}

Expand All @@ -11,20 +11,23 @@ version = project.mod_version
group = project.maven_group

repositories {
maven { url "https://maven.parchmentmc.org/" }
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"

mappings loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${project.minecraft_version}:${project.parchment_version}@zip")
}
forge "net.minecraftforge:forge:${project.forge_version}"
}

processResources {
inputs.property "version", project.version
inputs.property "version", project.mod_version

filesMatching("META-INF/mods.toml") {
expand "version": project.version
expand "version": project.mod_version
}
}

Expand All @@ -41,6 +44,7 @@ loom {
}

mixin {
useLegacyMixinAp = true
defaultRefmapName = "${project.archives_base_name}.refmap.json"
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx3G
loom.platform = forge

minecraft_version = 1.17.1
yarn_mappings = 1.17.1+build.65
parchment_version = 2021.12.12

mod_id = blossom
mod_author = yurisuika
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.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
149 changes: 77 additions & 72 deletions src/main/java/dev/yurisuika/blossom/Blossom.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
package dev.yurisuika.blossom;

import dev.yurisuika.blossom.block.FloweringLeavesBlock;
import dev.yurisuika.blossom.block.FruitingLeavesBlock;
import dev.yurisuika.blossom.client.particle.BlossomParticle;
import dev.yurisuika.blossom.entity.ai.goal.BlossomGoal;
import dev.yurisuika.blossom.entity.ai.goal.FruitGoal;
import dev.yurisuika.blossom.mixin.block.BlocksInvoker;
import dev.yurisuika.blossom.mixin.block.ComposterBlockInvoker;
import dev.yurisuika.blossom.mixin.block.FireBlockInvoker;
import dev.yurisuika.blossom.server.command.BlossomCommand;
import net.minecraft.block.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.color.world.FoliageColors;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.BeeEntity;
import net.minecraft.item.*;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.DefaultParticleType;
import net.minecraft.particle.ParticleType;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
import dev.yurisuika.blossom.mixin.world.level.block.BlocksInvoker;
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.level.block.FloweringLeavesBlock;
import dev.yurisuika.blossom.world.level.block.FruitingLeavesBlock;
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.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.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.client.event.ParticleFactoryRegisterEvent;
Expand All @@ -39,39 +47,38 @@
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

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

import static dev.yurisuika.blossom.client.option.BlossomConfig.*;

@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, AbstractBlock.Settings.of(Material.LEAVES)
.strength(0.2f)
.ticksRandomly()
.sounds(BlockSoundGroup.GRASS)
.nonOpaque()
.allowsSpawning(BlocksInvoker::invokeCanSpawnOnLeaves)
.suffocates(BlocksInvoker::invokeNever)
.blockVision(BlocksInvoker::invokeNever)), new Item.Settings());
public static final RegistryObject<Block> FLOWERING_OAK_LEAVES = register("flowering_oak_leaves", () -> new FloweringLeavesBlock(Blocks.OAK_LEAVES, Blossom.FRUITING_OAK_LEAVES.get(), AbstractBlock.Settings.of(Material.LEAVES)
.strength(0.2f)
.ticksRandomly()
.sounds(BlockSoundGroup.GRASS)
.nonOpaque()
.allowsSpawning(BlocksInvoker::invokeCanSpawnOnLeaves)
.suffocates(BlocksInvoker::invokeNever)
.blockVision(BlocksInvoker::invokeNever)), new Item.Settings());

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

public static <T extends Block> RegistryObject<T> register(String name, Supplier<T> supplier, Item.Settings settings) {
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(), settings.group(ItemGroup.DECORATIONS)));
ITEMS.register(name, () -> new BlockItem(block.get(), properties.tab(CreativeModeTab.TAB_DECORATIONS)));
return block;
}

Expand All @@ -86,9 +93,9 @@ public static void registerCommandsEvents(RegisterCommandsEvent event) {
@SubscribeEvent
public static void entityJoinWorldEvents(EntityJoinWorldEvent event) {
Entity entity = event.getEntity();
if (entity instanceof BeeEntity) {
((BeeEntity)entity).getGoalSelector().add(4, new BlossomGoal((BeeEntity)entity));
((BeeEntity)entity).getGoalSelector().add(4, new FruitGoal((BeeEntity)entity));
if (entity instanceof Bee) {
((Bee) entity).getGoalSelector().addGoal(4, new BlossomGoal((Bee) entity));
((Bee) entity).getGoalSelector().addGoal(4, new FruitGoal((Bee) entity));
}
}

Expand All @@ -99,16 +106,16 @@ public static class CommonModBusEvents {

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

((FireBlockInvoker)Blocks.FIRE).invokeRegisterFlammableBlock(Blossom.FLOWERING_OAK_LEAVES.get(), 30, 60);
((FireBlockInvoker) Blocks.FIRE).invokeRegisterFlammableBlock(Blossom.FRUITING_OAK_LEAVES.get(), 30, 60);
((FireBlockInvoker) Blocks.FIRE).invokeSetFlammable(Blossom.FLOWERING_OAK_LEAVES.get(), 30, 60);
((FireBlockInvoker) Blocks.FIRE).invokeSetFlammable(Blossom.FRUITING_OAK_LEAVES.get(), 30, 60);
}

@SubscribeEvent
public static void particleFactoryRegisterEvents(ParticleFactoryRegisterEvent event) {
MinecraftClient.getInstance().particleManager.registerFactory(BLOSSOM.get(), BlossomParticle.Factory::new);
Minecraft.getInstance().particleEngine.register(BLOSSOM.get(), BlossomParticle.Factory::new);
}

}
Expand All @@ -119,23 +126,23 @@ public static class ClientModBusEvents {
@SuppressWarnings("removal")
@SubscribeEvent
public static void clientSetup(FMLClientSetupEvent event) {
RenderLayers.setRenderLayer(Blossom.FLOWERING_OAK_LEAVES.get(), RenderLayer.getCutout());
RenderLayers.setRenderLayer(Blossom.FRUITING_OAK_LEAVES.get(), RenderLayer.getCutout());
ItemBlockRenderTypes.setRenderLayer(Blossom.FLOWERING_OAK_LEAVES.get(), RenderType.cutout());
ItemBlockRenderTypes.setRenderLayer(Blossom.FRUITING_OAK_LEAVES.get(), RenderType.cutout());

ModelPredicateProviderRegistry.register(FLOWERING_OAK_LEAVES.get().asItem(), new Identifier("age"), (stack, world, entity, seed) -> {
NbtCompound nbtCompound = stack.getSubNbt("BlockStateTag");
ItemProperties.register(FLOWERING_OAK_LEAVES.get().asItem(), new ResourceLocation("age"), (stack, world, entity, seed) -> {
CompoundTag tag = stack.getTagElement("BlockStateTag");
try {
if (nbtCompound != null && nbtCompound.get(FloweringLeavesBlock.AGE.getName()) != null) {
return (float)Integer.parseInt(nbtCompound.get(FloweringLeavesBlock.AGE.getName()).asString()) / 4.0F;
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;
});
ModelPredicateProviderRegistry.register(FRUITING_OAK_LEAVES.get().asItem(), new Identifier("age"), (stack, world, entity, seed) -> {
NbtCompound nbtCompound = stack.getSubNbt("BlockStateTag");
ItemProperties.register(FRUITING_OAK_LEAVES.get().asItem(), new ResourceLocation("age"), (stack, world, entity, seed) -> {
CompoundTag tag = stack.getTagElement("BlockStateTag");
try {
if (nbtCompound != null && nbtCompound.get(FloweringLeavesBlock.AGE.getName()) != null) {
return (float)Integer.parseInt(nbtCompound.get(FloweringLeavesBlock.AGE.getName()).asString()) / 8.0F;
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;
Expand All @@ -144,23 +151,21 @@ public static void clientSetup(FMLClientSetupEvent event) {

@SubscribeEvent
public static void blockColorHandlerEvents(ColorHandlerEvent.Block event) {
event.getBlockColors().registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getFoliageColor(world, pos) : FoliageColors.getColor(0.5, 1.0), Blossom.FLOWERING_OAK_LEAVES.get());
event.getBlockColors().registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getFoliageColor(world, pos) : FoliageColors.getColor(0.5, 1.0), Blossom.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), 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());
}

@SubscribeEvent
public static void itemColorHandlerEvents(ColorHandlerEvent.Item event) {
event.getItemColors().register((stack, tintIndex) -> tintIndex > 0 ? -1 : MinecraftClient.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().getDefaultState(), null, null, tintIndex), Blossom.FLOWERING_OAK_LEAVES.get());
event.getItemColors().register((stack, tintIndex) -> tintIndex > 0 ? -1 : MinecraftClient.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().getDefaultState(), null, null, tintIndex), FRUITING_OAK_LEAVES.get());
event.getItemColors().register((stack, tintIndex) -> tintIndex > 0 ? -1 : Minecraft.getInstance().getBlockColors().getColor(((BlockItem) stack.getItem()).getBlock().defaultBlockState(), null, null, tintIndex), Blossom.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 Blossom() {
if (!file.exists()) {
saveConfig();
}
loadConfig();
Config.loadConfig();
Validate.checkBounds();

MinecraftForge.EVENT_BUS.register(this);

Expand Down
Loading

0 comments on commit a0f70be

Please sign in to comment.