Skip to content

Commit

Permalink
feat: 1.20.6 port, gametests all pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamalam360 committed May 20, 2024
1 parent f51131e commit 9568afb
Show file tree
Hide file tree
Showing 32 changed files with 61 additions and 577 deletions.
18 changes: 3 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,23 @@ jobs:
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Setup JDK 17
- name: Setup JDK 21
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 21

- name: Run Game Tests
run: ./gradlew fabric-gametest:runGametest

- name: Build
run: ./gradlew clean neoforge:build forge:build fabric:build quilt:build
run: ./gradlew clean neoforge:build fabric:build

- name: Capture Fabric Build Artifacts
uses: actions/upload-artifact@v2
with:
name: Fabric Artifacts
path: fabric/build/libs/

- name: Capture Quilt Build Artifacts
uses: actions/upload-artifact@v2
with:
name: Quilt Artifacts
path: quilt/build/libs/

- name: Capture Forge Build Artifacts
uses: actions/upload-artifact@v2
with:
name: Forge Artifacts
path: forge/build/libs/

- name: Capture NeoForge Build Artifacts
uses: actions/upload-artifact@v2
with:
Expand Down
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
- Add automated testing.
- Add `rightclickharvest:blacklist` block tag.

1.20.6 update coming soon :)
- Port 4.2.0 to 1.20.6.
- Forge and Quilt support has been removed (see Discord announcements channel for reasoning).
- `RightClickHarvestFabricLikeCallbacks` has been renamed to `RightClickHarvestFabricCallbacks` (API).
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
id "com.github.breadmoirai.github-release" version "2.4.1"
id "maven-publish"
Expand Down Expand Up @@ -57,6 +57,10 @@ allprojects {
version = rootProject.version
group = rootProject.group

base {
archivesName = "rightclickharvest"
}

repositories {
mavenCentral()

Expand All @@ -73,7 +77,7 @@ allprojects {

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = 17
options.release = 21
}

tasks.create("prepareWorkspace") {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -183,7 +184,7 @@ private static InteractionResult completeHarvest(Level level, BlockState state,
setBlockAction.run();

if (hoeInUse) {
stackInHand.hurtAndBreak(1, player, (entity) -> entity.broadcastBreakEvent(hand));
stackInHand.hurtAndBreak(1, player, hand == InteractionHand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND);
}

// Regular block breaking causes 0.005f exhaustion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@
"config.rightclickharvest.hungerLevel.high": "High",
"config.rightclickharvest.discord": "Chat on Discord",
"config.rightclickharvest.github": "Report bugs and request new features on GitHub",
"config.rightclickharvest.modrinth": "Check for updates on Modrinth"
"config.rightclickharvest.modrinth": "Check for updates on Modrinth",
"tag.block.rightclickharvest.blacklist": "Harvest Blacklist",
"tag.block.rightclickharvest.hoe_never_required": "Hoe Not Required",
"tag.block.rightclickharvest.radius_harvest_blacklist": "Radius Harvest Blacklist",
"tag.item.rightclickharvest.low_tier_hoes": "Low Tier Hoes",
"tag.item.rightclickharvest.mid_tier_hoes": "Mid Tier Hoes",
"tag.item.rightclickharvest.high_tier_hoes": "High Tier Hoes"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.CropBlock;

public class ConfigTestSuite {
Expand Down Expand Up @@ -72,7 +73,7 @@ public void testHarvestInRadiusFalse(GameTestHelper helper) {

@GameTest(template = "rightclickharvest-gametest:wheat")
public void testHungerLevelNormal(GameTestHelper helper) {
Player player = helper.makeMockSurvivalPlayer();
Player player = helper.makeMockPlayer(GameType.SURVIVAL);
float exhaustion = player.getFoodData().getExhaustionLevel();
TestHelper.interact(helper, player, CROP_CENTRE_POS, Items.WOODEN_HOE.getDefaultInstance());

Expand All @@ -89,7 +90,7 @@ public void testHungerLevelNormal(GameTestHelper helper) {
@GameTest(template = "rightclickharvest-gametest:wheat")
public void testHungerLevelNone(GameTestHelper helper) {
RightClickHarvest.CONFIG.get().hungerLevel = HungerLevel.NONE;
Player player = helper.makeMockSurvivalPlayer();
Player player = helper.makeMockPlayer(GameType.SURVIVAL);
float exhaustion = player.getFoodData().getExhaustionLevel();
TestHelper.interact(helper, player, CROP_CENTRE_POS, Items.WOODEN_HOE.getDefaultInstance());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.CropBlock;

public class CropsTestSuite {
Expand Down Expand Up @@ -56,7 +57,7 @@ public void testNetheriteHoe(GameTestHelper helper) {

@GameTest(template = "rightclickharvest-gametest:wheat")
public void testHoeDurability(GameTestHelper helper) {
Player player = helper.makeMockSurvivalPlayer();
Player player = helper.makeMockPlayer(GameType.SURVIVAL);
TestHelper.interact(helper, player, CROP_CENTRE_POS, Items.WOODEN_HOE.getDefaultInstance());

helper.succeedIf(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;

public class TestHelper {

public static void interact(GameTestHelper helper, BlockPos pos, ItemStack stack) {
interact(helper, helper.makeMockPlayer(), pos, stack);
interact(helper, helper.makeMockPlayer(GameType.CREATIVE), pos, stack);
}

public static void interact(GameTestHelper helper, Player player, BlockPos pos, ItemStack stack) {
Expand Down
11 changes: 0 additions & 11 deletions fabric-like/build.gradle

This file was deleted.

This file was deleted.

6 changes: 2 additions & 4 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.github.johnrengelman.shadow" version "8.1.1"
id "me.shedaniel.unified-publishing"
}

Expand Down Expand Up @@ -29,8 +29,6 @@ dependencies {

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
common(project(path: ":fabric-like", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":fabric-like", configuration: "transformProductionFabric")) { transitive false }
}

if (System.getenv("CURSEFORGE_API_KEY") != null && System.getenv("MODRINTH_API_KEY") != null) {
Expand All @@ -40,7 +38,7 @@ if (System.getenv("CURSEFORGE_API_KEY") != null && System.getenv("MODRINTH_API_K
changelog = rootProject.file("CHANGELOG.md").text
releaseType = project.version.contains("beta") ? "beta" : "release"
gameVersions = [project.minecraft_version]
gameLoaders = ["fabric"]
gameLoaders = ["fabric", "quilt"]

mainPublication tasks.remapJar

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.github.jamalam360.rightclickharvest.fabric;

import io.github.jamalam360.rightclickharvest.fabriclike.RightClickHarvestFabricLike;
import io.github.jamalam360.rightclickharvest.RightClickHarvest;
import net.fabricmc.api.ModInitializer;

public class RightClickHarvestFabric implements ModInitializer {

@Override
public void onInitialize() {
RightClickHarvestFabricLike.init();
}
@Override
public void onInitialize() {
RightClickHarvest.init();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.jamalam360.rightclickharvest.fabriclike;
package io.github.jamalam360.rightclickharvest.fabric;

import io.github.jamalam360.rightclickharvest.HarvestContext;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;

public class RightClickHarvestFabricLikeCallbacks {
public class RightClickHarvestFabricCallbacks {
public static final Event<AfterHarvestCallback> AFTER_HARVEST = EventFactory.createArrayBacked(AfterHarvestCallback.class, (callbacks -> (ctx) -> {
for (AfterHarvestCallback callback : callbacks) {
callback.afterHarvest(ctx);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package io.github.jamalam360.rightclickharvest.fabric;

import io.github.jamalam360.rightclickharvest.HarvestContext;
import io.github.jamalam360.rightclickharvest.fabriclike.RightClickHarvestFabricLikeCallbacks;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

public class RightClickHarvestPlatformImpl {
public static void postAfterHarvestEvent(HarvestContext context) {
RightClickHarvestFabricLikeCallbacks.AFTER_HARVEST.invoker().afterHarvest(context);
}

public static boolean postBreakEvent(Level level, BlockPos pos, BlockState state, Player player) {
return !PlayerBlockBreakEvents.BEFORE.invoker().beforeBlockBreak(level, player, pos, state, level.getBlockEntity(pos));
}
public static void postAfterHarvestEvent(HarvestContext context) {
RightClickHarvestFabricCallbacks.AFTER_HARVEST.invoker().afterHarvest(context);
}

public static boolean postPlaceEvent(Level level, BlockPos pos, Player player) {
// no-op, fabric doesn't have a specific place block event.
return false;
}
public static boolean postBreakEvent(Level level, BlockPos pos, BlockState state, Player player) {
return !PlayerBlockBreakEvents.BEFORE.invoker().beforeBlockBreak(level, player, pos, state, level.getBlockEntity(pos));
}

public static boolean postPlaceEvent(Level level, BlockPos pos, Player player) {
// no-op, fabric doesn't have a specific place block event.
return false;
}
}
Loading

0 comments on commit 9568afb

Please sign in to comment.