2018-11-06 19:02:56 +01:00
|
|
|
package de.ellpeck.naturesaura.items;
|
|
|
|
|
|
|
|
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;
|
2018-12-01 18:56:05 +01:00
|
|
|
import de.ellpeck.naturesaura.items.tools.ItemArmorNA;
|
2018-11-06 19:02:56 +01:00
|
|
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
|
|
|
import de.ellpeck.naturesaura.packet.PacketParticles;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.SoundType;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.Gui;
|
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
|
|
|
import net.minecraft.client.renderer.RenderHelper;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2018-12-01 18:56:05 +01:00
|
|
|
import net.minecraft.init.MobEffects;
|
2018-11-06 19:02:56 +01:00
|
|
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2018-12-01 18:56:05 +01:00
|
|
|
import net.minecraft.potion.PotionEffect;
|
2018-11-06 19:02:56 +01:00
|
|
|
import net.minecraft.util.DamageSource;
|
|
|
|
import net.minecraft.util.EnumParticleTypes;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraft.util.SoundCategory;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.WorldServer;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem {
|
|
|
|
|
2018-11-20 11:48:45 +01:00
|
|
|
private static final ResourceLocation RES_WORN = new ResourceLocation(NaturesAura.MOD_ID, "textures/items/shockwave_creator_player.png");
|
2018-11-06 19:02:56 +01:00
|
|
|
|
|
|
|
public ItemShockwaveCreator() {
|
|
|
|
super("shockwave_creator");
|
|
|
|
this.setMaxStackSize(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
|
|
|
|
if (worldIn.isRemote || !(entityIn instanceof EntityLivingBase))
|
|
|
|
return;
|
|
|
|
EntityLivingBase living = (EntityLivingBase) entityIn;
|
|
|
|
if (!living.onGround) {
|
|
|
|
if (!stack.hasTagCompound())
|
|
|
|
stack.setTagCompound(new NBTTagCompound());
|
|
|
|
NBTTagCompound compound = stack.getTagCompound();
|
|
|
|
if (compound.getBoolean("air"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
compound.setBoolean("air", true);
|
|
|
|
compound.setDouble("x", living.posX);
|
|
|
|
compound.setDouble("y", living.posY);
|
|
|
|
compound.setDouble("z", living.posZ);
|
|
|
|
} else {
|
|
|
|
if (!stack.hasTagCompound())
|
|
|
|
return;
|
|
|
|
NBTTagCompound compound = stack.getTagCompound();
|
|
|
|
if (!compound.getBoolean("air"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
compound.setBoolean("air", false);
|
|
|
|
|
|
|
|
if (!living.isSneaking())
|
|
|
|
return;
|
|
|
|
if (living.getDistanceSq(compound.getDouble("x"), compound.getDouble("y"), compound.getDouble("z")) > 0.75F)
|
|
|
|
return;
|
2019-01-29 11:46:38 +01:00
|
|
|
if (living instanceof EntityPlayer && !NaturesAuraAPI.instance().extractAuraFromPlayer((EntityPlayer) living, 1000, false))
|
2018-11-06 19:02:56 +01:00
|
|
|
return;
|
|
|
|
|
2018-11-06 23:08:42 +01:00
|
|
|
DamageSource source;
|
|
|
|
if (living instanceof EntityPlayer)
|
|
|
|
source = DamageSource.causePlayerDamage((EntityPlayer) living);
|
|
|
|
else
|
|
|
|
source = DamageSource.MAGIC;
|
2018-12-01 18:56:05 +01:00
|
|
|
boolean infusedSet = ItemArmorNA.isFullSetEquipped(living, 0);
|
2018-11-06 23:08:42 +01:00
|
|
|
|
2018-11-06 19:02:56 +01:00
|
|
|
int range = 5;
|
2018-11-17 22:04:46 +01:00
|
|
|
List<EntityLivingBase> mobs = worldIn.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(
|
2018-11-06 19:02:56 +01:00
|
|
|
living.posX - range, living.posY - 0.5, living.posZ - range,
|
|
|
|
living.posX + range, living.posY + 0.5, living.posZ + range));
|
2018-11-17 22:04:46 +01:00
|
|
|
for (EntityLivingBase mob : mobs) {
|
2018-11-06 19:02:56 +01:00
|
|
|
if (mob.isDead || mob == living)
|
|
|
|
continue;
|
|
|
|
if (living.getDistanceSq(mob) > range * range)
|
|
|
|
continue;
|
2019-01-29 11:46:38 +01:00
|
|
|
if (living instanceof EntityPlayer && !NaturesAuraAPI.instance().extractAuraFromPlayer((EntityPlayer) 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)
|
|
|
|
mob.addPotionEffect(new PotionEffect(MobEffects.WITHER, 120));
|
2018-11-06 19:02:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BlockPos pos = living.getPosition();
|
|
|
|
BlockPos down = pos.down();
|
|
|
|
IBlockState downState = worldIn.getBlockState(down);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
if (worldIn instanceof WorldServer)
|
|
|
|
((WorldServer) worldIn).spawnParticle(EnumParticleTypes.BLOCK_DUST,
|
|
|
|
living.posX, living.posY + 0.01F, living.posZ,
|
|
|
|
15, 0F, 0F, 0F, 0.15F, Block.getStateId(downState));
|
|
|
|
PacketHandler.sendToAllAround(worldIn, pos, 32,
|
|
|
|
new PacketParticles((float) living.posX, (float) living.posY, (float) living.posZ, 11));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2018-11-21 20:36:55 +01:00
|
|
|
public void render(ItemStack stack, EntityPlayer player, RenderType type, boolean isHolding) {
|
|
|
|
if (type == RenderType.BODY && !isHolding) {
|
2018-11-06 19:02:56 +01:00
|
|
|
boolean armor = !player.inventory.armorInventory.get(EntityEquipmentSlot.CHEST.getIndex()).isEmpty();
|
2018-11-07 23:57:47 +01:00
|
|
|
GlStateManager.translate(-0.1675F, -0.05F, armor ? -0.195F : -0.1475F);
|
2018-11-06 19:02:56 +01:00
|
|
|
GlStateManager.scale(0.021F, 0.021F, 0.021F);
|
|
|
|
|
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
GlStateManager.disableLighting();
|
|
|
|
GlStateManager.pushAttrib();
|
|
|
|
RenderHelper.enableStandardItemLighting();
|
|
|
|
Minecraft.getMinecraft().getTextureManager().bindTexture(RES_WORN);
|
|
|
|
Gui.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, 16, 16, 16, 16);
|
|
|
|
RenderHelper.disableStandardItemLighting();
|
|
|
|
GlStateManager.popAttrib();
|
|
|
|
GlStateManager.enableLighting();
|
|
|
|
GlStateManager.popMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|