-
Notifications
You must be signed in to change notification settings - Fork 5
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
6 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
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
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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/mlib/gamemodifiers/contexts/OnFishingTimeSet.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,43 @@ | ||
package com.mlib.gamemodifiers.contexts; | ||
|
||
import com.mlib.gamemodifiers.Condition; | ||
import com.mlib.gamemodifiers.Context; | ||
import com.mlib.gamemodifiers.Contexts; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.entity.projectile.FishingHook; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.function.Consumer; | ||
|
||
public class OnFishingTimeSet { | ||
public static Context< Data > listen( Consumer< Data > consumer ) { | ||
return Contexts.get( Data.class ).add( consumer ); | ||
} | ||
|
||
public static Data dispatch( FishingHook hook, int timeUntilLured ) { | ||
return Contexts.get( Data.class ).dispatch( new Data( hook, timeUntilLured ) ); | ||
} | ||
|
||
public static Condition< Data > hasPlayer() { | ||
return new Condition<>( data->data.player != null ); | ||
} | ||
|
||
public static class Data { | ||
public FishingHook hook; | ||
public final int original; | ||
public int ticks; | ||
@Nullable | ||
public Player player; | ||
|
||
public Data( FishingHook hook, int original ) { | ||
this.hook = hook; | ||
this.original = original; | ||
this.ticks = original; | ||
this.player = hook.getPlayerOwner(); | ||
} | ||
|
||
public int getTicks() { | ||
return Math.max( this.ticks, 1 ); | ||
} | ||
} | ||
} |
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,23 @@ | ||
package com.mlib.mixin; | ||
|
||
import com.mlib.ObfuscationGetter; | ||
import com.mlib.gamemodifiers.contexts.OnFishingTimeSet; | ||
import net.minecraft.world.entity.projectile.FishingHook; | ||
import org.objectweb.asm.Opcodes; | ||
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.Redirect; | ||
|
||
@Mixin( FishingHook.class ) | ||
public abstract class MixinFishingHook { | ||
private static final ObfuscationGetter.Field< FishingHook, Integer > TIME_UNTIL_LURED = new ObfuscationGetter.Field<>( FishingHook.class, "f_37090_" ); | ||
|
||
@Shadow( aliases = { "this$0" } ) | ||
@Redirect( method = "catchingFish (Lnet/minecraft/core/BlockPos;)V", at = @At( value = "FIELD", target = "Lnet/minecraft/world/entity/projectile/FishingHook;timeUntilLured:I", opcode = Opcodes.PUTFIELD, ordinal = 3 ) ) | ||
private void catchingFish( FishingHook hook, int timeUntilLured ) { | ||
if( timeUntilLured > 0 ) { | ||
TIME_UNTIL_LURED.set( hook, OnFishingTimeSet.dispatch( hook, timeUntilLured ).getTicks() ); | ||
} | ||
} | ||
} |
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