generated from TropheusJ/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...in/java/io/github/fabricators_of_create/porting_lib/mixin/common/StartAttackingMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.github.fabricators_of_create.porting_lib.mixin.common; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.function.Predicate; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.mojang.datafixers.kinds.Const; | ||
import com.mojang.datafixers.kinds.OptionalBox; | ||
import com.mojang.datafixers.util.Unit; | ||
|
||
import io.github.fabricators_of_create.porting_lib.entity.events.LivingEntityEvents.ChangeTarget.ChangeTargetEvent; | ||
import io.github.fabricators_of_create.porting_lib.entity.events.LivingEntityEvents.ChangeTarget.ChangeTargetEvent.LivingTargetType; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.Mob; | ||
import net.minecraft.world.entity.ai.behavior.StartAttacking; | ||
import net.minecraft.world.entity.ai.behavior.declarative.MemoryAccessor; | ||
|
||
@Mixin(StartAttacking.class) | ||
public class StartAttackingMixin { | ||
@Unique private static ChangeTargetEvent port_lib$changeTargetEvent; | ||
|
||
@Inject( | ||
method = "method_47123(Ljava/util/function/Predicate;Ljava/util/function/Function;Lnet/minecraft/world/entity/ai/behavior/declarative/MemoryAccessor;Lnet/minecraft/world/entity/ai/behavior/declarative/MemoryAccessor;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/Mob;J)Z", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/entity/ai/behavior/declarative/MemoryAccessor;set(Ljava/lang/Object;)V" | ||
), | ||
cancellable = true | ||
) | ||
private static <E extends Mob> void port_lib$onChangeTarget(Predicate<E> predicate, Function<E, Optional<? extends LivingEntity>> function, MemoryAccessor<Const.Mu<Unit>, LivingEntity> memoryAccessor, MemoryAccessor<OptionalBox.Mu, Long> memoryAccessor2, ServerLevel serverLevel, Mob mob, long l, CallbackInfoReturnable<Boolean> cir, @Local LivingEntity livingEntity) { | ||
port_lib$changeTargetEvent = new ChangeTargetEvent(mob, livingEntity, LivingTargetType.BEHAVIOR_TARGET); | ||
port_lib$changeTargetEvent.sendEvent(); | ||
|
||
if (port_lib$changeTargetEvent.isCanceled()) | ||
cir.setReturnValue(false); | ||
} | ||
|
||
@WrapOperation( | ||
method = "method_47123(Ljava/util/function/Predicate;Ljava/util/function/Function;Lnet/minecraft/world/entity/ai/behavior/declarative/MemoryAccessor;Lnet/minecraft/world/entity/ai/behavior/declarative/MemoryAccessor;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/Mob;J)Z", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/entity/ai/behavior/declarative/MemoryAccessor;set(Ljava/lang/Object;)V" | ||
) | ||
) | ||
private static void port_lib$wrapToChangeTarget(MemoryAccessor<Const.Mu<Unit>, LivingEntity> instance, Object object, Operation<Void> original) { | ||
original.call(instance, port_lib$changeTargetEvent.getNewTarget()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 25 additions & 4 deletions
29
...c/main/java/io/github/fabricators_of_create/porting_lib/entity/mixin/common/MobMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters