Skip to content

Commit

Permalink
Update to 1.20.4, move some redirects to wrapoperation
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Dec 9, 2023
1 parent e7d0733 commit 398c7f3
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 62 deletions.
11 changes: 3 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.1.+'
id 'fabric-loom' version '1.4.+'
id 'maven-publish'
}

Expand All @@ -22,8 +22,6 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

implementation(include(annotationProcessor("com.llamalad7.mixinextras:mixinextras-fabric:${project.mixin_extras_version}")))
}

processResources {
Expand All @@ -37,12 +35,9 @@ processResources {
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
java {
withSourcesJar()
}

jar {
from "LICENSE"
}
Expand Down
12 changes: 5 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

minecraft_version=1.20.2
yarn_mappings=1.20.2+build.1
loader_version=0.14.22
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.0

#Fabric api
fabric_version=0.89.0+1.20.2

mixin_extras_version=0.2.0-beta.9
fabric_version=0.91.1+1.20.4

# Mod Properties
mod_version=0.4.9
mod_version=0.4.10
maven_group=xyz.nucleoid
archives_base_name=stimuli
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-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package xyz.nucleoid.stimuli.mixin.entity;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
Expand Down Expand Up @@ -62,21 +64,21 @@ private void callDeathListener(DamageSource source, CallbackInfo ci) {
}
}

@Redirect(method = "dropLoot", at = @At(value = "INVOKE", target = "Lnet/minecraft/loot/LootTable;generateLoot(Lnet/minecraft/loot/context/LootContextParameterSet;JLjava/util/function/Consumer;)V"))
private void modifyDroppedLoot(LootTable lootTable, LootContextParameterSet parameters, long seed, Consumer<ItemStack> lootConsumer) {
@WrapOperation(method = "dropLoot", at = @At(value = "INVOKE", target = "Lnet/minecraft/loot/LootTable;generateLoot(Lnet/minecraft/loot/context/LootContextParameterSet;JLjava/util/function/Consumer;)V"))
private void modifyDroppedLoot(LootTable instance, LootContextParameterSet parameters, long seed, Consumer<ItemStack> lootConsumer, Operation<Void> original) {
if (this.getWorld().isClient) {
lootTable.generateLoot(parameters, lootConsumer);
original.call(instance, parameters, seed, lootConsumer);
return;
}

try (var invokers = Stimuli.select().forEntity(this)) {
var droppedStacks = lootTable.generateLoot(parameters, seed);
var droppedStacks = instance.generateLoot(parameters, seed);

var result = invokers.get(EntityDropItemsEvent.EVENT)
.onDropItems((LivingEntity) (Object) this, droppedStacks);

if (result.getResult() != ActionResult.FAIL) {
result.getValue().forEach(this::dropStack);
result.getValue().forEach(lootConsumer);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package xyz.nucleoid.stimuli.mixin.entity;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand All @@ -15,15 +18,15 @@

@Mixin(ShearsDispenserBehavior.class)
public class ShearsDispenserBehaviorMixin {
@Redirect(
@WrapOperation(
method = "tryShearEntity",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/Shearable;isShearable()Z"
)
)
private static boolean onEntityShear(Shearable shearable, ServerWorld world, BlockPos pos) {
if (!shearable.isShearable()) {
private static boolean onEntityShear(Shearable shearable, Operation<Boolean> original, @Local BlockPos pos) {
if (!original.call(shearable)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package xyz.nucleoid.stimuli.mixin.world;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContextParameterSet;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import xyz.nucleoid.stimuli.Stimuli;
import xyz.nucleoid.stimuli.event.block.BlockDropItemsEvent;

import java.util.Collections;
import java.util.List;

@Mixin(AbstractBlock.class)
public class AbstractBlockMixin {
@WrapOperation(
method = "onExploded",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/BlockState;getDroppedStacks(Lnet/minecraft/loot/context/LootContextParameterSet$Builder;)Ljava/util/List;"
)
)
private List<ItemStack> stimuli_dropBlock(BlockState state, LootContextParameterSet.Builder builder, Operation<List<ItemStack>> operation,
@Local Explosion explosion, @Local World world) {
var events = Stimuli.select();
final var entity = explosion.getEntity();

var pos = entity != null ? entity.getBlockPos() : BlockPos.ofFloored(explosion.getPosition());
try (var invokers = entity != null ? events.forEntityAt(entity, pos) : events.at(world, pos)) {
var result = invokers.get(BlockDropItemsEvent.EVENT)
.onDropItems(entity, (ServerWorld) world, pos, state, operation.call(state, builder));

if (result.getResult() != ActionResult.FAIL) {
return result.getValue();
} else {
return Collections.emptyList();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.nucleoid.stimuli.mixin.world;

import com.llamalad7.mixinextras.injector.WrapWithCondition;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand All @@ -15,14 +16,15 @@

@Mixin(AbstractBlock.AbstractBlockState.class)
public class AbstractBlockStateMixin {
@Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;randomTick(Lnet/minecraft/block/BlockState;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/random/Random;)V"))
private void applyBlockRandomTickEvent(Block block, BlockState state, ServerWorld world, BlockPos pos, net.minecraft.util.math.random.Random random) {
@WrapWithCondition(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;randomTick(Lnet/minecraft/block/BlockState;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/random/Random;)V"))
private boolean applyBlockRandomTickEvent(Block block, BlockState state, ServerWorld world, BlockPos pos, net.minecraft.util.math.random.Random random) {
try (var invokers = Stimuli.select().at(world, pos)) {
var result = invokers.get(BlockRandomTickEvent.EVENT).onBlockRandomTick(world, pos, state);
if (result == ActionResult.FAIL) {
return;
return false;
}
}

block.randomTick(state, world, pos, random);
}}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package xyz.nucleoid.stimuli.mixin.world;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.pattern.BlockPattern;
import net.minecraft.item.EnderEyeItem;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -14,9 +18,9 @@

@Mixin(EnderEyeItem.class)
public class EnderEyeItemMixin {
@Redirect(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/pattern/BlockPattern;searchAround(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/pattern/BlockPattern$Result;"))
private BlockPattern.Result searchAround(BlockPattern pattern, WorldView patternWorld, BlockPos pos, ItemUsageContext context) {
var patternResult = pattern.searchAround(patternWorld, pos);
@WrapOperation(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/pattern/BlockPattern;searchAround(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/pattern/BlockPattern$Result;"))
private BlockPattern.Result searchAround(BlockPattern instance, WorldView worldView, BlockPos pos, Operation<BlockPattern.Result> original, @Local ItemUsageContext context) {
var patternResult = original.call(instance, worldView, pos);

var world = context.getWorld();
try (var invokers = Stimuli.select().at(world, pos)) {
Expand All @@ -26,6 +30,7 @@ private BlockPattern.Result searchAround(BlockPattern pattern, WorldView pattern
}
}


return patternResult;
}
}
19 changes: 0 additions & 19 deletions src/main/java/xyz/nucleoid/stimuli/mixin/world/ExplosionMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,4 @@ private void affectWorld(boolean particles, CallbackInfo ci) {
}
}
}

@Redirect(method = "affectWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getDroppedStacks(Lnet/minecraft/loot/context/LootContextParameterSet$Builder;)Ljava/util/List;"))
private List<ItemStack> stimuli_dropBlock(BlockState state, LootContextParameterSet.Builder builder) {
var stacks = state.getDroppedStacks(builder);

var events = Stimuli.select();

var pos = this.entity != null ? this.entity.getBlockPos() : BlockPos.ofFloored(this.x, this.y, this.z);
try (var invokers = this.entity != null ? events.forEntityAt(this.entity, pos) : events.at(world, pos)) {
var result = invokers.get(BlockDropItemsEvent.EVENT)
.onDropItems(entity, (ServerWorld) world, pos, state, stacks);

if (result.getResult() != ActionResult.FAIL) {
return result.getValue();
} else {
return Collections.emptyList();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package xyz.nucleoid.stimuli.mixin.world;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.BlockState;
import net.minecraft.block.FireBlock;
import net.minecraft.server.world.ServerWorld;
Expand All @@ -15,8 +18,8 @@

@Mixin(FireBlock.class)
public class FireBlockMixin {
@Redirect(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameRules;getBoolean(Lnet/minecraft/world/GameRules$Key;)Z"))
private boolean test(GameRules gameRules, GameRules.Key<GameRules.BooleanRule> rule, BlockState state, ServerWorld world, BlockPos pos, Random random) {
@WrapOperation(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameRules;getBoolean(Lnet/minecraft/world/GameRules$Key;)Z"))
private boolean test(GameRules instance, GameRules.Key<GameRules.BooleanRule> rule, Operation<Boolean> original, @Local ServerWorld world, @Local BlockPos pos) {
try (var invokers = Stimuli.select().at(world, pos)) {
var result = invokers.get(FireTickEvent.EVENT).onFireTick(world, pos);
if (result == ActionResult.SUCCESS) {
Expand All @@ -26,6 +29,6 @@ private boolean test(GameRules gameRules, GameRules.Key<GameRules.BooleanRule> r
}
}

return gameRules.getBoolean(GameRules.DO_FIRE_TICK);
return original.call(instance, rule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class FireworkRocketEntityMixin {
@Shadow
private static TrackedData<ItemStack> ITEM;

@Inject(method = "explodeAndRemove", at = @At("HEAD"), cancellable = true)
@Inject(method = "explodeAndRemove", at = @At("HEAD"))
private void explodeAndRemove(CallbackInfo ci) {
var firework = (FireworkRocketEntity) (Object) this;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.nucleoid.stimuli.mixin.world;

import com.llamalad7.mixinextras.injector.WrapWithCondition;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.server.world.ServerWorld;
Expand All @@ -16,17 +17,17 @@

@Mixin(FluidState.class)
public class FluidStateMixin {
@Redirect(method = "onRandomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/fluid/Fluid;onRandomTick(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/fluid/FluidState;Lnet/minecraft/util/math/random/Random;)V"))
private void applyFluidRandomTickEvent(Fluid fluid, World world, BlockPos pos, FluidState state, Random random) {
@WrapWithCondition(method = "onRandomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/fluid/Fluid;onRandomTick(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/fluid/FluidState;Lnet/minecraft/util/math/random/Random;)V"))
private boolean applyFluidRandomTickEvent(Fluid fluid, World world, BlockPos pos, FluidState state, Random random) {
ServerWorld serverWorld = (ServerWorld) world;

try (var invokers = Stimuli.select().at(world, pos)) {
var result = invokers.get(FluidRandomTickEvent.EVENT).onFluidRandomTick(serverWorld, pos, state);
if (result == ActionResult.FAIL) {
return;
return false;
}
}

((FluidAccessor) fluid).callOnRandomTick(world, pos, state, random);
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package xyz.nucleoid.stimuli.mixin.world;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.fluid.FluidState;
Expand Down Expand Up @@ -34,9 +36,9 @@ private void applyEntitySpawnEvent(Entity entity, CallbackInfoReturnable<Boolean
}
}

@Redirect(method = "tickIceAndSnow", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/Biome;canSetSnow(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)Z"))
private boolean applySnowFallEvent(Biome biome, WorldView world, BlockPos pos) {
if (!biome.canSetSnow(world, pos)) {
@WrapOperation(method = "tickIceAndSnow", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/Biome;canSetSnow(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)Z"))
private boolean applySnowFallEvent(Biome instance, WorldView world, BlockPos pos, Operation<Boolean> original) {
if (!original.call(instance, world, pos)) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/stimuli.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"projectile.CrossbowItemMixin",
"projectile.ProjectileEntityMixin",
"world.AbstractBlockStateMixin",
"world.AbstractBlockMixin",
"world.EnderEyeItemMixin",
"world.ExplosionMixin",
"world.FireBlockMixin",
Expand Down

0 comments on commit 398c7f3

Please sign in to comment.