Skip to content

Commit

Permalink
Merged 4.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz committed Jun 3, 2023
1 parent 0d1e7eb commit e6597d9
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 6 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ processResources {
filesMatching('META-INF/mods.toml') {
expand project.properties
}
outputs.upToDateWhen { false }
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ versions_minecraft=1.18.2
versions_minecraft_range=[1.18.2,1.19)
versions_forge=40.2.0
versions_forge_range=[40.2.0,)
versions_mod=4.1.0
versions_mod=4.2.0
20 changes: 15 additions & 5 deletions src/main/java/com/mlib/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.level.Level;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.loading.FMLEnvironment;
import net.minecraftforge.fml.util.thread.SidedThreadGroups;
import net.minecraftforge.registries.ForgeRegistries;
Expand Down Expand Up @@ -132,12 +133,21 @@ public static boolean isDevBuild() {

public static void profile( String sectionName, Runnable runnable ) {
ProfilerFiller profiler = getProfiler();
profiler.push( sectionName );
runnable.run();
profiler.pop();
if( profiler != null ) {
profiler.push( sectionName );
runnable.run();
profiler.pop();
} else {
runnable.run();
}
}

public static ProfilerFiller getProfiler() {
return isServerSide() ? ServerLifecycleHooks.getCurrentServer().getProfiler() : Minecraft.getInstance().getProfiler();
@Nullable
private static ProfilerFiller getProfiler() {
return DistExecutor.unsafeRunForDist( ()->()->{
return Minecraft.getInstance() != null ? Minecraft.getInstance().getProfiler() : null;
}, ()->()->{
return ServerLifecycleHooks.getCurrentServer() != null ? ServerLifecycleHooks.getCurrentServer().getProfiler() : null;
} );
}
}
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 );
}
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/mlib/mixin/MixinFishingHook.java
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() );
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.mlib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"mixins": [
"MixinArrow",
"MixinDifficultyInstance",
"MixinFishingHook",
"MixinItemStack",
"MixinLivingEntity",
"MixinLootTableSerializer",
Expand Down

0 comments on commit e6597d9

Please sign in to comment.