Skip to content

Commit

Permalink
core: fix usages of @at("INVOKE")
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Sanders <[email protected]>
  • Loading branch information
Zidane committed Sep 12, 2021
1 parent ece3eb6 commit cc3c29f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,31 @@
*/
package org.spongepowered.common.mixin.core.world.entity.monster;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion.BlockInteraction;
import org.spongepowered.api.entity.living.monster.Creeper;
import org.spongepowered.api.world.server.ServerLocation;
import org.spongepowered.api.world.explosion.Explosion;
import org.spongepowered.api.world.server.ServerLocation;
import org.spongepowered.api.world.server.ServerWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.CallbackInfo;
import org.spongepowered.common.bridge.world.entity.GrieferBridge;
import org.spongepowered.common.bridge.explosives.ExplosiveBridge;
import org.spongepowered.common.bridge.explosives.FusedExplosiveBridge;
import org.spongepowered.common.bridge.world.entity.GrieferBridge;
import org.spongepowered.common.event.SpongeCommonEventFactory;
import org.spongepowered.common.util.Constants;

import javax.annotation.Nullable;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion.BlockInteraction;
import java.util.Optional;
import java.util.function.Consumer;

import javax.annotation.Nullable;

@Mixin(net.minecraft.world.entity.monster.Creeper.class)
public abstract class CreeperMixin extends MonsterMixin implements FusedExplosiveBridge, ExplosiveBridge {

Expand All @@ -58,7 +59,6 @@ public abstract class CreeperMixin extends MonsterMixin implements FusedExplosiv

@Shadow public abstract void shadow$ignite();
@Shadow public abstract int shadow$getSwellDir();
@Shadow public abstract void shadow$setSwellDir(int state);
// @formatter:on

private int impl$fuseDuration = Constants.Entity.Creeper.FUSE_DURATION;
Expand Down Expand Up @@ -103,12 +103,12 @@ public abstract class CreeperMixin extends MonsterMixin implements FusedExplosiv
this.maxSwell = fuseTicks;
}

@Inject(method = "setSwellDir", at = @At("INVOKE"), cancellable = true)
private void onStateChange(final int state, final CallbackInfo ci) {
this.bridge$setFuseDuration(this.impl$fuseDuration);
@Inject(method = "setSwellDir", at = @At("HEAD"), cancellable = true)
private void impl$preStateChange(final int state, final CallbackInfo ci) {
if (this.level.isClientSide) {
return;
}
this.bridge$setFuseDuration(this.impl$fuseDuration);

final boolean isPrimed = this.shadow$getSwellDir() == Constants.Entity.Creeper.STATE_PRIMED;

Expand All @@ -122,7 +122,7 @@ private void onStateChange(final int state, final CallbackInfo ci) {
}

@Inject(method = "setSwellDir", at = @At("RETURN"))
private void postStateChange(final int state, final CallbackInfo ci) {
private void impl$postStateChange(final int state, final CallbackInfo ci) {
if (this.level.isClientSide) {
return;
}
Expand Down Expand Up @@ -154,7 +154,7 @@ private void postStateChange(final int state, final CallbackInfo ci) {
}

@Inject(method = "explodeCreeper", at = @At("RETURN"))
private void postExplode(final CallbackInfo ci) {
private void impl$postExplode(final CallbackInfo ci) {
if (this.impl$detonationCancelled) {
this.impl$detonationCancelled = this.dead = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
*/
package org.spongepowered.common.mixin.core.world.entity.vehicle;

import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.vehicle.MinecartTNT;
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.entity.vehicle.minecart.TNTMinecart;
import org.spongepowered.api.event.CauseStackManager;
import org.spongepowered.api.event.SpongeEventFactory;
import org.spongepowered.api.event.entity.AttackEntityEvent;
import org.spongepowered.api.world.server.ServerLocation;
import org.spongepowered.api.world.explosion.Explosion;
import org.spongepowered.api.world.server.ServerLocation;
import org.spongepowered.api.world.server.ServerWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -47,13 +50,11 @@
import org.spongepowered.common.event.tracking.PhaseTracker;
import org.spongepowered.common.util.Constants;

import javax.annotation.Nullable;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.vehicle.MinecartTNT;
import java.util.ArrayList;
import java.util.Optional;

import javax.annotation.Nullable;

@Mixin(MinecartTNT.class)
public abstract class MinecartTNTMixin extends AbstractMinecartMixin implements FusedExplosiveBridge, ExplosiveBridge {

Expand All @@ -72,8 +73,7 @@ public abstract class MinecartTNTMixin extends AbstractMinecartMixin implements
}

@Override
public void bridge$setExplosionRadius(final @Nullable
Integer radius) {
public void bridge$setExplosionRadius(final @Nullable Integer radius) {
this.impl$explosionRadius = radius;
}

Expand All @@ -98,14 +98,12 @@ public abstract class MinecartTNTMixin extends AbstractMinecartMixin implements
}


@Inject(method = "hurt",
at = @At("INVOKE"))
@Inject(method = "hurt", at = @At("HEAD"))
private void impl$onAttackSetPrimeCause(final DamageSource damageSource, final float amount, final CallbackInfoReturnable<Boolean> ci) {
this.impl$primeCause = damageSource;
}

@Inject(method = "activateMinecart(IIIZ)V",
at = @At("INVOKE"))
@Inject(method = "activateMinecart(IIIZ)V", at = @At("HEAD"))
private void impl$onActivateSetPrimeCauseNotifier(final int x, final int y, final int z, final boolean receivingPower, final CallbackInfo ci) {
if (((LevelBridge) this.level).bridge$isFake()) {
return;
Expand All @@ -115,19 +113,16 @@ public abstract class MinecartTNTMixin extends AbstractMinecartMixin implements
}
}

@Inject(method = "primeFuse",
at = @At("INVOKE"),
cancellable = true)
@Inject(method = "primeFuse", at = @At("HEAD"), cancellable = true)
private void impl$preIgnite(final CallbackInfo ci) {
if (!this.bridge$shouldPrime()) {
this.bridge$setFuseTicksRemaining(-1);
ci.cancel();
}
}

@Inject(method = "primeFuse",
at = @At("RETURN"))
private void impl$postSpongeIgnite(final CallbackInfo ci) {
@Inject(method = "primeFuse", at = @At("RETURN"))
private void impl$postIgnite(final CallbackInfo ci) {
this.bridge$setFuseTicksRemaining(this.impl$fuseDuration);
if (this.impl$primeCause != null) {
PhaseTracker.getCauseStackManager().pushCause(this.impl$primeCause);
Expand Down Expand Up @@ -161,17 +156,14 @@ public abstract class MinecartTNTMixin extends AbstractMinecartMixin implements
);
}

@Inject(method = "explode",
at = @At("RETURN"))
@Inject(method = "explode", at = @At("RETURN"))
private void impL$postExplode(final CallbackInfo ci) {
if (this.impl$detonationCancelled) {
this.impl$detonationCancelled = this.removed = false;
}
}

@Inject(method = "hurt",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/entity/vehicle/MinecartTNT;explode(D)V"), cancellable = true)
@Inject(method = "hurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/vehicle/MinecartTNT;explode(D)V"), cancellable = true)
private void impl$postOnAttackEntityFrom(final DamageSource source, final float amount, final CallbackInfoReturnable<Boolean> cir) {
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(source);
Expand Down

0 comments on commit cc3c29f

Please sign in to comment.