Skip to content

Commit

Permalink
Bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystal-Spider committed Aug 31, 2022
1 parent 975e950 commit 8154c46
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 6 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.0-final
mod_version = 1.0.0.1-final
author = Crystal Spider
group = crystalspider
modid = soulfired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private boolean redirectDamage(Entity caller, DamageSource damageSource, float d
*/
@Inject(method = "setFireTicks", at = @At(value = "HEAD"))
private void onSetFireTicks(int ticks, CallbackInfo ci) {
if (!world.isClient && (ticks <= 0 || ticks >= getFireTicks())) {
if (!world.isClient && ticks >= getFireTicks()) {
setFireId(FireManager.BASE_FIRE_ID);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,36 @@
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.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 implements FireTyped {
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);
}

/**
* Injects at the start of the method {@link PlayerEntity#getHurtSound(DamageSource)}.
* <p>
Expand All @@ -30,4 +47,26 @@ private void onGetHurtSound(DamageSource damageSource, CallbackInfoReturnable<So
cir.setReturnValue(FireManager.getHurtSound(getFireId()));
}
}

/**
* Modifies the assignment value returned by {@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.
*/
@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;
if (fireAspectLevel <= 0) {
for (Enchantment fireAspect : FireManager.getFireAspects()) {
int enchantmentLevel = EnchantmentHelper.getEquipmentLevel(fireAspect, this);
if (enchantmentLevel > 0) {
fireAspectLevel = enchantmentLevel;
break;
}
}
}
return fireAspectLevel;
}
}
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.0-final
mod_version = 1.0.0.1-final
author = Crystal Spider
group = crystalspider
modid = soulfired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private boolean redirectHurt(Entity caller, DamageSource damageSource, float dam
*/
@Inject(method = "setRemainingFireTicks", at = @At(value = "HEAD"))
private void onSetRemainingFireTicks(int ticks, CallbackInfo ci) {
if (!level.isClientSide && (ticks <= 0 || ticks >= getRemainingFireTicks())) {
if (!level.isClientSide && ticks >= getRemainingFireTicks()) {
setFireId(FireManager.BASE_FIRE_ID);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,36 @@
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.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.player.PlayerEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.SoundEvent;
import net.minecraft.world.World;

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

/**
* Injects at the start of the method {@link PlayerEntity#getHurtSound(DamageSource)}.
* <p>
Expand All @@ -30,4 +47,26 @@ private void onGetHurtSound(DamageSource damageSource, CallbackInfoReturnable<So
cir.setReturnValue(FireManager.getHurtSound(getFireId()));
}
}

/**
* Modifies the assignment value returned by {@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.
*/
@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;
if (fireAspectLevel <= 0) {
for (Enchantment fireAspect : FireManager.getFireAspects()) {
int enchantmentLevel = EnchantmentHelper.getEnchantmentLevel(fireAspect, this);
if (enchantmentLevel > 0) {
fireAspectLevel = enchantmentLevel;
break;
}
}
}
return fireAspectLevel;
}
}

0 comments on commit 8154c46

Please sign in to comment.