Deal damage based on the modifiers of the contained item

This commit is contained in:
Sollace 2021-02-14 23:13:36 +02:00
parent 63f2604e7e
commit ec50aadda3
2 changed files with 24 additions and 2 deletions

View file

@ -5,6 +5,9 @@ import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
import com.minelittlepony.unicopia.util.WorldEvent;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
@ -31,9 +34,24 @@ public class FilledJarItem extends JarItem implements ChameleonItem {
return ActionResult.PASS;
}
@Override
protected float getProjectileDamage(ItemStack stack) {
stack = getAppearanceStack(stack);
EntityAttributeInstance instance = new EntityAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE, i -> {});
stack.getAttributeModifiers(EquipmentSlot.MAINHAND).get(EntityAttributes.GENERIC_ATTACK_DAMAGE).forEach(modifier -> {
instance.addTemporaryModifier(modifier);
});
return (float)instance.getValue();
}
@Override
protected void onImpact(MagicProjectileEntity projectile) {
projectile.dropStack(getAppearanceStack(projectile.getStack()));
ItemStack stack = getAppearanceStack(projectile.getStack());
stack.damage(1, projectile.world.random, null);
projectile.dropStack(stack);
WorldEvent.play(WorldEvent.DESTROY_BLOCK, projectile.world, projectile.getBlockPos(), Blocks.GLASS.getDefaultState());
}
}

View file

@ -51,7 +51,7 @@ public class JarItem extends Item implements ProjectileDelegate, ItemImpl.Tickab
if (!world.isClient) {
MagicProjectileEntity projectile = new MagicProjectileEntity(world, player);
projectile.setItem(stack);
projectile.setThrowDamage(0.5F);
projectile.setThrowDamage(getProjectileDamage(stack));
projectile.setProperties(player, player.pitch, player.yaw, 0, 1.5F, 1);
world.spawnEntity(projectile);
@ -66,6 +66,10 @@ public class JarItem extends Item implements ProjectileDelegate, ItemImpl.Tickab
return TypedActionResult.success(stack, world.isClient());
}
protected float getProjectileDamage(ItemStack stack) {
return 0.5F;
}
@Override
public ActionResult onGroundTick(IItemEntity item) {
ItemEntity entity = item.get().getMaster();