2021-02-14 21:15:30 +01:00
|
|
|
package com.minelittlepony.unicopia.item;
|
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.entity.IItemEntity;
|
2022-09-26 21:11:28 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.Living;
|
2022-09-14 11:53:31 +02:00
|
|
|
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
|
2021-02-14 21:15:30 +01:00
|
|
|
|
2021-08-25 14:22:11 +02:00
|
|
|
import net.minecraft.block.Block;
|
2021-02-14 21:15:30 +01:00
|
|
|
import net.minecraft.block.Blocks;
|
2021-08-25 21:43:38 +02:00
|
|
|
import net.minecraft.enchantment.EnchantmentHelper;
|
|
|
|
import net.minecraft.enchantment.Enchantments;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityGroup;
|
2021-02-14 22:13:36 +01:00
|
|
|
import net.minecraft.entity.EquipmentSlot;
|
2022-03-27 16:02:14 +02:00
|
|
|
import net.minecraft.entity.FlyingItemEntity;
|
2021-08-25 21:43:38 +02:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
2021-02-14 22:13:36 +01:00
|
|
|
import net.minecraft.entity.attribute.EntityAttributeInstance;
|
|
|
|
import net.minecraft.entity.attribute.EntityAttributes;
|
2021-08-25 21:43:38 +02:00
|
|
|
import net.minecraft.entity.damage.DamageSource;
|
2021-02-14 21:15:30 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2021-08-25 21:43:38 +02:00
|
|
|
import net.minecraft.particle.ParticleTypes;
|
|
|
|
import net.minecraft.server.world.ServerWorld;
|
2021-02-14 21:15:30 +01:00
|
|
|
import net.minecraft.text.Text;
|
|
|
|
import net.minecraft.util.ActionResult;
|
2022-12-04 23:46:45 +01:00
|
|
|
import net.minecraft.util.hit.EntityHitResult;
|
2021-08-25 21:43:38 +02:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2021-08-25 14:22:11 +02:00
|
|
|
import net.minecraft.world.WorldEvents;
|
2021-02-14 21:15:30 +01:00
|
|
|
|
|
|
|
public class FilledJarItem extends JarItem implements ChameleonItem {
|
|
|
|
|
|
|
|
public FilledJarItem(Settings settings) {
|
|
|
|
super(settings, false, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Text getName(ItemStack stack) {
|
2022-06-25 00:19:55 +02:00
|
|
|
return hasAppearance(stack) ? Text.translatable(getTranslationKey(stack), getAppearanceStack(stack).getName()) : UItems.EMPTY_JAR.getName(UItems.EMPTY_JAR.getDefaultStack());
|
2021-02-14 21:15:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isFullyDisguised() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ActionResult onGroundTick(IItemEntity item) {
|
|
|
|
return ActionResult.PASS;
|
|
|
|
}
|
|
|
|
|
2021-02-14 22:13:36 +01:00
|
|
|
@Override
|
|
|
|
protected float getProjectileDamage(ItemStack stack) {
|
2021-08-25 21:43:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-12-04 23:46:45 +01:00
|
|
|
public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) {
|
|
|
|
super.onImpact(projectile, hit);
|
|
|
|
|
|
|
|
Entity entity = hit.getEntity();
|
2021-08-25 21:43:38 +02:00
|
|
|
|
2022-03-27 16:02:14 +02:00
|
|
|
if (!entity.isAttackable() || !(projectile instanceof FlyingItemEntity)) {
|
2021-08-25 21:43:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-27 16:02:14 +02:00
|
|
|
ItemStack stack = getAppearanceStack(((FlyingItemEntity)projectile).getStack());
|
2021-08-25 21:43:38 +02:00
|
|
|
|
|
|
|
boolean onFire = false;
|
|
|
|
|
|
|
|
float prevHealth = 0.0F;
|
|
|
|
int fire = EnchantmentHelper.getLevel(Enchantments.FIRE_ASPECT, stack);
|
|
|
|
|
|
|
|
if (entity instanceof LivingEntity) {
|
|
|
|
prevHealth = ((LivingEntity)entity).getHealth();
|
|
|
|
|
|
|
|
if (fire > 0 && !entity.isOnFire()) {
|
|
|
|
onFire = true;
|
|
|
|
entity.setOnFireFor(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float damage = EnchantmentHelper.getAttackDamage(stack, entity instanceof LivingEntity ? ((LivingEntity)entity).getGroup() : EntityGroup.DEFAULT);
|
2021-02-14 22:13:36 +01:00
|
|
|
|
|
|
|
EntityAttributeInstance instance = new EntityAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE, i -> {});
|
|
|
|
|
|
|
|
stack.getAttributeModifiers(EquipmentSlot.MAINHAND).get(EntityAttributes.GENERIC_ATTACK_DAMAGE).forEach(modifier -> {
|
|
|
|
instance.addTemporaryModifier(modifier);
|
|
|
|
});
|
|
|
|
|
2021-08-25 21:43:38 +02:00
|
|
|
damage += instance.getValue();
|
|
|
|
|
|
|
|
if (entity.damage(DamageSource.thrownProjectile(projectile, projectile.getOwner()), damage)) {
|
|
|
|
|
|
|
|
int knockback = EnchantmentHelper.getLevel(Enchantments.KNOCKBACK, stack);
|
|
|
|
|
|
|
|
final float toRadians = (float)Math.PI / 180F;
|
|
|
|
|
2022-09-26 21:11:28 +02:00
|
|
|
if (entity instanceof LivingEntity living) {
|
|
|
|
living.takeKnockback(
|
2021-08-25 21:43:38 +02:00
|
|
|
knockback / 2F,
|
|
|
|
MathHelper.sin(projectile.getYaw() * toRadians),
|
|
|
|
-MathHelper.cos(projectile.getYaw() * toRadians)
|
|
|
|
);
|
2022-09-26 21:11:28 +02:00
|
|
|
Living.updateVelocity(living);
|
2021-08-25 21:43:38 +02:00
|
|
|
|
|
|
|
if (fire > 0) {
|
|
|
|
entity.setOnFireFor(fire * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
float healthDiff = prevHealth - ((LivingEntity)entity).getHealth();
|
|
|
|
|
|
|
|
if (projectile.world instanceof ServerWorld && healthDiff > 2) {
|
|
|
|
((ServerWorld)projectile.world).spawnParticles(ParticleTypes.DAMAGE_INDICATOR, entity.getX(), entity.getBodyY(0.5D), entity.getZ(), (int)(healthDiff / 2F), 0.1, 0, 0.1, 0.2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
entity.addVelocity(
|
|
|
|
-MathHelper.sin(projectile.getYaw() * toRadians) * knockback / 2F, 0.1D,
|
|
|
|
MathHelper.cos(projectile.getYaw() * toRadians) * knockback / 2F
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (onFire) {
|
|
|
|
entity.setOnFire(false);
|
|
|
|
}
|
|
|
|
}
|
2021-02-14 22:13:36 +01:00
|
|
|
}
|
|
|
|
|
2021-02-14 21:15:30 +01:00
|
|
|
@Override
|
2022-12-04 23:46:45 +01:00
|
|
|
public void onImpact(MagicProjectileEntity projectile) {
|
2022-09-14 11:53:31 +02:00
|
|
|
ItemStack stack = getAppearanceStack(projectile.getStack());
|
2021-02-14 22:13:36 +01:00
|
|
|
stack.damage(1, projectile.world.random, null);
|
|
|
|
projectile.dropStack(stack);
|
2021-08-25 14:22:11 +02:00
|
|
|
projectile.world.syncWorldEvent(WorldEvents.BLOCK_BROKEN, projectile.getBlockPos(), Block.getRawIdFromState(Blocks.GLASS.getDefaultState()));
|
2021-02-14 21:15:30 +01:00
|
|
|
}
|
2021-08-24 22:33:11 +02:00
|
|
|
|
|
|
|
public ItemStack withContents(ItemStack contents) {
|
|
|
|
return setAppearance(getDefaultStack(), contents);
|
|
|
|
}
|
2021-02-14 21:15:30 +01:00
|
|
|
}
|