Skip to content

Commit

Permalink
First working build for 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Scillman committed Oct 24, 2024
1 parent eb61055 commit ab32728
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# certain platforms or Java versions, and provides a first line of defence
# against bad commits.

name: build
name: Growmeal-Fabric
on:
pull_request:
branches:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Growmeal-Fabric](https://github.com/Gamemassa/Growmeal-Fabric/actions/workflows/build.yml/badge.svg?branch=1.21.3&event=push)

# Growmeal-Fabric

Unofficial Fabric Port of bl4ckscor3's [Growmeal](https://github.com/bl4ckscor3/Growmeal) mod.
Expand Down
72 changes: 36 additions & 36 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
plugins {
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
id 'fabric-loom' version '1.8-SNAPSHOT'
id 'maven-publish'
}

version = project.mod_version
group = project.maven_group

base {
archivesName = project.archives_base_name
archivesName = project.archives_base_name
}

loom {
splitEnvironmentSourceSets()

mods {
"growmeal-fabric" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}
mods {
"growmeal-fabric" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}

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

filesMatching("fabric.mod.json") {
expand "version": project.version
}
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
it.options.release = 21
}

java {
withSourcesJar()
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
}
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
}
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
publications {
mavenJava(MavenPublication) {
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21
yarn_mappings=1.21+build.9
loader_version=0.15.11
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.7

# Mod Properties
mod_version=1.2.1
mod_version=1.3.0
maven_group=com.builtbroken.sbmgrowmeal
archives_base_name=growmeal-fabric

# Dependencies
fabric_version=0.100.6+1.21
fabric_version=0.106.1+1.21.3
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
16 changes: 8 additions & 8 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}
26 changes: 19 additions & 7 deletions src/main/java/com/builtbroken/sbmgrowmeal/GrowmealFabric.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
package com.builtbroken.sbmgrowmeal;

import java.util.function.Function;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.fabricmc.api.ModInitializer;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;

public class GrowmealFabric implements ModInitializer {

public static final String MOD_ID = "sbmgrowmeal";
public static final String MOD_NAME = "SBM Growmeal";
public static final String MOD_ID = "sbmgrowmeal";
public static final String MOD_NAME = "SBM Growmeal";

public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME);

public static final Item GROWMEAL = new GrowmealItem(new Item.Settings());
public static final Item GROWMEAL = register("growmeal", GrowmealItem::new);

@Override
public void onInitialize() {

}

@Override
public void onInitialize() {
Registry.register(Registries.ITEM, Identifier.of(MOD_ID, "growmeal"), GROWMEAL);
}
private static <T extends Item> T register(String id, Function<Item.Settings, T> factory) {
Identifier guid = Identifier.of(MOD_ID, id);
RegistryKey<Item> key = RegistryKey.of(RegistryKeys.ITEM, guid);
Item.Settings settings = (new Item.Settings()).registryKey(key);
T item = factory.apply(settings);
return Registry.register(Registries.ITEM, guid, item);
}
}
69 changes: 45 additions & 24 deletions src/main/java/com/builtbroken/sbmgrowmeal/GrowmealItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@
import net.minecraft.world.WorldEvents;
import net.minecraft.world.biome.Biome;

public class GrowmealItem
extends Item {
public static int tries = 1000;
/**
* @see {@link net.minecraft.item.BoneMealItem BoneMealItem}
* @see {@link net.minecraft.block.SaplingBlock SaplingBlock}
* @see {@link net.minecraft.block.CropBlock CropBlock}
*/
public class GrowmealItem extends Item {
public static int tries = 1000;

public GrowmealItem(Item.Settings settings) {
super(settings);
Expand All @@ -41,40 +45,42 @@ public ActionResult useOnBlock(ItemUsageContext context) {
BlockPos blockPos2 = blockPos.offset(context.getSide());
boolean isGrown = false;
for(int i = 0; i < tries; i++) {
if (GrowmealItem.useOnFertilizable(context.getStack(), world, blockPos)) {
// GrowmealFabric.LOGGER.info("using on plant " + i + " " + Boolean.toString(isGrown));
if (!world.isClient) {
world.syncWorldEvent(WorldEvents.BONE_MEAL_USED, blockPos, 0);
isGrown = true;
}
} else {
break;
}
if (GrowmealItem.useOnFertilizable(context.getStack(), world, blockPos)) {
// GrowmealFabric.LOGGER.info("using on plant " + i + " " + Boolean.toString(isGrown));
if (!world.isClient) {
world.syncWorldEvent(WorldEvents.BONE_MEAL_USED, blockPos, 0);
isGrown = true;
}
} else {
break;
}
}
if(isGrown) return ActionResult.success(world.isClient);

if (isGrown)
return ActionResult.SUCCESS; // ActionResult.success(world.isClient);

BlockState blockState = world.getBlockState(blockPos);
boolean bl = blockState.isSideSolidFullSquare(world, blockPos, context.getSide());
if (bl && BoneMealItem.useOnGround(context.getStack(), world, blockPos2, context.getSide())) {
if (!world.isClient) {
world.syncWorldEvent(WorldEvents.BONE_MEAL_USED, blockPos2, 0);
}
return ActionResult.success(world.isClient);
return ActionResult.SUCCESS; // ActionResult.success(world.isClient);
}
return ActionResult.PASS;
}

public static boolean useOnFertilizable(ItemStack stack, World world, BlockPos pos) {
Fertilizable fertilizable;
BlockState blockState = world.getBlockState(pos);
if (blockState.getBlock() instanceof Fertilizable && (fertilizable = (Fertilizable)((Object)blockState.getBlock())).isFertilizable(world, pos, blockState)) {
if (blockState.getBlock() instanceof Fertilizable fertilizable && fertilizable.isFertilizable(world, pos, blockState)) {
if (world instanceof ServerWorld) {
if (fertilizable.canGrow(world, world.random, pos, blockState)) {
// GrowmealFabric.LOGGER.info("Looping " + i);
fertilizable.grow((ServerWorld)world, world.random, pos, blockState);
}
if (fertilizable.canGrow(world, world.random, pos, blockState)) {
// GrowmealFabric.LOGGER.info("Looping " + i);
fertilizable.grow((ServerWorld)world, world.random, pos, blockState);
}
stack.decrement(1);
}
// GrowmealFabric.LOGGER.info("used on plant");
// GrowmealFabric.LOGGER.info("used on plant");
return true;
}
return false;
Expand All @@ -97,12 +103,27 @@ public static boolean useOnGround(ItemStack stack, World world, BlockPos blockPo
RegistryEntry<Biome> registryEntry = world.getBiome(blockPos2);
if (registryEntry.isIn(BiomeTags.PRODUCES_CORALS_FROM_BONEMEAL)) {
if (i == 0 && facing != null && facing.getAxis().isHorizontal()) {
blockState = Registries.BLOCK.getEntryList(BlockTags.WALL_CORALS).flatMap(blocks -> blocks.getRandom(world.random)).map(blockEntry -> ((Block)blockEntry.value()).getDefaultState()).orElse(blockState);
blockState = Registries.BLOCK
.getRandomEntry(BlockTags.WALL_CORALS, world.random)
.map(blockEntry -> blockEntry.value().getDefaultState())
.orElse(blockState);
// blockState = Registries.BLOCK
// .getEntryList(BlockTags.WALL_CORALS)
// .flatMap(blocks -> blocks.getRandom(world.random)).map(blockEntry -> ((Block)blockEntry.value()).getDefaultState())
// .orElse(blockState);
if (blockState.contains(DeadCoralWallFanBlock.FACING)) {
blockState = (BlockState)blockState.with(DeadCoralWallFanBlock.FACING, facing);
}
} else if (random.nextInt(4) == 0) {
blockState = Registries.BLOCK.getEntryList(BlockTags.UNDERWATER_BONEMEALS).flatMap(blocks -> blocks.getRandom(world.random)).map(blockEntry -> ((Block)blockEntry.value()).getDefaultState()).orElse(blockState);
blockState = Registries.BLOCK
.getRandomEntry(BlockTags.UNDERWATER_BONEMEALS, world.random)
.map(blockEntry -> blockEntry.value().getDefaultState())
.orElse(blockState);
// blockState = Registries.BLOCK
// .getEntryList(BlockTags.UNDERWATER_BONEMEALS)
// .flatMap(blocks -> blocks.getRandom(world.random))
// .map(blockEntry -> ((Block)blockEntry.value()).getDefaultState())
// .orElse(blockState);
}
}
if (blockState.isIn(BlockTags.WALL_CORALS, state -> state.contains(DeadCoralWallFanBlock.FACING))) {
Expand Down Expand Up @@ -137,7 +158,7 @@ public static void createParticles(WorldAccess world, BlockPos pos, int count) {
count *= 3;
e = 1.0;
d = 3.0;
} else if (blockState.isOpaqueFullCube(world, pos)) {
} else if (blockState.isOpaqueFullCube()) {
pos = pos.up();
count *= 3;
d = 3.0;
Expand Down
4 changes: 1 addition & 3 deletions src/main/resources/data/sbmgrowmeal/recipe/growmeal.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"category": "misc",
"group": "bonemeal",
"key": {
"b": {
"item": "minecraft:bone_meal"
}
"b": "minecraft:bone_meal"
},
"pattern": [
"b b",
Expand Down
Loading

0 comments on commit ab32728

Please sign in to comment.