Skip to content

Commit

Permalink
Fixed Fabric crash and possibly Forge too.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystal-Spider committed Sep 1, 2022
1 parent 4dfc6b3 commit faf966e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 42 deletions.
2 changes: 1 addition & 1 deletion fabric/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ org.gradle.daemon = false

# Mod Properties
mod_title = Soul fire'd
mod_version = 1.0.0.1
mod_version = 1.0.0.2
author = Crystal Spider
group = crystalspider
modid = soulfired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,24 @@
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import crystalspider.soulfired.api.FireManager;
import crystalspider.soulfired.api.type.FireTyped;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundEvent;
import net.minecraft.world.World;

/**
* Injects into {@link PlayerEntity} to alter Fire behavior for consistency.
*/
@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin extends LivingEntity implements FireTyped {
/**
* Useless constructor required by the super class to make the compiler happy.
*
* @param entityType
* @param world
*/
protected PlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World world) {
super(entityType, world);
}

public abstract class PlayerEntityMixin implements FireTyped {
/**
* Injects at the start of the method {@link PlayerEntity#getHurtSound(DamageSource)}.
* <p>
Expand All @@ -49,18 +37,18 @@ private void onGetHurtSound(DamageSource damageSource, CallbackInfoReturnable<So
}

/**
* Modifies the assignment value returned by {@link EnchantmentHelper#getFireAspect(LivingEntity)} in the method {@link PlayerEntity#attack(Entity)}.
* Redirects the call to the method {@link EnchantmentHelper#getFireAspect(LivingEntity)} in the method {@link PlayerEntity#attack(Entity)}.
* <p>
* Returns the proper Fire Aspect level taking into account all possible Fire Aspect enchantments.
*
* @param level level the basic Fire Aspect enchantment is at.
* @param player
*/
@ModifyVariable(method = "attack", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/enchantment/EnchantmentHelper;getFireAspect(Lnet/minecraft/entity/LivingEntity;)I"))
private int onAttack(int level) {
int fireAspectLevel = level;
@Redirect(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/enchantment/EnchantmentHelper;getFireAspect(Lnet/minecraft/entity/LivingEntity;)I"))
private int onAttack(LivingEntity player) {
int fireAspectLevel = EnchantmentHelper.getFireAspect(player);
if (fireAspectLevel <= 0) {
for (Enchantment fireAspect : FireManager.getFireAspects()) {
int enchantmentLevel = EnchantmentHelper.getEquipmentLevel(fireAspect, this);
int enchantmentLevel = EnchantmentHelper.getEquipmentLevel(fireAspect, player);
if (enchantmentLevel > 0) {
fireAspectLevel = enchantmentLevel;
break;
Expand Down
2 changes: 1 addition & 1 deletion forge/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ org.gradle.daemon = false

# Mod Properties
mod_title = Soul fire'd
mod_version = 1.0.0.1
mod_version = 1.0.0.2
author = Crystal Spider
group = crystalspider
modid = soulfired
Expand Down
28 changes: 8 additions & 20 deletions forge/src/main/java/crystalspider/soulfired/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,24 @@
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import crystalspider.soulfired.api.FireManager;
import crystalspider.soulfired.api.type.FireTyped;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;

/**
* Injects into {@link Player} to alter Fire behavior for consistency.
*/
@Mixin(Player.class)
public abstract class PlayerMixin extends LivingEntity implements FireTyped {
/**
* Useless constructor required by the super class to make the compiler happy.
*
* @param entityType
* @param world
*/
private PlayerMixin(EntityType<? extends LivingEntity> entityType, Level world) {
super(entityType, world);
}

public abstract class PlayerMixin implements FireTyped {
/**
* Injects at the start of the method {@link Player#getHurtSound(DamageSource)}.
* <p>
Expand All @@ -49,18 +37,18 @@ private void onGetHurtSound(DamageSource damageSource, CallbackInfoReturnable<So
}

/**
* Modifies the assignment value returned by {@link EnchantmentHelper#getFireAspect(LivingEntity)} in the method {@link Player#attack(Entity)}.
* Redirects the call to the method {@link EnchantmentHelper#getFireAspect(LivingEntity)} in the method {@link Player#attack(Entity)}.
* <p>
* Returns the proper Fire Aspect level taking into account all possible Fire Aspect enchantments.
*
* @param level level the basic Fire Aspect enchantment is at.
* @param player
*/
@ModifyVariable(method = "attack", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/item/enchantment/EnchantmentHelper;getFireAspect(Lnet/minecraft/world/entity/LivingEntity;)I"))
private int onAttack(int level) {
int fireAspectLevel = level;
@Redirect(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentHelper;getFireAspect(Lnet/minecraft/world/entity/LivingEntity;)I"))
private int onAttack(LivingEntity player) {
int fireAspectLevel = EnchantmentHelper.getFireAspect(player);
if (fireAspectLevel <= 0) {
for (Enchantment fireAspect : FireManager.getFireAspects()) {
int enchantmentLevel = EnchantmentHelper.getEnchantmentLevel(fireAspect, this);
int enchantmentLevel = EnchantmentHelper.getEnchantmentLevel(fireAspect, player);
if (enchantmentLevel > 0) {
fireAspectLevel = enchantmentLevel;
break;
Expand Down

0 comments on commit faf966e

Please sign in to comment.