Skip to content

Commit

Permalink
Fixed ranged item crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz committed Jul 29, 2022
1 parent 1ccab9c commit fd2943b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ repositories {

dependencies {
minecraft 'net.minecraftforge:forge:1.19-41.1.0'
implementation fg.deobf( 'com.mlib:majrusz-library-1.19:2.12.1' )
implementation fg.deobf( 'com.mlib:majrusz-library-1.19:2.13.0' )
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;

import java.util.function.Predicate;
import java.util.function.Supplier;

public class TelekinesisEnchantment extends CustomEnchantment {
Expand Down Expand Up @@ -51,7 +53,7 @@ public Modifier( TelekinesisEnchantment enchantment ) {
OnLootContext onLoot3 = new OnLootContext( data->this.addToInventory( data, data.killer ), LOWEST_PRIORITY );
onLoot3.addCondition( new Condition.IsServer() )
.addCondition( data->data.killer instanceof Player )
.addCondition( data->data.damageSource != null && enchantment.hasEnchantment( IMixinProjectile.getWeaponFromDirectEntity( data.damageSource ) ) );
.addCondition( this.doesProjectileHasEnchantmentPredicate() );

this.addContexts( onLoot, onLoot2, onLoot3 );
}
Expand All @@ -64,5 +66,16 @@ private void addToInventory( OnLootData data, Entity entity ) {
data.level.playSound( null, position.x, position.y, position.z, SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, 0.25f, Random.nextFloat( 0.8f, 1.2f ) );
}
}

private Predicate< OnLootData > doesProjectileHasEnchantmentPredicate() {
return data->{
if( data.damageSource != null ) {
ItemStack weapon = IMixinProjectile.getWeaponFromDirectEntity( data.damageSource );
return weapon != null && this.enchantment.hasEnchantment( weapon );
}

return false;
};
}
}
}

0 comments on commit fd2943b

Please sign in to comment.