mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Deal damage based on the modifiers of the contained item
This commit is contained in:
parent
63f2604e7e
commit
ec50aadda3
2 changed files with 24 additions and 2 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue