Skip to content

Commit

Permalink
Replaced legacy javascript asm with mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Nov 24, 2023
1 parent b30fcc6 commit 0fa9926
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 106 deletions.
24 changes: 24 additions & 0 deletions src/main/java/toughasnails/mixin/MixinFoodData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright 2023, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package toughasnails.mixin;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import toughasnails.thirst.ThirstHooks;

@Mixin(FoodData.class)
public abstract class MixinFoodData
{
@Inject(method="tick", at=@At(value="HEAD"), cancellable = true)
public void onTick(Player player, CallbackInfo ci)
{
ThirstHooks.doFoodDataTick((FoodData)(Object)this, player);
ci.cancel();
}
}
47 changes: 47 additions & 0 deletions src/main/java/toughasnails/mixin/MixinPlayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright 2023, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package toughasnails.mixin;

import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Abilities;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodData;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Final;
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.callback.CallbackInfo;
import toughasnails.thirst.ThirstHooks;

@Mixin(Player.class)
public abstract class MixinPlayer extends LivingEntity
{
@Shadow
protected FoodData foodData = new FoodData();

@Shadow
@Final
private Abilities abilities;

private MixinPlayer(EntityType<? extends LivingEntity> type, Level level)
{
super(type, level);
}

@Inject(method="causeFoodExhaustion", at=@At(value="HEAD"))
public void onCauseFoodExhaustion(float exhaustion, CallbackInfo ci)
{
if (!this.abilities.invulnerable)
{
if (!this.level().isClientSide)
{
ThirstHooks.onCauseFoodExhaustion((Player)(Object)this, exhaustion);
}
}
}
}
3 changes: 0 additions & 3 deletions src/main/resources/META-INF/coremods.json

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/resources/toughasnails.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"compatibilityLevel": "JAVA_17",
"refmap": "toughasnails.refmap.json",
"mixins": [
"MixinFoodData",
"MixinPlayer"
],
"client": [
"client.MixinGui",
Expand Down
103 changes: 0 additions & 103 deletions src/main/resources/transformers/tan.js

This file was deleted.

0 comments on commit 0fa9926

Please sign in to comment.