Skip to content

Commit

Permalink
Fix runtime error on NeoForge.
Browse files Browse the repository at this point in the history
Signed-off-by: 秋雨落 <[email protected]>
  • Loading branch information
qyl27 committed Aug 20, 2024
1 parent 1a22cd0 commit c1c0349
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(CropBlock.class)
public abstract class CropBlockMixin extends BlockMixin {
Expand All @@ -37,23 +32,4 @@ public abstract class CropBlockMixin extends BlockMixin {
public boolean arclight$blockGrowTick(ServerLevel world, BlockPos pos, BlockState newState, int flags) {
return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags);
}

@Inject(method = "getGrowthSpeed", cancellable = true, at = @At("RETURN"))
private static void arclight$spigotModifier(Block block, BlockGetter blockGetter, BlockPos pos, CallbackInfoReturnable<Float> cir) {
if (blockGetter instanceof WorldBridge bridge) {
int modifier;
if (block == Blocks.BEETROOTS) {
modifier = bridge.bridge$spigotConfig().beetrootModifier;
} else if (block == Blocks.CARROTS) {
modifier = bridge.bridge$spigotConfig().carrotModifier;
} else if (block == Blocks.POTATOES) {
modifier = bridge.bridge$spigotConfig().potatoModifier;
} else {
modifier = bridge.bridge$spigotConfig().wheatModifier;
}
var f = cir.getReturnValueF();
f /= (100F / modifier);
cir.setReturnValue(f);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.izzel.arclight.common.mixin.core.world.level.block;

import io.izzel.arclight.api.ArclightPlatform;
import io.izzel.arclight.common.bridge.core.world.WorldBridge;
import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.CropBlock;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@OnlyInPlatform(value = {ArclightPlatform.FABRIC, ArclightPlatform.FORGE, ArclightPlatform.VANILLA})
@Mixin(CropBlock.class)
public abstract class CropBlockMixin_NoNeoForge extends BlockMixin {
@Inject(method = "getGrowthSpeed", cancellable = true, at = @At("RETURN"))
private static void arclight$spigotModifier(Block block, BlockGetter blockGetter, BlockPos pos, CallbackInfoReturnable<Float> cir) {
if (blockGetter instanceof WorldBridge bridge) {
int modifier;
if (block == Blocks.BEETROOTS) {
modifier = bridge.bridge$spigotConfig().beetrootModifier;
} else if (block == Blocks.CARROTS) {
modifier = bridge.bridge$spigotConfig().carrotModifier;
} else if (block == Blocks.POTATOES) {
modifier = bridge.bridge$spigotConfig().potatoModifier;
} else {
modifier = bridge.bridge$spigotConfig().wheatModifier;
}
var f = cir.getReturnValueF();
f /= (100F / modifier);
cir.setReturnValue(f);
}
}
}
2 changes: 1 addition & 1 deletion arclight-common/src/main/resources/arclight.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mutable field net/minecraft/world/level/block/entity/trialspawner/TrialSpawner r
mutable field net/minecraft/world/level/block/entity/trialspawner/TrialSpawner ominousConfig Lnet/minecraft/world/level/block/entity/trialspawner/TrialSpawnerConfig;
accessible class net/minecraft/world/level/biome/Biome$ClimateSettings
accessible class net/minecraft/world/item/crafting/Ingredient$ItemValue
accessible field net/minecraft/world/level/biome/Biome climateSettings Lnet/minecraft/world/level/biome/Biome$ClimateSettings;
#accessible field net/minecraft/world/level/biome/Biome climateSettings Lnet/minecraft/world/level/biome/Biome$ClimateSettings;
accessible class net/minecraft/world/entity/monster/Guardian$GuardianAttackGoal
accessible class net/minecraft/world/entity/Interaction$PlayerAction
accessible class net/minecraft/world/item/ItemCooldowns$CooldownInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@
"world.level.block.CoralPlantBlockMixin",
"world.level.block.CoralWallFanBlockMixin",
"world.level.block.CropBlockMixin",
"world.level.block.CropBlockMixin_NoNeoForge",
"world.level.block.DaylightDetectorBlockMixin",
"world.level.block.DecoratedPotBlockMixin",
"world.level.block.DetectorRailBlockMixin",
Expand Down
2 changes: 1 addition & 1 deletion arclight-fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ loom {

arclight {
mcVersion = minecraftVersion
bukkitVersion = 'v1_20_R3'
bukkitVersion = 'v1_21_R1'
accessTransformer = project(':arclight-common').file('bukkit.at')
extraMapping = project(':arclight-common').file('extra_mapping.tsrg')
}
Expand Down
7 changes: 3 additions & 4 deletions arclight-forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ loom {
arclight {
mcVersion = minecraftVersion
forgeVersion = project.ext.forgeVersion
bukkitVersion = 'v1_20_R3'
bukkitVersion = 'v1_21_R1'
accessTransformer = project(':arclight-common').file('bukkit.at')
extraMapping = project(':arclight-common').file('extra_mapping.tsrg')
}
Expand All @@ -53,7 +53,7 @@ dependencies {
implementation 'net.md-5:bungeecord-chat:1.16-R0.4'

implementation("io.izzel.arclight:mixin-tools:$mixinToolsVersion") { transitive = false }
annotationProcessor("io.izzel.arclight:mixin-tools:$mixinToolsVersion") { transitive = false }
// annotationProcessor("io.izzel.arclight:mixin-tools:$mixinToolsVersion") { transitive = false }

shadowCommon("org.spigotmc:spigot-api:$minecraftVersion-R0.1-SNAPSHOT") { transitive = false }
shadowCommon "io.izzel.arclight.generated:spigot:$minecraftVersion:deobf"
Expand Down Expand Up @@ -107,11 +107,10 @@ shadowJar {
remapJar {
inputFile.set shadowJar.archiveFile
dependsOn shadowJar
enabled = false
}

tasks.register('reobfJar', RenameJarTask) {
inputJar.set shadowJar.archiveFile
inputJar.set remapJar.archiveFile
archiveClassifier.set 'reobf'
mappings = arclight.mappingsConfiguration.reobfBukkitPackage
}
Expand Down
2 changes: 1 addition & 1 deletion arclight-neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ loom {

arclight {
mcVersion = minecraftVersion
bukkitVersion = 'v1_20_R3'
bukkitVersion = 'v1_21_R1'
accessTransformer = project(':arclight-common').file('bukkit.at')
extraMapping = project(':arclight-common').file('extra_mapping.tsrg')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Mixin(HarvestFarmland.class)
public abstract class HarvestFarmlandMixin_NeoForge {

@Inject(method = "tick(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/npc/Villager;J)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z"))
@Inject(method = "tick(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/npc/Villager;J)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z"))
private void onSetBlock(ServerLevel worldIn, Villager owner, long gameTime, CallbackInfo ci) {
ArclightCaptures.captureEntityChangeBlock(owner);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package io.izzel.arclight.neoforge.mixin.core.world.level.block;

import io.izzel.arclight.common.bridge.core.world.WorldBridge;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.event.EventHooks;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(CropBlock.class)
public abstract class CropBlockMixin_NeoForge {
Expand All @@ -20,4 +25,23 @@ public abstract class CropBlockMixin_NeoForge {
return !CraftEventFactory.callEntityChangeBlockEvent(entity, pos, state, result);
}

@Inject(method = "getGrowthSpeed", cancellable = true, at = @At("RETURN"))
private static void arclight$spigotModifier(BlockState state, BlockGetter blockGetter, BlockPos pos, CallbackInfoReturnable<Float> cir) {
var block = state.getBlock();
if (blockGetter instanceof WorldBridge bridge) {
int modifier;
if (block == Blocks.BEETROOTS) {
modifier = bridge.bridge$spigotConfig().beetrootModifier;
} else if (block == Blocks.CARROTS) {
modifier = bridge.bridge$spigotConfig().carrotModifier;
} else if (block == Blocks.POTATOES) {
modifier = bridge.bridge$spigotConfig().potatoModifier;
} else {
modifier = bridge.bridge$spigotConfig().wheatModifier;
}
var f = cir.getReturnValueF();
f /= (100F / modifier);
cir.setReturnValue(f);
}
}
}
2 changes: 1 addition & 1 deletion bootstrap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ tasks.register('forgeJar', Jar) {
from sourceSets.main.output
from sourceSets.forge.output
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn(project(':arclight-forge').tasks.shadowJar)
dependsOn(project(':arclight-forge').tasks.reobfJar)
}

tasks.register('neoforgeJar', Jar) {
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ allprojects {
ext {
minecraftVersion = '1.21.1'
supportedPlatforms = ['forge', 'neoforge', 'fabric']
fabricLoaderVersion = '0.16.0'
fabricApiVersion = '0.102.0+1.21.1'
forgeVersion = '52.0.1'
neoForgeVersion = '21.1.2'
fabricLoaderVersion = '0.16.2'
fabricApiVersion = '0.102.1+1.21.1'
forgeVersion = '52.0.4'
neoForgeVersion = '21.1.22'
apiVersion = '1.7.3'
toolsVersion = '1.3.0'
mixinVersion = '0.8.5'
Expand Down

0 comments on commit c1c0349

Please sign in to comment.