2018-11-06 19:02:56 +01:00
|
|
|
package de.ellpeck.naturesaura.items;
|
|
|
|
|
2021-12-15 16:24:53 +01:00
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
|
|
import com.mojang.math.Vector3f;
|
2018-11-11 22:58:58 +01:00
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
2018-11-21 20:36:55 +01:00
|
|
|
import de.ellpeck.naturesaura.api.render.ITrinketItem;
|
2020-01-26 01:41:49 +01:00
|
|
|
import de.ellpeck.naturesaura.items.tools.ItemArmor;
|
2020-01-22 23:21:52 +01:00
|
|
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
|
|
|
import de.ellpeck.naturesaura.packet.PacketParticles;
|
2020-05-13 15:52:46 +02:00
|
|
|
import de.ellpeck.naturesaura.reg.ModArmorMaterial;
|
2018-11-06 19:02:56 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2021-12-15 16:24:53 +01:00
|
|
|
import net.minecraft.client.renderer.MultiBufferSource;
|
|
|
|
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
2020-01-29 19:04:33 +01:00
|
|
|
import net.minecraft.client.renderer.texture.OverlayTexture;
|
2021-12-15 16:24:53 +01:00
|
|
|
import net.minecraft.sounds.SoundSource;
|
|
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
|
|
import net.minecraft.world.effect.MobEffectInstance;
|
|
|
|
import net.minecraft.world.effect.MobEffects;
|
|
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
import net.minecraft.world.entity.EquipmentSlot;
|
|
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraft.world.level.material.Material;
|
|
|
|
import net.minecraft.world.phys.AABB;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2018-11-06 19:02:56 +01:00
|
|
|
|
2020-01-26 01:41:49 +01:00
|
|
|
public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem {
|
2018-11-06 19:02:56 +01:00
|
|
|
|
2020-01-26 01:41:49 +01:00
|
|
|
public ItemShockwaveCreator() {
|
2021-12-15 16:24:53 +01:00
|
|
|
super("shockwave_creator", new Properties().stacksTo(1));
|
2018-11-06 19:02:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-04 15:40:09 +01:00
|
|
|
public void inventoryTick(ItemStack stack, Level levelIn, Entity entityIn, int itemSlot, boolean isSelected) {
|
2021-12-15 16:24:53 +01:00
|
|
|
if (levelIn.isClientSide || !(entityIn instanceof LivingEntity living))
|
2018-11-06 19:02:56 +01:00
|
|
|
return;
|
2020-09-22 03:17:02 +02:00
|
|
|
if (!living.isOnGround()) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var compound = stack.getOrCreateTag();
|
2018-11-06 19:02:56 +01:00
|
|
|
if (compound.getBoolean("air"))
|
|
|
|
return;
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
compound.putBoolean("air", true);
|
2021-12-15 16:24:53 +01:00
|
|
|
compound.putDouble("x", living.getX());
|
|
|
|
compound.putDouble("y", living.getY());
|
|
|
|
compound.putDouble("z", living.getZ());
|
2018-11-06 19:02:56 +01:00
|
|
|
} else {
|
2019-11-04 19:08:49 +01:00
|
|
|
if (!stack.hasTag())
|
2018-11-06 19:02:56 +01:00
|
|
|
return;
|
2021-12-15 16:30:22 +01:00
|
|
|
var compound = stack.getTag();
|
2018-11-06 19:02:56 +01:00
|
|
|
if (!compound.getBoolean("air"))
|
|
|
|
return;
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
compound.putBoolean("air", false);
|
2018-11-06 19:02:56 +01:00
|
|
|
|
2023-02-21 11:43:10 +01:00
|
|
|
if (!living.isShiftKeyDown())
|
2018-11-06 19:02:56 +01:00
|
|
|
return;
|
2021-12-15 16:24:53 +01:00
|
|
|
if (living.distanceToSqr(compound.getDouble("x"), compound.getDouble("y"), compound.getDouble("z")) > 0.75F)
|
2018-11-06 19:02:56 +01:00
|
|
|
return;
|
2021-12-04 15:40:09 +01:00
|
|
|
if (living instanceof Player && !NaturesAuraAPI.instance().extractAuraFromPlayer((Player) living, 1000, false))
|
2018-11-06 19:02:56 +01:00
|
|
|
return;
|
|
|
|
|
2018-11-06 23:08:42 +01:00
|
|
|
DamageSource source;
|
2021-12-04 15:40:09 +01:00
|
|
|
if (living instanceof Player)
|
2021-12-15 16:24:53 +01:00
|
|
|
source = DamageSource.playerAttack((Player) living);
|
2018-11-06 23:08:42 +01:00
|
|
|
else
|
|
|
|
source = DamageSource.MAGIC;
|
2021-12-15 16:30:22 +01:00
|
|
|
var infusedSet = ItemArmor.isFullSetEquipped(living, ModArmorMaterial.INFUSED);
|
2018-11-06 23:08:42 +01:00
|
|
|
|
2021-12-15 16:30:22 +01:00
|
|
|
var range = 5;
|
|
|
|
var mobs = levelIn.getEntitiesOfClass(LivingEntity.class, new AABB(
|
2021-12-15 16:24:53 +01:00
|
|
|
living.getX() - range, living.getY() - 0.5, living.getZ() - range,
|
|
|
|
living.getX() + range, living.getY() + 0.5, living.getZ() + range));
|
2021-12-15 16:30:22 +01:00
|
|
|
for (var mob : mobs) {
|
2019-11-04 19:08:49 +01:00
|
|
|
if (!mob.isAlive() || mob == living)
|
2018-11-06 19:02:56 +01:00
|
|
|
continue;
|
2021-12-15 16:24:53 +01:00
|
|
|
if (living.distanceToSqr(mob) > range * range)
|
2018-11-06 19:02:56 +01:00
|
|
|
continue;
|
2021-12-04 15:40:09 +01:00
|
|
|
if (living instanceof Player && !NaturesAuraAPI.instance().extractAuraFromPlayer((Player) living, 500, false))
|
2018-11-06 19:02:56 +01:00
|
|
|
break;
|
2021-12-15 16:24:53 +01:00
|
|
|
mob.hurt(source, 4F);
|
2018-12-01 18:56:05 +01:00
|
|
|
|
|
|
|
if (infusedSet)
|
2021-12-15 16:24:53 +01:00
|
|
|
mob.addEffect(new MobEffectInstance(MobEffects.WITHER, 120));
|
2018-11-06 19:02:56 +01:00
|
|
|
}
|
|
|
|
|
2021-12-15 16:30:22 +01:00
|
|
|
var pos = living.blockPosition();
|
|
|
|
var down = pos.below();
|
|
|
|
var downState = levelIn.getBlockState(down);
|
2018-11-06 19:02:56 +01:00
|
|
|
|
|
|
|
if (downState.getMaterial() != Material.AIR) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var type = downState.getBlock().getSoundType(downState, levelIn, down, null);
|
2021-12-15 16:24:53 +01:00
|
|
|
levelIn.playSound(null, pos, type.getBreakSound(), SoundSource.BLOCKS, type.getVolume() * 0.5F, type.getPitch() * 0.8F);
|
2018-11-06 19:02:56 +01:00
|
|
|
}
|
2019-11-04 19:08:49 +01:00
|
|
|
|
2021-12-15 16:24:53 +01:00
|
|
|
PacketHandler.sendToAllAround(levelIn, pos, 32, new PacketParticles((float) living.getX(), (float) living.getY(), (float) living.getZ(), PacketParticles.Type.SHOCKWAVE_CREATOR));
|
2018-11-06 19:02:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2021-12-15 16:24:53 +01:00
|
|
|
public void render(ItemStack stack, Player player, RenderType type, PoseStack matrices, MultiBufferSource buffer, int packedLight, boolean isHolding) {
|
2018-11-21 20:36:55 +01:00
|
|
|
if (type == RenderType.BODY && !isHolding) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var armor = !player.getInventory().armor.get(EquipmentSlot.CHEST.getIndex()).isEmpty();
|
2020-01-29 19:04:33 +01:00
|
|
|
matrices.translate(0, 0.125F, armor ? -0.195F : -0.1475F);
|
|
|
|
matrices.scale(0.3F, 0.3F, 0.3F);
|
2021-12-15 16:24:53 +01:00
|
|
|
matrices.mulPose(Vector3f.XP.rotationDegrees(180));
|
|
|
|
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, packedLight, OverlayTexture.NO_OVERLAY, matrices, buffer, 0);
|
2018-11-06 19:02:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|