package com.yolp900.itsjustacharm.common.tileEntities; import com.yolp900.itsjustacharm.api.ItsJustaCharmAPI; import com.yolp900.itsjustacharm.common.integration.waila.IWailaBodyProvider; import com.yolp900.itsjustacharm.common.network.MessageParticle; import com.yolp900.itsjustacharm.common.network.NetworkHandler; import com.yolp900.itsjustacharm.config.ModConfigs; import com.yolp900.itsjustacharm.reference.LibModIntegrations; import com.yolp900.itsjustacharm.reference.LibParticles; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.ITickable; import net.minecraft.util.math.AxisAlignedBB; import java.util.List; import java.util.Random; public class TileEntityLevitator extends ModTileEntity implements ITickable, IWailaBodyProvider { private Random random = new Random(); @Override public void update() { if (worldObj == null) return; if (isPowered()) { List<Entity> entities = worldObj.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(getPos().getX(), getPos().getY() + 1, getPos().getZ(), getPos().getX() + 1, getPos().getY() + 1 + ModConfigs.LevitatorRange.getValueF(), getPos().getZ() + 1)); if (entities.size() > 0) { for (Entity entity : entities) { if (entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) entity; if (player.isSneaking()) { if (player.motionY > 0) { player.motionY -= 0.1; } else { if (player.motionY < -0.35) { player.motionY = -0.35; } } entity.fallDistance = 0; } else { if (!player.capabilities.isCreativeMode) { if (player.motionY < 0.35) { player.motionY += 0.1; } entity.fallDistance = 0; } } } else if (entity.canBePushed()) { if (!ItsJustaCharmAPI.isEntityBlacklistedFromLevitator(entity.getClass())) { if (entity.motionY < 0.35) { entity.motionY += 0.1; } } } else if (entity instanceof EntityItem) { if (!ItsJustaCharmAPI.isItemStackBlacklistedFromLevitator(((EntityItem) entity).getEntityItem())) { if (entity.motionY < 0.35) { entity.motionY += 0.1; } } } if (entity.motionY > 0) { if (random.nextDouble() < 0.75) NetworkHandler.sendToAllAround(new MessageParticle(LibParticles.Levitate, entity.posX - (entity.width / 2) + (random.nextDouble() * entity.width), entity.posY, entity.posZ - (entity.width / 2) + (random.nextDouble() * entity.width), random.nextDouble() + 0.25, (random.nextDouble() / 4) + 0.5, (random.nextDouble() / 4) + 0.5, (random.nextDouble() / 4) + 0.5, 0, -entity.motionY, 0), worldObj.provider.getDimension(), entity.posX, entity.posY, entity.posZ, 16); } } } double i = random.nextDouble(); if (i < 0.15) { NetworkHandler.sendToAllAround(new MessageParticle(LibParticles.Levitator, getPos().getX() + random.nextDouble(), getPos().getY() + 1.01, getPos().getZ() + random.nextDouble(), random.nextDouble() + 0.25, (random.nextDouble() / 4) + 0.5, (random.nextDouble() / 4) + 0.5, (random.nextDouble() / 4) + 0.5, 0, 0.1, 0), worldObj.provider.getDimension(), getPos().getX() + 0.5, getPos().getY() + 1.05, getPos().getZ() + 0.5, 16); } } } public boolean isPowered() { return worldObj.isBlockPowered(getPos()) || worldObj.isBlockPowered(getPos().up()) || worldObj.isBlockIndirectlyGettingPowered(getPos()) != 0; } @Override public LibModIntegrations.Waila.Tooltips getWailaBody(ItemStack stack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { if (isPowered()) { return LibModIntegrations.Waila.Tooltips.Active; } else { return LibModIntegrations.Waila.Tooltips.Inactive; } } }