2018-11-06 19:02:56 +01:00
|
|
|
package de.ellpeck.naturesaura.items;
|
|
|
|
|
2020-01-29 19:04:33 +01:00
|
|
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
2018-11-06 19:02:56 +01:00
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
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;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
2018-11-06 19:02:56 +01:00
|
|
|
import net.minecraft.block.SoundType;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.client.Minecraft;
|
2020-01-29 19:04:33 +01:00
|
|
|
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|
|
|
import net.minecraft.client.renderer.Vector3f;
|
|
|
|
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
|
|
|
import net.minecraft.client.renderer.texture.OverlayTexture;
|
2018-11-06 19:02:56 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.inventory.EquipmentSlotType;
|
2018-11-06 19:02:56 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
|
|
|
import net.minecraft.potion.EffectInstance;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.potion.Effects;
|
2018-11-06 19:02:56 +01:00
|
|
|
import net.minecraft.util.DamageSource;
|
|
|
|
import net.minecraft.util.SoundCategory;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
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
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
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() {
|
2019-11-04 19:08:49 +01:00
|
|
|
super("shockwave_creator", new Properties().maxStackSize(1).group(NaturesAura.CREATIVE_TAB));
|
2018-11-06 19:02:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-11-04 19:08:49 +01:00
|
|
|
public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
|
2019-10-20 22:30:49 +02:00
|
|
|
if (worldIn.isRemote || !(entityIn instanceof LivingEntity))
|
2018-11-06 19:02:56 +01:00
|
|
|
return;
|
2019-10-20 22:30:49 +02:00
|
|
|
LivingEntity living = (LivingEntity) entityIn;
|
2018-11-06 19:02:56 +01:00
|
|
|
if (!living.onGround) {
|
2019-11-04 19:08:49 +01:00
|
|
|
CompoundNBT 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);
|
2020-01-28 18:08:56 +01:00
|
|
|
compound.putDouble("x", living.getPosX());
|
|
|
|
compound.putDouble("y", living.getPosY());
|
|
|
|
compound.putDouble("z", living.getPosZ());
|
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;
|
2019-11-04 19:08:49 +01:00
|
|
|
CompoundNBT 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
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
if (!living.isShiftKeyDown())
|
2018-11-06 19:02:56 +01:00
|
|
|
return;
|
|
|
|
if (living.getDistanceSq(compound.getDouble("x"), compound.getDouble("y"), compound.getDouble("z")) > 0.75F)
|
|
|
|
return;
|
2019-10-20 22:30:49 +02:00
|
|
|
if (living instanceof PlayerEntity && !NaturesAuraAPI.instance().extractAuraFromPlayer((PlayerEntity) living, 1000, false))
|
2018-11-06 19:02:56 +01:00
|
|
|
return;
|
|
|
|
|
2018-11-06 23:08:42 +01:00
|
|
|
DamageSource source;
|
2019-10-20 22:30:49 +02:00
|
|
|
if (living instanceof PlayerEntity)
|
|
|
|
source = DamageSource.causePlayerDamage((PlayerEntity) living);
|
2018-11-06 23:08:42 +01:00
|
|
|
else
|
|
|
|
source = DamageSource.MAGIC;
|
2020-01-26 01:41:49 +01:00
|
|
|
boolean infusedSet = ItemArmor.isFullSetEquipped(living, 0);
|
2018-11-06 23:08:42 +01:00
|
|
|
|
2018-11-06 19:02:56 +01:00
|
|
|
int range = 5;
|
2019-10-20 22:30:49 +02:00
|
|
|
List<LivingEntity> mobs = worldIn.getEntitiesWithinAABB(LivingEntity.class, new AxisAlignedBB(
|
2020-01-28 18:08:56 +01:00
|
|
|
living.getPosX() - range, living.getPosY() - 0.5, living.getPosZ() - range,
|
|
|
|
living.getPosX() + range, living.getPosY() + 0.5, living.getPosZ() + range));
|
2019-10-20 22:30:49 +02:00
|
|
|
for (LivingEntity mob : mobs) {
|
2019-11-04 19:08:49 +01:00
|
|
|
if (!mob.isAlive() || mob == living)
|
2018-11-06 19:02:56 +01:00
|
|
|
continue;
|
|
|
|
if (living.getDistanceSq(mob) > range * range)
|
|
|
|
continue;
|
2019-10-20 22:30:49 +02:00
|
|
|
if (living instanceof PlayerEntity && !NaturesAuraAPI.instance().extractAuraFromPlayer((PlayerEntity) living, 500, false))
|
2018-11-06 19:02:56 +01:00
|
|
|
break;
|
2018-11-06 23:08:42 +01:00
|
|
|
mob.attackEntityFrom(source, 4F);
|
2018-12-01 18:56:05 +01:00
|
|
|
|
|
|
|
if (infusedSet)
|
2019-10-20 22:30:49 +02:00
|
|
|
mob.addPotionEffect(new EffectInstance(Effects.WITHER, 120));
|
2018-11-06 19:02:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BlockPos pos = living.getPosition();
|
|
|
|
BlockPos down = pos.down();
|
2019-10-20 22:30:49 +02:00
|
|
|
BlockState downState = worldIn.getBlockState(down);
|
2018-11-06 19:02:56 +01:00
|
|
|
|
|
|
|
if (downState.getMaterial() != Material.AIR) {
|
|
|
|
SoundType type = downState.getBlock().getSoundType(downState, worldIn, down, null);
|
|
|
|
worldIn.playSound(null, pos, type.getBreakSound(), SoundCategory.BLOCKS, type.getVolume() * 0.5F, type.getPitch() * 0.8F);
|
|
|
|
}
|
2019-11-04 19:08:49 +01:00
|
|
|
|
2020-01-28 18:08:56 +01:00
|
|
|
PacketHandler.sendToAllAround(worldIn, pos, 32, new PacketParticles((float) living.getPosX(), (float) living.getPosY(), (float) living.getPosZ(), PacketParticles.Type.SHOCKWAVE_CREATOR));
|
2018-11-06 19:02:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2020-01-29 19:04:33 +01:00
|
|
|
public void render(ItemStack stack, PlayerEntity player, RenderType type, MatrixStack matrices, IRenderTypeBuffer buffer, int packedLight, boolean isHolding) {
|
2018-11-21 20:36:55 +01:00
|
|
|
if (type == RenderType.BODY && !isHolding) {
|
2019-10-20 22:30:49 +02:00
|
|
|
boolean armor = !player.inventory.armorInventory.get(EquipmentSlotType.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);
|
|
|
|
matrices.rotate(Vector3f.XP.rotationDegrees(180));
|
|
|
|
Minecraft.getInstance().getItemRenderer().renderItem(stack, ItemCameraTransforms.TransformType.GROUND, packedLight, OverlayTexture.DEFAULT_LIGHT, matrices, buffer);
|
2018-11-06 19:02:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|