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 245eba7 commit 359ccc9
Show file tree
Hide file tree
Showing 6 changed files with 85 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
mod_version = 1.0.0.1
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
mod_version = 1.0.0.1
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.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 implements FireTyped {
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);
}

/**
* Injects at the start of the method {@link Player#getHurtSound(DamageSource)}.
* <p>
Expand All @@ -30,4 +47,27 @@ 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 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.
*/
@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;
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 359ccc9

Please sign in to comment.